From 4d3fc8320d6992c2fef28b8b8317215bd07e6039 Mon Sep 17 00:00:00 2001 From: HIGUCHI Yuta Date: Tue, 5 Mar 2013 15:47:20 +0900 Subject: [PATCH 1/4] Use Gem.bin_path to obtain `bundle` command name. --- lib/cucumber/rake/task.rb | 5 +++-- spec/cucumber/rake/forked_spec.rb | 8 ++++---- spec/cucumber/rake/rcov_spec.rb | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/cucumber/rake/task.rb b/lib/cucumber/rake/task.rb index c2f35650ea..b6c745d112 100644 --- a/lib/cucumber/rake/task.rb +++ b/lib/cucumber/rake/task.rb @@ -92,7 +92,7 @@ def gem_available_new_rubygems?(gemname) def cmd if use_bundler - bundle_cmd = Gem.default_exec_format % 'bundle' + bundle_cmd = Gem.bin_path('bundler', 'bundle') [ Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'cucumber', @cucumber_opts, @feature_files ].flatten else @@ -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 = 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, diff --git a/spec/cucumber/rake/forked_spec.rb b/spec/cucumber/rake/forked_spec.rb index 5307a198e7..e4521dd69d 100644 --- a/spec/cucumber/rake/forked_spec.rb +++ b/spec/cucumber/rake/forked_spec.rb @@ -24,22 +24,22 @@ 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') subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - bundle_cmd, + '/path/to/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', - 'XbundleY', + '/path/to/XbundleY', 'exec', 'cucumber', '--cuke-option'] + feature_files diff --git a/spec/cucumber/rake/rcov_spec.rb b/spec/cucumber/rake/rcov_spec.rb index 219868e6ec..d6686014fc 100644 --- a/spec/cucumber/rake/rcov_spec.rb +++ b/spec/cucumber/rake/rcov_spec.rb @@ -26,9 +26,24 @@ 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') subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - 'bundle', + '/path/to/bundle', + 'exec', + 'rcov', + '--rcov-option', + "\"#{Cucumber::BINARY }\"", + '--', + '--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', + '/path/to/XbundleY', 'exec', 'rcov', '--rcov-option', From ded958968e21d68a381e3b56ab9b497cc64d4eda Mon Sep 17 00:00:00 2001 From: HIGUCHI Yuta Date: Wed, 6 Mar 2013 23:05:01 +0900 Subject: [PATCH 2/4] Use only the basename of `bundle` command. --- lib/cucumber/rake/task.rb | 4 ++-- spec/cucumber/rake/forked_spec.rb | 4 ++-- spec/cucumber/rake/rcov_spec.rb | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/cucumber/rake/task.rb b/lib/cucumber/rake/task.rb index b6c745d112..d6f018b99f 100644 --- a/lib/cucumber/rake/task.rb +++ b/lib/cucumber/rake/task.rb @@ -92,7 +92,7 @@ def gem_available_new_rubygems?(gemname) def cmd if use_bundler - bundle_cmd = Gem.bin_path('bundler', 'bundle') + bundle_cmd = File.basename( Gem.bin_path('bundler', 'bundle') ) [ Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'cucumber', @cucumber_opts, @feature_files ].flatten else @@ -115,7 +115,7 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files, rcov_o def cmd if use_bundler - bundle_cmd = Gem.bin_path('bundler', 'bundle') + 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 diff --git a/spec/cucumber/rake/forked_spec.rb b/spec/cucumber/rake/forked_spec.rb index e4521dd69d..2f94251d12 100644 --- a/spec/cucumber/rake/forked_spec.rb +++ b/spec/cucumber/rake/forked_spec.rb @@ -28,7 +28,7 @@ module Rake subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - '/path/to/bundle', + 'bundle', 'exec', 'cucumber', '--cuke-option'] + feature_files @@ -39,7 +39,7 @@ module Rake subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - '/path/to/XbundleY', + 'XbundleY', 'exec', 'cucumber', '--cuke-option'] + feature_files diff --git a/spec/cucumber/rake/rcov_spec.rb b/spec/cucumber/rake/rcov_spec.rb index d6686014fc..92622652a3 100644 --- a/spec/cucumber/rake/rcov_spec.rb +++ b/spec/cucumber/rake/rcov_spec.rb @@ -29,7 +29,7 @@ module Rake Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/bundle') subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - '/path/to/bundle', + 'bundle', 'exec', 'rcov', '--rcov-option', @@ -43,7 +43,7 @@ module Rake subject.cmd.should == [Cucumber::RUBY_BINARY, '-S', - '/path/to/XbundleY', + 'XbundleY', 'exec', 'rcov', '--rcov-option', From d08dc897a786ae6ceff78eda2fe16935e365dab0 Mon Sep 17 00:00:00 2001 From: HIGUCHI Yuta Date: Thu, 7 Mar 2013 08:58:37 +0900 Subject: [PATCH 3/4] Remove duplicate code. --- lib/cucumber/rake/task.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/cucumber/rake/task.rb b/lib/cucumber/rake/task.rb index d6f018b99f..15246fc79f 100644 --- a/lib/cucumber/rake/task.rb +++ b/lib/cucumber/rake/task.rb @@ -78,6 +78,10 @@ def use_bundler @bundler.nil? ? File.exist?("./Gemfile") && gem_available?("bundler") : @bundler end + def bundle_cmd + File.basename( Gem.bin_path('bundler', 'bundle') ) + end + def gem_available?(gemname) gem_available_new_rubygems?(gemname) || gem_available_old_rubygems?(gemname) end @@ -92,7 +96,6 @@ def gem_available_new_rubygems?(gemname) def cmd if use_bundler - bundle_cmd = File.basename( Gem.bin_path('bundler', 'bundle') ) [ Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'cucumber', @cucumber_opts, @feature_files ].flatten else @@ -115,7 +118,6 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files, rcov_o def cmd if use_bundler - 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 From d5a677ccbfafff3872107b1d179a664ef4a04515 Mon Sep 17 00:00:00 2001 From: HIGUCHI Yuta Date: Fri, 8 Mar 2013 03:18:21 +0900 Subject: [PATCH 4/4] Stop using bundle exec and use bundler by preloading required library. --- lib/cucumber/rake/task.rb | 11 ++++++----- spec/cucumber/rake/forked_spec.rb | 25 ++++++++----------------- spec/cucumber/rake/rcov_spec.rb | 24 +++++++----------------- 3 files changed, 21 insertions(+), 39 deletions(-) diff --git a/lib/cucumber/rake/task.rb b/lib/cucumber/rake/task.rb index 15246fc79f..6671e55a5a 100644 --- a/lib/cucumber/rake/task.rb +++ b/lib/cucumber/rake/task.rb @@ -67,7 +67,7 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files) end def load_path(libs) - ['"%s"' % @libs.join(File::PATH_SEPARATOR)] + ['"%s"' % libs.join(File::PATH_SEPARATOR)] end def quoted_binary(cucumber_bin) @@ -78,8 +78,9 @@ def use_bundler @bundler.nil? ? File.exist?("./Gemfile") && gem_available?("bundler") : @bundler end - def bundle_cmd - File.basename( Gem.bin_path('bundler', 'bundle') ) + def bundler_lib_path + spec = Gem::Specification.find_by_name('bundler') + File.join(spec.gem_dir , 'lib') end def gem_available?(gemname) @@ -96,7 +97,7 @@ def gem_available_new_rubygems?(gemname) def cmd if use_bundler - [ Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'cucumber', @cucumber_opts, + [ Cucumber::RUBY_BINARY, '-I', load_path([bundler_lib_path] + @libs), '-rbundler/setup', quoted_binary(@cucumber_bin), @cucumber_opts, @feature_files ].flatten else [ Cucumber::RUBY_BINARY, '-I', load_path(@libs), quoted_binary(@cucumber_bin), @@ -118,7 +119,7 @@ def initialize(libs, cucumber_bin, cucumber_opts, bundler, feature_files, rcov_o def cmd if use_bundler - [Cucumber::RUBY_BINARY, '-S', bundle_cmd, 'exec', 'rcov', @rcov_opts, + [Cucumber::RUBY_BINARY, '-I', load_path([bundler_lib_path] + @libs), '-rbundler/setup', '-S', 'rcov', @rcov_opts, quoted_binary(@cucumber_bin), '--', @cucumber_opts, @feature_files].flatten else [Cucumber::RUBY_BINARY, '-I', load_path(@libs), '-S', 'rcov', @rcov_opts, diff --git a/spec/cucumber/rake/forked_spec.rb b/spec/cucumber/rake/forked_spec.rb index 2f94251d12..492d86b9d5 100644 --- a/spec/cucumber/rake/forked_spec.rb +++ b/spec/cucumber/rake/forked_spec.rb @@ -15,6 +15,8 @@ module Rake context "when running with bundler" do let(:bundler) { true } + let(:bundler_lib_dir) { File.join(Gem.dir, 'gems', 'bundler-1.2.3', 'lib') } + let(:bundler_spec) { Gem::Specification.new 'bundler', '1.2.3' } subject { Task::ForkedCucumberRunner.new( libs, binary, cucumber_opts, bundler, feature_files) } @@ -23,25 +25,14 @@ module Rake subject.use_bundler.should be_true end - it "uses bundle exec to find cucumber and libraries" do - Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/bundle') + it "uses bundler to find cucumber and libraries" do + Gem::Specification.should_receive(:find_by_name).with('bundler').and_return(bundler_spec) subject.cmd.should == [Cucumber::RUBY_BINARY, - '-S', - 'bundle', - 'exec', - 'cucumber', - '--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', - 'cucumber', + '-I', + '"%s"' % ([bundler_lib_dir]+libs).join(File::PATH_SEPARATOR), + '-rbundler/setup', + "\"#{Cucumber::BINARY }\"", '--cuke-option'] + feature_files end diff --git a/spec/cucumber/rake/rcov_spec.rb b/spec/cucumber/rake/rcov_spec.rb index 92622652a3..cd700ae996 100644 --- a/spec/cucumber/rake/rcov_spec.rb +++ b/spec/cucumber/rake/rcov_spec.rb @@ -17,6 +17,8 @@ module Rake context "when running with bundler" do let(:bundler) { true } + let(:bundler_lib_dir) { File.join(Gem.dir, 'gems', 'bundler-1.2.3', 'lib') } + let(:bundler_spec) { Gem::Specification.new 'bundler', '1.2.3' } subject { Task::RCovCucumberRunner.new( libs, binary, cucumber_opts, bundler, feature_files, rcov_opts) } @@ -25,26 +27,14 @@ module Rake subject.use_bundler.should be_true end - it "uses bundle exec to find cucumber and libraries" do - Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/bundle') - subject.cmd.should == [Cucumber::RUBY_BINARY, - '-S', - 'bundle', - 'exec', - 'rcov', - '--rcov-option', - "\"#{Cucumber::BINARY }\"", - '--', - '--cuke-option'] + feature_files - end - - it "obeys program suffix for bundler" do - Gem.stub(:bin_path).with('bundler','bundle').and_return('/path/to/XbundleY') + it "uses bundler to find cucumber and libraries" do + Gem::Specification.should_receive(:find_by_name).with('bundler').and_return(bundler_spec) subject.cmd.should == [Cucumber::RUBY_BINARY, + '-I', + '"%s"' % ([bundler_lib_dir]+libs).join(File::PATH_SEPARATOR), + '-rbundler/setup', '-S', - 'XbundleY', - 'exec', 'rcov', '--rcov-option', "\"#{Cucumber::BINARY }\"",