mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Adjust tests to use new hook methods
This commit is contained in:
parent
bd4d020d0f
commit
712aa99fed
5 changed files with 350 additions and 326 deletions
|
@ -64,58 +64,36 @@ def complex_root_group
|
|||
end
|
||||
|
||||
describe Spectator::RootExampleGroup do
|
||||
describe "#run_before_all_hooks" do
|
||||
it "runs a single hook" do
|
||||
describe "#run_before_hooks" do
|
||||
it "runs a before_all hook" do
|
||||
called = false
|
||||
hooks = new_hooks(before_all: ->{ called = true; nil })
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_all_hooks
|
||||
group.run_before_hooks
|
||||
called.should be_true
|
||||
end
|
||||
|
||||
it "runs multiple hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_all: [
|
||||
->{ call_count += 1; nil },
|
||||
->{ call_count += 2; nil },
|
||||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_all_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs hooks in the correct order" do
|
||||
calls = [] of Symbol
|
||||
hooks = new_hooks(before_all: [
|
||||
->{ calls << :a; nil },
|
||||
->{ calls << :b; nil },
|
||||
->{ calls << :c; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_all_hooks
|
||||
calls.should eq(%i[a b c])
|
||||
end
|
||||
|
||||
it "runs the hooks once" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_all: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_before_all_hooks }
|
||||
call_count.should eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#run_before_each_hooks" do
|
||||
it "runs a single hook" do
|
||||
it "runs a before_each hook" do
|
||||
called = false
|
||||
hooks = new_hooks(before_each: ->{ called = true; nil })
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_each_hooks
|
||||
group.run_before_hooks
|
||||
called.should be_true
|
||||
end
|
||||
|
||||
it "runs multiple hooks" do
|
||||
it "runs multiple before_all hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_all: [
|
||||
->{ call_count += 1; nil },
|
||||
->{ call_count += 2; nil },
|
||||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs multiple before_each hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_each: [
|
||||
->{ call_count += 1; nil },
|
||||
|
@ -123,44 +101,65 @@ describe Spectator::RootExampleGroup do
|
|||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_each_hooks
|
||||
group.run_before_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs hooks in the correct order" do
|
||||
calls = [] of Symbol
|
||||
hooks = new_hooks(before_each: [
|
||||
hooks = new_hooks(before_all: [
|
||||
->{ calls << :a; nil },
|
||||
->{ calls << :b; nil },
|
||||
->{ calls << :c; nil },
|
||||
])
|
||||
],
|
||||
before_each: [
|
||||
->{ calls << :d; nil },
|
||||
->{ calls << :e; nil },
|
||||
->{ calls << :f; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_before_each_hooks
|
||||
calls.should eq(%i[a b c])
|
||||
group.run_before_hooks
|
||||
calls.should eq(%i[a b c d e f])
|
||||
end
|
||||
|
||||
it "runs the hooks multiple times" do
|
||||
it "runs the before_all hooks once" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_all: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_before_hooks }
|
||||
call_count.should eq(1)
|
||||
end
|
||||
|
||||
it "runs the before_each hooks multiple times" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(before_each: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_before_each_hooks }
|
||||
2.times { group.run_before_hooks }
|
||||
call_count.should eq(2)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#run_after_all_hooks" do
|
||||
describe "#run_after_hooks" do
|
||||
# No children are used for most of these examples.
|
||||
# That's because `[].all?` is always true.
|
||||
# Which means that all examples are considered finished, since there are none.
|
||||
it "runs a single hook" do
|
||||
it "runs a single after_all hook" do
|
||||
called = false
|
||||
hooks = new_hooks(after_all: ->{ called = true; nil })
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_all_hooks
|
||||
group.run_after_hooks
|
||||
called.should be_true
|
||||
end
|
||||
|
||||
it "runs multiple hooks" do
|
||||
it "runs a single after_each hook" do
|
||||
called = false
|
||||
hooks = new_hooks(after_each: ->{ called = true; nil })
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_hooks
|
||||
called.should be_true
|
||||
end
|
||||
|
||||
it "runs multiple after_all hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_all: [
|
||||
->{ call_count += 1; nil },
|
||||
|
@ -168,45 +167,81 @@ describe Spectator::RootExampleGroup do
|
|||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_all_hooks
|
||||
group.run_after_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs multiple after_each hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_all: [
|
||||
->{ call_count += 1; nil },
|
||||
->{ call_count += 2; nil },
|
||||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs hooks in the correct order" do
|
||||
calls = [] of Symbol
|
||||
hooks = new_hooks(after_all: [
|
||||
hooks = new_hooks(after_each: [
|
||||
->{ calls << :a; nil },
|
||||
->{ calls << :b; nil },
|
||||
->{ calls << :c; nil },
|
||||
])
|
||||
],
|
||||
after_all: [
|
||||
->{ calls << :d; nil },
|
||||
->{ calls << :e; nil },
|
||||
->{ calls << :f; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_all_hooks
|
||||
calls.should eq(%i[a b c])
|
||||
group.run_after_hooks
|
||||
calls.should eq(%i[a b c d e f])
|
||||
end
|
||||
|
||||
it "runs the hooks once" do
|
||||
it "runs the after_all hooks once" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_all: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_after_all_hooks }
|
||||
2.times { group.run_after_hooks }
|
||||
call_count.should eq(1)
|
||||
end
|
||||
|
||||
it "runs the after_each hooks multiple times" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_each: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_after_hooks }
|
||||
call_count.should eq(2)
|
||||
end
|
||||
|
||||
context "with no examples finished" do
|
||||
it "doesn't run the hooks" do
|
||||
it "doesn't run the after_all hooks" do
|
||||
called = false
|
||||
hooks = new_hooks(after_all: ->{ called = true; nil })
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
group.children = Array(Spectator::ExampleComponent).new(5) do
|
||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||
end
|
||||
group.run_after_all_hooks
|
||||
group.run_after_hooks
|
||||
called.should be_false
|
||||
end
|
||||
|
||||
it "runs the after_each hooks" do
|
||||
called = false
|
||||
hooks = new_hooks(after_each: ->{ called = true; nil })
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
group.children = Array(Spectator::ExampleComponent).new(5) do
|
||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty)
|
||||
end
|
||||
group.run_after_hooks
|
||||
called.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context "with some examples finished" do
|
||||
it "doesn't run the hooks" do
|
||||
it "doesn't run the after_all hooks" do
|
||||
called = false
|
||||
hooks = new_hooks(after_all: ->{ called = true; nil })
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
|
@ -215,51 +250,22 @@ describe Spectator::RootExampleGroup do
|
|||
Spectator::Internals::Harness.run(example) if i % 2 == 0
|
||||
end
|
||||
end
|
||||
group.run_after_all_hooks
|
||||
group.run_after_hooks
|
||||
called.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#run_after_each_hooks" do
|
||||
it "runs a single hook" do
|
||||
called = false
|
||||
hooks = new_hooks(after_each: ->{ called = true; nil })
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_each_hooks
|
||||
called.should be_true
|
||||
end
|
||||
|
||||
it "runs multiple hooks" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_each: [
|
||||
->{ call_count += 1; nil },
|
||||
->{ call_count += 2; nil },
|
||||
->{ call_count += 3; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_each_hooks
|
||||
call_count.should eq(6)
|
||||
end
|
||||
|
||||
it "runs hooks in the correct order" do
|
||||
calls = [] of Symbol
|
||||
hooks = new_hooks(after_each: [
|
||||
->{ calls << :a; nil },
|
||||
->{ calls << :b; nil },
|
||||
->{ calls << :c; nil },
|
||||
])
|
||||
group = new_root_group(hooks)
|
||||
group.run_after_each_hooks
|
||||
calls.should eq(%i[a b c])
|
||||
end
|
||||
|
||||
it "runs the hooks multiple times" do
|
||||
call_count = 0
|
||||
hooks = new_hooks(after_each: ->{ call_count += 1; nil })
|
||||
group = new_root_group(hooks)
|
||||
2.times { group.run_after_each_hooks }
|
||||
call_count.should eq(2)
|
||||
it "runs the after_each hooks" do
|
||||
called = false
|
||||
hooks = new_hooks(after_each: ->{ called = true; nil })
|
||||
group = Spectator::RootExampleGroup.new(hooks)
|
||||
group.children = Array(Spectator::ExampleComponent).new(5) do |i|
|
||||
PassingExample.new(group, Spectator::Internals::SampleValues.empty).tap do |example|
|
||||
Spectator::Internals::Harness.run(example) if i % 2 == 0
|
||||
end
|
||||
end
|
||||
group.run_after_hooks
|
||||
called.should be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue