Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable#symbolic_hashes followed by DataTable#hashes produces undefined method: 'tr' #1199

Closed
Ben-Behar opened this issue Sep 15, 2017 · 3 comments
Labels
🐛 bug Defect / Bug 🚦 needs tests Needs tests

Comments

@Ben-Behar
Copy link
Contributor

Summary

When using a gherkin step with a DataTable, if in my step definition I use table.symbolic_hashes and then later use table.hashes, then I am presented with the error undefined method 'tr' for :my_key:Symbol.

Expected Behavior

I should be able to access my table as a list of symbolic hashes as needed without changing any of the state of the DataTable. After this, I should be able to access my table as a list of string hashes without issue.

Current Behavior

With a feature file:

Feature: Testificate
  Scenario: Testify
    When test
      | my_key   |
      | my_value |

And a step definition file:

When('test') do |table|
  table.symbolic_hashes
  table.hashes
end

I will receive the following error during execution:

Scenario: Testify
    When test      
      | my_key   |
      | my_value |
      undefined method `tr' for :my_key:Symbol
      Did you mean?  try (NoMethodError)
      ./features/step_definitions/testify_steps.rb:139:in `/^test$/'
      ./features/testben.feature:6:in `When test'

Possible Solution

In the following method:

def symbolic_hashes
  @header_conversion_proc = lambda { |h| symbolize_key(h) }
  @symbolic_hashes ||= build_hashes
end

Do not set the @header_conversion_proc, but instead pass an optional block through the method build_hashes that will define the appropriate strategy for header conversion.

Context & Motivation

I ran into the issue when trying to minimize use of string hashes from the testing framework at my company.

Your Environment

  • Version used: 2.4.0
  • Operating System and version: macOS Sierra 10.12.6
  • Link to your project: N/A
@danascheider
Copy link
Contributor

Thanks for reporting, @Ben-Behar! Is this something you'd be able to put together a pull request for? If so, we'd be happy to help you figure out the best implementation, etc.

@Ben-Behar
Copy link
Contributor Author

Sure, I'll give it a shot. I will definitely need some hand holding though.

danascheider added a commit that referenced this issue Sep 21, 2017
…ange-in-symbolic-hashes

Fix for issue: #1199: Changed DataTable#symbolic_hashes to not change the state of the table
@lock
Copy link

lock bot commented Oct 24, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🐛 bug Defect / Bug 🚦 needs tests Needs tests
Projects
None yet
Development

No branches or pull requests

2 participants