mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add spec for RootExampleGroupBuilder
This commit is contained in:
parent
6f5c269fcc
commit
1657518deb
1 changed files with 202 additions and 0 deletions
202
spec/dsl/root_example_group_builder_spec.cr
Normal file
202
spec/dsl/root_example_group_builder_spec.cr
Normal file
|
@ -0,0 +1,202 @@
|
|||
require "../spec_helper"
|
||||
|
||||
describe Spectator::DSL::RootExampleGroupBuilder do
|
||||
describe "#add_child" do
|
||||
it "creates the correct number of children" do
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
3.times do
|
||||
factory = Spectator::DSL::ExampleFactory.new(PassingExample)
|
||||
group_builder = Spectator::DSL::NestedExampleGroupBuilder.new("foo")
|
||||
builder.add_child(factory)
|
||||
builder.add_child(group_builder)
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.children.size.should eq(6)
|
||||
end
|
||||
|
||||
context "with an ExampleFactory" do
|
||||
it "creates the example" do
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
factory = Spectator::DSL::ExampleFactory.new(PassingExample)
|
||||
builder.add_child(factory)
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.children.first.should be_a(PassingExample)
|
||||
end
|
||||
end
|
||||
|
||||
context "with an ExampleGroupBuilder" do
|
||||
it "creates the group" do
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
group_builder = Spectator::DSL::NestedExampleGroupBuilder.new("foo")
|
||||
builder.add_child(group_builder)
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.children.first.should be_a(Spectator::NestedExampleGroup)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_before_all_hook" do
|
||||
it "adds a hook" do
|
||||
hook_called = false
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_before_all_hook(->{
|
||||
hook_called = true
|
||||
})
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_before_all_hooks
|
||||
hook_called.should eq(true)
|
||||
end
|
||||
|
||||
it "supports multiple hooks" do
|
||||
call_count = 0
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
5.times do |i|
|
||||
builder.add_before_all_hook(->{
|
||||
call_count += i + 1
|
||||
})
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_before_all_hooks
|
||||
call_count.should eq(15)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_before_each_hook" do
|
||||
it "adds a hook" do
|
||||
hook_called = false
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_before_each_hook(->{
|
||||
hook_called = true
|
||||
})
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_before_each_hooks
|
||||
hook_called.should eq(true)
|
||||
end
|
||||
|
||||
it "supports multiple hooks" do
|
||||
call_count = 0
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
5.times do |i|
|
||||
builder.add_before_each_hook(->{
|
||||
call_count += i + 1
|
||||
})
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_before_each_hooks
|
||||
call_count.should eq(15)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_after_all_hook" do
|
||||
it "adds a hook" do
|
||||
hook_called = false
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_after_all_hook(->{
|
||||
hook_called = true
|
||||
})
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_after_all_hooks
|
||||
hook_called.should eq(true)
|
||||
end
|
||||
|
||||
it "supports multiple hooks" do
|
||||
call_count = 0
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
5.times do |i|
|
||||
builder.add_after_all_hook(->{
|
||||
call_count += i + 1
|
||||
})
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_after_all_hooks
|
||||
call_count.should eq(15)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_after_each_hook" do
|
||||
it "adds a hook" do
|
||||
hook_called = false
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_after_each_hook(->{
|
||||
hook_called = true
|
||||
})
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_after_each_hooks
|
||||
hook_called.should eq(true)
|
||||
end
|
||||
|
||||
it "supports multiple hooks" do
|
||||
call_count = 0
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
5.times do |i|
|
||||
builder.add_after_each_hook(->{
|
||||
call_count += i + 1
|
||||
})
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.run_after_each_hooks
|
||||
call_count.should eq(15)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#add_around_each_hook" do
|
||||
it "adds a hook" do
|
||||
hook_called = false
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_around_each_hook(->(proc : ->) {
|
||||
hook_called = true
|
||||
})
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
proc = group.wrap_around_each_hooks { }
|
||||
proc.call
|
||||
hook_called.should eq(true)
|
||||
end
|
||||
|
||||
it "supports multiple hooks" do
|
||||
call_count = 0
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
5.times do |i|
|
||||
builder.add_around_each_hook(->(proc : ->) {
|
||||
call_count += i + 1
|
||||
proc.call
|
||||
})
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
proc = group.wrap_around_each_hooks { }
|
||||
proc.call
|
||||
call_count.should eq(15)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#build" do
|
||||
it "passes along the sample values" do
|
||||
factory = Spectator::DSL::ExampleFactory.new(SpyExample)
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
builder.add_child(factory)
|
||||
values = Spectator::Internals::SampleValues.empty.add(:foo, "foo", 12345)
|
||||
group = builder.build(values)
|
||||
group.children.first.as(SpyExample).sample_values.should eq(values)
|
||||
end
|
||||
|
||||
it "specifies the parent of the children correctly" do
|
||||
builder = Spectator::DSL::RootExampleGroupBuilder.new
|
||||
3.times do
|
||||
factory = Spectator::DSL::ExampleFactory.new(PassingExample)
|
||||
group_builder = Spectator::DSL::NestedExampleGroupBuilder.new("foo")
|
||||
builder.add_child(factory)
|
||||
builder.add_child(group_builder)
|
||||
end
|
||||
group = builder.build(Spectator::Internals::SampleValues.empty)
|
||||
group.children.all? do |child|
|
||||
case(child)
|
||||
when Spectator::Example
|
||||
child.group == group
|
||||
when Spectator::NestedExampleGroup
|
||||
child.parent == group
|
||||
else
|
||||
false
|
||||
end
|
||||
end.should be_true
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue