From f90b9f5c6ce5efdfb5cf18efbe27adf87d0fa848 Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Fri, 9 Sep 2011 07:43:15 -0500 Subject: [PATCH] Deprecate skip_bundler and gemfile options on rake task. Check for presence of BUNDLE_GEMFILE instead. - #454. --- lib/rspec/core/rake_task.rb | 25 +++++++---- spec/rspec/core/rake_task_spec.rb | 71 +++++++++++++++---------------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/lib/rspec/core/rake_task.rb b/lib/rspec/core/rake_task.rb index a1764ed70b..de12e81e7c 100644 --- a/lib/rspec/core/rake_task.rb +++ b/lib/rspec/core/rake_task.rb @@ -20,19 +20,29 @@ class RakeTask < ::Rake::TaskLib # 'spec/**/*_spec.rb' attr_accessor :pattern + # Deprecated and has no effect. The rake task now checks + # ENV['BUNDLE_GEMFILE'] instead. + # # By default, if there is a Gemfile, the generated command will include # 'bundle exec'. Set this to true to ignore the presence of a Gemfile, and # not add 'bundle exec' to the command. # # default: # false - attr_accessor :skip_bundler + def skip_bundler=(*) + RSpec.deprecate("RSpec::Core::RakeTask#skip_bundler=", 'ENV["BUNDLE_GEMFILE"]') + end - # Name of Gemfile to use + # Deprecated and has no effect. The rake task now checks + # ENV['BUNDLE_GEMFILE'] instead. + # + # Name of Gemfile to use. # # default: # Gemfile - attr_accessor :gemfile + def gemfile=(*) + RSpec.deprecate("RSpec::Core::RakeTask#gemfile=", 'ENV["BUNDLE_GEMFILE"]') + end # Deprecated. Use ruby_opts="-w" instead. # @@ -114,9 +124,8 @@ def spec_opts=(opts) def initialize(*args) @name = args.shift || :spec @pattern, @rcov_path, @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil, nil, nil - @warning, @rcov, @skip_bundler = false, false, false + @warning, @rcov = false, false @verbose, @fail_on_error = true, true - @gemfile = 'Gemfile' yield self if block_given? @@ -156,7 +165,7 @@ def files_to_run # :nodoc: def spec_command @spec_command ||= begin cmd_parts = [] - cmd_parts << "bundle exec" if gemfile? unless skip_bundler + cmd_parts << "bundle exec" if bundler? cmd_parts << RUBY cmd_parts << ruby_opts cmd_parts << "-w" if warning? @@ -189,8 +198,8 @@ def blank lambda {|s| s == ""} end - def gemfile? - File.exist?(gemfile) + def bundler? + ENV["BUNDLE_GEMFILE"] if ENV["BUNDLE_GEMFILE"] unless ENV["BUNDLE_GEMFILE"] == "" end end diff --git a/spec/rspec/core/rake_task_spec.rb b/spec/rspec/core/rake_task_spec.rb index fb1042d77c..8534adadad 100644 --- a/spec/rspec/core/rake_task_spec.rb +++ b/spec/rspec/core/rake_task_spec.rb @@ -9,14 +9,20 @@ def ruby FileUtils::RUBY end - before do - File.stub(:exist?) { false } + def with_bundle_gemfile(val) + begin + orig = ENV['BUNDLE_GEMFILE'] + ENV['BUNDLE_GEMFILE'] = val + yield + ensure + ENV['BUNDLE_GEMFILE'] = orig + end end - def with_bundler - task.skip_bundler = false - File.stub(:exist?) { true } - yield + def without_bundler + with_bundle_gemfile nil do + yield + end end def with_rcov @@ -28,50 +34,39 @@ def spec_command task.__send__(:spec_command) end - context "default" do + context "default (BUNDLE_GEMFILE nil)" do it "renders rspec" do - spec_command.should =~ /^#{ruby} -S rspec/ - end - end - - context "with bundler" do - context "with Gemfile" do - it "renders bundle exec rspec" do - File.stub(:exist?) { true } - task.skip_bundler = false - spec_command.should match(/bundle exec/) + with_bundle_gemfile nil do + spec_command.should =~ /^#{ruby} -S rspec/ end end + end - context "with non-standard Gemfile" do - it "renders bundle exec rspec" do - File.stub(:exist?) {|f| f =~ /AltGemfile/} - task.gemfile = 'AltGemfile' - task.skip_bundler = false - spec_command.should match(/bundle exec/) + context "default (BUNDLE_GEMFILE '')" do + it "renders rspec" do + with_bundle_gemfile '' do + spec_command.should =~ /^#{ruby} -S rspec/ end end + end - context "without Gemfile" do - it "renders bundle exec rspec" do - File.stub(:exist?) { false } - task.skip_bundler = false - spec_command.should_not match(/bundle exec/) - end + context "with bundler (BUNDLE_GEMFILE non-blank)" do + it "renders bundle exec rspec" do + spec_command.should match(/bundle exec/) end end context "with rcov" do it "renders rcov" do - with_rcov do - spec_command.should =~ /^#{ruby} -S rcov/ + without_bundler do + with_rcov do + spec_command.should =~ /^#{ruby} -S rcov/ + end end end - end - context "with bundler and rcov" do - it "renders bundle exec rcov" do - with_bundler do + context "with bundler" do + it "renders bundle exec rcov" do with_rcov do spec_command.should =~ /^bundle exec #{ruby} -S rcov/ end @@ -81,8 +76,10 @@ def spec_command context "with ruby options" do it "renders them before -S" do - task.ruby_opts = "-w" - spec_command.should =~ /^#{ruby} -w -S rspec/ + without_bundler do + task.ruby_opts = "-w" + spec_command.should =~ /^#{ruby} -w -S rspec/ + end end end