Permalink
Browse files

add -I config option

  • Loading branch information...
1 parent 8c6e5ee commit 245efedbc3b23ba15c69e77599b14cbf203a2341 @dchelimsky dchelimsky committed Apr 11, 2010
View
1 .rspec
@@ -0,0 +1 @@
+-Ispec
@@ -92,6 +92,10 @@ def full_backtrace=(bool)
@options[:backtrace_clean_patterns].clear
end
+ def libs=(libs)
+ libs.map {|lib| $LOAD_PATH.unshift lib}
+ end
+
def debug=(bool)
return unless bool
begin
@@ -60,23 +60,41 @@ def parser(options)
OptionParser.new do |parser|
parser.banner = "Usage: rspec [options] [files or directories]"
+ parser.on('-b', '--backtrace', 'Enable full backtrace') do |o|
+ options[:full_backtrace] = true
+ end
+
parser.on('-c', '--[no-]color', '--[no-]colour', 'Enable color in the output') do |o|
options[:color_enabled] = o
end
+ parser.on('-d', '--debug', 'Enable debugging') do |o|
+ options[:debug] = true
+ end
+
+ parser.on('-e', '--example PATTERN', "Run examples whose full descriptions match this pattern",
+ "(PATTERN is compiled into a Ruby regular expression)") do |o|
+ options[:full_description] = /#{o}/
+ end
+
parser.on('-f', '--formatter FORMATTER', 'Choose a formatter',
' [p]rogress (default - dots)',
' [d]ocumentation (group and example names)') do |o|
options[:formatter] = o
end
- parser.on('-l', '--line_number LINE', 'Specify the line number of a single example to run') do |o|
- options[:line_number] = o
+ parser.on_tail('-h', '--help', "You're looking at it.") do
+ puts parser
+ exit
end
- parser.on('-e', '--example PATTERN', "Run examples whose full descriptions match this pattern",
- "(PATTERN is compiled into a Ruby regular expression)") do |o|
- options[:full_description] = /#{o}/
+ parser.on('-I DIRECTORY', 'specify $LOAD_PATH directory (may be used more than once)') do |dir|
+ options[:libs] ||= []
+ options[:libs] << dir
+ end
+
+ parser.on('-l', '--line_number LINE', 'Specify the line number of a single example to run') do |o|
+ options[:line_number] = o
end
parser.on('-o', '--options PATH', 'Read configuration options from a file path. (Defaults to spec/spec.parser)') do |o|
@@ -86,19 +104,6 @@ def parser(options)
parser.on('-p', '--profile', 'Enable profiling of examples with output of the top 10 slowest examples') do |o|
options[:profile_examples] = o
end
-
- parser.on('-b', '--backtrace', 'Enable full backtrace') do |o|
- options[:full_backtrace] = true
- end
-
- parser.on('-d', '--debug', 'Enable debugging') do |o|
- options[:debug] = true
- end
-
- parser.on_tail('-h', '--help', "You're looking at it.") do
- puts parser
- exit
- end
end
end
end
View
@@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.files = [
".document",
".gitignore",
+ ".rspec",
".treasure_map.rb",
"License.txt",
"README.markdown",
@@ -133,7 +134,7 @@ Gem::Specification.new do |s|
"script/console",
"spec/autotest/failed_results_re_spec.rb",
"spec/autotest/rspec_spec.rb",
- "spec/rspec/core/config_options_spec.rb",
+ "spec/rspec/core/configuration_options_spec.rb",
"spec/rspec/core/configuration_spec.rb",
"spec/rspec/core/example_group_spec.rb",
"spec/rspec/core/example_spec.rb",
@@ -181,7 +182,7 @@ Gem::Specification.new do |s|
s.test_files = [
"spec/autotest/failed_results_re_spec.rb",
"spec/autotest/rspec_spec.rb",
- "spec/rspec/core/config_options_spec.rb",
+ "spec/rspec/core/configuration_options_spec.rb",
"spec/rspec/core/configuration_spec.rb",
"spec/rspec/core/example_group_spec.rb",
"spec/rspec/core/example_spec.rb",
@@ -19,6 +19,15 @@ def options_from_args(*args)
end
end
+ describe 'load path additions' do
+ example "-I parses like it does w/ ruby command" do
+ options_from_args('-I', 'a_dir').should include(:libs => ['a_dir'])
+ end
+ example "-I can be used more than once" do
+ options_from_args('-I', 'dir_1', '-I', 'dir_2').should include(:libs => ['dir_1','dir_2'])
+ end
+ end
+
describe 'formatter' do
example '-f or --formatter with an argument should parse' do
options_from_args('--formatter', 'd').should include(:formatter => 'd')
@@ -4,7 +4,7 @@ module Rspec::Core
describe Configuration do
- let(:config) { Configuration.new }
+ let(:config) { subject }
describe "#mock_framework_class" do
before(:each) do
@@ -237,11 +237,11 @@ def that_thing
end
end
-
context "transactional examples" do
it "defaults to use transactional examples" do
- config.use_transactional_examples?.should be_true
+ config.use_transactional_examples?.should be_true
end
+
describe "#use_transactional_examples=" do
it "remembers that I don't want transactional exmaples" do
config.use_transactional_examples = false
@@ -250,6 +250,13 @@ def that_thing
end
end
+ describe "libs=" do
+ it "adds directories to the LOAD_PATH" do
+ $LOAD_PATH.should_receive(:unshift).with("a/dir")
+ config.libs = ["a/dir"]
+ end
+ end
+
end
end

0 comments on commit 245efed

Please sign in to comment.