Update old references to Value and Block

This commit is contained in:
Michael Miller 2021-01-16 11:02:29 -07:00
parent 58e7981b0c
commit 4500ebcddc
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
44 changed files with 196 additions and 215 deletions

View file

@ -1,9 +1,9 @@
require "../block"
require "../matchers"
require "../test_block"
require "../test_value"
require "../value"
module Spectator
module DSL
module Spectator::DSL
module Matchers
# Indicates that some value should equal another.
# The == operator is used for this check.
# The value passed to this method is the expected value.
@ -13,8 +13,8 @@ module Spectator
# expect(1 + 2).to eq(3)
# ```
macro eq(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::EqualityMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::EqualityMatcher.new(%value)
end
# Indicates that some value should not equal another.
@ -26,8 +26,8 @@ module Spectator
# expect(1 + 2).to ne(5)
# ```
macro ne(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::InequalityMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::InequalityMatcher.new(%value)
end
# Indicates that some value when compared to another satisfies an operator.
@ -61,8 +61,8 @@ module Spectator
# expect(obj.dup).to_not be(obj)
# ```
macro be(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::ReferenceMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::ReferenceMatcher.new(%value)
end
# Indicates that some value should be of a specified type.
@ -173,8 +173,8 @@ module Spectator
# expect(3 - 1).to be_lt(3)
# ```
macro be_lt(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::LessThanMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::LessThanMatcher.new(%value)
end
# Indicates that some value should be less than or equal to another.
@ -186,8 +186,8 @@ module Spectator
# expect(3 - 1).to be_le(3)
# ```
macro be_le(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::LessThanEqualMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::LessThanEqualMatcher.new(%value)
end
# Indicates that some value should be greater than another.
@ -199,8 +199,8 @@ module Spectator
# expect(3 + 1).to be_gt(3)
# ```
macro be_gt(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::GreaterThanMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::GreaterThanMatcher.new(%value)
end
# Indicates that some value should be greater than or equal to another.
@ -212,8 +212,8 @@ module Spectator
# expect(3 + 1).to be_ge(3)
# ```
macro be_ge(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::GreaterThanEqualMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::GreaterThanEqualMatcher.new(%value)
end
# Indicates that some value should match another.
@ -230,8 +230,8 @@ module Spectator
# expect({:foo, 5}).to match({Symbol, Int32})
# ```
macro match(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::CaseMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::CaseMatcher.new(%value)
end
# Indicates that some value should be true.
@ -321,8 +321,8 @@ module Spectator
# NOTE: Do not attempt to mix the two use cases.
# It likely won't work and will result in a compilation error.
macro be_within(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::CollectionMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::CollectionMatcher.new(%value)
end
# Indicates that some value should be between a lower and upper-bound.
@ -344,8 +344,8 @@ module Spectator
macro be_between(min, max)
%range = Range.new({{min}}, {{max}})
%label = [{{min.stringify}}, {{max.stringify}}].join(" to ")
%test_value = ::Spectator::TestValue.new(%range, %label)
::Spectator::Matchers::RangeMatcher.new(%test_value)
%value = ::Spectator::Value.new(%range, %label)
::Spectator::Matchers::RangeMatcher.new(%value)
end
# Indicates that some value should be within a delta of an expected value.
@ -403,8 +403,8 @@ module Spectator
# expect(%w[foo bar]).to start_with(/foo/)
# ```
macro start_with(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::StartWithMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::StartWithMatcher.new(%value)
end
# Indicates that some value or set should end with another value.
@ -426,8 +426,8 @@ module Spectator
# expect(%w[foo bar]).to end_with(/bar/)
# ```
macro end_with(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::EndWithMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::EndWithMatcher.new(%value)
end
# Indicates that some value or set should contain another value.
@ -451,11 +451,11 @@ module Spectator
# ```
macro contain(*expected)
{% if expected.id.starts_with?("{*") %}
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%value)
{% else %}
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%value)
{% end %}
end
@ -475,8 +475,8 @@ module Spectator
# expect(%i[a b c]).to contain_elements(%i[a b])
# ```
macro contain_elements(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::ContainMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::ContainMatcher.new(%value)
end
# Indicates that some range (or collection) should contain another value.
@ -497,11 +497,11 @@ module Spectator
# ```
macro cover(*expected)
{% if expected.id.starts_with?("{*") %}
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%value)
{% else %}
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::ContainMatcher.new(%value)
{% end %}
end
@ -532,11 +532,11 @@ module Spectator
# ```
macro have(*expected)
{% if expected.id.starts_with?("{*") %}
%test_value = ::Spectator::TestValue.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::HaveMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected.id[2...-1]}}, {{expected.splat.stringify}})
::Spectator::Matchers::HaveMatcher.new(%value)
{% else %}
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::HaveMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.splat.stringify}})
::Spectator::Matchers::HaveMatcher.new(%value)
{% end %}
end
@ -559,8 +559,8 @@ module Spectator
# expect([1, 2, 3, :a, :b, :c]).to have_elements([Int32, Symbol])
# ```
macro have_elements(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveMatcher.new(%value)
end
# Indicates that some set, such as a `Hash`, has a given key.
@ -572,8 +572,8 @@ module Spectator
# expect({"lucky" => 7}).to have_key("lucky")
# ```
macro have_key(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveKeyMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveKeyMatcher.new(%value)
end
# :ditto:
@ -590,8 +590,8 @@ module Spectator
# expect({"lucky" => 7}).to have_value(7)
# ```
macro have_value(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveValueMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::HaveValueMatcher.new(%value)
end
# :ditto:
@ -607,11 +607,11 @@ module Spectator
# ```
macro contain_exactly(*expected)
{% if expected.id.starts_with?("{*") %}
%test_value = ::Spectator::TestValue.new(({{expected.id[2...-1]}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%test_value)
%value = ::Spectator::Value.new(({{expected.id[2...-1]}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%value)
{% else %}
%test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%test_value)
%value = ::Spectator::Value.new(({{expected}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%value)
{% end %}
end
@ -623,8 +623,8 @@ module Spectator
# expect([1, 2, 3]).to match_array([3, 2, 1])
# ```
macro match_array(expected)
%test_value = ::Spectator::TestValue.new(({{expected}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%test_value)
%value = ::Spectator::Value.new(({{expected}}).to_a, {{expected.stringify}})
::Spectator::Matchers::ArrayMatcher.new(%value)
end
# Indicates that some set should have a specified size.
@ -634,8 +634,8 @@ module Spectator
# expect([1, 2, 3]).to have_size(3)
# ```
macro have_size(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::SizeMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::SizeMatcher.new(%value)
end
# Indicates that some set should have the same size (number of elements) as another set.
@ -645,8 +645,8 @@ module Spectator
# expect([1, 2, 3]).to have_size_of(%i[x y z])
# ```
macro have_size_of(expected)
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::SizeOfMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.stringify}})
::Spectator::Matchers::SizeOfMatcher.new(%value)
end
# Indicates that some value should have a set of attributes matching some conditions.
@ -661,11 +661,11 @@ module Spectator
# ```
macro have_attributes(**expected)
{% if expected.id.starts_with?("{**") %}
%test_value = ::Spectator::TestValue.new({{expected.id[3...-1]}}, {{expected.double_splat.stringify}})
::Spectator::Matchers::AttributesMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected.id[3...-1]}}, {{expected.double_splat.stringify}})
::Spectator::Matchers::AttributesMatcher.new(%value)
{% else %}
%test_value = ::Spectator::TestValue.new({{expected}}, {{expected.double_splat.stringify}})
::Spectator::Matchers::AttributesMatcher.new(%test_value)
%value = ::Spectator::Value.new({{expected}}, {{expected.double_splat.stringify}})
::Spectator::Matchers::AttributesMatcher.new(%value)
{% end %}
end
@ -718,37 +718,18 @@ module Spectator
# expect { subject << :foo }.to change(&.size).by(1)
# ```
macro change(&expression)
{% if expression.is_a?(Nop) %}
{% raise "Block must be provided to change matcher" %}
{% end %}
# Check if the short-hand method syntax is used.
# This is a hack, since macros don't get this as a "literal" or something similar.
# The Crystal compiler will translate:
# ```
# &.foo
# ```
# to:
# ```
# { |__arg0| __arg0.foo }
# ```
# The hack used here is to check if it looks like a compiler-generated block.
{% if expression.args == ["__arg0".id] && expression.body.is_a?(Call) && expression.body.id =~ /^__arg0\./ %}
# Extract the method name to make it clear to the user what is tested.
# The raw block can't be used because it's not clear to the user.
{% method_name = expression.body.id.split('.')[1..-1].join('.') %}
%proc = ->{ subject.{{method_name.id}} }
%test_block = ::Spectator::TestBlock.create(%proc, {{"#" + method_name}})
{% elsif expression.args.empty? %}
# In this case, it looks like the short-hand method syntax wasn't used.
# Capture the block as a proc and pass along.
%proc = ->{{expression}}
%test_block = ::Spectator::TestBlock.create(%proc, {{"`" + expression.body.stringify + "`"}})
{% if block.args.size == 1 && block.args[0] =~ /^__arg\d+$/ && block.body.is_a?(Call) && block.body.id =~ /^__arg\d+\./ %}
{% method_name = block.body.id.split('.')[1..-1].join('.') %}
%block = ::Spectator::Block.new({{"#" + method_name}}) do
subject.{{method_name.id}}
end
{% elsif block.args.empty? %}
%block = ::Spectator::Block.new({{"`" + block.body.stringify + "`"}}) {{block}}
{% else %}
{% raise "Unexpected block arguments in change matcher" %}
{% raise "Unexpected block arguments in 'expect' call" %}
{% end %}
::Spectator::Matchers::ChangeMatcher.new(%test_block)
::Spectator::Matchers::ChangeMatcher.new(%block)
end
# Indicates that some block should raise an error.
@ -828,8 +809,8 @@ module Spectator
end
macro have_received(method)
%test_value = ::Spectator::TestValue.new(({{method.id.symbolize}}), {{method.id.stringify}})
::Spectator::Matchers::ReceiveMatcher.new(%test_value)
%value = ::Spectator::Value.new(({{method.id.symbolize}}), {{method.id.stringify}})
::Spectator::Matchers::ReceiveMatcher.new(%value)
end
# Used to create predicate matchers.
@ -872,8 +853,8 @@ module Spectator
{% end %}
label << ')'
{% end %}
test_value = ::Spectator::TestValue.new(descriptor, label.to_s)
::Spectator::Matchers::{{matcher.id}}.new(test_value)
value = ::Spectator::Value.new(descriptor, label.to_s)
::Spectator::Matchers::{{matcher.id}}.new(value)
end
end
end

View file

@ -38,7 +38,7 @@ module Spectator
def to(stub : Mocks::MethodStub) : Nil
Harness.current.mocks.expect(@expression.value, stub)
value = TestValue.new(stub.name, stub.to_s)
value = Value.new(stub.name, stub.to_s)
matcher = Matchers::ReceiveMatcher.new(value, stub.arguments?)
to_eventually(matcher)
end
@ -55,7 +55,7 @@ module Spectator
end
def to_not(stub : Mocks::MethodStub) : Nil
value = TestValue.new(stub.name, stub.to_s)
value = Value.new(stub.name, stub.to_s)
matcher = Matchers::ReceiveMatcher.new(value, stub.arguments?)
to_never(matcher)
end
@ -107,7 +107,7 @@ module Spectator
# Reports an expectation to the current harness.
private def report(match_data : Matchers::MatchData)
expectation = Expectation.new(match_data, @source)
Harness.current.report_expectation(expectation)
Harness.current.report(expectation)
end
end
end

View file

@ -1,4 +1,4 @@
require "../test_value"
require "../value"
require "./failed_match_data"
require "./matcher"
require "./successful_match_data"
@ -21,8 +21,8 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
found = test_values(actual).each do |element|
def match(actual : Expression(T)) : MatchData forall T
found = values(actual).each do |element|
match_data = matcher.match(element)
break match_data unless match_data.matched?
end
@ -39,18 +39,18 @@ module Spectator::Matchers
# What if the collection is empty?
#
# RSpec doesn't support this syntax either.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
{% raise "The `expect { }.to_not all()` syntax is not supported (ambiguous)." %}
end
# Maps all values in the test collection to their own test values.
# Each value is given their own label,
# which is the original label with an index appended.
private def test_values(actual)
private def values(actual)
label_prefix = actual.label
actual.value.map_with_index do |value, index|
label = "#{label_prefix}[#{index}]"
TestValue.new(value, label)
Value.new(value, label)
end
end
end

View file

@ -11,7 +11,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(Array(ExpectedType)))
def initialize(@expected : Value(Array(ExpectedType)))
end
# Short text about the matcher's purpose.
@ -22,7 +22,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a)
@ -46,7 +46,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a)

View file

@ -1,4 +1,4 @@
require "../test_value"
require "../value"
require "./failed_match_data"
require "./matcher"
require "./successful_match_data"
@ -14,7 +14,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -25,7 +25,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new(description)
@ -36,7 +36,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new(description, "#{actual.label} has attributes #{expected.label}", negated_values(snapshot).to_a)

View file

@ -12,13 +12,13 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
expected.value === actual.value
end
# Overload that takes a regex so that the operands are flipped.
# This mimics RSpec's behavior.
private def match?(actual : TestExpression(Regex)) : Bool forall T
private def match?(actual : Expression(Regex)) : Bool forall T
actual.value === expected.value
end

View file

@ -15,7 +15,7 @@ module Spectator::Matchers
private getter expected_after
# Creates a new change matcher.
def initialize(@expression : TestBlock(ExpressionType), @expected_before : FromType, @expected_after : ToType)
def initialize(@expression : Block(ExpressionType), @expected_before : FromType, @expected_after : ToType)
end
# Short text about the matcher's purpose.
@ -26,7 +26,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if expected_before == before
if before == after
@ -53,7 +53,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if expected_before == before
if expected_after == after

View file

@ -13,7 +13,7 @@ module Spectator::Matchers
private getter expected
# Creates a new change matcher.
def initialize(@expression : TestBlock(ExpressionType), @expected : FromType)
def initialize(@expression : Block(ExpressionType), @expected : FromType)
end
# Short text about the matcher's purpose.
@ -24,7 +24,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if expected != before
FailedMatchData.new(description, "#{expression.label} was not initially #{expected}",
@ -44,7 +44,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if expected != before
FailedMatchData.new(description, "#{expression.label} was not initially #{expected}",

View file

@ -11,7 +11,7 @@ module Spectator::Matchers
private getter expression
# Creates a new change matcher.
def initialize(@expression : TestBlock(ExpressionType))
def initialize(@expression : Block(ExpressionType))
end
# Short text about the matcher's purpose.
@ -22,7 +22,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}",
@ -36,7 +36,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if before == after
SuccessfulMatchData.new(description)

View file

@ -9,7 +9,7 @@ module Spectator::Matchers
private getter expression
# Creates a new change matcher.
def initialize(@expression : TestBlock(ExpressionType), @relativity : String,
def initialize(@expression : Block(ExpressionType), @relativity : String,
&evaluator : ExpressionType, ExpressionType -> Bool)
@evaluator = evaluator
end
@ -22,7 +22,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}",
@ -41,7 +41,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
{% raise "The `expect { }.to_not change { }.by_...()` syntax is not supported (ambiguous)." %}
end

View file

@ -13,7 +13,7 @@ module Spectator::Matchers
private getter expected
# Creates a new change matcher.
def initialize(@expression : TestBlock(ExpressionType), @expected : ToType)
def initialize(@expression : Block(ExpressionType), @expected : ToType)
end
# Short text about the matcher's purpose.
@ -24,7 +24,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
before, after = change(actual)
if before == after
FailedMatchData.new(description, "#{actual.label} did not change #{expression.label}",
@ -52,7 +52,7 @@ module Spectator::Matchers
# but it is the expected value?
#
# RSpec doesn't support this syntax either.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
{% raise "The `expect { }.to_not change { }.to()` syntax is not supported (ambiguous)." %}
end

View file

@ -1,4 +1,4 @@
require "../test_value"
require "../value"
require "./range_matcher"
require "./value_matcher"
@ -13,7 +13,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
expected.value.includes?(actual.value)
end
@ -55,8 +55,8 @@ module Spectator::Matchers
lower = center - diff
upper = center + diff
range = Range.new(lower, upper)
test_value = TestValue.new(range, "#{center} ± #{expected.label}")
RangeMatcher.new(test_value)
value = Value.new(range, "#{center} ± #{expected.label}")
RangeMatcher.new(value)
end
end
end

View file

@ -8,7 +8,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -19,7 +19,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:includes?)
@ -42,7 +42,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:includes?)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:empty?)

View file

@ -11,7 +11,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -22,7 +22,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
value = actual.value
if value.is_a?(String) || value.responds_to?(:ends_with?)
match_ends_with(value, actual.label)
@ -33,7 +33,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
value = actual.value
if value.is_a?(String) || value.responds_to?(:ends_with?)
negated_match_ends_with(value, actual.label)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
expected.value == actual.value
end

View file

@ -1,4 +1,4 @@
require "../test_value"
require "../value"
require "./failed_match_data"
require "./matcher"
require "./successful_match_data"
@ -11,11 +11,11 @@ module Spectator::Matchers
# Creates the matcher with no expectation of the message.
def initialize
@expected = TestValue.new(nil, ExceptionType.to_s)
@expected = Value.new(nil, ExceptionType.to_s)
end
# Creates the matcher with an expected message.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -30,7 +30,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
exception = capture_exception { actual.value }
if exception.nil?
FailedMatchData.new(description, "#{actual.label} did not raise", expected: ExceptionType.inspect)
@ -61,7 +61,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
exception = capture_exception { actual.value }
if exception.nil?
SuccessfulMatchData.new(description)
@ -91,7 +91,7 @@ module Spectator::Matchers
end
def with_message(message : T) forall T
value = TestValue.new(message)
value = Value.new(message)
ExceptionMatcher(ExceptionType, T).new(value)
end
@ -114,13 +114,13 @@ module Spectator::Matchers
# Creates a new exception matcher with a message check.
def self.create(value, label : String)
expected = TestValue.new(value, label)
expected = Value.new(value, label)
ExceptionMatcher(Exception, typeof(value)).new(expected)
end
# Creates a new exception matcher with a type and message check.
def self.create(exception_type : T.class, value, label : String) forall T
expected = TestValue.new(value, label)
expected = Value.new(value, label)
ExceptionMatcher(T, typeof(value)).new(expected)
end
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value >= expected.value
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value > expected.value
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:has_key?)

View file

@ -9,7 +9,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -20,7 +20,7 @@ module Spectator::Matchers
end
# Entrypoint for the matcher, forwards to the correct method for string or enumerable.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
if (value = actual.value).is_a?(String)
match_string(value, actual.label)
else
@ -70,7 +70,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
if (value = actual.value).is_a?(String)
negated_match_string(value, actual.label)
else

View file

@ -15,7 +15,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new(description)
@ -26,7 +26,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new(description, "#{actual.label} has #{expected.label}", values(snapshot).to_a)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:has_value?)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
expected.value != actual.value
end

View file

@ -11,7 +11,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value.class == Expected
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value <= expected.value
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value < expected.value
end

View file

@ -16,10 +16,10 @@ module Spectator::Matchers
abstract def description : String
# Actually performs the test against the expression (value or block).
abstract def match(actual : TestExpression(T)) : MatchData forall T
abstract def match(actual : Expression(T)) : MatchData forall T
# Performs the test against the expression (value or block), but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
abstract def negated_match(actual : TestExpression(T)) : MatchData forall T
abstract def negated_match(actual : Expression(T)) : MatchData forall T
end
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value.nil?
end

View file

@ -10,7 +10,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with a expected values.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -21,7 +21,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new(description)
@ -32,7 +32,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new(description, "#{actual.label} is #{expected.label}", values(snapshot).to_a)

View file

@ -15,7 +15,7 @@ module Spectator::Matchers
def inclusive
label = expected.label
new_range = Range.new(range.begin, range.end, exclusive: false)
expected = TestValue.new(new_range, label)
expected = Value.new(new_range, label)
RangeMatcher.new(expected)
end
@ -23,12 +23,12 @@ module Spectator::Matchers
def exclusive
label = expected.label
new_range = Range.new(range.begin, range.end, exclusive: true)
expected = TestValue.new(new_range, label)
expected = Value.new(new_range, label)
RangeMatcher.new(expected)
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
expected.value.includes?(actual.value)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
struct ReceiveMatcher < StandardMatcher
alias Range = ::Range(Int32, Int32) | ::Range(Nil, Int32) | ::Range(Int32, Nil)
def initialize(@expected : TestExpression(Symbol), @args : Mocks::Arguments? = nil, @range : Range? = nil)
def initialize(@expected : Expression(Symbol), @args : Mocks::Arguments? = nil, @range : Range? = nil)
end
def description : String
@ -13,7 +13,7 @@ module Spectator::Matchers
"received message #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "At least once"} with #{@args || "any arguments"}"
end
def match?(actual : TestExpression(T)) : Bool forall T
def match?(actual : Expression(T)) : Bool forall T
calls = Harness.current.mocks.calls_for(actual.value, @expected.value)
calls.select! { |call| @args === call.args } if @args
if (range = @range)
@ -23,7 +23,7 @@ module Spectator::Matchers
end
end
def failure_message(actual : TestExpression(T)) : String forall T
def failure_message(actual : Expression(T)) : String forall T
range = @range
"#{actual.label} did not receive #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "at least once"} with #{@args || "any arguments"}"
end
@ -33,7 +33,7 @@ module Spectator::Matchers
"#{actual.label} received #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "at least once"} with #{@args || "any arguments"}"
end
def values(actual : TestExpression(T)) forall T
def values(actual : Expression(T)) forall T
calls = Harness.current.mocks.calls_for(actual.value, @expected.value)
calls.select! { |call| @args === call.args } if @args
range = @range
@ -43,7 +43,7 @@ module Spectator::Matchers
}
end
def negated_values(actual : TestExpression(T)) forall T
def negated_values(actual : Expression(T)) forall T
calls = Harness.current.mocks.calls_for(actual.value, @expected.value)
calls.select! { |call| @args === call.args } if @args
range = @range
@ -115,7 +115,7 @@ module Spectator::Matchers
end
private struct Count
def initialize(@expected : TestExpression(Symbol), @args : Mocks::Arguments?, @range : Range)
def initialize(@expected : Expression(Symbol), @args : Mocks::Arguments?, @range : Range)
end
def times

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
struct ReceiveTypeMatcher < StandardMatcher
alias Range = ::Range(Int32, Int32) | ::Range(Nil, Int32) | ::Range(Int32, Nil)
def initialize(@expected : TestExpression(Symbol), @args : Mocks::Arguments? = nil, @range : Range? = nil)
def initialize(@expected : Expression(Symbol), @args : Mocks::Arguments? = nil, @range : Range? = nil)
end
def description : String
@ -13,7 +13,7 @@ module Spectator::Matchers
"received message #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "At least once"} with #{@args || "any arguments"}"
end
def match?(actual : TestExpression(T)) : Bool forall T
def match?(actual : Expression(T)) : Bool forall T
calls = Harness.current.mocks.calls_for_type(actual.value, @expected.value)
calls.select! { |call| @args === call.args } if @args
if (range = @range)
@ -23,17 +23,17 @@ module Spectator::Matchers
end
end
def failure_message(actual : TestExpression(T)) : String forall T
def failure_message(actual : Expression(T)) : String forall T
range = @range
"#{actual.label} did not receive #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "at least once"} with #{@args || "any arguments"}"
end
def failure_message_when_negated(actual : TestExpression(T)) : String forall T
def failure_message_when_negated(actual : Expression(T)) : String forall T
range = @range
"#{actual.label} received #{@expected.label} #{range ? "#{humanize_range(range)} time(s)" : "at least once"} with #{@args || "any arguments"}"
end
def values(actual : TestExpression(T)) forall T
def values(actual : Expression(T)) forall T
calls = Harness.current.mocks.calls_for_type(T, @expected.value)
calls.select! { |call| @args === call.args } if @args
range = @range
@ -43,7 +43,7 @@ module Spectator::Matchers
}
end
def negated_values(actual : TestExpression(T)) forall T
def negated_values(actual : Expression(T)) forall T
calls = Harness.current.mocks.calls_for_type(T, @expected.value)
calls.select! { |call| @args === call.args } if @args
range = @range
@ -115,7 +115,7 @@ module Spectator::Matchers
end
private struct Count
def initialize(@expected : TestExpression(Symbol), @args : Mocks::Arguments?, @range : Range)
def initialize(@expected : Expression(Symbol), @args : Mocks::Arguments?, @range : Range)
end
def times

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
value = expected.value
if value && value.responds_to?(:same?)
value.same?(actual.value)

