Skip to content

NoMethodError when method(sym) used for ParameterType.transformer #1788

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

Open
mitchgrout opened this issue May 27, 2025 · 2 comments
Open

NoMethodError when method(sym) used for ParameterType.transformer #1788

mitchgrout opened this issue May 27, 2025 · 2 comments

Comments

@mitchgrout
Copy link

mitchgrout commented May 27, 2025

👓 What did you see?

$ cucumber 
undefined method '[]' for nil (NoMethodError)
/usr/local/bundle/gems/cucumber-9.2.1/lib/cucumber/glue/registry_and_more.rb:211:in 'Cucumber::Glue::RegistryAndMore#parameter_type_envelope'
/usr/local/bundle/gems/cucumber-9.2.1/lib/cucumber/glue/registry_and_more.rb:83:in 'Cucumber::Glue::RegistryAndMore#define_parameter_type'
/usr/local/bundle/gems/cucumber-9.2.1/lib/cucumber/glue/dsl.rb:27:in 'Cucumber::Glue::Dsl.define_parameter_type'
/usr/local/bundle/gems/cucumber-9.2.1/lib/cucumber/glue/dsl.rb:103:in 'Cucumber::Glue::Dsl#ParameterType'
/tmp/tmp.yvPAzY6fzD/features/support/env.rb:3:in '<top (required)>'
...

✅ What did you expect to see?

No uncaught errors should have been raised/propagated to the top-level

📦 Which tool/library version are you using?

ruby (3.4.4)
cucumber (9.2.1)
cucumber-ci-environment (10.0.1)
cucumber-core (13.0.3)
cucumber-cucumber-expressions (17.1.0)
cucumber-gherkin (27.0.0)
cucumber-html-formatter (21.9.0)
cucumber-messages (22.0.0)
cucumber-tag-expressions (6.1.2)

🔬 How could we reproduce it?

Feature: Reproduction for issue #1788
  Scenario: Using a top-level method() to populate the transformer of a ParameterType
    Given a file named "features/test.feature" with:
      """
      Feature: Example
        Scenario: Sample
          Given a path named "example"
      """
    And a file named "features/support/env.rb" with:
      """
      require "pathname"
      ParameterType(
        name:        "path",
        regexp:      /"([^"]*)"/,
        transformer: method(:Pathname),
      )
      """
    And a file named "features/step_definitions/all.rb" with:
      """
      Given("a path named {path}") do |actual|
        expected = Pathname("example")
        fail [actual, expected].inspect unless actual == expected
      end
      """
    When I run `cucumber -q`
    Then it should pass with:
      """
      Feature: Reprod
      
        Scenario: Example
          Given a path named "example"
      
      1 scenario (1 passed)
      1 step (1 passed)
      """

📚 Any additional context?

If you replace the transformer value with a block/lambda/proc:

transformer: ->(x) { Pathname(x) },

...then the issue is alleviated.

This issue does not seem to affect cucumber-8.0 + ruby-2.6

@luke-hill
Copy link
Contributor

Thanks for this. Looks fairly simple.

Just for clarity again, this won't be fixed for v10, as this has been already quite delayed. Once v10 is out I promise I will get to these.

@mitchgrout
Copy link
Author

Thanks for this. Looks fairly simple.

Just for clarity again, this won't be fixed for v10, as this has been already quite delayed. Once v10 is out I promise I will get to these.

No worries! Just posting issues as I find them, most of the things I tend to find have very straight-forward workarounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants