Last active
April 28, 2020 09:40
-
-
Save Mattamorphic/31650444b4bfa143e39e0f5648dca2be to your computer and use it in GitHub Desktop.
Non-Dry-Example
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
# frozen_string_literal: true | |
require "minitest/mock" | |
class MyJobTest < ActiveJob::TestCase | |
test "check job calls method" do | |
mock = Minitest::Mock.new | |
mock.expect :mymethod, nil do |id:, message:| | |
id.is_a?(Integer) && | |
message.is_a?(String) | |
end | |
MyModule::myclass.any_instance.stub(:mymethod, mock) do | |
MyJob.perform_now(id: 1234) | |
end | |
assert mock.verify | |
end | |
test "check job creates message" do | |
mock = Minitest::Mock.new | |
mock.expect :mymethod, nil do |id:, message:| | |
id.is_a?(Integer) && | |
message.is_a?(String) && | |
message.downcase.include?("hello, world!") | |
end | |
MyModule::myclass.any_instance.stub(:mymethod, mock) do | |
MyJob.perform_now(id: 1234) | |
end | |
assert mock.verify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment