Last active
March 11, 2024 17:45
-
-
Save artur-intech/e84b814da4227af5988a75ce25760d7e to your computer and use it in GitHub Desktop.
Ruby Minitest method call assertion examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PersonalNote | |
def initialize(note) | |
@note = note | |
end | |
def update | |
@note.update | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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