Skip to content

Commit

Permalink
Make --formatter option work with fully qualified classes names
Browse files Browse the repository at this point in the history
Closes rspec#48.
  • Loading branch information
iromeo authored and dchelimsky committed Jun 26, 2010
1 parent d6964f7 commit ae1f718
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/rspec/core/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ def full_description=(description)
end

def formatter=(formatter_to_use)
if string_const?(formatter_to_use) && Object.const_defined?(formatter_to_use)
formatter_class = Object.const_get(formatter_to_use)
if string_const?(formatter_to_use) && (class_name = eval(formatter_to_use)).is_a?(Class)
formatter_class = class_name
elsif formatter_to_use.is_a?(Class)
formatter_class = formatter_to_use
else
Expand Down
16 changes: 11 additions & 5 deletions spec/rspec/core/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,17 @@ def that_thing
end

it "sets a formatter based on its class name" do
Object.const_set("CustomFormatter",Class.new(Formatters::BaseFormatter))
Object.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
config.formatter = "CustomFormatter"
config.formatter.should be_an_instance_of(CustomFormatter)
end


it "sets a formatter based on its class fully qualified name" do
RSpec.const_set("CustomFormatter", Class.new(Formatters::BaseFormatter))
config.formatter = "RSpec::CustomFormatter"
config.formatter.should be_an_instance_of(RSpec::CustomFormatter)
end

it "raises ArgumentError if formatter is unknown" do
lambda { config.formatter = :progresss }.should raise_error(ArgumentError)
end
Expand All @@ -277,13 +283,13 @@ def that_thing
config.line_number = '37'
config.filter.should == {:line_number => 37}
end

it "overrides :focused" do
config.filter_run :focused => true
config.line_number = '37'
config.filter.should == {:line_number => 37}
end

it "prevents :focused" do
config.line_number = '37'
config.filter_run :focused => true
Expand Down Expand Up @@ -319,7 +325,7 @@ def that_thing
config.debug = false
end
end

describe "#output=" do
it "sets the output" do
output = mock("output")
Expand Down

0 comments on commit ae1f718

Please sign in to comment.