Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Don't call example_group_[started|finished] unless the group or any of

its children have at least one example to run.

- Closes #317.
  • Loading branch information...
commit 40758a1435e31216e4d500591d6b6570d4c5298e 1 parent 1758f81
David Chelimsky dchelimsky authored
1  features/Changelog.md
View
@@ -26,6 +26,7 @@
* Include RSpec::Matchers when first example group is defined, rather
than just before running the examples. This works around an obscure
bug in ruby 1.9 that can cause infinite recursion. (Myron Marston)
+ * Don't send example_group_[started|finished] to formatters for empty groups.
### 2.5.1 / 2011-02-06
4 lib/rspec/core/reporter.rb
View
@@ -39,11 +39,11 @@ def message(message)
end
def example_group_started(group)
- notify :example_group_started, group
+ notify :example_group_started, group unless group.descendant_filtered_examples.empty?
end
def example_group_finished(group)
- notify :example_group_finished, group
+ notify :example_group_finished, group unless group.descendant_filtered_examples.empty?
end
def example_started(example)
22 spec/rspec/core/reporter_spec.rb
View
@@ -30,13 +30,17 @@ module RSpec::Core
it "passes example_group_started and example_group_finished messages to that formatter in that order" do
order = []
- formatter = stub("formatter")
+ formatter = stub("formatter").as_null_object
formatter.stub(:example_group_started) { |group| order << "Started: #{group.description}" }
formatter.stub(:example_group_finished) { |group| order << "Finished: #{group.description}" }
group = ExampleGroup.describe("root")
- group.describe("context 1")
- group.describe("context 2")
+ group.describe("context 1") do
+ example("ignore") {}
+ end
+ group.describe("context 2") do
+ example("ignore") {}
+ end
group.run(Reporter.new(formatter))
@@ -51,6 +55,18 @@ module RSpec::Core
end
end
+ context "given an example group with no examples" do
+ it "does not pass example_group_started or example_group_finished to formatter" do
+ formatter = stub("formatter").as_null_object
+ formatter.should_not_receive(:example_group_started)
+ formatter.should_not_receive(:example_group_finished)
+
+ group = ExampleGroup.describe("root")
+
+ group.run(Reporter.new(formatter))
+ end
+ end
+
context "given multiple formatters" do
it "passes messages to all formatters" do
formatters = [double("formatter"), double("formatter")]
Please sign in to comment.
Something went wrong with that request. Please try again.