module Shoulda::Macros
def should_not_change(description, &block)
should_not_change("the number of posts") { Post.count }
setup { @post.update_attributes(:title => "new") }
context "Updating a post" do
Example:
The passed description will be used when generating the test name and failure message.
is run. This is the logical opposite of should_change.
of a block that is run before and after the current setup block
Macro that creates a test asserting no change between the return value
def should_not_change(description, &block) if block_given? code = block else warn "[DEPRECATION] should_not_change(expression) is deprecated. " << "Use should_not_change(description) { code } instead." code = lambda { eval(description) } end before = lambda { @_before_should_not_change = code.bind(self).call } should "not change #{description}", :before => before do new_value = code.bind(self).call assert_equal @_before_should_not_change, new_value, "#{description} changed" end end