Flowdock
change(receiver=nil, message=nil, &block) public

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.develop_great_new_social_networking_app
  }.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).

Show source
Register or log in to add new notes.