Class: Assay::RSpec::Expect
Overview
Wraps the target of an expectation.
Instance Method Summary collapse
- #check_message(msg) ⇒ Object private
- #handle_negative_matcher(actual, matcher, message = nil, &block) ⇒ Object private
- #handle_positive_matcher(actual, matcher, message = nil, &block) ⇒ Object private
-
#initialize(target) ⇒ Expect
constructor
private
A new instance of Expect.
- #message_must_be_string(msg) ⇒ Object private
-
#to(matcher = nil, message = nil, &block) ⇒ Boolean
Runs the given expectation, passing if
matcherreturns true. -
#to_not(matcher = nil, message = nil, &block) ⇒ Boolean
(also: #not_to)
Runs the given expectation, passing if
matcherreturns false.
Constructor Details
#initialize(target) ⇒ Expect
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Expect.
17 18 19 |
# File 'lib/assay/rspec/expect.rb', line 17 def initialize(target) @target = target end |
Instance Method Details
#check_message(msg) ⇒ Object (private)
145 146 147 |
# File 'lib/assay/rspec/expect.rb', line 145 def (msg) ::Kernel.warn (msg) unless msg.nil? || msg.is_a?(String) end |
#handle_negative_matcher(actual, matcher, message = nil, &block) ⇒ Object (private)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/assay/rspec/expect.rb', line 108 def handle_negative_matcher(actual, matcher, =nil, &block) () #::RSpec::Matchers.last_should = :should_not #::RSpec::Matchers.last_matcher = matcher if block actual = block.call(actual) end #return ::RSpec::Matchers::BuiltIn::NegativeOperatorMatcher.new(actual) if matcher.nil? return Operatics.new(actual, true) if matcher.nil? matcher !~ actual #match = matcher.respond_to?(:does_not_match?) ? # !matcher.does_not_match?(actual, &block) : # matcher.matches?(actual, &block) #return match unless match #message ||= matcher.respond_to?(:failure_message_for_should_not) ? # matcher.failure_message_for_should_not : # matcher.negative_failure_message #if matcher.respond_to?(:diffable?) && matcher.diffable? # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual #else # ::RSpec::Expectations.fail_with message #end end |
#handle_positive_matcher(actual, matcher, message = nil, &block) ⇒ Object (private)
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/assay/rspec/expect.rb', line 75 def handle_positive_matcher(actual, matcher, =nil, &block) () #::RSpec::Matchers.last_should = :should #::RSpec::Matchers.last_matcher = matcher if block actual = block.call(actual) end #return ::RSpec::Matchers::BuiltIn::PositiveOperatorMatcher.new(actual) if matcher.nil? return Operatics.new(actual) if matcher.nil? matcher =~ actual #match = matcher.matches?(actual, &block) #return match if match #message ||= matcher.respond_to?(:failure_message_for_should) ? # matcher.failure_message_for_should : # matcher.failure_message #if matcher.respond_to?(:diffable?) && matcher.diffable? # ::RSpec::Expectations.fail_with message, matcher.expected, matcher.actual #else # ::RSpec::Expectations.fail_with message #end end |
#message_must_be_string(msg) ⇒ Object (private)
140 141 142 143 |
# File 'lib/assay/rspec/expect.rb', line 140 def (msg) "WARNING: ignoring the provided expectation message argument " + "(#{msg.inspect}) since it is not a string." end |
#to(matcher = nil, message = nil, &block) ⇒ Boolean
Runs the given expectation, passing if matcher returns true.
36 37 38 39 |
# File 'lib/assay/rspec/expect.rb', line 36 def to(matcher=nil, =nil, &block) #prevent_operator_matchers(:to, matcher) handle_positive_matcher(@target, matcher, , &block) end |
#to_not(matcher = nil, message = nil, &block) ⇒ Boolean Also known as: not_to
Runs the given expectation, passing if matcher returns false.
56 57 58 59 |
# File 'lib/assay/rspec/expect.rb', line 56 def to_not(matcher=nil, =nil, &block) #prevent_operator_matchers(:to_not, matcher) handle_negative_matcher(@target, matcher, , &block) end |