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

gherkin: namespace conflict between old and new gems #1063

Closed
enkessler opened this issue Jun 16, 2020 · 9 comments
Closed

gherkin: namespace conflict between old and new gems #1063

enkessler opened this issue Jun 16, 2020 · 9 comments
Labels
⌛ stale Will soon be closed by stalebot unless there is activity library: gherkin

Comments

@enkessler
Copy link

enkessler commented Jun 16, 2020

Summary

Both the gherkin gem and the cucumber-gherkin gem that replaced it use the same module namespace (e.g. Gherkin) and so they can conflict if they are both loaded.

According to all conventions and tools, they are separate gems and so will not conflict with each other but, because they effectively are the same gem from a code standpoint, they cannot co-exist in the same runtime without stepping on each other's toes. This is causing some Dependency Hell for projects that end up transitively needing both gems because Bundler (or anything else) doesn't know that they are the same library.

In my case, I am now limited to using Cucumber 2.2.0 in several of my projects. Even 3.x Cucumber has been 'broken' because of the namespace issue. Cucumber 3.x doesn't use cucumber-gherkin according to its gem specification but Ruby will still end up in that code at runtime, even though it should end up in code from the gherkin gem, which is what my project explicitly declares as a dependency and intends to be using.

Expected Behavior

gherkin and cucumber-gherkin would either use their respective conventional namespaces of Gherkin and CucumberGherkin or be prevented from co-exsisting in a dependency tree, thus preventing any code conflicts.

Current Behavior

