Skip to content

Commit

Permalink
add -I config option
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Apr 11, 2010
1 parent 8c6e5ee commit 245efed
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 23 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Ispec
4 changes: 4 additions & 0 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 23 additions & 18 deletions lib/rspec/core/configuration_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions rspec-core.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |s|
s.files = [
".document",
".gitignore",
".rspec",
".treasure_map.rb",
"License.txt",
"README.markdown",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions spec/rspec/core/configuration_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
13 changes: 10 additions & 3 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.