Skip to content

Instantly share code, notes, and snippets.

@artur-intech
Last active March 11, 2024 17:45
Show Gist options
  • Save artur-intech/e84b814da4227af5988a75ce25760d7e to your computer and use it in GitHub Desktop.
Save artur-intech/e84b814da4227af5988a75ce25760d7e to your computer and use it in GitHub Desktop.
Ruby Minitest method call assertion examples
class PersonalNote
def initialize(note)
@note = note
end
def update
@note.update
end
end
require 'minitest/autorun'
class FakeNote
def initialize
@updated = false
end
def update
@updated = true
end
def updated?
@updated
end
end
class PersonalNoteTest < Minitest::Test
def test_update_using_mock
mock = Minitest::Mock.new
mock.expect(:update, nil)
p_note = PersonalNote.new(mock)
p_note.update
assert_mock mock
end
def test_update_using_fake
note = FakeNote.new
pnote = PersonalNote.new(note)
pnote.update
assert note.updated?
end
end
class PgNote
def update(text); end
def owned_by?(user); end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment