Skip to content

Commit

Permalink
Move decision about failing fast from example to group
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Oct 3, 2010
1 parent 38a244a commit 3d8eebf
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
8 changes: 6 additions & 2 deletions lib/rspec/core.rb
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions lib/rspec/core/example_group.rb
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/core/world.rb
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions spec/rspec/core/example_group_spec.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3d8eebf

Please sign in to comment.