Skip to content

Commit

Permalink
Deprecate skip_bundler and gemfile options on rake task. Check for
Browse files Browse the repository at this point in the history
presence of BUNDLE_GEMFILE instead.

- Closes #454.
  • Loading branch information
dchelimsky committed Oct 9, 2011
1 parent eebf8ba commit d731a27
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 45 deletions.
2 changes: 2 additions & 0 deletions Changelog.md
Expand Up @@ -24,6 +24,8 @@ As of 2.7.0, you must explicity `require "rspec/autorun"` unless you use the
* Provide more accurate run time by registering start time before code * Provide more accurate run time by registering start time before code
is loaded (David Chelimsky) is loaded (David Chelimsky)
* Rake task default pattern finds specs in symlinked dirs (Kelly Felkins) * Rake task default pattern finds specs in symlinked dirs (Kelly Felkins)
* Rake task decides whether to use bundler or not based on presence
of BUNDLE_GEMFILE (David Chelimsky)


* Bug fixes * Bug fixes
* Include Rake::DSL to remove deprecation warnings in Rake > 0.8.7 (Pivotal * Include Rake::DSL to remove deprecation warnings in Rake > 0.8.7 (Pivotal
Expand Down
25 changes: 17 additions & 8 deletions lib/rspec/core/rake_task.rb
Expand Up @@ -20,19 +20,29 @@ class RakeTask < ::Rake::TaskLib
# 'spec/**/*_spec.rb' # 'spec/**/*_spec.rb'
attr_accessor :pattern 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 # 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 # 'bundle exec'. Set this to true to ignore the presence of a Gemfile, and
# not add 'bundle exec' to the command. # not add 'bundle exec' to the command.
# #
# default: # default:
# false # 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: # default:
# Gemfile # Gemfile
attr_accessor :gemfile def gemfile=(*)
RSpec.deprecate("RSpec::Core::RakeTask#gemfile=", 'ENV["BUNDLE_GEMFILE"]')
end


# Deprecated. Use ruby_opts="-w" instead. # Deprecated. Use ruby_opts="-w" instead.
# #
Expand Down Expand Up @@ -114,9 +124,8 @@ def spec_opts=(opts)
def initialize(*args) def initialize(*args)
@name = args.shift || :spec @name = args.shift || :spec
@pattern, @rcov_path, @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil, nil, nil @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 @verbose, @fail_on_error = true, true
@gemfile = 'Gemfile'


yield self if block_given? yield self if block_given?


Expand Down Expand Up @@ -156,7 +165,7 @@ def files_to_run # :nodoc:
def spec_command def spec_command
@spec_command ||= begin @spec_command ||= begin
cmd_parts = [] cmd_parts = []
cmd_parts << "bundle exec" if gemfile? unless skip_bundler cmd_parts << "bundle exec" if bundler?
cmd_parts << RUBY cmd_parts << RUBY
cmd_parts << ruby_opts cmd_parts << ruby_opts
cmd_parts << "-w" if warning? cmd_parts << "-w" if warning?
Expand Down Expand Up @@ -189,8 +198,8 @@ def blank
lambda {|s| s == ""} lambda {|s| s == ""}
end end


def gemfile? def bundler?
File.exist?(gemfile) ENV["BUNDLE_GEMFILE"] if ENV["BUNDLE_GEMFILE"] unless ENV["BUNDLE_GEMFILE"] == ""
end end


end end
Expand Down
71 changes: 34 additions & 37 deletions spec/rspec/core/rake_task_spec.rb
Expand Up @@ -10,14 +10,20 @@ def ruby
FileUtils::RUBY FileUtils::RUBY
end end


before do def with_bundle_gemfile(val)
File.stub(:exist?) { false } begin
orig = ENV['BUNDLE_GEMFILE']
ENV['BUNDLE_GEMFILE'] = val
yield
ensure
ENV['BUNDLE_GEMFILE'] = orig
end
end end


def with_bundler def without_bundler
task.skip_bundler = false with_bundle_gemfile nil do
File.stub(:exist?) { true } yield
yield end
end end


def with_rcov def with_rcov
Expand All @@ -29,50 +35,39 @@ def spec_command
task.__send__(:spec_command) task.__send__(:spec_command)
end end


context "default" do context "default (BUNDLE_GEMFILE nil)" do
it "renders rspec" do it "renders rspec" do
spec_command.should =~ /^#{ruby} -S rspec/ with_bundle_gemfile nil do
end spec_command.should =~ /^#{ruby} -S rspec/
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/)
end end
end end
end


context "with non-standard Gemfile" do context "default (BUNDLE_GEMFILE '')" do
it "renders bundle exec rspec" do it "renders rspec" do
File.stub(:exist?) {|f| f =~ /AltGemfile/} with_bundle_gemfile '' do
task.gemfile = 'AltGemfile' spec_command.should =~ /^#{ruby} -S rspec/
task.skip_bundler = false
spec_command.should match(/bundle exec/)
end end
end end
end


context "without Gemfile" do context "with bundler (BUNDLE_GEMFILE non-blank)" do
it "renders bundle exec rspec" do it "renders bundle exec rspec" do
File.stub(:exist?) { false } spec_command.should match(/bundle exec/)
task.skip_bundler = false
spec_command.should_not match(/bundle exec/)
end
end end
end end


context "with rcov" do context "with rcov" do
it "renders rcov" do it "renders rcov" do
with_rcov do without_bundler do
spec_command.should =~ /^#{ruby} -S rcov/ with_rcov do
spec_command.should =~ /^#{ruby} -S rcov/
end
end end
end end
end


context "with bundler and rcov" do context "with bundler" do
it "renders bundle exec rcov" do it "renders bundle exec rcov" do
with_bundler do
with_rcov do with_rcov do
spec_command.should =~ /^bundle exec #{ruby} -S rcov/ spec_command.should =~ /^bundle exec #{ruby} -S rcov/
end end
Expand All @@ -82,8 +77,10 @@ def spec_command


context "with ruby options" do context "with ruby options" do
it "renders them before -S" do it "renders them before -S" do
task.ruby_opts = "-w" without_bundler do
spec_command.should =~ /^#{ruby} -w -S rspec/ task.ruby_opts = "-w"
spec_command.should =~ /^#{ruby} -w -S rspec/
end
end end
end end


Expand Down

0 comments on commit d731a27

Please sign in to comment.