Minitest Change Assertions
Provides assertions for your Minitest suite to determine if an object has been changed.
Install
gem 'minitest_change_assertions'
Usage
assert_changed
assert_changed 'user.name' do
user.name = 'Bob'
end
assert_changed -> { user.name } do
user.name = 'Bob'
end
### OR with optional :to argument
assert_changed 'user.name', to: 'Bob' do
user.name = 'Bob'
end
assert_changed -> { user.name }, to: 'Bob' do
user.name = 'Bob'
end
assert_not_changed
assert_not_changed 'user.name' do
user.update(attrs)
end
assert_not_changed -> { user.name } do
user.update(attrs)
end
### OR with optional :to argument
assert_not_changed 'user.name', to: 'Allen' do
user.name = 'Bob'
end
assert_not_changed -> { user.name }, to: 'Allen' do
user.name = 'Bob'
end
Credits
Created by Weston Ganger - @westonganger