summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/runner/formatters/multi_spec.rb
blob: 2d13c0583693a3f4c8b656204a8d4bc867f3cc64 (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
68
require File.dirname(__FILE__) + '/../../spec_helper'
require 'mspec/runner/formatters/dotted'
require 'mspec/runner/formatters/multi'
require 'mspec/runner/example'
require 'yaml'

RSpec.describe MultiFormatter, "#aggregate_results" do
  before :each do
    @stdout, $stdout = $stdout, IOStub.new

    @file = double("file").as_null_object

    allow(File).to receive(:delete)
    allow(File).to receive(:read)

    @hash = { "files"=>1, "examples"=>1, "expectations"=>2, "failures"=>0, "errors"=>0 }
    allow(YAML).to receive(:load).and_return(@hash)

    @formatter = DottedFormatter.new.extend(MultiFormatter)
    allow(@formatter.timer).to receive(:format).and_return("Finished in 42 seconds")
  end

  after :each do
    $stdout = @stdout
  end

  it "outputs a summary without errors" do
    @formatter.aggregate_results(["a", "b"])
    @formatter.finish
    expect($stdout).to eq(%[

Finished in 42 seconds

2 files, 2 examples, 4 expectations, 0 failures, 0 errors, 0 tagged
])
  end

  it "outputs a summary with errors" do
    @hash["exceptions"] = [
      "Some#method works real good FAILED\nExpected real good\n to equal fail\n\nfoo.rb:1\nfoo.rb:2",
      "Some#method never fails ERROR\nExpected 5\n to equal 3\n\nfoo.rb:1\nfoo.rb:2"
    ]
    @formatter.aggregate_results(["a"])
    @formatter.finish
    expect($stdout).to eq(%[

1)
Some#method works real good FAILED
Expected real good
 to equal fail

foo.rb:1
foo.rb:2

2)
Some#method never fails ERROR
Expected 5
 to equal 3

foo.rb:1
foo.rb:2

Finished in 42 seconds

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