mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Shorten pre and post usage
This commit is contained in:
parent
ed8fad2c97
commit
37c45eb285
2 changed files with 14 additions and 14 deletions
|
@ -1,34 +1,34 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
describe Spectator::ExampleConditions do
|
describe Spectator::ExampleConditions do
|
||||||
{% for condition in %i[pre_condition post_condition] %}
|
{% for condition in %i[pre post] %}
|
||||||
describe "#run_{{condition.id}}s" do
|
describe "#run_{{condition.id}}_conditions" do
|
||||||
it "calls a proc" do
|
it "calls a proc" do
|
||||||
called = false
|
called = false
|
||||||
conditions = new_conditions({{condition.id}}: ->{ called = true; nil })
|
conditions = new_conditions({{condition.id}}: ->{ called = true; nil })
|
||||||
conditions.run_{{condition.id}}s
|
conditions.run_{{condition.id}}_conditions
|
||||||
called.should be_true
|
called.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls multiple procs" do
|
it "calls multiple procs" do
|
||||||
call_count = 0
|
call_count = 0
|
||||||
conditions = new_conditions({{condition.id}}s: [
|
conditions = new_conditions({{condition.id}}: [
|
||||||
->{ call_count += 1; nil },
|
->{ call_count += 1; nil },
|
||||||
->{ call_count += 2; nil },
|
->{ call_count += 2; nil },
|
||||||
->{ call_count += 3; nil },
|
->{ call_count += 3; nil },
|
||||||
])
|
])
|
||||||
conditions.run_{{condition.id}}s
|
conditions.run_{{condition.id}}_conditions
|
||||||
call_count.should eq(6)
|
call_count.should eq(6)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "calls procs in the correct order" do
|
it "calls procs in the correct order" do
|
||||||
calls = [] of Symbol
|
calls = [] of Symbol
|
||||||
conditions = new_conditions({{condition.id}}s: [
|
conditions = new_conditions({{condition.id}}: [
|
||||||
->{ calls << :a; nil },
|
->{ calls << :a; nil },
|
||||||
->{ calls << :b; nil },
|
->{ calls << :b; nil },
|
||||||
->{ calls << :c; nil },
|
->{ calls << :c; nil },
|
||||||
])
|
])
|
||||||
conditions.run_{{condition.id}}s
|
conditions.run_{{condition.id}}_conditions
|
||||||
calls.should eq(\%i[a b c])
|
calls.should eq(\%i[a b c])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,10 +38,10 @@ end
|
||||||
# only specify the sets of conditions that are needed.
|
# only specify the sets of conditions that are needed.
|
||||||
# The conditions that aren't specified will be left empty.
|
# The conditions that aren't specified will be left empty.
|
||||||
def new_conditions(
|
def new_conditions(
|
||||||
pre_conditions = [] of ->,
|
pre = [] of ->,
|
||||||
post_conditions = [] of ->
|
post = [] of ->
|
||||||
)
|
)
|
||||||
Spectator::ExampleConditions.new(pre_conditions, post_conditions)
|
Spectator::ExampleConditions.new(pre, post)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Creates a new `Spectator::ExampleConditions` instance.
|
# Creates a new `Spectator::ExampleConditions` instance.
|
||||||
|
@ -49,11 +49,11 @@ end
|
||||||
# only specify a condition for the types that are needed.
|
# only specify a condition for the types that are needed.
|
||||||
# The conditions that aren't specified will be left empty.
|
# The conditions that aren't specified will be left empty.
|
||||||
def new_conditions(
|
def new_conditions(
|
||||||
pre_condition : Proc(Nil)? = nil,
|
pre : Proc(Nil)? = nil,
|
||||||
post_condition : Proc(Nil)? = nil
|
post : Proc(Nil)? = nil
|
||||||
)
|
)
|
||||||
new_conditions(
|
new_conditions(
|
||||||
pre_condition ? [pre_condition] : [] of ->,
|
pre ? [pre] : [] of ->,
|
||||||
post_condition ? [post_condition] : [] of ->
|
post ? [post] : [] of ->
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue