From 3d8eebf438eb827d18bcb6d5aff40b81d8a8ecfa Mon Sep 17 00:00:00 2001 From: David Chelimsky Date: Sun, 3 Oct 2010 16:26:44 -0500 Subject: [PATCH] Move decision about failing fast from example to group --- lib/rspec/core.rb | 8 ++++++-- lib/rspec/core/example_group.rb | 8 +++++--- lib/rspec/core/world.rb | 2 +- spec/rspec/core/example_group_spec.rb | 26 +++++++++++++------------- spec/spec_helper.rb | 5 ++++- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/lib/rspec/core.rb b/lib/rspec/core.rb index 5de53b30be..495b889e13 100644 --- a/lib/rspec/core.rb +++ b/lib/rspec/core.rb @@ -47,8 +47,12 @@ def self.world end - class << self - attr_accessor :wants_to_quit + def self.wants_to_quit + world.wants_to_quit + end + + def self.wants_to_quit=(maybe) + world.wants_to_quit=(maybe) end def self.world diff --git a/lib/rspec/core/example_group.rb b/lib/rspec/core/example_group.rb index fce5e4b788..41f783da7a 100644 --- a/lib/rspec/core/example_group.rb +++ b/lib/rspec/core/example_group.rb @@ -235,15 +235,17 @@ def self.fail_filtered_examples(exception, reporter) end end + def self.fail_fast? + RSpec.configuration.fail_fast? + end + def self.run_examples(instance, reporter) filtered_examples.map do |example| next if RSpec.wants_to_quit begin set_ivars(instance, before_all_ivars) succeeded = example.run(instance, reporter) - if Rspec.configuration.fail_fast? && !succeeded - Rspec.wants_to_quit = true - end + RSpec.wants_to_quit = true if fail_fast? && !succeeded succeeded ensure clear_ivars(instance) diff --git a/lib/rspec/core/world.rb b/lib/rspec/core/world.rb index 26e37230a3..947e604638 100644 --- a/lib/rspec/core/world.rb +++ b/lib/rspec/core/world.rb @@ -2,7 +2,7 @@ module RSpec module Core class World - attr_reader :example_groups, :filtered_examples + attr_reader :example_groups, :filtered_examples, :wants_to_quit def initialize(configuration=RSpec.configuration) @configuration = configuration diff --git a/spec/rspec/core/example_group_spec.rb b/spec/rspec/core/example_group_spec.rb index 296c4d0e58..e820321a3b 100644 --- a/spec/rspec/core/example_group_spec.rb +++ b/spec/rspec/core/example_group_spec.rb @@ -606,7 +606,7 @@ def name end end end - + context "calling and overriding super" do it "calls to the subject defined in the parent group" do group = ExampleGroup.describe(Array) do @@ -644,25 +644,25 @@ def subject; super().first; end describe "#run" do let(:reporter) { double("reporter").as_null_object } - context "with RSpec.wants_to_quit=true" do - it "returns without starting the example" do + context "with fail_fast? => true" do + it "does not run examples after the failed example" do group = RSpec::Core::ExampleGroup.describe - group.example('example 1') {} - group.example('example 2') {} - group.example('example 3') {} + group.stub(:fail_fast?) { true } + examples_run = [] + group.example('example 1') { examples_run << self } + group.example('example 2') { examples_run << self; fail; } + group.example('example 3') { examples_run << self } - reporter = RSpec::Core::Reporter.new - reporter.should_not_receive(:example_started)#.exactly(2).times + group.run - group.run(reporter) + examples_run.length.should eq(2) end - end - + end context "with RSpec.wants_to_quit=true" do before do - RSpec.stub(:clear_remaining_example_groups) - RSpec.stub(:wants_to_quit) { true } + RSpec.world.stub(:example_groups) { [] } + RSpec.world.stub(:wants_to_quit) { true } end it "returns without starting the group" do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a61623d7eb..732a097544 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,7 +26,11 @@ def method_missing(method, *args, &block) module RSpec::Core class SandboxedExampleGroup < ExampleGroup def self.run(reporter=nil) + @orig_mock_space = RSpec::Mocks::space + RSpec::Mocks::space = RSpec::Mocks::Space.new super(reporter || NullObject.new) + ensure + RSpec::Mocks::space = @orig_mock_space end end end @@ -61,7 +65,6 @@ def in_editor? end RSpec.configure do |c| - c.fail_fast = true c.color_enabled = !in_editor? c.filter_run :focused => true c.run_all_when_everything_filtered = true