instance method
assert_no_changes
Ruby on Rails 6.1.7.10
Since v5.2.8.1Signature
assert_no_changes(expression, message = nil, &block)
Assertion that the result of evaluating an expression is not changed before and after invoking the passed in block.
assert_no_changes 'Status.all_good?' do post :create, params: { status: { ok: true } } end
An error message can be specified.
assert_no_changes -> { Status.all_good? }, 'Expected the status to be good' do post :create, params: { status: { ok: false } } end
Parameters
-
expressionreq -
messageopt = nil -
blockblock
Source
# File activesupport/lib/active_support/testing/assertions.rb, line 215
def assert_no_changes(expression, message = nil, &block)
exp = expression.respond_to?(:call) ? expression : -> { eval(expression.to_s, block.binding) }
before = exp.call
retval = assert_nothing_raised(&block)
after = exp.call
error = "#{expression.inspect} changed"
error = "#{message}.\n#{error}" if message
if before.nil?
assert_nil after, error
else
assert_equal before, after, error
end
retval
end
Defined in activesupport/lib/active_support/testing/assertions.rb line 215
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActiveSupport::Testing::Assertions