ruby-on-railsrspecresqueprivate-pub

Acceptance tests with RSPEC, private_pub and Resque


I'm looking for a bit of guidance on writing acceptance tests for a process that uses Ryan Bates' private_pub gem (https://github.com/ryanb/private_pub) and Resque.

In my controller I have an execute action that queues up a file generation process in Resque and then makes an AJAX request to display a "waiting" modal window. The modal window contains the javascript to subscribe to a private_pub channel and wait for a message on that channel. Upon completion of the file generation process in the Resque worker, a message with the newly generated file name is pushed to private_pub. The javascript in the modal receives the message and uses the filename to kick off a download of the file in the browser.

I'm looking for suggestions on techniques to run tests on this process. I've considered mocking the private_pub server (not sure how to even accomplish this after much Googling) so that it simply returns a pre-staged file. Basically I think I need a way to exercise my workflow without the need to run a private_pub server and the whole Resque infrastructure in my test environment.


Solution

  • I'd recommend stubbing out the call to the Resque worker and simply returning what you'd expect it to return. Then test the Resque worker code in a separate test.

    If your goal is specifically to test the functionality of the modal window, you could write a test that simply makes the call to the Resque worker and use Capybara to determine if the modal shows up. In this example, you would not want to stub the Resque call - simply end the test after you've found the modal window appears.