librelist archives

« back to archive

[ANN] resque_spec for RSpec and Cucumber

[ANN] resque_spec for RSpec and Cucumber

From:
Les Hill
Date:
2010-06-13 @ 22:06
A simple RSpec and Cucumber matcher for Resque, loosely based on resque_unit.

Find it here:

http://github.com/leshill/resque_spec

Install it as a gem:

% gem install resque_spec

Given this scenario

    Given a person
    When I recalculate
    Then the person has calculate queued

And I write this spec using the resque_spec matcher

    describe "#recalculate" do
      before do
        ResqueSpec.reset!
      end

      it "adds to the calculate to the person queue" do
        person.recalculate
        Person.should have_queued(person.id, :calculate)
      end
    end

(And I take note of the `before` block that is using `reset` every spec)

And I might write this as a cucumber step

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

Then I write some code to make it pass:

    class Person
      @queue = :people

      def recalculate
        Resque.enqueue(Person, id, :calculate)
      end
    end

Enjoy!

-- 
Les Hill
leshill@gmail.com