1 require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2 require 'spec/runner/formatter/specdoc_formatter'
7 describe SpecdocFormatter do
8 it_should_behave_like "sandboxed rspec_options"
9 attr_reader :io, :options, :formatter, :example_group
12 options.stub!(:dry_run).and_return(false)
13 options.stub!(:colour).and_return(false)
14 @formatter = SpecdocFormatter.new(options, io)
15 @example_group = Class.new(::Spec::Example::ExampleGroup).describe("ExampleGroup")
18 describe "where ExampleGroup has no superclasss with a description" do
20 formatter.add_example_group(example_group)
23 it "should produce standard summary without pending when pending has a 0 count" do
24 formatter.dump_summary(3, 2, 1, 0)
25 io.string.should have_example_group_output("\nFinished in 3 seconds\n\n2 examples, 1 failure\n")
28 it "should produce standard summary" do
29 formatter.dump_summary(3, 2, 1, 4)
30 io.string.should have_example_group_output("\nFinished in 3 seconds\n\n2 examples, 1 failure, 4 pending\n")
33 it "should push ExampleGroup name" do
34 io.string.should eql("\nExampleGroup\n")
37 it "when having an error, should push failing spec name and failure number" do
38 formatter.example_failed(
39 example_group.it("spec"),
41 Reporter::Failure.new("c s", RuntimeError.new)
43 io.string.should have_example_group_output("- spec (ERROR - 98)\n")
46 it "when having an expectation failure, should push failing spec name and failure number" do
47 formatter.example_failed(
48 example_group.it("spec"),
50 Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
52 io.string.should have_example_group_output("- spec (FAILED - 98)\n")
55 it "should push nothing on start" do
57 io.string.should have_example_group_output("")
60 it "should push nothing on start dump" do
62 io.string.should have_example_group_output("")
65 it "should push passing spec name" do
66 formatter.example_passed(example_group.it("spec"))
67 io.string.should have_example_group_output("- spec\n")
70 it "should push pending example name and message" do
71 formatter.example_pending('example_group', ExampleGroup.new("example"), 'reason')
72 io.string.should have_example_group_output("- example (PENDING: reason)\n")
75 it "should dump pending" do
76 formatter.example_pending('example_group', ExampleGroup.new("example"), 'reason')
78 formatter.dump_pending
79 io.string.should =~ /Pending\:\nexample_group example \(reason\)\n/
82 def have_example_group_output(expected_output)
83 expected = "\nExampleGroup\n#{expected_output}"
84 ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
90 describe "where ExampleGroup has two superclasses with a description" do
91 attr_reader :child_example_group, :grand_child_example_group
93 @child_example_group = Class.new(example_group).describe("Child ExampleGroup")
94 @grand_child_example_group = Class.new(child_example_group).describe("GrandChild ExampleGroup")
95 formatter.add_example_group(grand_child_example_group)
98 specify "when having an error, should push failing spec name and failure number" do
99 formatter.example_failed(
100 example_group.it("spec"),
102 Reporter::Failure.new("c s", RuntimeError.new)
104 io.string.should have_nested_example_group_output("- spec (ERROR - 98)\n")
107 specify "when having an expectation failure, should push failing spec name and failure number" do
108 formatter.example_failed(
109 example_group.it("spec"),
111 Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
113 io.string.should have_nested_example_group_output("- spec (FAILED - 98)\n")
116 def have_nested_example_group_output(expected_output)
117 expected_full_output = "\nExampleGroup Child ExampleGroup GrandChild ExampleGroup\n#{expected_output}"
118 ::Spec::Matchers::SimpleMatcher.new(expected_full_output) do |actual|
119 actual == expected_full_output