shard-spectator/spec/example_conditions_spec.cr

37 lines
1.1 KiB
Crystal
Raw Normal View History

2019-01-17 21:14:10 +00:00
require "./spec_helper"
describe Spectator::ExampleConditions do
2019-01-23 21:46:15 +00:00
{% for condition in %i[pre post] %}
describe "#run_{{condition.id}}_conditions" do
2019-01-17 21:14:10 +00:00
it "calls a proc" do
called = false
conditions = new_conditions({{condition.id}}: ->{ called = true; nil })
2019-01-23 21:46:15 +00:00
conditions.run_{{condition.id}}_conditions
2019-01-17 21:14:10 +00:00
called.should be_true
end
it "calls multiple procs" do
call_count = 0
2019-01-23 21:46:15 +00:00
conditions = new_conditions({{condition.id}}: [
2019-01-17 21:14:10 +00:00
->{ call_count += 1; nil },
->{ call_count += 2; nil },
->{ call_count += 3; nil },
])
2019-01-23 21:46:15 +00:00
conditions.run_{{condition.id}}_conditions
2019-01-17 21:14:10 +00:00
call_count.should eq(6)
end
it "calls procs in the correct order" do
calls = [] of Symbol
2019-01-23 21:46:15 +00:00
conditions = new_conditions({{condition.id}}: [
2019-01-17 21:14:10 +00:00
->{ calls << :a; nil },
->{ calls << :b; nil },
->{ calls << :c; nil },
])
2019-01-23 21:46:15 +00:00
conditions.run_{{condition.id}}_conditions
2019-01-17 21:14:10 +00:00
calls.should eq(\%i[a b c])
end
end
{% end %}
end