Add return type annotations

Addresses Crystal compiler warning about abstract method return types.
This commit is contained in:
Michael Miller 2019-09-23 20:32:21 -06:00
parent adbfb7da7c
commit 43dc106c18
58 changed files with 146 additions and 139 deletions

View file

@ -1,17 +1,17 @@
# Example that always raises an exception. # Example that always raises an exception.
class ErroredExample < Spectator::RunnableExample class ErroredExample < Spectator::RunnableExample
# Dummy description. # Dummy description.
def what def what : Symbol | String
"ERROR" "ERROR"
end end
# Dummy source. # Dummy source.
def source def source : ::Spectator::Source
::Spectator::Source.new(__FILE__, __LINE__) ::Spectator::Source.new(__FILE__, __LINE__)
end end
# Dummy symbolic flag. # Dummy symbolic flag.
def symbolic? def symbolic? : Bool
false false
end end

View file

@ -1,17 +1,17 @@
# Example that always fails. # Example that always fails.
class FailingExample < Spectator::RunnableExample class FailingExample < Spectator::RunnableExample
# Dummy description. # Dummy description.
def what def what : Symbol | String
"FAIL" "FAIL"
end end
# Dummy source. # Dummy source.
def source def source : ::Spectator::Source
::Spectator::Source.new(__FILE__, __LINE__) ::Spectator::Source.new(__FILE__, __LINE__)
end end
# Dummy symbolic flag. # Dummy symbolic flag.
def symbolic? def symbolic? : Bool
false false
end end

View file

@ -6,17 +6,17 @@ class PassingExample < Spectator::RunnableExample
end end
# Dummy description. # Dummy description.
def what def what : Symbol | String
"PASS" "PASS"
end end
# Dummy source. # Dummy source.
def source def source : ::Spectator::Source
::Spectator::Source.new(__FILE__, __LINE__) ::Spectator::Source.new(__FILE__, __LINE__)
end end
# Dummy symbolic flag. # Dummy symbolic flag.
def symbolic? def symbolic? : Bool
@symbolic @symbolic
end end

View file

@ -2,17 +2,17 @@
# This is useful for capturing what's going on when an event is running. # This is useful for capturing what's going on when an event is running.
class SpyExample < Spectator::RunnableExample class SpyExample < Spectator::RunnableExample
# Dummy description. # Dummy description.
def what def what : Symbol | String
"SPY" "SPY"
end end
# Dummy source. # Dummy source.
def source def source : ::Spectator::Source
::Spectator::Source.new(__FILE__, __LINE__) ::Spectator::Source.new(__FILE__, __LINE__)
end end
# Dummy symbolic flag. # Dummy symbolic flag.
def symbolic? def symbolic? : Bool
false false
end end

View file

@ -1,15 +1,15 @@
require "./spec_helper" require "./spec_helper"
class ConcretePendingExample < Spectator::PendingExample class ConcretePendingExample < Spectator::PendingExample
def what def what : Symbol | String
"PENDING_TEST_EXAMPLE" "PENDING_TEST_EXAMPLE"
end end
def source def source : ::Spectator::Source
::Spectator::Source.new(__FILE__, __LINE__) ::Spectator::Source.new(__FILE__, __LINE__)
end end
def symbolic? def symbolic? : Bool
false false
end end

View file

@ -6,7 +6,7 @@ module Spectator
end end
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) def includes?(example) : Bool
@filters.any?(&.includes?(example)) @filters.any?(&.includes?(example))
end end
end end

View file

@ -10,17 +10,17 @@ module Spectator
# This class shouldn't be used, it's just to trick the compiler. # This class shouldn't be used, it's just to trick the compiler.
private class DummyExample < RunnableExample private class DummyExample < RunnableExample
# Dummy description. # Dummy description.
def what def what : Symbol | String
"DUMMY" "DUMMY"
end end
# Dummy symbolic flag. # Dummy symbolic flag.
def symbolic? def symbolic? : Bool
false false
end end
# Dummy source. # Dummy source.
def source def source : Source
Source.new(__FILE__, __LINE__) Source.new(__FILE__, __LINE__)
end end

