changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/runner/command_line_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'
2
3module 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,"-p","**/*.rb"], @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 # NOTE - this used to say /dev/null but jruby hangs on that for some reason
39 Spec::Runner::CommandLine.run(
40 OptionParser.parse(['--generate-options', '/tmp/foo'], @err, @out)
41 ).should be_true
42 end
43
44 it "should dump even if Interrupt exception is occurred" do
45 example_group = Class.new(::Spec::Example::ExampleGroup) do
46 describe("example_group")
47 it "no error" do
48 end
49
50 it "should interrupt" do
51 raise Interrupt, "I'm interrupting"
52 end
53 end
54
55 options = ::Spec::Runner::Options.new(@err, @out)
56 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
57 options.reporter.should_receive(:dump)
58 options.add_example_group(example_group)
59
60 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
61 end
62
63 it "should heckle when options have heckle_runner" do
64 example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
65 it "no error" do
66 end
67 end
68 options = ::Spec::Runner::Options.new(@err, @out)
69 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
70 options.add_example_group example_group
71
72 heckle_runner = mock("heckle_runner")
73 heckle_runner.should_receive(:heckle_with)
74 $rspec_mocks.__send__(:mocks).delete(heckle_runner)
75
76 options.heckle_runner = heckle_runner
77 options.add_example_group(example_group)
78
79 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
80 heckle_runner.rspec_verify
81 end
82
83 it "should run examples backwards if options.reverse is true" do
84 options = ::Spec::Runner::Options.new(@err, @out)
85 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
86 options.reverse = true
87
88 b1 = Class.new(Spec::Example::ExampleGroup)
89 b2 = Class.new(Spec::Example::ExampleGroup)
90
91 b2.should_receive(:run).ordered
92 b1.should_receive(:run).ordered
93
94 options.add_example_group(b1)
95 options.add_example_group(b2)
96
97 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
98 end
99
100 it "should pass its ExampleGroup to the reporter" do
101 example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
102 it "should" do
103 end
104 end
105 options = ::Spec::Runner::Options.new(@err, @out)
106 options.add_example_group(example_group)
107
108 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
109 options.reporter.should_receive(:add_example_group).with(example_group)
110
111 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
112 end
113
114 it "runs only selected Examples when options.examples is set" do
115 options = ::Spec::Runner::Options.new(@err, @out)
116 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
117
118 options.examples << "example_group should"
119 should_has_run = false
120 should_not_has_run = false
121 example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
122 it "should" do
123 should_has_run = true
124 end
125 it "should not" do
126 should_not_has_run = true
127 end
128 end
129
130 options.reporter.should_receive(:add_example_group).with(example_group)
131
132 options.add_example_group example_group
133 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
134
135 should_has_run.should be_true
136 should_not_has_run.should be_false
137 end
138
139 it "sets Spec.run to true" do
140 ::Spec.run = false
141 ::Spec.should_not be_run
142 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
143 ::Spec.should be_run
144 end
145 end
146 end
147end