1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 describe CommandLine, ".run" do
6 it_should_behave_like "sandboxed rspec_options"
7 attr_reader :options, :err, :out
9 @err = options.error_stream
10 @out = options.output_stream
13 it "should run directory" do
14 file = File.dirname(__FILE__) + '/../../../examples/pure'
15 Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
18 @out.read.should =~ /\d+ examples, 0 failures, 3 pending/n
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))
26 @out.read.should =~ /2 examples, 1 failure/n
29 it "should raise when file does not exist" do
30 file = File.dirname(__FILE__) + '/doesntexist'
33 Spec::Runner::CommandLine.run(OptionParser.parse([file], @err, @out))
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)
43 it "should dump even if Interrupt exception is occurred" do
44 example_group = Class.new(::Spec::Example::ExampleGroup) do
45 describe("example_group")
49 it "should interrupt" do
50 raise Interrupt, "I'm interrupting"
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)
59 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
62 it "should heckle when options have heckle_runner" do
63 example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
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
71 heckle_runner = mock("heckle_runner")
72 heckle_runner.should_receive(:heckle_with)
73 $rspec_mocks.__send__(:mocks).delete(heckle_runner)
75 options.heckle_runner = heckle_runner
76 options.add_example_group(example_group)
78 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
79 heckle_runner.rspec_verify
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
87 b1 = Class.new(Spec::Example::ExampleGroup)
88 b2 = Class.new(Spec::Example::ExampleGroup)
90 b2.should_receive(:run).ordered
91 b1.should_receive(:run).ordered
93 options.add_example_group(b1)
94 options.add_example_group(b2)
96 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
99 it "should pass its ExampleGroup to the reporter" do
100 example_group = Class.new(::Spec::Example::ExampleGroup).describe("example_group") do
104 options = ::Spec::Runner::Options.new(@err, @out)
105 options.add_example_group(example_group)
107 ::Spec::Runner::Options.should_receive(:new).with(@err, @out).and_return(options)
108 options.reporter.should_receive(:add_example_group).with(example_group)
110 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
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)
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
122 should_has_run = true
125 should_not_has_run = true
129 options.reporter.should_receive(:add_example_group).with(example_group)
131 options.add_example_group example_group
132 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))
134 should_has_run.should be_true
135 should_not_has_run.should be_false
138 it "sets Spec.run to true" do
140 ::Spec.should_not be_run
141 Spec::Runner::CommandLine.run(OptionParser.parse([], @err, @out))