62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/speccify.rb', line 62
def self.build_matcher(matcher_name, args, &block)
match_block = lambda do |actual, matcher|
block.call(actual, matcher, args)
end
body = lambda do |klass|
@matcher_name = matcher_name.to_s
def self.matcher_name
@matcher_name
end
attr_accessor :positive_msg, :negative_msg, :msgs, :loc
def initialize match_block
@match_block = match_block
end
def method_missing id, *args, &block
require 'ostruct'
(self.msgs ||= []) << OpenStruct.new( "name" => id, "args" => args, "block" => block )
self
end
def matches? given
@positive_msg ||= Speccify::Functions::message("#{given} should #{self.class.matcher_name}", "no match", self.class.matcher_name , self.loc || "")
@negative_msg ||= Speccify::Functions::message("#{given} should not #{self.class.matcher_name}", "match", self.class.matcher_name , self.loc || "")
@match_block.call(given, self)
end
end
Class.new(&body).new(match_block)
end
|