View file

@ -14,7 +14,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if snapshot.values.all?
SuccessfulMatchData.new(description)
@ -25,7 +25,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if snapshot.values.any?
FailedMatchData.new(description, "#{actual.label} responds to #{label}", values(snapshot).to_a)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:size?)

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:size?)

View file

@ -1,4 +1,4 @@
require "../test_value"
require "../expression"
require "./failed_match_data"
require "./matcher"
require "./successful_match_data"
@ -23,7 +23,7 @@ module Spectator::Matchers
# If it returns true, then a `SuccessfulMatchData` instance is returned.
# Otherwise, a `FailedMatchData` instance is returned.
# Additionally, `#failure_message` and `#values` are called for a failed match.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
if match?(actual)
SuccessfulMatchData.new(description)
else
@ -38,7 +38,7 @@ module Spectator::Matchers
# If it returns true, then a `SuccessfulMatchData` instance is returned.
# Otherwise, a `FailedMatchData` instance is returned.
# Additionally, `#failure_message_when_negated` and `#negated_values` are called for a failed match.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
# TODO: Invert description.
if does_not_match?(actual)
SuccessfulMatchData.new(description)
@ -53,7 +53,7 @@ module Spectator::Matchers
#
# The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`.
private abstract def failure_message(actual : TestExpression(T)) : String forall T
private abstract def failure_message(actual : Expression(T)) : String forall T
# Message displayed when the matcher isn't satisifed and is negated.
# This is essentially what would satisfy the matcher if it wasn't negated.
@ -66,12 +66,12 @@ module Spectator::Matchers
#
# The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`.
private def failure_message_when_negated(actual : TestExpression(T)) : String forall T
private def failure_message_when_negated(actual : Expression(T)) : String forall T
raise "Negation with #{self.class} is not supported."
end
# Checks whether the matcher is satisifed with the expression given to it.
private abstract def match?(actual : TestExpression(T)) : Bool forall T
private abstract def match?(actual : Expression(T)) : Bool forall T
# If the expectation is negated, then this method is called instead of `#match?`.
#
@ -79,7 +79,7 @@ module Spectator::Matchers
# If the matcher requires custom handling of negated matches,
# then this method should be overriden.
# Remember to override `#failure_message_when_negated` as well.
private def does_not_match?(actual : TestExpression(T)) : Bool forall T
private def does_not_match?(actual : Expression(T)) : Bool forall T
!match?(actual)
end
@ -101,7 +101,7 @@ module Spectator::Matchers
#
# The values should typically only contain the test expression values, not the labels.
# Labeled should be returned by `#failure_message`.
private def values(actual : TestExpression(T)) forall T
private def values(actual : Expression(T)) forall T
{actual: actual.value.inspect}
end
@ -123,7 +123,7 @@ module Spectator::Matchers
#
# The values should typically only contain the test expression values, not the labels.
# Labeled should be returned by `#failure_message_when_negated`.
private def negated_values(actual : TestExpression(T)) forall T
private def negated_values(actual : Expression(T)) forall T
values(actual)
end
end

View file

@ -10,7 +10,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Short text about the matcher's purpose.
@ -21,7 +21,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
value = actual.value
if value.is_a?(String) || value.responds_to?(:starts_with?)
match_starts_with(value, actual.label)
@ -32,7 +32,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
value = actual.value
if value.is_a?(String) || value.responds_to?(:starts_with?)
negated_match_starts_with(value, actual.label)

View file

@ -28,7 +28,7 @@ module Spectator::Matchers
# expect(0).to be < 1
# ```
def <(value)
expected = TestValue.new(value)
expected = Value.new(value)
LessThanMatcher.new(expected)
end
@ -38,7 +38,7 @@ module Spectator::Matchers
# expect(0).to be <= 1
# ```
def <=(value)
expected = TestValue.new(value)
expected = Value.new(value)
LessThanEqualMatcher.new(expected)
end
@ -48,7 +48,7 @@ module Spectator::Matchers
# expect(2).to be > 1
# ```
def >(value)
expected = TestValue.new(value)
expected = Value.new(value)
GreaterThanMatcher.new(expected)
end
@ -58,7 +58,7 @@ module Spectator::Matchers
# expect(2).to be >= 1
# ```
def >=(value)
expected = TestValue.new(value)
expected = Value.new(value)
GreaterThanEqualMatcher.new(expected)
end
@ -68,7 +68,7 @@ module Spectator::Matchers
# expect(0).to be == 0
# ```
def ==(value)
expected = TestValue.new(value)
expected = Value.new(value)
EqualityMatcher.new(expected)
end
@ -78,12 +78,12 @@ module Spectator::Matchers
# expect(0).to be != 1
# ```
def !=(value)
expected = TestValue.new(value)
expected = Value.new(value)
InequalityMatcher.new(expected)
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
@truthy == !!actual.value
end

View file

@ -12,7 +12,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) : Bool forall T
private def match?(actual : Expression(T)) : Bool forall T
actual.value.is_a?(Expected)
end

View file

@ -8,7 +8,7 @@ module Spectator::Matchers
private getter expected
# Creates the matcher with an expected value.
def initialize(@expected : TestValue(Array(ExpectedType)))
def initialize(@expected : Value(Array(ExpectedType)))
end
# Short text about the matcher's purpose.
@ -19,7 +19,7 @@ module Spectator::Matchers
end
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
def match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a)
@ -41,7 +41,7 @@ module Spectator::Matchers
# Performs the test against the expression, but inverted.
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
def negated_match(actual : Expression(T)) : MatchData forall T
actual_value = actual.value
return unexpected(actual_value, actual.label) unless actual_value.responds_to?(:to_a)

View file

@ -22,7 +22,7 @@ module Spectator::Matchers
# Creates the value matcher.
# The expected value is stored for later use.
def initialize(@expected : TestValue(ExpectedType))
def initialize(@expected : Value(ExpectedType))
end
# Additional information about the match failure.
@ -40,7 +40,7 @@ module Spectator::Matchers
# actual: "bar",
# }
# ```
private def values(actual : TestExpression(T)) forall T
private def values(actual : Expression(T)) forall T
super.merge(expected: expected.value.inspect)
end
@ -60,7 +60,7 @@ module Spectator::Matchers
# actual: "bar",
# }
# ```
private def negated_values(actual : TestExpression(T)) forall T
private def negated_values(actual : Expression(T)) forall T
super.merge(expected: "Not #{expected.value.inspect}")
end
end

View file

@ -6,9 +6,9 @@ module Spectator::Mocks
end
def to(stub : MethodStub) : Nil
actual = TestValue.new(T)
actual = Value.new(T)
Harness.current.mocks.expect(T, stub)
value = TestValue.new(stub.name, stub.to_s)
value = Value.new(stub.name, stub.to_s)
matcher = Matchers::ReceiveTypeMatcher.new(value, stub.arguments?)
partial = Expectations::ExpectationPartial.new(actual, @source)
partial.to_eventually(matcher)