Skip to content

Commit

Permalink
Run specs in spec directory (if exists) by default
Browse files Browse the repository at this point in the history
Closes #14
Closes #12
  • Loading branch information
Ben Rady authored and dchelimsky committed May 8, 2010
1 parent 98909a2 commit bcea9dc
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rspec/core/configuration_options.rb
Expand Up @@ -23,6 +23,7 @@ def apply_to(config)


def parse_command_line_options def parse_command_line_options
@options = Parser.parse!(@args) @options = Parser.parse!(@args)
@args << 'spec' if @args.empty? and FileTest.directory? 'spec'
@options[:files_or_directories_to_run] = @args @options[:files_or_directories_to_run] = @args
@options @options
end end
Expand Down
12 changes: 11 additions & 1 deletion lib/rspec/core/shared_example_group.rb
Expand Up @@ -9,11 +9,17 @@ def share_examples_for(name, &block)


def share_as(name, &block) def share_as(name, &block)
if Object.const_defined?(name) 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 end


mod = Module.new do mod = Module.new do
@shared_block = block @shared_block = block
@caller_line = caller.last

def self.created_from_caller(other_caller)
@caller_line == other_caller.last
end


def self.included(kls) def self.included(kls)
kls.module_eval(&@shared_block) kls.module_eval(&@shared_block)
Expand All @@ -28,6 +34,10 @@ def self.included(kls)


private 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) def ensure_shared_example_group_name_not_taken(name)
if Rspec::Core.world.shared_example_groups.has_key?(name) if Rspec::Core.world.shared_example_groups.has_key?(name)
raise ArgumentError.new("Shared example group '#{name}' already exists") raise ArgumentError.new("Shared example group '#{name}' already exists")
Expand Down
15 changes: 15 additions & 0 deletions spec/rspec/core/configuration_options_spec.rb
Expand Up @@ -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"]) 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


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 end


describe "--backtrace (-b)" do describe "--backtrace (-b)" do
Expand Down

0 comments on commit bcea9dc

Please sign in to comment.