mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Update specs for new Result#call functionality
This commit is contained in:
parent
002c1d892b
commit
919e2b96f6
5 changed files with 136 additions and 38 deletions
|
@ -16,17 +16,40 @@ end
|
|||
|
||||
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
|
||||
context "without a block" do
|
||||
it "invokes #error on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_errored_result.call(spy)
|
||||
spy.error?.should be_true
|
||||
end
|
||||
|
||||
it "returns the value of #failure" do
|
||||
result = new_errored_result
|
||||
returned = result.call(ResultCallSpy.new)
|
||||
returned.should eq(:error)
|
||||
end
|
||||
end
|
||||
|
||||
it "passes itself" do
|
||||
spy = ResultCallSpy.new
|
||||
result = new_errored_result
|
||||
result.call(spy)
|
||||
spy.error.should eq(result)
|
||||
context "with a block" do
|
||||
it "invokes #error on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_errored_result.call(spy) { nil }
|
||||
spy.error?.should be_true
|
||||
end
|
||||
|
||||
it "yields itself" do
|
||||
result = new_errored_result
|
||||
value = nil.as(Spectator::Result?)
|
||||
result.call(ResultCallSpy.new) { |r| value = r }
|
||||
value.should eq(result)
|
||||
end
|
||||
|
||||
it "returns the value of #failure" do
|
||||
result = new_errored_result
|
||||
value = 42
|
||||
returned = result.call(ResultCallSpy.new) { value }
|
||||
returned.should eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -16,17 +16,40 @@ end
|
|||
|
||||
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
|
||||
context "without a block" do
|
||||
it "invokes #failure on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_failed_result.call(spy)
|
||||
spy.failure?.should be_true
|
||||
end
|
||||
|
||||
it "returns the value of #failure" do
|
||||
result = new_failed_result
|
||||
returned = result.call(ResultCallSpy.new)
|
||||
returned.should eq(:failure)
|
||||
end
|
||||
end
|
||||
|
||||
it "passes itself" do
|
||||
spy = ResultCallSpy.new
|
||||
result = new_failed_result
|
||||
result.call(spy)
|
||||
spy.failure.should eq(result)
|
||||
context "with a block" do
|
||||
it "invokes #failure on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_failed_result.call(spy) { nil }
|
||||
spy.failure?.should be_true
|
||||
end
|
||||
|
||||
it "yields itself" do
|
||||
result = new_failed_result
|
||||
value = nil.as(Spectator::Result?)
|
||||
result.call(ResultCallSpy.new) { |r| value = r }
|
||||
value.should eq(result)
|
||||
end
|
||||
|
||||
it "returns the value of #failure" do
|
||||
result = new_failed_result
|
||||
value = 42
|
||||
returned = result.call(ResultCallSpy.new) { value }
|
||||
returned.should eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
# Spy class for testing `Spectator::Result#call`.
|
||||
class ResultCallSpy
|
||||
{% for name in %i[success failure error pending] %}
|
||||
getter! {{name.id}} : ::Spectator::Result
|
||||
getter? {{name.id}} = false
|
||||
|
||||
def {{name.id}}
|
||||
@{{name.id}} = true
|
||||
{{name}}
|
||||
end
|
||||
|
||||
def {{name.id}}(arg)
|
||||
@{{name.id}} = arg
|
||||
@{{name.id}} = true
|
||||
arg
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
|
|
|
@ -6,17 +6,40 @@ end
|
|||
|
||||
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
|
||||
context "without a block" do
|
||||
it "invokes #pending on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_pending_result.call(spy)
|
||||
spy.pending?.should be_true
|
||||
end
|
||||
|
||||
it "returns the value of #pending" do
|
||||
result = new_pending_result
|
||||
returned = result.call(ResultCallSpy.new)
|
||||
returned.should eq(:pending)
|
||||
end
|
||||
end
|
||||
|
||||
it "passes itself" do
|
||||
spy = ResultCallSpy.new
|
||||
result = new_pending_result
|
||||
result.call(spy)
|
||||
spy.pending.should eq(result)
|
||||
context "with a block" do
|
||||
it "invokes #pending on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_pending_result.call(spy) { nil }
|
||||
spy.pending?.should be_true
|
||||
end
|
||||
|
||||
it "yields itself" do
|
||||
result = new_pending_result
|
||||
value = nil.as(Spectator::Result?)
|
||||
result.call(ResultCallSpy.new) { |r| value = r }
|
||||
value.should eq(result)
|
||||
end
|
||||
|
||||
it "returns the value of #pending" do
|
||||
result = new_pending_result
|
||||
value = 42
|
||||
returned = result.call(ResultCallSpy.new) { value }
|
||||
returned.should eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -14,17 +14,40 @@ end
|
|||
|
||||
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
|
||||
context "without a block" do
|
||||
it "invokes #success on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_successful_result.call(spy)
|
||||
spy.success?.should be_true
|
||||
end
|
||||
|
||||
it "returns the value of #success" do
|
||||
result = new_successful_result
|
||||
returned = result.call(ResultCallSpy.new)
|
||||
returned.should eq(:success)
|
||||
end
|
||||
end
|
||||
|
||||
it "passes itself" do
|
||||
spy = ResultCallSpy.new
|
||||
result = new_successful_result
|
||||
result.call(spy)
|
||||
spy.success.should eq(result)
|
||||
context "with a block" do
|
||||
it "invokes #success on an instance" do
|
||||
spy = ResultCallSpy.new
|
||||
new_successful_result.call(spy) { nil }
|
||||
spy.success?.should be_true
|
||||
end
|
||||
|
||||
it "yields itself" do
|
||||
result = new_successful_result
|
||||
value = nil.as(Spectator::Result?)
|
||||
result.call(ResultCallSpy.new) { |r| value = r }
|
||||
value.should eq(result)
|
||||
end
|
||||
|
||||
it "returns the value of #success" do
|
||||
result = new_successful_result
|
||||
value = 42
|
||||
returned = result.call(ResultCallSpy.new) { value }
|
||||
returned.should eq(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue