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

Cucumber v4 incompatibility #825

Closed
orien opened this issue Jun 23, 2020 · 8 comments
Closed

Cucumber v4 incompatibility #825

orien opened this issue Jun 23, 2020 · 8 comments

Comments

@orien
Copy link

orien commented Jun 23, 2020

There seems to be an incompatibility with the VCR.cucumber_tags functionality and the newly released Cucumber version 4.

See the following backtrace detailing the error I am experiencing.

6: from /usr/local/bundle/ruby/gems/2.6.0/gems/cucumber-core-7.0.0/lib/cucumber/core/test/step.rb:35:in `execute'
5: from /usr/local/bundle/ruby/gems/2.6.0/gems/cucumber-core-7.0.0/lib/cucumber/core/test/action.rb:24:in `execute'
4: from /usr/local/bundle/ruby/gems/2.6.0/gems/cucumber-4.0.1/lib/cucumber/runtime/before_hooks.rb:25:in `block (2 levels) in before_hooks'
3: from /usr/local/bundle/ruby/gems/2.6.0/gems/cucumber-4.0.1/lib/cucumber/glue/hook.rb:22:in `invoke'
2: from /usr/local/bundle/ruby/gems/2.6.0/gems/cucumber-4.0.1/lib/cucumber/glue/invoke_in_world.rb:26:in `cucumber_instance_exec_in'
1: from /usr/local/bundle/ruby/gems/2.6.0/gems/vcr-6.0.0/lib/vcr/test_frameworks/cucumber.rb:51:in `Before'
/usr/local/bundle/ruby/2.6.0/delegate.rb:87:in `method_missing': undefined method `feature' for #<Cucumber::RunningTestCase::TestCase:0x00007ff5877dee78> (NoMethodError)

https://github.com/vcr/vcr/blob/v6.0.0/lib/vcr/test_frameworks/cucumber.rb#L51

VCR 6.0.0
Ruby 2.6.6
Gem 3.1.4
Rails 5.2.4.3
Cucumber 4.0.1

@swatosh
Copy link

swatosh commented Jul 9, 2020

We're running into this problem as well when using use_scenario_name: true. Seems quite similar to (the ancient) #288.

@orien
Copy link
Author

orien commented Jul 10, 2020

It seems the ability to obtain the feature name in before and after hooks has been removed in Cucumber v4. An issue has been raised in cucumber/cucumber-ruby#1432 to discuss the problem.

@thedeeno
Copy link

Monkey-patch work-around while the issue is being discussed.

# HACK: this method was available in cucumber 3.1 but not cucumber 4 and VCR relies on it to
# generate cassette names.
module Cucumber
  module RunningTestCase
    class TestCase < SimpleDelegator

      def feature
        string = File.read(location.file)
        document = ::Gherkin::Parser.new.parse(string)
        document[:feature]
      end

    end
  end
end

@camthompson
Copy link

If anyone else is still dealing with this, this is what we're using now after a recent Cucumber/Gherkin change broke the above fix:

module Cucumber
  module RunningTestCase
    class TestCase
      def feature
        ::Gherkin::Parser.new.parse(File.read(location.file)).feature
      end
    end
  end
end

@luke-hill
Copy link

Do you "need" the feature name, or would just the location / something else wholly unique be good enough?

@mattwynne
Copy link

It seems like using the location.file is a better idea, since it's guaranteed to be unique.

@andrehjr
Copy link
Contributor

Also ran into this issue and ended up using master. As this is already fixed in master by #845 I'll wait for the next release.

The monkeypatch also works if you can't use vcr's master branch.

@olleolleolle
Copy link
Member

Thanks for the notes, 6.1.0 contains the fix. Closing!

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

8 participants