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

Fix for bundler path issue in Cucumber Rake task #386 #388

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/cucumber/rake/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def gem_available_new_rubygems?(gemname)

def cmd
if use_bundler
bundle_cmd = Gem.default_exec_format % 'bundle'
bundle_cmd = File.basename( Gem.bin_path('bundler', 'bundle') )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please extract this code into separate method. To remove code duplication and make this code more readable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've extracted the duplicate as ForkedCucumberRunner#bundle_cmd method. d08dc89

[ Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'cucumber', @cucumber_opts,
@feature_files ].flatten
else
Expand All @@ -115,7 +115,8 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files, rcov_o

def cmd
if use_bundler
[Cucumber::RUBY_BINARY, '-S', 'bundle', 'exec', 'rcov', @rcov_opts,
bundle_cmd = File.basename( Gem.bin_path('bundler', 'bundle') )
[Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'rcov', @rcov_opts,
quoted_binary(@cucumber_bin), '--', @cucumber_opts, @feature_files].flatten
else
[Cucumber::RUBY_BINARY, '-I', load_path(@libs), '-S', 'rcov', @rcov_opts,
Expand Down
6 changes: 3 additions & 3 deletions spec/cucumber/rake/forked_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ module Rake
end

it "uses bundle exec to find cucumber and libraries" do
bundle_cmd = Gem.default_exec_format % 'bundle'
Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/bundle')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to stub this method?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stubbed this method to make these spec examples to cover 2 types of test cases.

  • One is a case where bundle is not suffixed or prefixed,
    • "uses bundle exec to find cucumber and libraries" example
  • and another is a case where bundle is suffixed and/or prefixed.
    • "obeys program suffix for bundler" example

If it directly calls the Gem.bin_path, it will return the path of bundler on the user's gem environment where this spec was run. And without a stub, it will not be able to control which flavor of the bundle path is returned.


subject.cmd.should == [Cucumber::RUBY_BINARY,
'-S',
bundle_cmd,
'bundle',
'exec',
'cucumber',
'--cuke-option'] + feature_files
end

it "obeys program suffix for bundler" do
Gem::ConfigMap.stub(:[]).with(:ruby_install_name).and_return('XrubyY')
Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/XbundleY')

subject.cmd.should == [Cucumber::RUBY_BINARY,
'-S',
Expand Down
15 changes: 15 additions & 0 deletions spec/cucumber/rake/rcov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module Rake
end

it "uses bundle exec to find cucumber and libraries" do
Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/bundle')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question: why do we have to stub the method here?

subject.cmd.should == [Cucumber::RUBY_BINARY,
'-S',
'bundle',
Expand All @@ -37,6 +38,20 @@ module Rake
'--cuke-option'] + feature_files
end

it "obeys program suffix for bundler" do
Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/XbundleY')

subject.cmd.should == [Cucumber::RUBY_BINARY,
'-S',
'XbundleY',
'exec',
'rcov',
'--rcov-option',
"\"#{Cucumber::BINARY }\"",
'--',
'--cuke-option'] + feature_files
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you, please, describe the purpose of the spec?
Have you seen situations when Gem.bin_path() returns something with prefix and suffix?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spec is a derivative of spec added with the original issue #324, which introduced the use of Gem.default_exec_format % 'bundle'.
I personally have never encountered a situation, where bundle command is suffixed or prefixed,
but since #324 was created, I assume there exist an environment, where bundle command is suffixed or prefixed.
Under such environment, I am expecting Gem.bin_path to return a path with prefix and/or suffix.

end

context "when running without bundler" do
Expand Down