Skip to content
This repository
Browse code

prefer SPEC_OPTS over .rspec and CLI

- this is really for IDEs like RubyMine to be able to take over the
  options, as opposed to a user using it on his/her system.
  • Loading branch information...
commit eb52101bfb5c613e8e5d0acaee966fa9e3a69bbe 1 parent 2e18711
David Chelimsky authored June 10, 2010
7  lib/rspec/core/configuration_options.rb
@@ -37,8 +37,9 @@ def parse_options
37 37
                      command_line_options = parse_command_line_options
38 38
                      local_options        = parse_local_options(command_line_options)
39 39
                      global_options       = parse_global_options
  40
+                     env_options          = parse_env_options
40 41
 
41  
-                     [global_options, local_options, command_line_options].inject do |merged, options|
  42
+                     [global_options, local_options, command_line_options, env_options].inject do |merged, options|
42 43
                        merged.merge(options)
43 44
                      end
44 45
                    end
@@ -46,6 +47,10 @@ def parse_options
46 47
 
47 48
     private
48 49
 
  50
+      def parse_env_options
  51
+        ENV["SPEC_OPTS"] ? Parser.parse!(ENV["SPEC_OPTS"].split) : {}
  52
+      end
  53
+
49 54
       def parse_command_line_options
50 55
         options = Parser.parse!(@args)
51 56
         options[:files_or_directories_to_run] = @args
19  spec/rspec/core/configuration_options_spec.rb
@@ -264,6 +264,25 @@ def options_from_args(*args)
264 264
 
265 265
       config.formatter.should == 'progress'
266 266
     end
  267
+
  268
+    context "with SPEC_OPTS" do
  269
+      around do |example|
  270
+        orig_spec_opts = ENV["SPEC_OPTS"]
  271
+        example.run
  272
+        ENV["SPEC_OPTS"] = orig_spec_opts
  273
+      end
  274
+
  275
+      it "prefers SPEC_OPTS options over file options" do
  276
+        config = OpenStruct.new
  277
+        ENV["SPEC_OPTS"] = "--formatter documentation"
  278
+        config_options = RSpec::Core::ConfigurationOptions.new(['--formatter', 'progress'])
  279
+
  280
+        config_options.parse_options
  281
+        config_options.configure(config)
  282
+
  283
+        config.formatter.should == 'documentation'
  284
+      end
  285
+    end
267 286
   end
268 287
 end
269 288
 

0 notes on commit eb52101

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