mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add tests for Result#call implementations
This commit is contained in:
parent
75f9a5838b
commit
6a8d447570
5 changed files with 70 additions and 0 deletions
|
@ -15,6 +15,21 @@ def new_errored_result(
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::ErroredResult do
|
describe Spectator::ErroredResult do
|
||||||
|
describe "#call" do
|
||||||
|
it "invokes #error on an instance" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
new_errored_result.call(spy)
|
||||||
|
spy.error?.should be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "passes itself" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
result = new_errored_result
|
||||||
|
result.call(spy)
|
||||||
|
spy.error.should eq(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#example" do
|
describe "#example" do
|
||||||
it "is the expected value" do
|
it "is the expected value" do
|
||||||
example = FailingExample.create
|
example = FailingExample.create
|
||||||
|
|
|
@ -15,6 +15,21 @@ def new_failed_result(
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::FailedResult do
|
describe Spectator::FailedResult do
|
||||||
|
describe "#call" do
|
||||||
|
it "invokes #failure on an instance" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
new_failed_result.call(spy)
|
||||||
|
spy.failure?.should be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "passes itself" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
result = new_failed_result
|
||||||
|
result.call(spy)
|
||||||
|
spy.failure.should eq(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#example" do
|
describe "#example" do
|
||||||
it "is the expected value" do
|
it "is the expected value" do
|
||||||
example = FailingExample.create
|
example = FailingExample.create
|
||||||
|
|
10
spec/helpers/result_call_spy.cr
Normal file
10
spec/helpers/result_call_spy.cr
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Spy class for testing `Spectator::Result#call`.
|
||||||
|
class ResultCallSpy
|
||||||
|
{% for name in %i[success failure error pending] %}
|
||||||
|
getter! {{name.id}} : ::Spectator::Result
|
||||||
|
|
||||||
|
def {{name.id}}(arg)
|
||||||
|
@{{name.id}} = arg
|
||||||
|
end
|
||||||
|
{% end %}
|
||||||
|
end
|
|
@ -5,6 +5,21 @@ def new_pending_result(example : Spectator::Example? = nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::PendingResult do
|
describe Spectator::PendingResult do
|
||||||
|
describe "#call" do
|
||||||
|
it "invokes #pending on an instance" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
new_pending_result.call(spy)
|
||||||
|
spy.pending?.should be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "passes itself" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
result = new_pending_result
|
||||||
|
result.call(spy)
|
||||||
|
spy.pending.should eq(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#example" do
|
describe "#example" do
|
||||||
it "is the expected value" do
|
it "is the expected value" do
|
||||||
example = PassingExample.create
|
example = PassingExample.create
|
||||||
|
|
|
@ -13,6 +13,21 @@ def new_successful_result(
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Spectator::SuccessfulResult do
|
describe Spectator::SuccessfulResult do
|
||||||
|
describe "#call" do
|
||||||
|
it "invokes #success on an instance" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
new_successful_result.call(spy)
|
||||||
|
spy.success?.should be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "passes itself" do
|
||||||
|
spy = ResultCallSpy.new
|
||||||
|
result = new_successful_result
|
||||||
|
result.call(spy)
|
||||||
|
spy.success.should eq(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe "#example" do
|
describe "#example" do
|
||||||
it "is the expected value" do
|
it "is the expected value" do
|
||||||
example = PassingExample.create
|
example = PassingExample.create
|
||||||
|
|
Loading…
Reference in a new issue