First off, I am using the Interactor Gem. (You should check it out if you haven't. Pretty cool lib)
Let's say I've got an Interactor::Organizer as follows:
class InitiateImport
include Interactor::Organizer
organize CreateImport, QueueImport
end
And I've also got two Interactors as follows:
class CreateImport
include Interactor
def call
import = Import.create()
if import
context.import = import
else
context.fail!(message: 'import failed!')
end
end
end
and
class QueueImport
include Interactor
def call
unless QueueHandler.perform_later(context.import.id)
context.fail!(message: 'Queue broke!')
end
end
end
BIG QUESTION - How do I -- using Minitest -- test that organize
is being called on InitiateImport
with the argument [CreateImport, QueueImport]
assert_send
will let me verify that organize
is being called, but it won't let me verify what arguments I pass it. Something like this:
class InitiateImportTest < Minitest::Test
def test_organize_called
InitiateImport.new(file: file)
assert_send([InitiateImport, :organize, [CreateImport, QueueImport]])
end
end
I found this question / answer from nearly 3 years ago, but it didn't provide much clarity for me. Maybe it's in there and I'm just missing something?
I also realize that I could just call
the organizer with valid param data such that it passes and I verify the output from there, however I've already got those two classes under test and I'd basically just be exercising the same functionality twice. I'd really like to just verify method invocation and arguments if possible.
Any help or suggestions would be greatly appreciated.
Aucun commentaire:
Enregistrer un commentaire