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 Rake task creates invalid path to bundle command #386

Closed
y-higuchi opened this issue Mar 5, 2013 · 8 comments
Closed

Cucumber Rake task creates invalid path to bundle command #386

y-higuchi opened this issue Mar 5, 2013 · 8 comments
Assignees
Milestone

Comments

@y-higuchi
Copy link

Using cucumber rake task with bundler, fails with invalid bundle command path on Ubuntu.

This problem seems to be introduced in 1.2.2 as a side-effect of #324.

Steps to reproduce the problem

Environment

  • Ubuntu 12.04
  • ruby and gem installed through apt-get
    • Not using rvm or other ruby environment manager.
  • bundler installed by gem install bundler

Gemfile

gem "cucumber", "1.2.2"
gem "rake"

Rakefile

require "cucumber/rake/task"
Cucumber::Rake::Task.new do | t |
  t.cucumber_opts = "."
end
$ bundle exec rake cucumber
/usr/bin/ruby1.8 -S bundle1.8 exec cucumber .
/usr/bin/ruby1.8: No such file or directory -- bundle1.8 (LoadError)
rake aborted!
Command failed with status (1): [/usr/bin/ruby1.8 -S bundle1.8 exec cucumbe...]
/var/lib/gems/1.8/gems/cucumber-1.2.2/lib/cucumber/rake/task.rb:105:in `run'
/var/lib/gems/1.8/gems/cucumber-1.2.2/lib/cucumber/rake/task.rb:194:in `define_task'
Tasks: TOP => cucumber
(See full trace by running task with --trace)

Note that bundle exec rake cucumber runs without problem when "1.2.1" is specified as the cucumber version in the Gemfile

Cause of the problem

When ruby and gem is installed on a Ubuntu environment through apt-get,
binaries built with version suffix is installed,
but symbolic link with plain filename without suffix is also introduced with alternatives mechanism.

$ ls -l /usr/bin/ruby /etc/alternatives/ruby /usr/bin/gem /etc/alternatives/gem
lrwxrwxrwx 1 root root 15 Oct 31 13:08 /etc/alternatives/gem -> /usr/bin/gem1.8
lrwxrwxrwx 1 root root 16 Oct 30 11:09 /etc/alternatives/ruby -> /usr/bin/ruby1.8
lrwxrwxrwx 1 root root 21 Oct 31 13:08 /usr/bin/gem -> /etc/alternatives/gem
lrwxrwxrwx 1 root root 22 Oct 30 11:09 /usr/bin/ruby -> /etc/alternatives/ruby

When I gem install bundler on above environment,
bundle command will be installed without any suffix.

Maybe because ruby or gem command with no suffix is on PATH?

$ ls -l `which bundle`
-rwxr-xr-x 1 root root 378 Mar  4 11:02 /usr/local/bin/bundle

As a result, environment where bundle command without suffix is used on ruby1.8 and gem1.8 binary is created.
When cucumber try to determine the bundle command name by Gem.default_exec_format % 'bundle',
it creates a command name bundle1.8, which actually does not exist.

Notes

I am not familiar with gem's best practice, so it may be true that this is not a cucumber problem, but a problem with bundler or gem, where they should have installed bundle with 1.8 suffix under such environment.

I haven't checked in details, but there seems to be a way to get a absolute path to bundle command through Gem, so it may be possible to solve the problem on cucumber side using method in Gem module.

Gem.bin_path('bundler', 'bundle')
@mattwynne
Copy link
Member

Thanks for the thorough report. @os97673 do you want to look into this, since you're on Ubuntu?

@ghost ghost assigned os97673 Mar 5, 2013
@os97673
Copy link
Member

os97673 commented Mar 5, 2013

@mattwynne sure.

@y-higuchi
Copy link
Author

I wrote a patch I mentioned at the end of Notes section, about using Gem.bin_path to obtain bundle_cmd.
4d3fc83, Branch compare view

This patch worked for my environment where bundle and ruby1.8 co-exists.
I've also tested this patch on rvm enabled environment where both bundle and ruby is not suffixed, and had no problem.

I'm not sure how to create an environment that the original issue #324 was trying to support (both bundleX.Y and rubyX.Y suffixed), so I haven't been able to test on such environment.

This patch also changes the content of bundle_cmd variable from only the bundle command name to
absolute path to bundle command.
I could have passed bundle_cmd variable through File.basename to extract only the command name,
but I couldn't think of a reason to do so when an absolute path is available, so I left them as is.
If it is more appropriate for the bundle_cmd variable to hold only the command name,
I can add a commit to fix it and send a pull request.

@os97673
Copy link
Member

os97673 commented Mar 5, 2013

@y-higuchi imho this not a cucumber or rubygems problem. I'd say that this is a problem of Ubuntu's packages name.
Though I agree that it would be nice to fix it and your suggestion looks promising, but I'm not sure if this will work on Windows :( Do you have Windows to test the code? Also it would be nice to have a test for the change.

@y-higuchi
Copy link
Author

@os97673 I don't have Ruby+Windows environment, but I have Windows environment so I'll give it a try if I can setup a test environment when I have access to Windows environment.

Also it would be nice to have a test for the change.

About the "change" in the above comment.
Are you talking about the change I already have in my branch,
or about new change which is likely to be needed to support Windows environment?

If it is the former case, modification to spec/cucumber/rake/forked_spec.rb was meant to be the test for the change. It may not be a perfect test case, since it uses a mock for Gem.bin_path so it is sort of like a tautalogy, but I thought that is the best I can do without modifying the actual user Gem environment.

If it is the latter case, I'll try to do that when I come up with an additional patch for Windows.

@y-higuchi
Copy link
Author

I've tested the patch on Windows environment, and it worked.

But while creating the Ruby environment on Windows, handling a path containing space can be troublesome,
So I've added File.basename() call to extract only the basename portion as bundle_cmd to avoid command line parsing problem.
Branch compare view

About adding tests for changes,
I thought about adding backspace separated path version of rspec tests if that's necessary, but
it turned out that Gem.bin_path returns a slash separated path even on Windows, so I haven't added any test specific for Windows environment.
I'll send a Pull Request shortly, so please add a comment there if I should add other kind of tests.

@os97673
Copy link
Member

os97673 commented Mar 6, 2013

Thank you for the PR, let's move our discussion there

@lock
Copy link

lock bot commented Oct 25, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Oct 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants