Permalink
Browse files

Deprecate automatic assumption of bundler with autotest.

- use Autotest's bundler plugin instead.
- use 'autotest -- --skip-bundler' to skip 'bundle exec'.
  • Loading branch information...
1 parent f1a43fd commit 8aca7e06a804a6af61c5568920a9b33851a2761c @dchelimsky dchelimsky committed Jan 21, 2011
Showing with 143 additions and 12 deletions.
  1. +8 −2 features/Upgrade.md
  2. +36 −3 lib/autotest/rspec2.rb
  3. +99 −7 spec/autotest/rspec_spec.rb
View
@@ -7,8 +7,14 @@
By default, RSpec adds `bundle exec` to the command generated by Autotest if
there is a `Gemfile` in the project root directory.
-As of rspec-core-2.5, you can pass `--skip-bundler` to the `autotest` command
-and it won't include `bundle exec` even if there is a `Gemfile`.
+As of rspec-core-2.5, this automatic inclusion of 'bundle exec' is deprecated.
+If you want to include 'bundle exec', use Autotest's bundler plugin by adding
+a .autotest file to the project root directory with the following:
+
+ require 'autotest/bundler'
+
+If you want to skip 'bundle exec', pass `--skip-bundler` to the `autotest`
+command and it won't include `bundle exec` even if there is a `Gemfile`.
autotest -- --skip-bundler
View
@@ -1,4 +1,5 @@
require 'autotest'
+require 'rspec/core/deprecation'
class RSpecCommandError < StandardError; end
@@ -46,12 +47,40 @@ def consolidate_failures(failed)
end
def make_test_cmd(files_to_test)
+ if File.exist?('./Gemfile') && prefix !~ /bundle exec/ && !skip_bundler?
+ RSpec.warn_deprecation <<-WARNING
+
+****************************************************************************
+DEPRECATION WARNING: you are using deprecated behaviour that will be removed
+from a future version of RSpec.
+
+RSpec's autotest extension is relying on the presence of a Gemfile in the
+project root directory to generate a command including 'bundle exec'.
+
+You have two options to disable this message:
+
+If you want to include 'bundle exec' in the command, add a .autotest file to
+the project root with the following content:
+
+ require 'autotest/bundler'
+
+If you prefer to skip 'bundle exec', pass the --skip-bundler to autotest as
+an extra argument, like this:
+
+ autotest -- --skip-bundler
+*****************************************************************
+WARNING
+ end
files_to_test.empty? ? '' :
- "#{bundle_exec}#{ruby} #{require_rubygems}-S #{SPEC_PROGRAM} #{cli_args.join(' ')} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
+ "#{prefix}#{bundle_exec}#{ruby} #{require_rubygems}-S #{SPEC_PROGRAM} #{cli_args.join(' ')} #{normalize(files_to_test).keys.flatten.map { |f| "'#{f}'"}.join(' ')}"
end
def bundle_exec
- using_bundler? ? "bundle exec " : ""
+ if using_bundler? && prefix !~ /bundle exec/
+ "bundle exec "
+ else
+ ""
+ end
end
def require_rubygems
@@ -66,7 +95,11 @@ def normalize(files_to_test)
end
def using_bundler?
- File.exists?('./Gemfile') unless skip_bundler?
+ gemfile? unless skip_bundler?
+ end
+
+ def gemfile?
+ File.exist?('./Gemfile')
end
end
View
@@ -1,9 +1,19 @@
require "spec_helper"
describe Autotest::Rspec2 do
+ let(:rspec_autotest) { Autotest::Rspec2.new }
+ let(:spec_cmd) { File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec')) }
+ let(:ruby_cmd) { "ruby" }
+
+ before do
+ RSpec.stub(:warn_deprecation)
+ File.stub(:exist?) { false }
+ @orig_argv = ARGV.dup; ARGV.clear
+ end
+
+ after { ARGV.clear; ARGV.concat(@orig_argv) }
+
context "with ARGV" do
- before { @orig_argv = ARGV.dup; ARGV.clear }
- after { ARGV.clear; ARGV.concat(@orig_argv) }
it "passes ARGV to command" do
ARGV.concat(%w[-c -f d])
@@ -21,9 +31,91 @@
end
end
- let(:rspec_autotest) { Autotest::Rspec2.new }
- let(:spec_cmd) { File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'rspec')) }
- let(:ruby_cmd) { "ruby" }
+ describe "warning about bundler" do
+ context "gemfile, no prefix" do
+ before do
+ File.stub(:exist?).with("./Gemfile") { true }
+ end
+
+ it "warns" do
+ RSpec.should_receive(:warn_deprecation)
+ rspec_autotest.make_test_cmd({})
+ end
+
+ it "includes bundle exec" do
+ rspec_autotest.
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
+ end
+ end
+
+ context "gemfile, no prefix, --skip-bundler" do
+ before do
+ File.stub(:exist?).with("./Gemfile") { true }
+ ARGV.concat(%w[--skip-bundler])
+ end
+
+ it "does not warn" do
+ RSpec.should_not_receive(:warn_deprecation)
+ rspec_autotest.make_test_cmd({})
+ end
+
+ it "does not include bundle exec" do
+ rspec_autotest.
+ make_test_cmd({'a' => 'b'}).should_not match(/bundle exec/)
+ end
+ end
+
+ context "no gemfile, prefix" do
+ before do
+ File.stub(:exist?).with("./Gemfile") { false }
+ end
+
+ it "does not warn" do
+ RSpec.should_not_receive(:warn_deprecation)
+ rspec_autotest.make_test_cmd({'a' => 'b'})
+ end
+
+ it "includes bundle exec" do
+ rspec_autotest.prefix = "bundle exec "
+ rspec_autotest.
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
+ end
+ end
+
+ context "gemfile, prefix" do
+ before do
+ File.stub(:exist?).with("./Gemfile") { true }
+ rspec_autotest.prefix = "bundle exec "
+ end
+
+ it "does not warn" do
+ RSpec.should_not_receive(:warn_deprecation)
+ rspec_autotest.make_test_cmd({'a' => 'b'})
+ end
+
+ it "includes bundle exec" do
+ rspec_autotest.prefix = "bundle exec "
+ rspec_autotest.
+ make_test_cmd({'a' => 'b'}).should match(/bundle exec/)
+ end
+ end
+
+ context "no gemfile, no prefix" do
+ before do
+ File.stub(:exist?).with("./Gemfile") { false }
+ end
+
+ it "does not warn" do
+ RSpec.should_not_receive(:warn_deprecation)
+ rspec_autotest.make_test_cmd({'a' => 'b'})
+ end
+
+ it "does not include bundle exec" do
+ rspec_autotest.
+ make_test_cmd({'a' => 'b'}).should_not match(/bundle exec/)
+ end
+ end
+ end
describe "commands" do
before do
@@ -134,14 +226,14 @@
describe "ruby command" do
context "using bundler" do
it "returns 'bundle exec'" do
- File.stub(:exists?).with("./Gemfile") { true }
+ File.stub(:exist?).with("./Gemfile") { true }
rspec_autotest.make_test_cmd({'a' => 'b'}).should =~ /bundle exec .*ruby/
end
end
context "not using bundler" do
it "returns the ruby command generated by Autotest" do
- File.stub(:exists?).with("./Gemfile") { false }
+ File.stub(:exist?).with("./Gemfile") { false }
rspec_autotest.make_test_cmd({'a' => 'b'}).should_not =~ /bundle exec/
end
end

0 comments on commit 8aca7e0

Please sign in to comment.