You need to setup the expectation (the call to should_receive) before the code under test runs.
Rspec and spawn gem: How to test "should_receive" in spawned_out process
-
01-04-2022 - |
문제
I have a controller action which calls a spawn block
class MyController < ApplicationController
....
def send_product_mails
if @user.has_rights?
spawn_block(:nice => 19 ) do
@current_product.send_mail
end
end
end
...
end
and I want to spec thet send_mail is called on @current_product, but it tells me it didn't receive it.. How should one do it?
My Spec looks like so:
it "works with spawn" do
# Setup: create Product, Usersession (via UserSession.create(user))
get :send_product_mails, :id => product.id
MyController.any_instance.should_receive(:spawn_block).and_yield("sd")
end
I want to spec that something is passed to the spawn_block
if the user has the rights, and nothing otherwise. Right now with different trys (calling .should_receive
in the test on MyController, MyController.any_instance, @controller, with or without and_yield this always gives errors that the message spawn_block
wasn't received. (Yes, I checked that the rights are acutally okay by adding a puts-debug-output within the if-statement.)
EDIT: Gave more context and code to the question, and what I've tried
해결책
제휴하지 않습니다 StackOverflow