Both gherkin and cucumber-gherkin use the Gherkin namespace and there are not version limits in place in the cucumber tech stack to prevent various support libraries from transitively pulling in both gems. cucumber 2.2.0 remains safe to use due to (I'm guessing) it's usage of gherkin3 instead of gherkin and gherkin3 follows convention by using the Gherkin3 namespace, thus avoiding conflicts with cucumber-gherkin.

Possible Solution

From what I can tell, the namespace overlap is intentional, so as to make cucumber-gherkin a 'drop-in' replacement of gherkin. That rules out fixing the namespace overlap, Therefore, it will probably have to be handled by updating all of the various support libraries to have better version limits.

Steps to Reproduce (for bugs)

Here is cucumber 3.x ending up in cucumber-gherkin

wrong number of arguments (given 0, expected 1) (ArgumentError)
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/ast_builder.rb:6:in `initialize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/parser.rb:59:in `new'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/parser.rb:59:in `initialize'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:23:in `new'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:23:in `document'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:30:in `block in parse'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `each'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in `parse'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:21:in `compile'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-3.2.0/lib/cucumber/runtime.rb:75:in `run!'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-3.2.0/lib/cucumber/cli/main.rb:34:in `execute!'
C:/Ruby23/lib/ruby/gems/2.3.0/gems/cucumber-3.2.0/bin/cucumber:9:in `<top (required)>'
C:/Ruby23/bin/cucumber:23:in `load'
C:/Ruby23/bin/cucumber:23:in `<main>'
Coverage report generated for cucumber_tests, rspec_tests to C:/projects/cuke-linter/coverage. 536 / 536 LOC (100.0%) covered.
rake aborted!
Cucumber tests encountered problems!

and here is cucumber 4.x ending up in gherkin

wrong number of arguments (given 1, expected 0) (ArgumentError)
/home/travis/.rvm/gems/ruby-2.4.0/gems/gherkin-5.1.0/lib/gherkin/ast_builder.rb:5:in `initialize'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/stream/parser_message_stream.rb:15:in `new'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/stream/parser_message_stream.rb:15:in `initialize'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-gherkin-13.0.0/lib/gherkin.rb:19:in `new'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-gherkin-13.0.0/lib/gherkin.rb:19:in `from_sources'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-gherkin-13.0.0/lib/gherkin.rb:27:in `from_source'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-core-7.0.0/lib/cucumber/core/gherkin/parser.rb:20:in `document'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-core-7.0.0/lib/cucumber/core.rb:33:in `block in parse'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-core-7.0.0/lib/cucumber/core.rb:32:in `each'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-core-7.0.0/lib/cucumber/core.rb:32:in `parse'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-core-7.0.0/lib/cucumber/core.rb:24:in `compile'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-4.0.0/lib/cucumber/runtime.rb:78:in `run!'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-4.0.0/lib/cucumber/cli/main.rb:29:in `execute!'
/home/travis/.rvm/gems/ruby-2.4.0/gems/cucumber-4.0.0/bin/cucumber:9:in `<top (required)>'
/home/travis/.rvm/gems/ruby-2.4.0/bin/cucumber:23:in `load'
/home/travis/.rvm/gems/ruby-2.4.0/bin/cucumber:23:in `<main>'
/home/travis/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:24:in `eval'
/home/travis/.rvm/gems/ruby-2.4.0/bin/ruby_executable_hooks:24:in `<main>'

Context & Motivation

I tried upgrading to the newest version of cucumber and ended up having to immediately downgrade so hard that I had to go back in time 4 years to make things work again. I am limited to using cucumber 2.2.0 in all of my projects* and, if I ever need to start using the Rule keyword or any of the newer syntax, Cucumber will become entirely unusable for me. Given that my primary project models Gherkin syntax, that will become an issue sooner rather than later.

*Even the most recent version of my project that only uses cucumber 4.x and cucumber-gherkin won't work because cucumber-gherkin doesn't work on JRuby 9.1.7 (#1064).

Your Environment

  • Version used: varies
  • Operating System and version: the big 3 (Windows, Linux, and OSX)
  • Link to your project: cuke_modeler and pretty much every gem project that relies on it. Take your pick. If you choose cuke_linter, you'll get a twofer and encounter gherkin: Encoding issues on Windows #1065.
@enkessler
Copy link
Author

Anything?

@enkessler
Copy link
Author

Good news! This is no longer a necessarily a blocking issue for my project. I am able to model Rules and test my gem as long as I don't use rules in my tests themselves.

@stale
Copy link

stale bot commented Oct 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Oct 11, 2020
@enkessler
Copy link
Author

It is a problem that resurfaces on a regular basis, including within the past week. I'm going to say that that is still counts as 'active'

@stale stale bot removed the ⌛ stale Will soon be closed by stalebot unless there is activity label Oct 12, 2020
@enkessler
Copy link
Author

Unfortunately, I'm not sure that there is a way to solve this problem that doesn't boil down to "upgrade all of your dependencies and stop using the old stuff". Even with added version restrictions on the newer libraries, users would still have to update those libraries to get the fixes. An once they've upgraded to get then they're already no longer using the old stuff and so the problem is solved anyway.

So...I think that this kind of problem could only have been avoided by deciding against the design choices that led to it in the first place. :/

A fix for the issue being practically moot, this issue can be closed. I'll just keep linking to it for reference as people encounter problems until the community as a whole has moved on to the newer libraries.

@stale
Copy link

stale bot commented Dec 15, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in a week if no further activity occurs.

@stale stale bot added the ⌛ stale Will soon be closed by stalebot unless there is activity label Dec 15, 2020
@stale
Copy link

stale bot commented Dec 25, 2020

This issue has been automatically closed because of inactivity. You can support the Cucumber core team on opencollective.

@stale stale bot closed this as completed Dec 25, 2020
@rohalravi
Copy link

Can anyone please help me, I am also getting the same issue , I am using these gems
gem 'gherkin'
gem 'cucumber', '> 3.1.2'
gem 'cuke_modeler', '
> 3.3.0'

Error:
wrong number of arguments (given 0, expected 1) (ArgumentError)
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/ast_builder.rb:6:in initialize' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/parser.rb:59:in new'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-gherkin-13.0.0/lib/gherkin/parser.rb:59:in initialize' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:23:in new'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core/gherkin/parser.rb:23:in document' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:30:in block in parse'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in each' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:29:in parse'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-core-3.2.1/lib/cucumber/core.rb:21:in compile' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/lib/cucumber/runtime.rb:75:in run!'
C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/lib/cucumber/cli/main.rb:34:in execute!' C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/cucumber-3.1.2/bin/cucumber:9:in <top (required)>'
C:/Ruby25-x64/bin/cucumber:23:in load' C:/Ruby25-x64/bin/cucumber:23:in

'

I tried

Keep the default argument

def initialize(ast_builder = AstBuilder.new(Cucumber::Messages::IdGenerator::UUID.new))

@luke-hill
Copy link
Contributor

luke-hill commented Feb 9, 2023

You are likely using the conflicting gems for gherkin. Ideally ensure you don't install gherkin manually (Although it is possible).

There is a cucumber-gherkin gem which has replaced gherkin

As you are using an old version of cucumber (v3), I'd also advise you to upgrade that if possible. As we don't support legacy versions of the software currently.

If you have an issue still after this, please open a new issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⌛ stale Will soon be closed by stalebot unless there is activity library: gherkin
Projects
None yet
Development

No branches or pull requests

4 participants