Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Move parts of background to relevant scenario and add specs

  • Loading branch information...
commit 42b6846477d89cfd0a2e744abaa52778920abb12 1 parent f8a28d7
@dchelimsky dchelimsky authored
View
37 features/command_line/exit_status.feature
@@ -1,9 +1,8 @@
Feature: exit status
In order to fail the build when it should,
- the spec CLI should exit with an appropriate
- exit status
+ the spec CLI exits with an appropriate exit status
- Background:
+ Scenario: exit with 0 when all examples pass
Given a file named "ok_spec.rb" with:
"""
describe "ok" do
@@ -11,6 +10,13 @@ Feature: exit status
end
end
"""
+ When I run "rspec ok_spec.rb"
+ Then it should pass with:
+ """
+ 1 example, 0 failures
+ """
+
+ Scenario: exit with 1 when one example fails
Given a file named "ko_spec.rb" with:
"""
describe "KO" do
@@ -19,6 +25,13 @@ Feature: exit status
end
end
"""
+ When I run "rspec ko_spec.rb"
+ Then it should fail with:
+ """
+ 1 example, 1 failure
+ """
+
+ Scenario: exit with 1 when a nested examples fails
Given a file named "nested_ko_spec.rb" with:
"""
describe "KO" do
@@ -29,24 +42,8 @@ Feature: exit status
end
end
"""
-
- Scenario: exit with 0 when all pass
- When I run "ruby -rubygems ../../bin/rspec ok_spec.rb"
- Then it should pass with:
- """
- 1 example, 0 failures
- """
-
- Scenario: exit with 1 when one fails
- When I run "ruby -rubygems ../../bin/rspec ko_spec.rb"
+ When I run "rspec nested_ko_spec.rb"
Then it should fail with:
"""
1 example, 1 failure
"""
-
- Scenario: exit with 1 when one fails in a nested one
- When I run "ruby -rubygems ../../bin/rspec nested_ko_spec.rb"
- Then it should fail with:
- """
- 1 example, 1 failure
- """
View
5 lib/rspec/core/example_group.rb
@@ -172,9 +172,8 @@ def self.run(reporter)
reporter.add_example_group(self)
begin
eval_before_alls(example_group_instance)
- result_for_this_group = run_examples(example_group_instance, reporter)
- results_for_descendants = children.map {|child| child.run(reporter)}
- result_for_this_group && (children.empty? ? true : results_for_descendants.all?)
+ run_examples(example_group_instance, reporter) &&
+ children.map {|child| child.run(reporter)}.all?
ensure
eval_after_alls(example_group_instance)
end
View
67 spec/rspec/core/example_group_spec.rb
@@ -17,15 +17,15 @@ module RSpec::Core
describe "top level group" do
it "runs its children" do
examples_run = []
- parent = ExampleGroup.describe("parent")
- child = parent.describe("child") do
- it "does something" do
- examples_run << running_example
+ group = ExampleGroup.describe("parent") do
+ describe("child") do
+ it "does something" do
+ examples_run << running_example
+ end
end
end
- child.filtered_examples.replace(child.examples)
- parent.run_all
+ group.run_all
examples_run.should have(1).example
end
@@ -455,5 +455,60 @@ def nil_value
end
end
+ describe "#run" do
+ let(:reporter) { double("reporter").as_null_object }
+
+ context "with all examples passing" do
+ it "returns true" do
+ group = describe("something") do
+ it "does something" do
+ # pass
+ end
+ describe ("nested") do
+ it "does something else" do
+ # pass
+ end
+ end
+ end
+
+ group.run(reporter).should be_true
+ end
+ end
+
+ context "with top level example failing" do
+ it "returns false" do
+ group = describe("something") do
+ it "does something (wrong - fail)" do
+ raise "fail"
+ end
+ describe ("nested") do
+ it "does something else" do
+ # pass
+ end
+ end
+ end
+
+ group.run(reporter).should be_false
+ end
+ end
+
+ context "with nested example failing" do
+ it "returns true" do
+ group = describe("something") do
+ it "does something" do
+ # pass
+ end
+ describe ("nested") do
+ it "does something else (wrong -fail)" do
+ raise "fail"
+ end
+ end
+ end
+
+ group.run(reporter).should be_false
+ end
+ end
+ end
+
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.