Closed CeeBeeUK closed 4 years ago
I think the issue is simpler here. You are calling StartIntegrationTestsWorker.perform_async
, which is a class method on StartIntegrationTestsWorker
, not an instance method. The above expect_any_instance_of
is expecting an instance, StartIntegrationTestsWorker.new
, and so doesn't work.
The expect(StartIntegrationTestsWorker).to receive(:perform_async)
version should work. Are you sure it does not?
The start_typing
, and respond_with_slack_message
and other rspec matchers setup a message handler/hook instance that in a real app is setup listening on slack's message events, and keep track of the client
instance, so you don't have to.
Minor, but I don't remember if we handle commands with spaces, run tests
. If it doesn't work try without?
I started with expect(StartIntegrationTestsWorker).to receive(:perform_async)
and have also tried expect(StartIntegrationTestsWorker).to receive(:perform)
in case ruby magic was translating it internally!
Both fail with
(StartIntegrationTestsWorker (class)).perform(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
This is actually working nicely in Slack!
If I take out the StartIntegrationTestsWorker
line the start_typing(channel: 'channel')
test passes fine 🤔
Thanks for the response and clarification, knowing that it should work, I'll keep playing!
Thanks for maintaining all these repos!
Hmm, looking at my other tests, I am using a different format
expect { perform }.to change(MonitorTestRunWorker.jobs, :size).by(1)
In the same tests
it 'works?' do
expect(MonitorTestRunWorker).to receive(:perform)
perform
end
fails.
Can I call message_send in a block? failing, but something like
it 'triggers the sidekiq job' do
expect { SlackRubyBot::Hooks::Message.new(message: user_input, channel: 'channel') }
.to change(MonitorTestRunWorker.jobs, :size).by(1)
end
If I take out the
StartIntegrationTestsWorker
line thestart_typing(channel: 'channel')
test passes fine 🤔
Is this code valid at all? Add a puts
above to see if it's called? Then wrap it in an exception handler, maybe there's a typo? :)
command 'run tests' do |client, data, _match|
begin
client.typing(channel: data.channel)
StartIntegrationTestsWorker.perform_async(data)
rescue Exception => e
puts e
raise
end
end
See anything?
Can I call message_send in a block? failing, but something like
it 'triggers the sidekiq job' do expect { SlackRubyBot::Hooks::Message.new(message: user_input, channel: 'channel') } .to change(MonitorTestRunWorker.jobs, :size).by(1) end
yes you can
If you're still having trouble, feel free to upload the project somewhere and I can try to help.
Either way this is 100% not a problem with the bot library, I'm going to close this for housekeeping, but feel free to add more questions and I'll do my best to answer.
So I have a simple command that shows the user a typing message while queuing a sidekiq job that processes a long running task and outputs further details...
My simple test ensures that start_typing is received..
Is there a way to successfully test the execution of code other than the chat message? This all works in reality, but despite trying the above and...
expect(StartIntegrationTestsWorker).to receive(:perform_async)
and other varieties I cannot successfully get the tests to simulate calling the
StartIntegrationTestsWorker
. Do thestart_typing
,respond_with_slack_message
and other rspec matchers mock out the entire process? If so, is there a guide anywhere for testing other code handling inside commands?