module Minitest::Rails::Expectations::ActiveSupport

Public Instance Methods

must_change(expression, from: UNTRACKED, to: UNTRACKED) click to toggle source

Assertion that the result of evaluating an expression is changed before and after invoking the passed in block.

value { User.create password: "valid" }.must_change "User.count"
value { 3.times do
          User.create password: "valid"
        end }.must_change "User.count", from: 5, to: 8

See also ActiveSupport::TestCase#assert_difference See api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_changes

# File lib/minitest/rails/expectations/active_support.rb, line 19
infect_an_assertion :assert_changes, :must_change, :block
must_differ(expression, *args) click to toggle source

Test numeric difference between the return value of an expression as a result of what is evaluated.

value { User.create password: "valid" }.must_differ "User.count"
value { 3.times do
          User.create password: "valid"
        end }.must_differ "User.count", 3

See also ActiveSupport::TestCase#assert_difference See api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_difference

# File lib/minitest/rails/expectations/active_support.rb, line 50
infect_an_assertion :assert_difference, :must_differ, :block
wont_change(expression) click to toggle source

Assertion that the result of evaluating an expression is not changed before and after invoking the passed in block.

refute_changes "Status.all_good?" do
  post :create, params: { status: { ok: true } }
end

See also ActiveSupport::TestCase#assert_difference See api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_changes

# File lib/minitest/rails/expectations/active_support.rb, line 34
infect_an_assertion :refute_changes, :wont_change, :block
wont_differ(expression) click to toggle source

Assertion that the numeric result of evaluating an expression is not changed before and after invoking.

value { User.new }.wont_differ "User.count"

See also ActiveSupport::TestCase#refute_difference See api.rubyonrails.org/v6.1/classes/ActiveSupport/Testing/Assertions.html#method-i-assert_no_difference

# File lib/minitest/rails/expectations/active_support.rb, line 63
infect_an_assertion :refute_difference, :wont_differ, :block