Class: Assay::Assertor
- Inherits:
-
Object
- Object
- Assay::Assertor
- Defined in:
- lib/assay/assertor.rb
Overview
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.
Instance Attribute Summary collapse
-
#assay ⇒ Object
readonly
The assay class to which this assertor delegates.
-
#block ⇒ Object
readonly
Block criterion.
-
#criteria ⇒ Object
readonly
The criteria for applying the assertor.
Instance Method Summary collapse
-
#!@ ⇒ Object
Create a negated form of the matcher.
- #assert!(subject, &block) ⇒ Object (also: #=~, #===)
-
#assert_message(subject, &block) ⇒ Object
(also: #failure_message_for_should)
Assertion message.
- #fail?(subject, &block) ⇒ Boolean (also: #!=, #does_not_match?)
-
#initialize(assay_class, *criteria, &block) ⇒ Assertor
constructor
A new instance of Assertor.
-
#not ⇒ Object
Create a negated form of the matcher.
-
#not? ⇒ Boolean
Is the assertor negated?.
- #pass?(subject, &block) ⇒ Boolean (also: #==, #matches?)
- #refute!(subject, &block) ⇒ Object (also: #!~)
-
#refute_message(subject, &block) ⇒ Object
(also: #failure_message_for_should_not)
Refutation message.
Constructor Details
#initialize(assay_class, *criteria, &block) ⇒ Assertor
Returns a new instance of Assertor.
11 12 13 14 15 16 |
# File 'lib/assay/assertor.rb', line 11 def initialize(assay_class, *criteria, &block) @assay = assay_class @criteria = criteria @block = block @not = false end |
Instance Attribute Details
#assay ⇒ Object (readonly)
The assay class to which this assertor delegates.
21 22 23 |
# File 'lib/assay/assertor.rb', line 21 def assay @assay end |
#block ⇒ Object (readonly)
Block criterion.
31 32 33 |
# File 'lib/assay/assertor.rb', line 31 def block @block end |
#criteria ⇒ Object (readonly)
The criteria for applying the assertor.
26 27 28 |
# File 'lib/assay/assertor.rb', line 26 def criteria @criteria end |
Instance Method Details
#!@ ⇒ Object
Should this be @! method instead?
Create a negated form of the matcher.
103 104 105 |
# File 'lib/assay/assertor.rb', line 103 def !@ dup.negate! end |
#assert!(subject, &block) ⇒ Object Also known as: =~, ===
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# 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) ⇒ Object Also known as: failure_message_for_should
Assertion message. This is only used by RSpec compatibility methods.
119 120 121 122 |
# File 'lib/assay/assertor.rb', line 119 def (subject, &block) arguments, block = complete_criteria(subject, &block) @assay.(*arguments, &block) end |
#fail?(subject, &block) ⇒ Boolean Also known as: !=, does_not_match?
49 50 51 52 |
# File 'lib/assay/assertor.rb', line 49 def fail?(subject, &block) arguments, block = complete_criteria(subject, &block) @not ^ @assay.fail?(*arguments, &block) end |
#not ⇒ Object
Best name for this method?
Create a negated form of the matcher.
112 113 114 |
# File 'lib/assay/assertor.rb', line 112 def not dup.negate! end |
#not? ⇒ Boolean
Is the assertor negated?
36 37 38 |
# File 'lib/assay/assertor.rb', line 36 def not? @not end |
#pass?(subject, &block) ⇒ Boolean Also known as: ==, matches?
42 43 44 45 |
# 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) ⇒ Object Also known as: !~
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# 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 |
#refute_message(subject, &block) ⇒ Object Also known as: failure_message_for_should_not
Refutation message. This is only used by RSpec compatibility methods.
127 128 129 130 |
# File 'lib/assay/assertor.rb', line 127 def (subject, &block) arguments, block = complete_criteria(subject, &block) @assay.(*arguments, &block) end |