Add tests for fail-fast and after hooks

Inspecting issue #2
This commit is contained in:
Michael Miller 2019-04-22 19:12:45 -06:00
parent b305c829be
commit 1d530de5b1
2 changed files with 42 additions and 0 deletions

View file

@ -33,4 +33,12 @@ class FailingExample < Spectator::RunnableExample
group.children = [example.as(Spectator::ExampleComponent)]
end
end
# Creates a group of failing examples.
def self.create_group(count = 5, hooks = Spectator::ExampleHooks.empty, conditions = Spectator::ExampleConditions.empty)
values = Spectator::Internals::SampleValues.empty
Spectator::RootExampleGroup.new(hooks, conditions).tap do |group|
group.children = Array.new(count) { new(group, values).as(Spectator::ExampleComponent) }
end
end
end

View file

@ -40,6 +40,40 @@ describe Spectator::Runner do
called.should eq([0, 1, 2, 3, 4, 5, 6])
end
it "runs after_each hooks" do
called = false
hooks = new_hooks(after_each: ->{ called = true; nil })
group = FailingExample.create_group(hooks: hooks)
suite = new_test_suite(group)
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
runner.run
called.should be_true
end
it "runs after_all hooks" do
called = false
hooks = new_hooks(after_all: ->{ called = true; nil })
group = FailingExample.create_group(hooks: hooks)
suite = new_test_suite(group)
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
runner.run
called.should be_true
end
it "runs the remaining around_each hook code" do
called = false
hooks = new_hooks(around_each: ->(proc : ->) {
proc.call
called = true
nil
})
group = FailingExample.create_group(hooks: hooks)
suite = new_test_suite(group)
runner = Spectator::Runner.new(suite, spectator_test_config(fail_fast: true))
runner.run
called.should be_true
end
context "the report" do
it "has the remaining tests" do
spy = SpyFormatter.new