Class: Sus::RespondTo
- Inherits:
-
Object
- Object
- Sus::RespondTo
- Defined in:
- lib/sus/respond_to.rb
Overview
Represents a predicate that checks if an object responds to a method.
Defined Under Namespace
Classes: WithOptions, WithParameters
Instance Method Summary collapse
-
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
-
#initialize(method) ⇒ RespondTo
constructor
Initialize a new RespondTo predicate.
-
#print(output) ⇒ Object
Print a representation of this predicate.
-
#with_options(*options) ⇒ Object
Specify that the method should have specific keyword options.
Constructor Details
#initialize(method) ⇒ RespondTo
Initialize a new RespondTo predicate.
76 77 78 79 80 |
# File 'lib/sus/respond_to.rb', line 76 def initialize(method) @method = method @parameters = nil @options = nil end |
Instance Method Details
#call(assertions, subject) ⇒ Object
Evaluate this predicate against a subject.
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/sus/respond_to.rb', line 99 def call(assertions, subject) assertions.nested(self) do |assertions| condition = subject.respond_to?(@method) assertions.assert(condition, self) if condition and (@parameters or @options) parameters = subject.method(@method).parameters @parameters.call(assertions, parameters) if @parameters @options.call(assertions, parameters) if @options end end end |
#print(output) ⇒ Object
Print a representation of this predicate.
92 93 94 |
# File 'lib/sus/respond_to.rb', line 92 def print(output) output.write("respond to ", :variable, @method.to_s, :reset) end |
#with_options(*options) ⇒ Object
Specify that the method should have specific keyword options.
85 86 87 88 |
# File 'lib/sus/respond_to.rb', line 85 def (*) @options = WithOptions.new() return self end |