B Seven
B Seven

Reputation: 45941

How to test background process in RSpec?

Found this simple way to run a separate process in Sinatra: Run background process in Sinatra

get '/start_process'
  @@pid = Process.spawn('external_command_to_run')
end

How would you test this in RSpec?

Ruby 1.9.3.

Upvotes: 0

Views: 863

Answers (1)

Tomek Wałkuski
Tomek Wałkuski

Reputation: 1019

Extract a class which does the background processing and unit-test it. Then test expectation that your action invokes method on this class

Some "pseudocode":

before do
  MyWorker.should_receive(:perform)
end

specify { get :something }

Upvotes: 3

Related Questions