# File lib/matchy/matcher_builder.rb, line 5 5: def build_matcher(matcher_name=nil, args=[], &block) 6: match_block = lambda do |actual, matcher| 7: block.call(actual, matcher, args) 8: end 9: 10: body = lambda do |klass| 11: include Test::Unit::Assertions 12: @matcher_name = matcher_name.to_s 13: 14: def self.matcher_name 15: @matcher_name 16: end 17: 18: attr_reader :matcher_name 19: attr_accessor :positive_failure_message, :negative_failure_message, :chained_messages 20: 21: def initialize(match_block, test_case) 22: @match_block, @test_case = match_block, test_case 23: @matcher_name = self.class.matcher_name 24: end 25: 26: def method_missing(id, *args, &block) 27: (self.chained_messages ||= []) << ChainedMessage.new(id, args, block) 28: self 29: end 30: 31: def matches?(given) 32: @positive_failure_message ||= "Matching with '#{matcher_name}' failed, although it should match." 33: @negative_failure_message ||= "Matching with '#{matcher_name}' passed, although it should_not match." 34: @match_block.call(given, self) 35: end 36: 37: def fail!(which) 38: @test_case.flunk(which ? failure_message : negative_failure_message) 39: end 40: 41: def pass!(which) 42: @test_case.assert true 43: end 44: 45: alias_method :failure_message, :positive_failure_message 46: end 47: 48: Class.new(&body).new(match_block, self) 49: end
# File lib/matchy/matcher_builder.rb, line 37 37: def fail!(which) 38: @test_case.flunk(which ? failure_message : negative_failure_message) 39: end
# File lib/matchy/matcher_builder.rb, line 31 31: def matches?(given) 32: @positive_failure_message ||= "Matching with '#{matcher_name}' failed, although it should match." 33: @negative_failure_message ||= "Matching with '#{matcher_name}' passed, although it should_not match." 34: @match_block.call(given, self) 35: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.