summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/formatters/describe_spec.rb
blob: 415ced71fbed2912c75f766108aeddf46816d7ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/describe'
require 'mspec/runner/example'

describe DescribeFormatter, "#finish" do
  before :each do
    MSpec.stub(:register)
    MSpec.stub(:unregister)

    @timer = double("timer").as_null_object
    TimerAction.stub(:new).and_return(@timer)
    @timer.stub(:format).and_return("Finished in 2.0 seconds")

    $stdout = @out = IOStub.new
    context = ContextState.new "Class#method"
    @state = ExampleState.new(context, "runs")

    @formatter = DescribeFormatter.new
    @formatter.register

    @tally = @formatter.tally
    @counter = @tally.counter

    @counter.files!
    @counter.examples!
    @counter.expectations! 2
  end

  after :each do
    $stdout = STDOUT
  end

  it "prints a summary of elapsed time" do
    @formatter.finish
    @out.should =~ /^Finished in 2.0 seconds$/
  end

  it "prints a tally of counts" do
    @formatter.finish
    @out.should =~ /^1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged$/
  end

  it "does not print exceptions" do
    @formatter.finish
    @out.should == %[

Finished in 2.0 seconds

1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
]
  end

  it "prints a summary of failures and errors for each describe block" do
    exc = ExceptionState.new @state, nil, MSpecExampleError.new("broken")
    exc.stub(:backtrace).and_return("path/to/some/file.rb:35:in method")
    @formatter.exception exc
    @formatter.finish
    @out.should == %[

Class#method                             0 failures, 1 error

Finished in 2.0 seconds

1 file, 1 example, 2 expectations, 0 failures, 0 errors, 0 tagged
]
  end
end