0

Given the example sinatra app

post '/1' do
  sleep(1) until @2
  0
end

post '/2' do
  @2 = true
  0
end

and the example RSpec test

describe 'test' do

  it 'does /1' do
    post '/1'
    expect(last_response.body) to eq?(0)
  end

  it 'does /2'
    post '/2'
    expect(last_response.body) to eq?(0)
  end

end

The first test (it does /1) will hang, waiting for /2 to be called.

Is it possible to tell RSpec to not wait for the outcome of test #1 to complete before beginning test #2? A.K.A, are asynchronous tests possible in RSpec?

VULPINE
  • 31
  • 3
  • The given app doesn't make a whole lot of sense since instance variables don't persist across requests. But regardless, the answer to your question is "use threads". – Chris Heald Feb 10 '15 at 20:56

1 Answers1

1

Yes. An easy way is to use the parallel tests gem:

Similar gems suitable for a CI server:

These gems are all about spreading tests across CPUs. What your code is even better suited for is concurrent tests.

If you're open to using Minitest (which is awesome) then there's excellent concurrency. "Minitest gives you the ability to denote that some or all of your test cases are able to run concurrently, and as pointed out in the source comments, that can only mean one thing: that you rule and your tests are awesome."

See this blog that explains it in detail:

joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119