Method: Spec::Matchers#change
- Defined in:
- lib/spec/matchers/change.rb
#change(receiver = nil, message = nil, &block) ⇒ Object
:call-seq:
should change(receiver, , &block)
should change(receiver, , &block).by(value)
should change(receiver, , &block).from(old).to(new)
should_not change(receiver, , &block)
Allows you to specify that a Proc will cause some value to change.
Examples
lambda {
team.add_player(player)
}.should change(roster, :count)
lambda {
team.add_player(player)
}.should change(roster, :count).by(1)
lambda {
team.add_player(player)
}.should change(roster, :count).by_at_least(1)
lambda {
team.add_player(player)
}.should change(roster, :count).by_at_most(1)
string = "string"
lambda {
string.reverse!
}.should change { string }.from("string").to("gnirts")
lambda {
person.happy_birthday
}.should change(person, :birthday).from(32).to(33)
lambda {
employee.
}.should change(employee, :title).from("Mail Clerk").to("CEO")
Evaluates receiver.message or block before and after it evaluates the c object (generated by the lambdas in the examples above).
Then compares the values before and after the receiver.message and evaluates the difference compared to the expected difference.
WARNING
should_not change only supports the form with no subsequent calls to by, by_at_least, by_at_most, to or from.
blocks passed to should change and should_not change must use the {} form (do/end is not supported).
147 148 149 |
# File 'lib/spec/matchers/change.rb', line 147 def change(receiver=nil, =nil, &block) Matchers::Change.new(receiver, , &block) end |