Method: RSpec::Matchers#change
- Defined in:
- lib/rspec/matchers.rb
#change(receiver = nil, message = nil, &block) ⇒ Object Also known as: a_block_changing, changing
Applied to a proc, specifies that its execution will cause some value to change.
You can either pass receiver and message, or a block, but not both.
When passing a block, it must use the { ... } format, not
do/end, as { ... } binds to the change method, whereas do/end
would errantly bind to the expect(..).to or expect(...).not_to method.
You can chain any of the following off of the end to specify details about the change:
fromto
or any one of:
byby_at_leastby_at_most
== Notes
Evaluates receiver.message or block before and after it
evaluates the block passed to expect. If the value is the same
object, its before/after hash value is used to see if it has changed.
Therefore, your object needs to properly implement hash to work correctly
with this matcher.
expect( ... ).not_to change supports the form that specifies from
(which specifies what you expect the starting, unchanged value to be)
but does not support forms with subsequent calls to by, by_at_least,
by_at_most or to.
492 493 494 |
# File 'lib/rspec/matchers.rb', line 492 def change(receiver=nil, =nil, &block) BuiltIn::Change.new(receiver, , &block) end |