require File.dirname(__FILE__) + '/../../spec_helper' require 'mspec/guards/guard' require 'mspec/runner/formatters/html' require 'mspec/runner/mspec' require 'mspec/runner/state' describe HtmlFormatter do before :each do @formatter = HtmlFormatter.new end it "responds to #register by registering itself with MSpec for appropriate actions" do MSpec.stub!(:register) MSpec.should_receive(:register).with(:start, @formatter) MSpec.should_receive(:register).with(:enter, @formatter) MSpec.should_receive(:register).with(:leave, @formatter) @formatter.register end end describe HtmlFormatter, "#start" do before :each do $stdout = @out = IOStub.new @formatter = HtmlFormatter.new end after :each do $stdout = STDOUT end it "prints the HTML head" do @formatter.start ruby_name = RUBY_NAME ruby_name.should =~ /^ruby/ @out.should == %[
describe
\ndescribe it ERROR
] end it "prints a backtrace for an exception" do @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method") @state.exceptions << ["msg", @exception] @formatter.instance_variable_set :@states, [@state] @formatter.finish @out.should =~ %r[.*path/to/some/file.rb:35:in method.*]m end it "prints a summary of elapsed time" do @timer.should_receive(:format).and_return("Finished in 2.0 seconds") @formatter.finish @out.should =~ %r[
Finished in 2.0 seconds
\n] end it "prints a tally of counts" do @tally.should_receive(:format).and_return("1 example, 0 failures") @formatter.finish @out.should =~ %r[1 example, 0 failures
] end it "prints errors, backtraces, elapsed time, and tallies" do @state.exceptions << ["msg", @exception] @formatter.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method") @timer.should_receive(:format).and_return("Finished in 2.0 seconds") @tally.should_receive(:format).and_return("1 example, 1 failures") @formatter.instance_variable_set :@states, [@state] @formatter.finish @out.should == %[describe it ERROR
MSpecExampleError: broken
path/to/some/file.rb:35:in method
Finished in 2.0 seconds
1 example, 1 failures
] end end