Permalink
Browse files

Add --require command line option

Closes #27.
  • Loading branch information...
1 parent 2a5e510 commit 8df905484472128457a3d42d206e79077b6dc031 @dchelimsky dchelimsky committed Jun 13, 2010
@@ -140,6 +140,10 @@ def libs=(libs)
libs.map {|lib| $LOAD_PATH.unshift lib}
end
+ def requires=(paths)
+ paths.map {|path| require path}
+ end
+
def debug=(bool)
return unless bool
begin
@@ -16,7 +16,7 @@ def initialize(args)
def configure(config)
options.each do |key, value|
- config.send("#{key}=", value) rescue nil
+ config.send("#{key}=", value)
end
end
@@ -70,6 +70,11 @@ def parser(options)
options[:profile_examples] = o
end
+ parser.on('-r', '--require PATH', 'Require a file') do |path|
+ options[:requires] ||= []
+ options[:requires] << path
+ end
+
parser.on('-v', '--version', 'Show version') do
puts RSpec::Core::Version::STRING
exit
View
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
s.authors = ["Chad Humphries", "David Chelimsky"]
- s.date = %q{2010-06-12}
+ s.date = %q{2010-06-13}
s.description = %q{RSpec runner and example group classes}
s.email = %q{dchelimsky@gmail.com;chad.humphries@gmail.com}
s.executables = ["rspec", "spec"]
@@ -14,6 +14,16 @@ def options_from_args(*args)
config_options_object(*args).options
end
+ describe "#configure" do
+ it "sends libs before requires" do
+ opts = config_options_object(*%w[--require a/path -I a/lib])
+ config = double("config").as_null_object
+ config.should_receive(:libs=).ordered
+ config.should_receive(:requires=).ordered
+ opts.configure(config)
+ end
+ end
+
describe 'color_enabled' do
example "-c, --colour, or --color are parsed as true" do
options_from_args('-c').should include(:color_enabled => true)
@@ -35,6 +45,15 @@ def options_from_args(*args)
end
end
+ describe '--require' do
+ example "--requires files" do
+ options_from_args('--require', 'a/path').should include(:requires => ['a/path'])
+ end
+ example "--require can be used more than once" do
+ options_from_args('--require', 'path/1', '--require', 'path/2').should include(:requires => ['path/1','path/2'])
+ end
+ end
+
describe 'format' do
example '-f or --format with an argument should parse' do
options_from_args('--format', 'd').should include(:formatter => 'd')
@@ -315,6 +315,13 @@ def that_thing
end
end
+ describe "requires=" do
+ it "requires paths" do
+ config.should_receive(:require).with("a/path")
+ config.requires = ["a/path"]
+ end
+ end
+
describe "#add_setting" do
describe "with no modifiers" do
context "with no additional options" do

0 comments on commit 8df9054

Please sign in to comment.