resque_spec is a simple RSpec and Cucumber matcher for Resque , loosely based on resque_unit .

Install it as a gem:

% gem install resque_spec

Given this scenario

1Given a person
2When I recalculate
3Then the person has calculate queued

And I write this spec using the resque_spec matcher

 1describe "#recalculate" do
 2  before do
 3    ResqueSpec.reset!
 4  end
 5
 6  it "adds person.calculate to the Person queue" do
 7    person.recalculate
 8    Person.should have_queued(person.id, :calculate)
 9  end
10end

(And I take note of the before block that is calling reset! for every spec)

And I might write this as a Cucumber step

1Then /the (\w?) has (\w?) queued/ do |thing, method|
2  thing_obj = instance_variable_get("@#{thing}")
3  thing_obj.class.should have_queued(thing_obj.id, method.to_sym)
4end

Then I write some code to make it pass:

1class Person
2  @queue = :people
3
4  def recalculate
5    Resque.enqueue(Person, id, :calculate)
6  end
7end

The source is up on github .

blog comments powered by Disqus