Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Deprecate skip_bundler and gemfile options on rake task. Check for

presence of BUNDLE_GEMFILE instead.

- #454.
  • Loading branch information...
commit f90b9f5c6ce5efdfb5cf18efbe27adf87d0fa848 1 parent 28c1b57
David Chelimsky authored September 09, 2011
25  lib/rspec/core/rake_task.rb
@@ -20,19 +20,29 @@ class RakeTask < ::Rake::TaskLib
20 20
       #   'spec/**/*_spec.rb'
21 21
       attr_accessor :pattern
22 22
 
  23
+      # Deprecated and has no effect. The rake task now checks
  24
+      # ENV['BUNDLE_GEMFILE'] instead.
  25
+      #
23 26
       # By default, if there is a Gemfile, the generated command will include
24 27
       # 'bundle exec'. Set this to true to ignore the presence of a Gemfile, and
25 28
       # not add 'bundle exec' to the command.
26 29
       #
27 30
       # default:
28 31
       #   false
29  
-      attr_accessor :skip_bundler
  32
+      def skip_bundler=(*)
  33
+        RSpec.deprecate("RSpec::Core::RakeTask#skip_bundler=", 'ENV["BUNDLE_GEMFILE"]')
  34
+      end
30 35
 
31  
-      # Name of Gemfile to use
  36
+      # Deprecated and has no effect. The rake task now checks
  37
+      # ENV['BUNDLE_GEMFILE'] instead.
  38
+      #
  39
+      # Name of Gemfile to use.
32 40
       #
33 41
       # default:
34 42
       #   Gemfile
35  
-      attr_accessor :gemfile
  43
+      def gemfile=(*)
  44
+        RSpec.deprecate("RSpec::Core::RakeTask#gemfile=", 'ENV["BUNDLE_GEMFILE"]')
  45
+      end
36 46
 
37 47
       # Deprecated. Use ruby_opts="-w" instead.
38 48
       #
@@ -114,9 +124,8 @@ def spec_opts=(opts)
114 124
       def initialize(*args)
115 125
         @name = args.shift || :spec
116 126
         @pattern, @rcov_path, @rcov_opts, @ruby_opts, @rspec_opts = nil, nil, nil, nil, nil
117  
-        @warning, @rcov, @skip_bundler = false, false, false
  127
+        @warning, @rcov = false, false
118 128
         @verbose, @fail_on_error = true, true
119  
-        @gemfile = 'Gemfile'
120 129
 
121 130
         yield self if block_given?
122 131
 
@@ -156,7 +165,7 @@ def files_to_run # :nodoc:
156 165
       def spec_command
157 166
         @spec_command ||= begin
158 167
                             cmd_parts = []
159  
-                            cmd_parts << "bundle exec" if gemfile? unless skip_bundler
  168
+                            cmd_parts << "bundle exec" if bundler?
160 169
                             cmd_parts << RUBY
161 170
                             cmd_parts << ruby_opts
162 171
                             cmd_parts << "-w" if warning?
@@ -189,8 +198,8 @@ def blank
189 198
         lambda {|s| s == ""}
190 199
       end
191 200
 
192  
-      def gemfile?
193  
-        File.exist?(gemfile)
  201
+      def bundler?
  202
+        ENV["BUNDLE_GEMFILE"] if ENV["BUNDLE_GEMFILE"] unless ENV["BUNDLE_GEMFILE"] == ""
194 203
       end
195 204
 
196 205
     end
71  spec/rspec/core/rake_task_spec.rb
@@ -9,14 +9,20 @@ def ruby
9 9
       FileUtils::RUBY
10 10
     end
11 11
 
12  
-    before do
13  
-      File.stub(:exist?) { false }
  12
+    def with_bundle_gemfile(val)
  13
+      begin
  14
+        orig = ENV['BUNDLE_GEMFILE']
  15
+        ENV['BUNDLE_GEMFILE'] = val
  16
+        yield
  17
+      ensure
  18
+        ENV['BUNDLE_GEMFILE'] = orig
  19
+      end
14 20
     end
15 21
 
16  
-    def with_bundler
17  
-      task.skip_bundler = false
18  
-      File.stub(:exist?) { true }
19  
-      yield
  22
+    def without_bundler
  23
+      with_bundle_gemfile nil do
  24
+        yield
  25
+      end
20 26
     end
21 27
 
22 28
     def with_rcov
@@ -28,50 +34,39 @@ def spec_command
28 34
       task.__send__(:spec_command)
29 35
     end
30 36
 
31  
-    context "default" do
  37
+    context "default (BUNDLE_GEMFILE nil)" do
32 38
       it "renders rspec" do
33  
-        spec_command.should =~ /^#{ruby} -S rspec/
34  
-      end
35  
-    end
36  
-
37  
-    context "with bundler" do
38  
-      context "with Gemfile" do
39  
-        it "renders bundle exec rspec" do
40  
-          File.stub(:exist?) { true }
41  
-          task.skip_bundler = false
42  
-          spec_command.should match(/bundle exec/)
  39
+        with_bundle_gemfile nil do
  40
+          spec_command.should =~ /^#{ruby} -S rspec/
43 41
         end
44 42
       end
  43
+    end
45 44
 
46  
-      context "with non-standard Gemfile" do
47  
-        it "renders bundle exec rspec" do
48  
-          File.stub(:exist?) {|f| f =~ /AltGemfile/}
49  
-          task.gemfile = 'AltGemfile'
50  
-          task.skip_bundler = false
51  
-          spec_command.should match(/bundle exec/)
  45
+    context "default (BUNDLE_GEMFILE '')" do
  46
+      it "renders rspec" do
  47
+        with_bundle_gemfile '' do
  48
+          spec_command.should =~ /^#{ruby} -S rspec/
52 49
         end
53 50
       end
  51
+    end
54 52
 
55  
-      context "without Gemfile" do
56  
-        it "renders bundle exec rspec" do
57  
-          File.stub(:exist?) { false }
58  
-          task.skip_bundler = false
59  
-          spec_command.should_not match(/bundle exec/)
60  
-        end
  53
+    context "with bundler (BUNDLE_GEMFILE non-blank)" do
  54
+      it "renders bundle exec rspec" do
  55
+        spec_command.should match(/bundle exec/)
61 56
       end
62 57
     end
63 58
 
64 59
     context "with rcov" do
65 60
       it "renders rcov" do
66  
-        with_rcov do
67  
-          spec_command.should =~ /^#{ruby} -S rcov/
  61
+        without_bundler do
  62
+          with_rcov do
  63
+            spec_command.should =~ /^#{ruby} -S rcov/
  64
+          end
68 65
         end
69 66
       end
70  
-    end
71 67
 
72  
-    context "with bundler and rcov" do
73  
-      it "renders bundle exec rcov" do
74  
-        with_bundler do
  68
+      context "with bundler" do
  69
+        it "renders bundle exec rcov" do
75 70
           with_rcov do
76 71
             spec_command.should =~ /^bundle exec #{ruby} -S rcov/
77 72
           end
@@ -81,8 +76,10 @@ def spec_command
81 76
 
82 77
     context "with ruby options" do
83 78
       it "renders them before -S" do
84  
-        task.ruby_opts = "-w"
85  
-        spec_command.should =~ /^#{ruby} -w -S rspec/
  79
+        without_bundler do
  80
+          task.ruby_opts = "-w"
  81
+          spec_command.should =~ /^#{ruby} -w -S rspec/
  82
+        end
86 83
       end
87 84
     end
88 85
 

0 notes on commit f90b9f5

Please sign in to comment.
Something went wrong with that request. Please try again.