changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/formatter/specdoc_formatter_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../../spec_helper.rb'
2require 'spec/runner/formatter/specdoc_formatter'
3
4module Spec
5 module Runner
6 module Formatter
7 describe SpecdocFormatter do
8 it_should_behave_like "sandboxed rspec_options"
9 attr_reader :io, :options, :formatter, :example_group
10 before(:each) do
11 @io = StringIO.new
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")
16 end
17
18 describe "where ExampleGroup has no superclasss with a description" do
19 before do
20 formatter.add_example_group(example_group)
21 end
22
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")
26 end
27
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")
31 end
32
33 it "should push ExampleGroup name" do
34 io.string.should eql("\nExampleGroup\n")
35 end
36
37 it "when having an error, should push failing spec name and failure number" do
38 formatter.example_failed(
39 example_group.it("spec"),
40 98,
41 Reporter::Failure.new("c s", RuntimeError.new)
42 )
43 io.string.should have_example_group_output("- spec (ERROR - 98)\n")
44 end
45
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"),
49 98,
50 Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
51 )
52 io.string.should have_example_group_output("- spec (FAILED - 98)\n")
53 end
54
55 it "should push nothing on start" do
56 formatter.start(5)
57 io.string.should have_example_group_output("")
58 end
59
60 it "should push nothing on start dump" do
61 formatter.start_dump
62 io.string.should have_example_group_output("")
63 end
64
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")
68 end
69
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")
73 end
74
75 it "should dump pending" do
76 formatter.example_pending('example_group', ExampleGroup.new("example"), 'reason')
77 io.rewind
78 formatter.dump_pending
79 io.string.should =~ /Pending\:\nexample_group example \(reason\)\n/
80 end
81
82 def have_example_group_output(expected_output)
83 expected = "\nExampleGroup\n#{expected_output}"
84 ::Spec::Matchers::SimpleMatcher.new(expected) do |actual|
85 actual == expected
86 end
87 end
88 end
89
90 describe "where ExampleGroup has two superclasses with a description" do
91 attr_reader :child_example_group, :grand_child_example_group
92 before do
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)
96 end
97
98 specify "when having an error, should push failing spec name and failure number" do
99 formatter.example_failed(
100 example_group.it("spec"),
101 98,
102 Reporter::Failure.new("c s", RuntimeError.new)
103 )
104 io.string.should have_nested_example_group_output("- spec (ERROR - 98)\n")
105 end
106
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"),
110 98,
111 Reporter::Failure.new("c s", Spec::Expectations::ExpectationNotMetError.new)
112 )
113 io.string.should have_nested_example_group_output("- spec (FAILED - 98)\n")
114 end
115
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
120 end
121 end
122 end
123 end
124 end
125 end
126end