Permalink
Browse files

Better support for add_formatter in configuration.

- create the formatter's output file in config instead of opt parser.
  • Loading branch information...
1 parent 83262db commit fbc9bfdf67701a6b2136c70141f396e3f179af98 @dchelimsky dchelimsky committed Jan 1, 2011
@@ -269,7 +269,7 @@ def add_formatter(formatter_to_use, output=nil)
custom_formatter(formatter_to_use) ||
(raise ArgumentError, "Formatter '#{formatter_to_use}' unknown - maybe you meant 'documentation' or 'progress'?.")
- formatters << formatter_class.new(output || self.output)
+ formatters << formatter_class.new(output ? File.new(output, 'w') : self.output)
end
alias_method :formatter=, :add_formatter
@@ -58,7 +58,7 @@ def parser(options)
'no format is specified.'
) do |o|
options[:formatters] ||= [['progress']]
- options[:formatters].last << File.open(o,'w')
+ options[:formatters].last << o
end
parser.on_tail('-h', '--help', "You're looking at it.") do
@@ -410,11 +410,11 @@ def that_thing
end
context "with a 2nd arg defining the output" do
- it "sets that as the output" do
- file = File.join(Dir.tmpdir, 'output.txt')
- config.add_formatter('doc', file)
- config.formatters.first.should be_a(RSpec::Core::Formatters::DocumentationFormatter)
- config.formatters.first.output.should eq(file)
+ it "creates a file at that path and sets it as the output" do
+ path = File.join(Dir.tmpdir, 'output.txt')
+ config.add_formatter('doc', path)
+ config.formatters.first.output.should be_a(File)
+ config.formatters.first.output.path.should eq(path)
end
end
@@ -46,25 +46,25 @@ module RSpec::Core
%w[--out -o].each do |option|
describe option do
- let(:options) { Parser.parse!([option, 'foo.txt']) }
+ let(:options) { Parser.parse!([option, 'out.txt']) }
it "sets the output stream for the formatter" do
- options[:formatters].last.should eq(['progress', output_file])
+ options[:formatters].last.should eq(['progress', 'out.txt'])
end
context "with multiple formatters" do
context "after last formatter" do
it "sets the output stream for the last formatter" do
- options = Parser.parse!(['-f', 'progress', '-f', 'doc', option, 'foo.txt'])
+ options = Parser.parse!(['-f', 'progress', '-f', 'doc', option, 'out.txt'])
options[:formatters][0].should eq(['progress'])
- options[:formatters][1].should eq(['doc', output_file])
+ options[:formatters][1].should eq(['doc', 'out.txt'])
end
end
context "after first formatter" do
it "sets the output stream for the first formatter" do
- options = Parser.parse!(['-f', 'progress', option, 'foo.txt', '-f', 'doc'])
- options[:formatters][0].should eq(['progress', output_file])
+ options = Parser.parse!(['-f', 'progress', option, 'out.txt', '-f', 'doc'])
+ options[:formatters][0].should eq(['progress', 'out.txt'])
options[:formatters][1].should eq(['doc'])
end
end

0 comments on commit fbc9bfd

Please sign in to comment.