Skip to content

Commit

Permalink
Use match instead of process
Browse files Browse the repository at this point in the history
  • Loading branch information
icy-arctic-fox committed Jul 30, 2024
1 parent af4c067 commit 2bdf9e1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/spectator/matchers/built_in/all_matcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Spectator::Matchers::BuiltIn
def matches?(actual_value)
raise "`all` matcher requires value to be `Enumerable`" unless actual_value.is_a?(Enumerable)
actual_value.each_with_index do |value, index|
next unless failure = Matcher.process(@matcher, value)
next unless failure = Matcher.match(@matcher, value)
@failed_index = index
@failure = failure
return false
Expand All @@ -19,7 +19,7 @@ module Spectator::Matchers::BuiltIn
def does_not_match?(actual_value)
raise "`all` matcher requires value to be `Enumerable`" unless actual_value.is_a?(Enumerable)
actual_value.each_with_index do |value, index|
next unless failure = Matcher.process_negated(@matcher, value)
next unless failure = Matcher.match_negated(@matcher, value)
@failed_index = index
@failure = failure
return false
Expand Down
10 changes: 5 additions & 5 deletions src/spectator/matchers/expect.cr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process(matcher, @actual_value,
failure = Matcher.match(matcher, @actual_value,
failure_message: failure_message,
location: location)
raise failure if failure
Expand All @@ -23,7 +23,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process_negated(matcher, @actual_value,
failure = Matcher.match_negated(matcher, @actual_value,
failure_message: failure_message,
location: location)
raise failure if failure
Expand All @@ -49,7 +49,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process_block(matcher, @block,
failure = Matcher.match_block(matcher, @block,
failure_message: failure_message,
location: location)
raise failure if failure
Expand All @@ -60,7 +60,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Exception
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process_block(matcher, @block,
failure = Matcher.match_block(matcher, @block,
failure_message: failure_message,
location: location)
raise failure if failure
Expand All @@ -72,7 +72,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process_block_negated(matcher, @block,
failure = Matcher.match_block_negated(matcher, @block,
failure_message: failure_message,
location: location)
raise failure if failure
Expand Down
24 changes: 12 additions & 12 deletions src/spectator/matchers/matcher.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ module Spectator::Matchers
module Matcher
extend self

def process(matcher, actual_value, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
def match(matcher, actual_value, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
if matcher.responds_to?(:matches?) && matcher.responds_to?(:failure_message)
return if matcher.matches?(actual_value)
failure_message ||= matcher.failure_message(actual_value).to_s
Expand All @@ -19,9 +19,9 @@ module Spectator::Matchers
end
end

def process_negated(matcher, actual_value, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
def match_negated(matcher, actual_value, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
if matcher.responds_to?(:negated_failure_message)
passed = if matcher.responds_to?(:does_not_match?)
matcher.does_not_match?(actual_value)
Expand All @@ -40,9 +40,9 @@ module Spectator::Matchers
end
end

def process_block(matcher, block, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
def match_block(matcher, block, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
if matcher.responds_to?(:matches?) && matcher.responds_to?(:failure_message)
return if matcher.matches?(&block)
failure_message ||= matcher.failure_message(&block).to_s
Expand All @@ -53,9 +53,9 @@ module Spectator::Matchers
end
end

def process_block_negated(matcher, block, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
def match_block_negated(matcher, block, *,
failure_message : String? = nil,
location : Core::LocationRange? = nil) : AssertionFailed?
if matcher.responds_to?(:negated_failure_message)
passed = if matcher.responds_to?(:does_not_match?)
matcher.does_not_match?(&block)
Expand Down
4 changes: 2 additions & 2 deletions src/spectator/matchers/should_methods.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process(matcher, self,
failure = Matcher.match(matcher, self,
failure_message: failure_message,
location: location)
raise failure if failure
Expand All @@ -19,7 +19,7 @@ module Spectator::Matchers
source_line = __LINE__,
source_end_line = __END_LINE__) : Nil
location = Core::LocationRange.new(source_file, source_line, source_end_line)
failure = Matcher.process_negated(matcher, self,
failure = Matcher.match_negated(matcher, self,
failure_message: failure_message,
location: location)
raise failure if failure
Expand Down

0 comments on commit 2bdf9e1

Please sign in to comment.