Class: Assay::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/assay/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(fail_class, *arguments, &block) ⇒ Matcher

Returns a new instance of Matcher.



5
6
7
8
9
# File 'lib/assay/matcher.rb', line 5

def initialize(fail_class, *arguments, &block)
  @fail_class = fail_class
  @arguments  = arguments
  @block      = block
end

Instance Method Details

#exception(message = nil) ⇒ Object

Returns Exception class.



25
26
27
28
29
# File 'lib/assay/matcher.rb', line 25

def exception(message=nil)
  @exception ||= fail_class.new(message, @target, *@arguments, &@block)     
  #  :negated   => options[:negated],
  #  :backtrace => options[:backtrace] || caller,
end

#fail(backtrace = nil) ⇒ Object



43
44
45
# File 'lib/assay/matcher.rb', line 43

def fail(backtrace=nil)
  super exception #(backtrace || caller)
end

#fail_classObject



12
13
14
# File 'lib/assay/matcher.rb', line 12

def fail_class
  @fail_class
end

#fail_messageObject

This is just for RSpec matcher compatability.



32
33
34
# File 'lib/assay/matcher.rb', line 32

def fail_message
  exception.to_s
end

#matches?(target) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/assay/matcher.rb', line 17

def matches?(target)
  @exception = nil
  @target    = target

  @fail_class.pass?(target, *@arguments, &@block)
end

#negative_fail_messageObject

This is just for RSpec matcher compatability.



37
38
39
40
# File 'lib/assay/matcher.rb', line 37

def negative_fail_message
  #exception.set_negative(true)
  exception.to_s
end