class Assay::Assertor
Assertor
delegates to Assay
class. It provides an object-oriented interface to makeing assertions, as opposed to the functional interface of the Assay
classes themselves.
Attributes
assay[R]
The assay class to which this assertor delegates.
block[R]
Block criterion.
criteria[R]
The criteria for applying the assertor.
Public Class Methods
new(assay_class, *criteria, &block)
click to toggle source
# File lib/assay/assertor.rb, line 11 def initialize(assay_class, *criteria, &block) @assay = assay_class @criteria = criteria @block = block @not = false end
Public Instance Methods
assert!(subject, &block)
click to toggle source
# File lib/assay/assertor.rb, line 56 def assert!(subject, &block) # technically this needs to be controlled by the assay class if block.nil? && Proc === subject block = subject subject = NA end arguments, block = complete_criteria(subject, &block) if @not @assay.refute!(*arguments, &block) else @assay.assert!(*arguments, &block) end end
assert_message(subject, &block)
click to toggle source
Assertion
message. This is only used by RSpec compatibility methods.
# File lib/assay/assertor.rb, line 119 def assert_message(subject, &block) arguments, block = complete_criteria(subject, &block) @assay.assert_message(*arguments, &block) end
Also aliased as: failure_message_for_should
fail?(subject, &block)
click to toggle source
# File lib/assay/assertor.rb, line 49 def fail?(subject, &block) arguments, block = complete_criteria(subject, &block) @not ^ @assay.fail?(*arguments, &block) end
Also aliased as: !=, does_not_match?
failure_message_for_should(subject, &block)
For RSpec matcher compatability.
Alias for: assert_message
failure_message_for_should_not(subject, &block)
For RSpec matcher compatability.
Alias for: refute_message
not()
click to toggle source
Create a negated form of the matcher.
@todo Best name for this method?
# File lib/assay/assertor.rb, line 112 def not dup.negate! end
not?()
click to toggle source
Is the assertor negated?
# File lib/assay/assertor.rb, line 36 def not? @not end
pass?(subject, &block)
click to toggle source
# File lib/assay/assertor.rb, line 42 def pass?(subject, &block) arguments, block = complete_criteria(subject, &block) @not ^ @assay.pass?(*arguments, &block) end
refute!(subject, &block)
click to toggle source
# File lib/assay/assertor.rb, line 74 def refute!(subject, &block) # technically this needs to be controlled by the assay class if block.nil? && Proc === subject block = subject subject = NA end arguments, block = complete_criteria(subject, &block) if @not @assay.assert!(*arguments, &block) else @assay.refute!(*arguments, &block) end end
Also aliased as: !~
refute_message(subject, &block)
click to toggle source
Refutation message. This is only used by RSpec compatibility methods.
# File lib/assay/assertor.rb, line 127 def refute_message(subject, &block) arguments, block = complete_criteria(subject, &block) @assay.refute_message(*arguments, &block) end
Also aliased as: failure_message_for_should_not
Protected Instance Methods
negate!()
click to toggle source
Toggle the ‘@not` flag.
# File lib/assay/assertor.rb, line 160 def negate! @not = !@not self end
Private Instance Methods
complete_criteria(subject, &block)
click to toggle source
# File lib/assay/assertor.rb, line 170 def complete_criteria(subject, &block) block = block || @block return @criteria, block if subject == NA if i = @criteria.index(NA) args = @criteria[0...i] + [subject] + @criteria[i+1..-1] else args = [subject] + @criteria end return args, block end