Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git style configuration and deprecate spec.opts.

  • Loading branch information...
commit fd0398e9e8e61c69cf95aa9e41b440d0d622a095 1 parent f839307
@RipTheJacker RipTheJacker authored dchelimsky committed
View
2  features/support/env.rb
@@ -1,4 +1,4 @@
-$LOAD_PATH << File.expand_path("../../../../rspec-expectations/lib", __FILE__)
+$LOAD_PATH.unshift File.expand_path("../../../../rspec-expectations/lib", __FILE__)
require 'rspec/expectations'
require 'aruba'
View
27 lib/rspec/core/command_line_options.rb
@@ -5,7 +5,8 @@ module Rspec
module Core
class CommandLineOptions
- DEFAULT_OPTIONS_FILE = 'spec/spec.opts'
+ DEFAULT_OPTIONS_FILE = 'spec/.rspecrc'
+ DEFAULT_GLOBAL_OPTIONS_FILE = File.join(File.expand_path('~'), '.rspecrc')
attr_reader :args, :options
@@ -42,9 +43,13 @@ def parse
end
opts.on('-o', '--options [PATH]', 'Read configuration options from a file path. (Defaults to spec/spec.opts)') do |o|
- options[:options_file] = o || DEFAULT_OPTIONS_FILE
+ options[:options_file] = o || default_options_file
end
-
+
+ opts.on('-g', '--global [PATH]', "Location of global .rspecrc") do |o|
+ options[:global_options_file] = o || DEFAULT_GLOBAL_OPTIONS_FILE
+ end
+
opts.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
options[:profile_examples] = o
end
@@ -70,9 +75,13 @@ def apply(config)
# 1) option file, cli options, rspec core configure
# TODO: Add options_file to configuration
# TODO: Store command line options for reference
- options_file = options.delete(:options_file) || DEFAULT_OPTIONS_FILE
- merged_options = parse_spec_file_contents(options_file).merge!(options)
- options.replace merged_options
+ options_file = options.delete(:options_file){ default_options_file }
+ global_options_file = options.delete(:global_options_file) { DEFAULT_GLOBAL_OPTIONS_FILE }
+ default_options = parse_spec_file_contents(options_file)
+ global_options = parse_spec_file_contents(global_options_file)
+
+ merged_options = default_options.merge(options)
+ options = global_options.merge(merged_options)
options.each do |key, value|
config.send("#{key}=", value)
@@ -81,6 +90,12 @@ def apply(config)
private
+ def default_options_file
+ return DEFAULT_OPTIONS_FILE if File.exist?(DEFAULT_OPTIONS_FILE)
+ Rspec.deprecate("spec/spec.opts", "spec/.rspecrc", "2.0.0") if File.exist?("spec/spec.opts")
+ "spec/spec.opts"
+ end
+
def parse_spec_file_contents(options_file)
return {} unless File.exist?(options_file)
spec_file_contents = File.readlines(options_file).map {|l| l.split}.flatten
View
20 spec/rspec/core/command_line_options_spec.rb
@@ -62,7 +62,23 @@ def options_from_args(*args)
options_from_args('-o').should include(:options_file => "spec/spec.opts")
options_from_args('--options').should include(:options_file => "spec/spec.opts")
end
-
+
+ it "loads a global .rspecrc" do
+ options_from_args('-g').should include(:global_options_file => File.join(File.expand_path('~'), '.rspecrc'))
+ options_from_args('--global').should include(:global_options_file => File.join(File.expand_path('~'), '.rspecrc'))
+ end
+
+ it "merges options from the global and local .rspecrc" do
+ opts = ['--formatter', 'progress']
+ File.stub(:exist?){ true }
+ File.should_receive(:readlines).with('spec/.rspecrc').and_return(['--formatter', 'documentation'])
+ File.should_receive(:readlines).with(File.join(File.expand_path('~'), '.rspecrc')).and_return(opts)
+ cli_options = Rspec::Core::CommandLineOptions.new([]).parse
+ config = OpenStruct.new
+ cli_options.apply(config)
+ config.formatter.should == 'documentation'
+ end
+
it "loads automatically" do
cli_options = Rspec::Core::CommandLineOptions.new([]).parse
File.stub(:exist?) { true }
@@ -71,7 +87,7 @@ def options_from_args(*args)
cli_options.apply(config)
config.formatter.should == 'doc'
end
-
+
it "allows options on one line" do
cli_options = Rspec::Core::CommandLineOptions.new([]).parse
File.stub(:exist?) { true }
Please sign in to comment.
Something went wrong with that request. Please try again.