Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Dupe rides on top of ActiveResource to allow you to cuke the client side of a service-oriented app without having to worry about whether or not the service is live or available while cuking.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
features
lib
.gitignore
README.rdoc
Rakefile
VERSION
dupe.gemspec

README.rdoc

Dupe

Dupe allows you to define resources, create a pool of resources, extend those resources with your own custom response mocks, and even override the default mocks Dupe provides (find(:all) and find(id)).

Dupe is ideally suited for working with Cucumber. It also relies on ActiveResource::HttpMock for mocking resource responses.

Installation

# gem install moonmaster9000-dupe

Example

Let's suppose your cuking a book search application for a library that consumes a RESTFUL book datastore service via ActiveResource. You might start by writing the following feature in RAILS_ROOT/features/library/find_book.feature:

Feature: find a book
  As a reader
  I want to search for books
  so that I can check them out and read them. 

Scenario: search by author
  Given an author "Arthur C. Clarke"
  And a book "2001: A Space Odyssey" by "Arthur C. Clarke"
  When I search for "Arthur C. Clarke"
  I should see "2001: A Space Odyssey"

To get this to pass, you might first create an ActiveResource model for a Book and an Author that will connect to the RESTful book service:

class Book < ActiveResource::Base
  self.site = 'http://bookservice.domain'
end

class Author < ActiveResource::Base
  self.site = 'http://bookservice.domain'
end

Then you might create the following resource definition via Dupe.define (put it in a file with a .rb extension and place it in RAILS_ROOT/features/support/):

Dupe.define :book do |define|
  define.author do |author_name|
    Dupe.find(:author) {|a| a.name == author_name}
  end
end

and the following cucumber step definitions (utilizing Dupe.create):

Given /^an author "([^\"]*)"$/ do |author|
  Dupe.create :author, :name => author
end

Given /^a book "([^\"]*)" by "([^\"]*)"$/ do |book, author|
  Dupe.create :book, :title => book, :author => author 
end

Dupe.create will in turn mock two service responses for each resource. For example, for the Book resource, it will mock:

# Book.find(:all) --> GET /books.xml
<?xml version="1.0" encoding="UTF-8"?>
<books type="array">
  <book>
    <id type="integer">1</id>
    <title>2001: A Space Odyssey</title>
    <author>
      <id type="integer">1</id>
      <name>Arthur C. Clarke</name>
    </author>
  </book>
</books>

# Book.find(1) --> GET /books/1.xml
<?xml version="1.0" encoding="UTF-8"?>
<book>
  <id type="integer">1</id>
  <title>2001: A Space Odyssey</title>
  <author>
    <id type="integer">1</id>
    <name>Arthur C. Clarke</name>
  </author>
</book>
Something went wrong with that request. Please try again.