37: def should_change(description, options = {}, &block)
38: by, from, to = get_options!([options], :by, :from, :to)
39: stmt = "change #{description}"
40: stmt << " from #{from.inspect}" if from
41: stmt << " to #{to.inspect}" if to
42: stmt << " by #{by.inspect}" if by
43:
44: if block_given?
45: code = block
46: else
47: warn "[DEPRECATION] should_change(expression, options) is deprecated. " <<
48: "Use should_change(description, options) { code } instead."
49: code = lambda { eval(description) }
50: end
51: before = lambda { @_before_should_change = code.bind(self).call }
52: should stmt, :before => before do
53: old_value = @_before_should_change
54: new_value = code.bind(self).call
55: assert_operator from, :===, old_value, "#{description} did not originally match #{from.inspect}" if from
56: assert_not_equal old_value, new_value, "#{description} did not change" unless by == 0
57: assert_operator to, :===, new_value, "#{description} was not changed to match #{to.inspect}" if to
58: assert_equal old_value + by, new_value if by
59: end
60: end