class Be::Assertor
An assertor is what RSpec calls a matcher.
Public Class Methods
new(messages, criteria={})
click to toggle source
# File lib/be/assertor.rb, line 8 def initialize(messages, criteria={}) @messages = messages @criteria = criteria @comparator = criteria[:compare] || :== end
Public Instance Methods
assert!(target)
click to toggle source
# File lib/be/assertor.rb, line 34 def assert!(target) handle(pass?(target), target) end
fail?(target)
click to toggle source
# File lib/be/assertor.rb, line 29 def fail?(target) ! pass?(target) end
Also aliased as: !=, does_not_match?
pass?(target)
click to toggle source
# 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)
click to toggle source
# File lib/be/assertor.rb, line 39 def refute!(target) handle(fail?(target), target) end
Also aliased as: !~
Private Instance Methods
assert_message(target)
click to toggle source
Produce an error message.
# File lib/be/assertor.rb, line 75 def assert_message(target) #"#{target.inspect} #{@operator} #{@arguemnts.map{ |x| x.inspect }}" s = "b" r = target sigs = [] @messages.each do |meth, args, blk| vars = [] list = [] args.each do |a| vars << s list << "#{s}) " + a.inspect s = s.succ end sigs << [meth, vars, list] end msgs = [] vest = ["a) #{r.inspect}"] sigs.each do |meth, vars, list| msgs << "#{meth}(#{vars.join(', ')})" vest << list.join("\n") unless list.empty? end "a." + msgs.join(".") + "\n" + vest.join("\n") end
Also aliased as: failure_message_for_should
handle(result, target)
click to toggle source
# File lib/be/assertor.rb, line 56 def handle(result, target) if result increment_passing else increment_failing error_class = Be::ASSERTION_ERRORS[@operator] || StandardError msg = assert_message(target) #, @operator, @arguments) err = error_class.new(msg) err.set_backtrace(@criteria[:caller] || caller[2..-1]) err.set_assertion(true) raise err end end
increment_failing()
click to toggle source
Increment BRASS standard assertion counts for failing assertion.
# File lib/be/assertor.rb, line 124 def increment_failing $ASSERTION_COUNTS[:total] += 1 $ASSERTION_COUNTS[:fail] += 1 end
increment_passing()
click to toggle source
Increment BRASS standard assertion counts for passing assertion.
# File lib/be/assertor.rb, line 116 def increment_passing $ASSERTION_COUNTS[:total] += 1 $ASSERTION_COUNTS[:pass] += 1 end
refute_message(target)
click to toggle source
# File lib/be/assertor.rb, line 109 def refute_message(target) "! " + assert_message(target) end
Also aliased as: failure_message_for_should_not