Permalink
Browse files

CommandLine.run returns 0/1 instead of true/false

- Closes #366
  • Loading branch information...
1 parent a37ff24 commit 7410e6f42bcc941e67ae62ff8a6f4c2281a120ca @dchelimsky dchelimsky committed May 7, 2011
View
@@ -1,3 +1,10 @@
+### dev
+
+[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0.rc6...master)
+
+* Bug fixes
+ * CommandLine returns exit status (0/1) instead of true/false
+
### 2.6.0.rc6 / 2011-05-06
[full changelog](http://github.com/rspec/rspec-core/compare/v2.6.0.rc4...v2.6.0.rc6)
@@ -21,7 +21,7 @@ def run(err, out)
@configuration.reporter.report(@world.example_count) do |reporter|
begin
@configuration.run_hook(:before, :suite)
- @world.example_groups.map {|g| g.run(reporter)}.all?
+ @world.example_groups.map {|g| g.run(reporter)}.all? ? 0 : 1
ensure
@configuration.run_hook(:after, :suite)
end
View
@@ -7,7 +7,7 @@ class Runner
def self.autorun
return if autorun_disabled? || installed_at_exit? || running_in_drb?
@installed_at_exit = true
- at_exit { run(ARGV, $stderr, $stdout) ? exit(0) : exit(1) }
+ at_exit { exit(run(ARGV, $stderr, $stdout)) }
end
AT_EXIT_HOOK_BACKTRACE_LINE = "#{__FILE__}:#{__LINE__ - 2}:in `autorun'"
@@ -4,6 +4,42 @@
module RSpec::Core
describe CommandLine do
+
+ describe "#run" do
+ include_context "spec files"
+
+ let(:out) { StringIO.new }
+ let(:err) { StringIO.new }
+
+ def config_options(argv=[])
+ options = RSpec::Core::ConfigurationOptions.new(argv)
+ options.parse_options
+ options
+ end
+
+ def command_line(args)
+ RSpec::Core::CommandLine.new(config_options(args))
+ end
+
+ def config_options(argv=[])
+ options = RSpec::Core::ConfigurationOptions.new(argv)
+ options.parse_options
+ options
+ end
+
+ it "returns 0 if spec passes" do
+ err, out = StringIO.new, StringIO.new
+ result = command_line([passing_spec_filename]).run(err, out)
+ result.should be(0)
+ end
+
+ it "returns 1 if spec passes" do
+ err, out = StringIO.new, StringIO.new
+ result = command_line([failing_spec_filename]).run(err, out)
+ result.should be(1)
+ end
+ end
+
context "given an Array of options" do
it "assigns ConfigurationOptions built from Array to @options" do
config_options = ConfigurationOptions.new(%w[--color])
@@ -5,18 +5,20 @@
let(:out) { StringIO.new }
let(:err) { StringIO.new }
+ include_context "spec files"
+
+ def command_line(args)
+ RSpec::Core::DRbCommandLine.new(config_options(args))
+ end
+
def config_options(argv=[])
options = RSpec::Core::ConfigurationOptions.new(argv)
options.parse_options
options
end
- def drb_command_line(args)
- RSpec::Core::DRbCommandLine.new(config_options(args))
- end
-
def run_with(args)
- drb_command_line(args).run(err, out)
+ command_line(args).run(err, out)
end
context "without server running" do
@@ -39,14 +41,14 @@ def with_RSPEC_DRB_set_to(val)
context "without RSPEC_DRB environment variable set" do
it "defaults to 8989" do
with_RSPEC_DRB_set_to(nil) do
- drb_command_line([]).drb_port.should == 8989
+ command_line([]).drb_port.should == 8989
end
end
it "sets the DRb port" do
with_RSPEC_DRB_set_to(nil) do
- drb_command_line(["--drb-port", "1234"]).drb_port.should == 1234
- drb_command_line(["--drb-port", "5678"]).drb_port.should == 5678
+ command_line(["--drb-port", "1234"]).drb_port.should == 1234
+ command_line(["--drb-port", "5678"]).drb_port.should == 5678
end
end
end
@@ -56,15 +58,15 @@ def with_RSPEC_DRB_set_to(val)
context "without config variable set" do
it "uses RSPEC_DRB value" do
with_RSPEC_DRB_set_to('9000') do
- drb_command_line([]).drb_port.should == "9000"
+ command_line([]).drb_port.should == "9000"
end
end
end
context "and config variable set" do
it "uses configured value" do
with_RSPEC_DRB_set_to('9000') do
- drb_command_line(%w[--drb-port 5678]).drb_port.should == 5678
+ command_line(%w[--drb-port 5678]).drb_port.should == 5678
end
end
end
@@ -80,59 +82,30 @@ def self.run(argv, err, out)
end
end
- def dummy_spec_filename
- @dummy_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_dummy_spec#{@drb_example_file_counter}.rb"
- end
-
before(:all) do
@drb_port = 8990
@drb_example_file_counter = 0
DRb::start_service("druby://127.0.0.1:#{@drb_port}", ::FakeDrbSpecServer)
end
- before(:each) do
- @drb_example_file_counter += 1
- create_dummy_spec_file
- end
-
- after(:each) do
- File.delete(dummy_spec_filename)
- end
-
after(:all) do
DRb::stop_service
end
- def create_dummy_spec_file
- File.open(dummy_spec_filename, 'w') do |f|
- f.write %q{
- describe "DUMMY CONTEXT for 'DrbCommandLine with -c option'" do
- it "should be output with green bar" do
- true.should be_true
- end
-
- it "should be output with red bar" do
- raise("I want to see a red bar!")
- end
- end
- }
- end
- end
-
- it "returns true" do
+ it "returns 0 if spec passes" do
err, out = StringIO.new, StringIO.new
- result = drb_command_line(["--drb-port", @drb_port.to_s]).run(err, out)
- result.should be_true
+ result = command_line(["--drb-port", @drb_port.to_s, passing_spec_filename]).run(err, out)
+ result.should be(0)
end
- it "integrates via Runner.new.run" do
+ it "returns 1 if spec passes" do
err, out = StringIO.new, StringIO.new
- result = RSpec::Core::Runner.run(%W[ --drb --drb-port #{@drb_port} #{dummy_spec_filename}], err, out)
- result.should be_false
+ result = command_line(["--drb-port", @drb_port.to_s, failing_spec_filename]).run(err, out)
+ result.should be(1)
end
def run_spec_via_druby
- run_with([dummy_spec_filename, "--colour", "--drb-port", @drb_port.to_s])
+ run_with([failing_spec_filename, "--colour", "--drb-port", @drb_port.to_s])
out.rewind
out.read
end
View
@@ -0,0 +1,44 @@
+shared_context "spec files" do
+ def failing_spec_filename
+ @failing_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_failing_spec.rb"
+ end
+
+ def passing_spec_filename
+ @passing_spec_filename ||= File.expand_path(File.dirname(__FILE__)) + "/_passing_spec.rb"
+ end
+
+ def create_passing_spec_file
+ File.open(passing_spec_filename, 'w') do |f|
+ f.write %q{
+ describe "passing spec" do
+ it "passes" do
+ 1.should eq(1)
+ end
+ end
+ }
+ end
+ end
+
+ def create_failing_spec_file
+ File.open(failing_spec_filename, 'w') do |f|
+ f.write %q{
+ describe "failing spec" do
+ it "fails" do
+ 1.should eq(2)
+ end
+ end
+ }
+ end
+ end
+
+ before(:all) do
+ create_passing_spec_file
+ create_failing_spec_file
+ end
+
+ after(:all) do
+ File.delete(passing_spec_filename)
+ File.delete(failing_spec_filename)
+ end
+
+end

0 comments on commit 7410e6f

Please sign in to comment.