]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/runner/command_line_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / runner / command_line_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
3 module Spec
4   module Runner
5     describe CommandLine, ".run" do
6       it_should_behave_like "sandboxed rspec_options"
7       attr_reader :options, :err, :out
8       before do
9         @err = options.error_stream
10         @out = options.output_stream
11       end
12
13       it "should run directory" do
14         file = File.dirname(__FILE__) + '/../../../examples/pure'
15         Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
16
17         @out.rewind
18         @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
19       end
20
21       it "should run file" do
22         file = File.dirname(__FILE__) + '/../../../failing_examples/predicate_example.rb'
23         Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
24
25         @out.rewind
26         @out.read.should =~ /2 examples, 1 failure/n
27       end
28
29       it "should raise when file does not exist" do
30         file = File.dirname(__FILE__) + '/doesntexist'
31
32         lambda {
33           Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
34         }.should raise_error
35       end
36
37       it "should return true when in --generate-options mode" do
38         Spec::Runner::CommandLine.run(
39           OptionParser.parse(['--generate-options', '/dev/null'], @err, @out)
40         ).should be_true
41       end
42
43       it "should dump even if Interrupt exception is occurred" do
44         example_group = Class.new(::Spec::Example::ExampleGroup) do
45           describe("example_group")
46           it "no error" do
47           end
48
49           it "should interrupt" do
50             raise Interrupt, "I'm interrupting"
51           end
52         end
53
54         options = ::Spec::Runner::Options.new(@err, @out)
55         ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
56         options.reporter.should_receive(:dump)
57         options.add_example_group(example_group)
58
59         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
60       end
61
62       it "should heckle when options have heckle_runner" do
63         example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
64           it "no error" do
65           end
66         end
67         options = ::Spec::Runner::Options.new(@err, @out)
68         ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
69         options.add_example_group example_group
70
71         heckle_runner = mock("heckle_runner")
72         heckle_runner.should_receive(:heckle_with)
73         $rspec_mocks.__send__(:mocks).delete(heckle_runner)
74
75         options.heckle_runner = heckle_runner
76         options.add_example_group(example_group)
77
78         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
79         heckle_runner.rspec_verify
80       end
81
82       it "should run examples backwards if options.reverse is true" do
83         options = ::Spec::Runner::Options.new(@err, @out)
84         ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
85         options.reverse = true
86
87         b1 = Class.new(Spec::Example::ExampleGroup)
88         b2 = Class.new(Spec::Example::ExampleGroup)
89
90         b2.should_receive(:run).ordered
91         b1.should_receive(:run).ordered
92
93         options.add_example_group(b1)
94         options.add_example_group(b2)
95
96         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
97       end
98
99       it "should pass its ExampleGroup to the reporter" do
100         example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
101           it "should" do
102           end
103         end
104         options = ::Spec::Runner::Options.new(@err, @out)
105         options.add_example_group(example_group)
106
107         ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
108         options.reporter.should_receive(:add_example_group).with(example_group)
109         
110         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
111       end
112
113       it "runs only selected Examples when options.examples is set" do
114         options = ::Spec::Runner::Options.new(@err, @out)
115         ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
116
117         options.examples << "example_group should"
118         should_has_run = false
119         should_not_has_run = false
120         example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
121           it "should" do
122             should_has_run = true
123           end
124           it "should not" do
125             should_not_has_run = true
126           end
127         end
128
129         options.reporter.should_receive(:add_example_group).with(example_group)
130
131         options.add_example_group example_group
132         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
133
134         should_has_run.should be_true
135         should_not_has_run.should be_false
136       end
137
138       it "sets Spec.run to true" do
139         ::Spec.run = false
140         ::Spec.should_not be_run
141         Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
142         ::Spec.should be_run
143       end
144     end
145   end
146 end