leshill / resque_spec

RSpec matcher for Resque
MIT License
295 stars 86 forks source link

Enqueue_at works in RSpec but not Cucumber step #103

Open noreaster opened 10 years ago

noreaster commented 10 years ago

I'm not quite sure what I'm doing wrong. I can get enqueue_at to work in RSpec, but not cucumber.

Resque.enqueue works properly in cucumber (and RSpec) but I always get "Invalid argument - connect(2) (Errno::EINVAL)" when I try to run Resque.enqueue_at in cucumber

.env

require 'rubygems'
require 'spork'

Spork.prefork do
  require 'resque_spec/cucumber'
  require 'resque_spec/scheduler'
end

phone_poll_steps.rb (doesn't work)

When(/^It is time to be called$/) do

  PhonePollTaker.should have_schedule_size_of(0)
  Resque.enqueue_at(DateTime.now + 2.seconds, PhonePollTaker,  1) # line that fails
  PhonePollTaker.should have_schedule_size_of(1)
end

phone_poll_spec.rb (works)

describe PhonePoll do
  it 'should be able to make a call' do
    ...
    PhonePollTaker.should have_schedule_size_of(0)
    Resque.enqueue_at(DateTime.now + 2.seconds, PhonePollTaker,  1)
    PhonePollTaker.should have_schedule_size_of(1)
  end
end

Works in both

  Resque.enqueue(PhonePollTaker,  1)
leshill commented 10 years ago

Hi @noreaster,

No idea. Here are some suggestions:

The error message makes me think that you are running in a different environment. Do you have any invocations of ResqueSpec.disable_ext = true?

Another cause may be due to the prefork. If Resque is loaded afterwards, the hooks will not have been set correctly by ResqueSpec. The way to debug this is to stop inside [https://github.com/leshill/resque_spec/blob/master/lib/resque_spec/scheduler.rb#L19] and verify that you have ResqueSpec hooked up.

A failing example would be great.

noreaster commented 10 years ago

I've tried putting the requires inside and outside of the prefork and it doesn't make a difference. It is loading up the resque-scheduler rather than resque_spec for enqueue_at. However it does load up resque_spec for enqueue.

I'll try to boil down the issue into a separate example instance and post it when I sort that out.

noreaster commented 10 years ago

Here's an instance of how I had it set up. https://github.com/noreaster/resque_spec_example Is there somewhere I have the configuration wrong?

The examples are: /spec/models/phone_poll_spec.rb and /features/phone_polls/test_case.feature

I was using guard to test if that makes a difference

leshill commented 10 years ago

Hi @noreaster,

Thanks for the example, the only thing I can suggest is to move the require 'resque_spec/scheduler' to the each_run block? I will run it myself when I have some free time later this week.

noreaster commented 10 years ago

No worries, unfortunately that doesn't seem to solve the issue. It's probably a configuration issue, but I just don't know where it would be.

leshill commented 10 years ago

Hi @noreaster,

That last message was confusing :) — you are still having the problem?

noreaster commented 10 years ago

Whoops, learning how to type is important. I meant that it's still a problem