Skip to content

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

Open
@mitchgrout

Description

@mitchgrout

👓 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions