Module: MiniTest::Assertions

Defined in:
lib/minitest/matchers.rb

Instance Method Summary collapse

Instance Method Details

#assert_must(matcher, subject, msg = nil) ⇒ Object

Fails unless matcher.matches?(subject) returns true

Example:

def test_validations
  assert_must be_valid, @user
end


14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/minitest/matchers.rb', line 14

def assert_must matcher, subject, msg = nil
  result = matcher.matches? subject

  msg = message(msg) do
    if matcher.respond_to? :failure_message_for_should
      matcher.failure_message_for_should
    else
      matcher.failure_message
    end
  end

  assert result, msg
end

#assert_wont(matcher, subject, msg = nil) ⇒ Object

Fails if matcher.matches?(subject) returns true

Example:

def test_validations
  assert_wont be_valid, @user
end


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/minitest/matchers.rb', line 37

def assert_wont matcher, subject, msg = nil
  msg = message(msg) do
    if matcher.respond_to? :failure_message_for_should_not
      matcher.failure_message_for_should_not
    else
      matcher.negative_failure_message
    end
  end

  if matcher.respond_to? :does_not_match?
    assert matcher.does_not_match?(subject), msg
  else
    refute matcher.matches?(subject), msg
  end
end