Class: Be::Assertor
Overview
An assertor is what RSpec calls a matcher.
Instance Method Summary collapse
- #assert!(target) ⇒ Object (also: #=~, #===)
- #fail?(target) ⇒ Boolean (also: #!=, #does_not_match?)
-
#initialize(messages, criteria = {}) ⇒ Assertor
constructor
A new instance of Assertor.
- #pass?(target) ⇒ Boolean (also: #==, #matches?)
- #refute!(target) ⇒ Object (also: #!~)
Constructor Details
#initialize(messages, criteria = {}) ⇒ Assertor
Returns a new instance of Assertor.
8 9 10 11 12 |
# File 'lib/be/assertor.rb', line 8 def initialize(, criteria={}) @messages = @criteria = criteria @comparator = criteria[:compare] || :== end |
Instance Method Details
#assert!(target) ⇒ Object Also known as: =~, ===
34 35 36 |
# File 'lib/be/assertor.rb', line 34 def assert!(target) handle(pass?(target), target) end |
#fail?(target) ⇒ Boolean Also known as: !=, does_not_match?
29 30 31 |
# File 'lib/be/assertor.rb', line 29 def fail?(target) ! pass?(target) end |
#pass?(target) ⇒ Boolean Also known as: ==, matches?
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/be/assertor.rb', line 15 def pass?(target) result = target @messages.each do |op, args, blk| result = result.__send__(op, *args, &blk) end if @criteria.key?(:measure) @criteria[:measure].__send__(@comparator, result) else result end end |
#refute!(target) ⇒ Object Also known as: !~
39 40 41 |
# File 'lib/be/assertor.rb', line 39 def refute!(target) handle(fail?(target), target) end |