mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove BlockExpectation
This commit is contained in:
parent
ff4e148509
commit
3731b6d785
3 changed files with 1 additions and 191 deletions
|
@ -1,159 +0,0 @@
|
||||||
require "../spec_helper"
|
|
||||||
|
|
||||||
describe Spectator::Expectations::BlockExpectation do
|
|
||||||
describe "#satisifed?" do
|
|
||||||
context "with a successful match" do
|
|
||||||
it "is true" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.satisfied?.should be_true
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "is false" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.satisfied?.should be_false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with an unsuccessful match" do
|
|
||||||
it "is false" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.satisfied?.should be_false
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "is true" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.satisfied?.should be_true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#actual_message" do
|
|
||||||
context "with a successful match" do
|
|
||||||
it "equals the matcher's #message" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.actual_message.should eq(matcher.message(partial))
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "equals the matcher's #negated_message" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.actual_message.should eq(matcher.negated_message(partial))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with an unsuccessful match" do
|
|
||||||
it "equals the matcher's #negated_message" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.actual_message.should eq(matcher.negated_message(partial))
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "equals the matcher's #message" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.actual_message.should eq(matcher.message(partial))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "#expected_message" do
|
|
||||||
context "with a successful match" do
|
|
||||||
it "equals the matcher's #message" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.expected_message.should eq(matcher.message(partial))
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "equals the matcher's #negated_message" do
|
|
||||||
value = 42
|
|
||||||
block = ->{ value }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value.to_s, value)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(true, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_true # Sanity check.
|
|
||||||
expectation.expected_message.should eq(matcher.negated_message(partial))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "with an unsuccessful match" do
|
|
||||||
it "equals the matcher's #message" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, false, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.expected_message.should eq(matcher.message(partial))
|
|
||||||
end
|
|
||||||
|
|
||||||
context "when negated" do
|
|
||||||
it "equals the matcher's #negated_message" do
|
|
||||||
value1 = 42
|
|
||||||
value2 = 777
|
|
||||||
block = ->{ value1 }
|
|
||||||
partial = Spectator::Expectations::BlockExpectationPartial.new(block.to_s, block)
|
|
||||||
matcher = Spectator::Matchers::EqualityMatcher.new(value2.to_s, value2)
|
|
||||||
expectation = Spectator::Expectations::BlockExpectation.new(false, true, partial, matcher)
|
|
||||||
matcher.match?(partial).should be_false # Sanity check.
|
|
||||||
expectation.expected_message.should eq(matcher.negated_message(partial))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,31 +0,0 @@
|
||||||
require "./expectation"
|
|
||||||
|
|
||||||
module Spectator::Expectations
|
|
||||||
# Expectation that operates on a block.
|
|
||||||
# A block produces some value one or more times.
|
|
||||||
# A matcher checks whether the values produced by the block satisfy some conditions.
|
|
||||||
# The behavior of the block can be tested by verifying the values produced by it.
|
|
||||||
class BlockExpectation(ReturnType) < Expectation
|
|
||||||
# Creates the expectation.
|
|
||||||
# The `matched` flag should be true if the matcher is satisfied with the partial.
|
|
||||||
# The `negated` flag should be true if the expectation is inverted.
|
|
||||||
# See `Expectation#initialize` for details on these two arguments.
|
|
||||||
# The `partial` and the `matcher` arguments should reference
|
|
||||||
# the actual and expected value with matcher respectively.
|
|
||||||
def initialize(matched, negated,
|
|
||||||
@partial : BlockExpectationPartial(ReturnType),
|
|
||||||
@matcher : Matchers::Matcher)
|
|
||||||
super(matched, negated)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Describes the condition that must be met for the expectation to be satisifed.
|
|
||||||
private def message : String
|
|
||||||
@matcher.message(@partial)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Describes the condition under which the expectation won't be satisifed.
|
|
||||||
private def negated_message : String
|
|
||||||
@matcher.negated_message(@partial)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -25,7 +25,7 @@ module Spectator::Expectations
|
||||||
# Evaluates the expectation and returns it.
|
# Evaluates the expectation and returns it.
|
||||||
private def eval(matcher, negated = false) : Expectation
|
private def eval(matcher, negated = false) : Expectation
|
||||||
matched = matcher.match?(self)
|
matched = matcher.match?(self)
|
||||||
BlockExpectation.new(matched, negated, self, matcher)
|
Expectation.new(matched, negated, self, matcher)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue