Les Hill github twitter facebook linked in archives
Posted June 13, 2010

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

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

And I write this spec using the resque_spec matcher

 1 describe "#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
10 end

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

And I might write this as a Cucumber step

1 Then /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)
4 end

Then I write some code to make it pass:

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

The source is up on github .

Thanks to Tom Preston-Werner for the CSS layout, Webby for the blog renderer, and GitHub Pages for the blog hosting.