Module: Minitest::Assertions
- Defined in:
- lib/minitest/matchers_vaccine.rb
Instance Method Summary collapse
-
#assert_must(matcher, subject, msg = nil) ⇒ Object
Passes if matcher.matches?(subject) returns true.
-
#assert_wont(matcher, subject, msg = nil) ⇒ Object
Passes if matcher.matches?(subject) returns false.
-
#must(matcher, subject = (defined?(@subject) && @subject) || subject()), msg = nil) ⇒ Object
Facilitator to assert_must for use with minitest-spec.
-
#wont(matcher, subject = (defined?(@subject) && @subject) || subject()), msg = nil) ⇒ Object
Facilitator to assert_wont for use with minitest-spec.
Instance Method Details
#assert_must(matcher, subject, msg = nil) ⇒ Object
Passes if matcher.matches?(subject) returns true
Example:
def test_validations
assert_must be_valid, @user
end
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/minitest/matchers_vaccine.rb', line 16 def assert_must(matcher, subject, msg = nil) msg = (msg) do if matcher.respond_to? :failure_message matcher. # RSpec 3.x, 1.1 else matcher. # RSpec 2.x, 1.2 end end assert matcher.matches?(subject), msg end |
#assert_wont(matcher, subject, msg = nil) ⇒ Object
Passes if matcher.matches?(subject) returns false
Example:
def test_validations
assert_wont be_valid, @user
end
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/minitest/matchers_vaccine.rb', line 53 def assert_wont(matcher, subject, msg = nil) msg = (msg) do if matcher.respond_to? :failure_message_when_negated # RSpec 3.x matcher. # RSpec 3.x elsif matcher.respond_to? :failure_message_for_should_not matcher. # RSpec 2.x, 1.2 else matcher. # RSpec 1.1 end end if matcher.respond_to? :does_not_match? assert matcher.does_not_match?(subject), msg else refute matcher.matches?(subject), msg end end |
#must(matcher, subject = (defined?(@subject) && @subject) || subject()), msg = nil) ⇒ Object
Facilitator to assert_must for use with minitest-spec. If no subject given, defaults to matching against the current ‘subject` or the instance variable `@subject`.
Example:
subject { Order.new }
it "should have associations" do
must belong_to :account
must have_many :line_items
end
41 42 43 |
# File 'lib/minitest/matchers_vaccine.rb', line 41 def must(matcher, subject = ((defined?(@subject) && @subject) || subject()), msg = nil) assert_must matcher, subject, msg end |
#wont(matcher, subject = (defined?(@subject) && @subject) || subject()), msg = nil) ⇒ Object
Facilitator to assert_wont for use with minitest-spec. If no subject given, defaults to matching against the current ‘subject` or the instance variable `@subject`.
Example:
subject { User.new }
it "should validate" do
wont have_valid(:email).when("foo", "foo@bar", "@bar.com")
end
83 84 85 |
# File 'lib/minitest/matchers_vaccine.rb', line 83 def wont(matcher, subject = ((defined?(@subject) && @subject) || subject()), msg = nil) assert_wont matcher, subject, msg end |