Permalink
Browse files

Run specs in spec directory (if exists) by default

Closes #14
Closes #12
  • Loading branch information...
1 parent 98909a2 commit bcea9dc3c6468b8eb62c50ab9e9873c5acf73172 Ben Rady committed with dchelimsky May 7, 2010
@@ -23,6 +23,7 @@ def apply_to(config)
def parse_command_line_options
@options = Parser.parse!(@args)
+ @args << 'spec' if @args.empty? and FileTest.directory? 'spec'
@options[:files_or_directories_to_run] = @args
@options
end
@@ -9,11 +9,17 @@ def share_examples_for(name, &block)
def share_as(name, &block)
if Object.const_defined?(name)
- raise NameError, "The first argument (#{name}) to share_as must be a legal name for a constant not already in use."
+ mod = Object.const_get(name)
+ raise_name_error unless mod.created_from_caller(caller)
end
mod = Module.new do
@shared_block = block
+ @caller_line = caller.last
+
+ def self.created_from_caller(other_caller)
+ @caller_line == other_caller.last
+ end
def self.included(kls)
kls.module_eval(&@shared_block)
@@ -28,6 +34,10 @@ def self.included(kls)
private
+ def raise_name_error
+ raise NameError, "The first argument (#{name}) to share_as must be a legal name for a constant not already in use."
+ end
+
def ensure_shared_example_group_name_not_taken(name)
if Rspec::Core.world.shared_example_groups.has_key?(name)
raise ArgumentError.new("Shared example group '#{name}' already exists")
@@ -77,6 +77,21 @@ def options_from_args(*args)
options_from_args("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
end
+ it "assumes a 'spec' directory if it exists" do
+ FileTest.stub(:directory?).with("spec").and_return true
+ options_from_args().should include(:files_or_directories_to_run => ["spec"])
+ end
+
+ it "provides no files or directories if spec directory does not exist" do
+ FileTest.stub(:directory?).with("spec").and_return false
+ options_from_args().should include(:files_or_directories_to_run => [])
+ end
+
+ it "parses dir and files from 'spec/file1_spec.rb, spec/file2_spec.rb'" do
+ options_from_args("dir", "spec/file1_spec.rb", "spec/file2_spec.rb").should include(:files_or_directories_to_run => ["dir", "spec/file1_spec.rb", "spec/file2_spec.rb"])
+
+ end
+
end
describe "--backtrace (-b)" do

0 comments on commit bcea9dc

Please sign in to comment.