Skip to content

Instantly share code, notes, and snippets.

@Mattamorphic
Last active April 28, 2020 09:40
Show Gist options
  • Save Mattamorphic/31650444b4bfa143e39e0f5648dca2be to your computer and use it in GitHub Desktop.
Save Mattamorphic/31650444b4bfa143e39e0f5648dca2be to your computer and use it in GitHub Desktop.
Non-Dry-Example
# 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