View file

@ -4,8 +4,12 @@ module Spectator
# Base class for all types of examples. # Base class for all types of examples.
# Concrete types must implement the `#run_impl, `#what`, `#instance`, and `#source` methods. # Concrete types must implement the `#run_impl, `#what`, `#instance`, and `#source` methods.
abstract class Example < ExampleComponent abstract class Example < ExampleComponent
@finished = false
# Indicates whether the example has already been run. # Indicates whether the example has already been run.
getter? finished = false def finished? : Bool
@finished
end
# Group that the example belongs to. # Group that the example belongs to.
getter group : ExampleGroup getter group : ExampleGroup
@ -36,12 +40,12 @@ module Spectator
end end
# Indicates there is only one example to run. # Indicates there is only one example to run.
def example_count def example_count : Int
1 1
end end
# Retrieve the current example. # Retrieve the current example.
def [](index : Int) def [](index : Int) : Example
self self
end end

View file

@ -3,7 +3,7 @@ module Spectator
# This is used as the base node type for the composite design pattern. # This is used as the base node type for the composite design pattern.
abstract class ExampleComponent abstract class ExampleComponent
# Text that describes the context or test. # Text that describes the context or test.
abstract def what : String abstract def what : Symbol | String
# Indicates whether the example (or group) has been completely run. # Indicates whether the example (or group) has been completely run.
abstract def finished? : Bool abstract def finished? : Bool

View file

@ -18,6 +18,7 @@ module Spectator
# Creates the example group. # Creates the example group.
# The hooks are stored to be triggered later. # The hooks are stored to be triggered later.
def initialize(@hooks : ExampleHooks, @conditions : ExampleConditions) def initialize(@hooks : ExampleHooks, @conditions : ExampleConditions)
@example_count = 0
@before_all_hooks_run = false @before_all_hooks_run = false
@after_all_hooks_run = false @after_all_hooks_run = false
end end
@ -53,7 +54,9 @@ module Spectator
end end
# Number of examples in this group and all sub-groups. # Number of examples in this group and all sub-groups.
getter example_count = 0 def example_count : Int
@example_count
end
# Retrieves an example by its index. # Retrieves an example by its index.
# This recursively searches for an example. # This recursively searches for an example.
@ -118,7 +121,7 @@ module Spectator
end end
# Checks whether all examples in the group have been run. # Checks whether all examples in the group have been run.
def finished? def finished? : Bool
children.all?(&.finished?) children.all?(&.finished?)
end end

View file

@ -11,7 +11,7 @@ module Spectator::Formatting
end end
# Status string specific to the result type. # Status string specific to the result type.
private def status private def status : String
"FAIL" "FAIL"
end end

View file

@ -11,7 +11,7 @@ module Spectator::Formatting
end end
# Status string specific to the result type. # Status string specific to the result type.
private def status private def status : String
"TODO" "TODO"
end end

View file

@ -9,7 +9,7 @@ module Spectator::Formatting
end end
# Status string specific to the result type. # Status string specific to the result type.
private def status private def status : String
"PASS" "PASS"
end end
end end

View file

@ -6,7 +6,7 @@ module Spectator
end end
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) def includes?(example) : Bool
@line == example.source.line @line == example.source.line
end end
end end

View file

@ -16,7 +16,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"all #{matcher.description}" "all #{matcher.description}"
end end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"contains exactly #{expected.label}" "contains exactly #{expected.label}"
end end

View file

@ -20,7 +20,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"has attributes #{expected.label}" "has attributes #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"matches #{expected.label}" "matches #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value === actual.value expected.value === actual.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not match #{expected.label}" "#{actual.label} does not match #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} matched #{expected.label}" "#{actual.label} matched #{expected.label}"
end end
end end

View file

@ -21,7 +21,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"changes #{expression.label} from #{expected_before.inspect} to #{expected_after.inspect}" "changes #{expression.label} from #{expected_before.inspect} to #{expected_after.inspect}"
end end

View file

@ -19,7 +19,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"changes #{expression.label} from #{expected}" "changes #{expression.label} from #{expected}"
end end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"changes #{expression.label}" "changes #{expression.label}"
end end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"changes #{expression.label} #{@relativity}" "changes #{expression.label} #{@relativity}"
end end

View file

@ -19,7 +19,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"changes #{expression.label} to #{expected}" "changes #{expression.label} to #{expected}"
end end

View file

@ -8,12 +8,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is in #{expected.label}" "is in #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value.includes?(actual.value) expected.value.includes?(actual.value)
end end
@ -23,7 +23,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not in #{expected.label}" "#{actual.label} is not in #{expected.label}"
end end
@ -34,7 +34,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is in #{expected.label}" "#{actual.label} is in #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"contains #{expected.label}" "contains #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value.all? do |item| expected.value.all? do |item|
actual.value.includes?(item) actual.value.includes?(item)
end end
@ -24,7 +24,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not match #{expected.label}" "#{actual.label} does not match #{expected.label}"
end end
@ -35,7 +35,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} contains #{expected.label}" "#{actual.label} contains #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is empty" "is empty"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value.empty? actual.value.empty?
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not empty" "#{actual.label} is not empty"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is empty" "#{actual.label} is empty"
end end
end end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"ends with #{expected.label}" "ends with #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"equals #{expected.label}" "equals #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value == actual.value expected.value == actual.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not equal #{expected.label}" "#{actual.label} does not equal #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} equals #{expected.label}" "#{actual.label} equals #{expected.label}"
end end
end end

View file

@ -21,7 +21,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
if (message = @expected) if (message = @expected)
"raises #{ExceptionType} with message #{message}" "raises #{ExceptionType} with message #{message}"
else else

View file

@ -4,7 +4,7 @@ module Spectator::Matchers
# Information about a failed match. # Information about a failed match.
struct FailedMatchData < MatchData struct FailedMatchData < MatchData
# Indicates that the match failed. # Indicates that the match failed.
def matched? def matched? : Bool
false false
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"greater than or equal to #{expected.label}" "greater than or equal to #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value >= expected.value actual.value >= expected.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is less than #{expected.label}" "#{actual.label} is less than #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is greater than or equal to #{expected.label}" "#{actual.label} is greater than or equal to #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"greater than #{expected.label}" "greater than #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value > expected.value actual.value > expected.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is less than or equal to #{expected.label}" "#{actual.label} is less than or equal to #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is greater than #{expected.label}" "#{actual.label} is greater than #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"has key #{expected.label}" "has key #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value.has_key?(expected.value) actual.value.has_key?(expected.value)
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not have key #{expected.label}" "#{actual.label} does not have key #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} has key #{expected.label}" "#{actual.label} has key #{expected.label}"
end end

View file

@ -8,12 +8,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"includes #{expected.label}" "includes #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
if (value = actual.value).is_a?(String) if (value = actual.value).is_a?(String)
match_string?(value) match_string?(value)
else else
@ -46,7 +46,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not include #{expected.label}" "#{actual.label} does not include #{expected.label}"
end end
@ -57,7 +57,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} includes #{expected.label}" "#{actual.label} includes #{expected.label}"
end end

View file

@ -17,7 +17,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"has #{expected.label}" "has #{expected.label}"
end end
@ -48,7 +48,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not have #{expected.label}" "#{actual.label} does not have #{expected.label}"
end end
@ -59,7 +59,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} has #{expected.label}" "#{actual.label} has #{expected.label}"
end end
@ -76,7 +76,7 @@ module Spectator::Matchers
end end
# Checks if all predicate methods from the snapshot of them are satisified. # Checks if all predicate methods from the snapshot of them are satisified.
private def match?(snapshot) private def match?(snapshot) : Bool
# Test each predicate and immediately return false if one is false. # Test each predicate and immediately return false if one is false.
{% for attribute in ExpectedType.keys %} {% for attribute in ExpectedType.keys %}
return false unless snapshot[{{attribute.symbolize}}] return false unless snapshot[{{attribute.symbolize}}]

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"has value #{expected.label}" "has value #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value.has_value?(expected.value) actual.value.has_value?(expected.value)
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not have value #{expected.label}" "#{actual.label} does not have value #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} has value #{expected.label}" "#{actual.label} has value #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is not equal to #{expected.label}" "is not equal to #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value != actual.value expected.value != actual.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is equal to #{expected.label}" "#{actual.label} is equal to #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is not equal to #{expected.label}" "#{actual.label} is not equal to #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"less than or equal to #{expected.label}" "less than or equal to #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value <= expected.value actual.value <= expected.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is greater than #{expected.label}" "#{actual.label} is greater than #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is less than or equal to #{expected.label}" "#{actual.label} is less than or equal to #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"less than #{expected.label}" "less than #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value < expected.value actual.value < expected.value
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is greater than or equal to #{expected.label}" "#{actual.label} is greater than or equal to #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is less than #{expected.label}" "#{actual.label} is less than #{expected.label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is nil" "is nil"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value.nil? actual.value.nil?
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not nil" "#{actual.label} is not nil"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is nil" "#{actual.label} is nil"
end end
end end

View file

@ -16,7 +16,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is #{expected.label}" "is #{expected.label}"
end end
@ -47,7 +47,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not #{expected.label}" "#{actual.label} is not #{expected.label}"
end end
@ -58,7 +58,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is #{expected.label}" "#{actual.label} is #{expected.label}"
end end

View file

@ -7,7 +7,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is in #{expected.label}" "is in #{expected.label}"
end end
@ -26,7 +26,7 @@ module Spectator::Matchers
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value.includes?(actual.value) expected.value.includes?(actual.value)
end end
@ -36,7 +36,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not in #{expected.label} (#{exclusivity})" "#{actual.label} is not in #{expected.label} (#{exclusivity})"
end end
@ -47,7 +47,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is in #{expected.label} (#{exclusivity})" "#{actual.label} is in #{expected.label} (#{exclusivity})"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is #{expected.label}" "is #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value.same?(actual.value) expected.value.same?(actual.value)
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not #{expected.label}" "#{actual.label} is not #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is #{expected.label}" "#{actual.label} is #{expected.label}"
end end
end end

View file

@ -9,7 +9,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"responds to #{label}" "responds to #{label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"has size #{expected.label}" "has size #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value == actual.value.size expected.value == actual.value.size
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} does not have #{expected.label} elements" "#{actual.label} does not have #{expected.label} elements"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} has #{expected.label} elements" "#{actual.label} has #{expected.label} elements"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is the same size as #{expected.label}" "is the same size as #{expected.label}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
expected.value.size == actual.value.size expected.value.size == actual.value.size
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not the same size as #{expected.label}" "#{actual.label} is not the same size as #{expected.label}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is the same size as #{expected.label}" "#{actual.label} is the same size as #{expected.label}"
end end

View file

@ -16,7 +16,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"starts with #{expected.label}" "starts with #{expected.label}"
end end

View file

@ -4,7 +4,7 @@ module Spectator::Matchers
# Information about a successful match. # Information about a successful match.
struct SuccessfulMatchData < MatchData struct SuccessfulMatchData < MatchData
# Indicates that the match succeeded. # Indicates that the match succeeded.
def matched? def matched? : Bool
true true
end end
end end

View file

@ -18,7 +18,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is #{label}" "is #{label}"
end end
@ -83,7 +83,7 @@ module Spectator::Matchers
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
@truthy == !!actual.value @truthy == !!actual.value
end end
@ -93,7 +93,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is #{negated_label}" "#{actual.label} is #{negated_label}"
end end
@ -104,7 +104,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is #{label}" "#{actual.label} is #{label}"
end end

View file

@ -7,12 +7,12 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"is as #{Expected}" "is as #{Expected}"
end end
# Checks whether the matcher is satisifed with the expression given to it. # Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual : TestExpression(T)) forall T private def match?(actual : TestExpression(T)) : Bool forall T
actual.value.is_a?(Expected) actual.value.is_a?(Expected)
end end
@ -22,7 +22,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message(actual) private def failure_message(actual) : String
"#{actual.label} is not a #{Expected}" "#{actual.label} is not a #{Expected}"
end end
@ -33,7 +33,7 @@ module Spectator::Matchers
# #
# The message should typically only contain the test expression labels. # The message should typically only contain the test expression labels.
# Actual values should be returned by `#values`. # Actual values should be returned by `#values`.
private def failure_message_when_negated(actual) private def failure_message_when_negated(actual) : String
"#{actual.label} is a #{Expected}" "#{actual.label} is a #{Expected}"
end end

View file

@ -14,7 +14,7 @@ module Spectator::Matchers
# Short text about the matcher's purpose. # Short text about the matcher's purpose.
# This explains what condition satisfies the matcher. # This explains what condition satisfies the matcher.
# The description is used when the one-liner syntax is used. # The description is used when the one-liner syntax is used.
def description def description : String
"contains #{expected.label} in any order" "contains #{expected.label} in any order"
end end

View file

@ -6,7 +6,7 @@ module Spectator
end end
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) def includes?(example) : Bool
@name == example.to_s @name == example.to_s
end end
end end

View file

@ -23,7 +23,7 @@ module Spectator
end end
# Indicates wheter the group references a type. # Indicates wheter the group references a type.
def symbolic? def symbolic? : Bool
@what.is_a?(Symbol) @what.is_a?(Symbol)
end end

View file

@ -2,7 +2,7 @@ module Spectator
# Filter that matches all examples. # Filter that matches all examples.
class NullExampleFilter < ExampleFilter class NullExampleFilter < ExampleFilter
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) def includes?(example) : Bool
true true
end end
end end

View file

@ -5,7 +5,7 @@ module Spectator
# This class will not run example code. # This class will not run example code.
abstract class PendingExample < Example abstract class PendingExample < Example
# Returns a pending result. # Returns a pending result.
private def run_impl private def run_impl : Result
PendingResult.new(self) PendingResult.new(self)
end end
end end

View file

@ -5,12 +5,12 @@ module Spectator
# The root has no parent. # The root has no parent.
class RootExampleGroup < ExampleGroup class RootExampleGroup < ExampleGroup
# Dummy value - this should never be used. # Dummy value - this should never be used.
def what def what : Symbol | String
"ROOT" "ROOT"
end end
# Indicates that the group is symbolic. # Indicates that the group is symbolic.
def symbolic? def symbolic? : Bool
true true
end end

View file

@ -8,7 +8,7 @@ module Spectator
abstract class RunnableExample < Example abstract class RunnableExample < Example
# Runs the example, hooks, and captures the result # Runs the example, hooks, and captures the result
# and translates to a usable result. # and translates to a usable result.
def run_impl def run_impl : Result
result = capture_result result = capture_result
expectations = Internals::Harness.current.expectations expectations = Internals::Harness.current.expectations
translate_result(result, expectations) translate_result(result, expectations)

View file

@ -7,7 +7,7 @@ module Spectator
end end
# Checks whether the example satisfies the filter. # Checks whether the example satisfies the filter.
def includes?(example) def includes?(example) : Bool
@source === example.source @source === example.source
end end
end end