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.

- #454.
  • Loading branch information
dchelimsky committed Sep 9, 2011
1 parent 28c1b57 commit f90b9f5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 45 deletions.
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'
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.
#
Expand Down Expand Up @@ -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?

Expand Down Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
71 changes: 34 additions & 37 deletions spec/rspec/core/rake_task_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit f90b9f5

Please sign in to comment.