1 require File.dirname(__FILE__) + '/../../spec_helper'
2 require 'mspec/runner/formatters/yaml'
3 require 'mspec/runner/example'
5 describe YamlFormatter, "#initialize" do
6 it "permits zero arguments" do
10 it "accepts one argument" do
15 describe YamlFormatter, "#print" do
19 File.stub!(:open).and_return(@out)
20 @formatter = YamlFormatter.new "some/file"
27 it "writes to $stdout if #switch has not been called" do
28 @formatter.print "begonias"
29 $stdout.should == "begonias"
33 it "writes to the file passed to #initialize once #switch has been called" do
35 @formatter.print "begonias"
37 @out.should == "begonias"
40 it "writes to $stdout once #switch is called if no file was passed to #initialize" do
41 formatter = YamlFormatter.new
43 formatter.print "begonias"
44 $stdout.should == "begonias"
49 describe YamlFormatter, "#finish" do
51 @tally = mock("tally", :null_object => true)
52 @counter = mock("counter", :null_object => true)
53 @tally.stub!(:counter).and_return(@counter)
54 TallyAction.stub!(:new).and_return(@tally)
56 @timer = mock("timer", :null_object => true)
57 TimerAction.stub!(:new).and_return(@timer)
60 context = ContextState.new "describe"
61 @state = ExampleState.new(context, "it")
63 @formatter = YamlFormatter.new
64 @formatter.stub!(:backtrace).and_return("")
65 MSpec.stub!(:register)
68 exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
69 exc.stub!(:backtrace).and_return("path/to/some/file.rb:35:in method")
70 @formatter.exception exc
71 @formatter.after @state
79 @formatter.should_receive(:switch)
83 it "outputs a failure message and backtrace" do
85 $stdout.should =~ /describe it ERROR/
86 $stdout.should =~ /MSpecExampleError: broken\\n/
87 $stdout.should =~ %r[path/to/some/file.rb:35:in method]
90 it "outputs an elapsed time" do
91 @timer.should_receive(:elapsed).and_return(4.2)
93 $stdout.should =~ /time: 4.2/
96 it "outputs a file count" do
97 @counter.should_receive(:files).and_return(3)
99 $stdout.should =~ /files: 3/
102 it "outputs an example count" do
103 @counter.should_receive(:examples).and_return(3)
105 $stdout.should =~ /examples: 3/
108 it "outputs an expectation count" do
109 @counter.should_receive(:expectations).and_return(9)
111 $stdout.should =~ /expectations: 9/
114 it "outputs a failure count" do
115 @counter.should_receive(:failures).and_return(2)
117 $stdout.should =~ /failures: 2/
120 it "outputs an error count" do
121 @counter.should_receive(:errors).and_return(1)
123 $stdout.should =~ /errors: 1/