PageRenderTime 22ms CodeModel.GetById 1ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 1ms

/vendor/bundle/jruby/2.1/gems/rspec-core-2.14.8/spec/rspec/core/formatters/documentation_formatter_spec.rb

https://github.com/delowong/logstash
Ruby | 88 lines | 70 code | 18 blank | 0 comment | 1 complexity | beb887035e26c74404f7e74460566e83 MD5 | raw file
 1require 'spec_helper'
 2require 'rspec/core/formatters/documentation_formatter'
 3
 4module RSpec::Core::Formatters
 5  describe DocumentationFormatter do
 6    it "numbers the failures" do
 7
 8      examples = [
 9        double("example 1",
10               :description => "first example",
11               :execution_result => {:status => 'failed', :exception => Exception.new }
12              ),
13        double("example 2",
14               :description => "second example",
15               :execution_result => {:status => 'failed', :exception => Exception.new }
16              )
17      ]
18
19      output = StringIO.new
20      RSpec.configuration.stub(:color_enabled?) { false }
21
22      formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
23
24      examples.each {|e| formatter.example_failed(e) }
25
26      expect(output.string).to match(/first example \(FAILED - 1\)/m)
27      expect(output.string).to match(/second example \(FAILED - 2\)/m)
28    end
29
30    it "represents nested group using hierarchy tree" do
31      output = StringIO.new
32      RSpec.configuration.stub(:color_enabled?) { false }
33
34      formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
35
36      group = RSpec::Core::ExampleGroup.describe("root")
37      context1 = group.describe("context 1")
38      context1.example("nested example 1.1"){}
39      context1.example("nested example 1.2"){}
40
41      context11 = context1.describe("context 1.1")
42      context11.example("nested example 1.1.1"){}
43      context11.example("nested example 1.1.2"){}
44
45      context2 = group.describe("context 2")
46      context2.example("nested example 2.1"){}
47      context2.example("nested example 2.2"){}
48
49      group.run(RSpec::Core::Reporter.new(formatter))
50
51      expect(output.string).to eql("
52root
53  context 1
54    nested example 1.1
55    nested example 1.2
56    context 1.1
57      nested example 1.1.1
58      nested example 1.1.2
59  context 2
60    nested example 2.1
61    nested example 2.2
62")
63    end
64
65    it "strips whitespace for each row" do
66      output = StringIO.new
67      RSpec.configuration.stub(:color_enabled?) { false }
68
69      formatter = RSpec::Core::Formatters::DocumentationFormatter.new(output)
70
71      group = RSpec::Core::ExampleGroup.describe(" root ")
72      context1 = group.describe(" nested ")
73      context1.example(" example 1 ") {}
74      context1.example(" example 2 ", :pending => true){}
75      context1.example(" example 3 ") { fail }
76
77      group.run(RSpec::Core::Reporter.new(formatter))
78
79      expect(output.string).to eql("
80root
81  nested
82    example 1
83    example 2 (PENDING: No reason given)
84    example 3 (FAILED - 1)
85")
86    end
87  end
88end