github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

ianwhite / pickle

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 228
    • 25
  • Source
  • Commits
  • Network (25)
  • Downloads (21)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • gh-pages
    • master ✓
  • Tags (21)
    • v0.2.0
    • v0.1.23
    • v0.1.22
    • v0.1.21
    • v0.1.20
    • v0.1.19
    • v0.1.18
    • v0.1.17
    • 0.1.15
    • 0.1.14
    • 0.1.13
    • 0.1.10
    • 0.1.9
    • 0.1.8
    • 0.1.7
    • 0.1.6
    • 0.1.5
    • 0.1.4
    • 0.1.3
    • 0.1.2
    • 0.1.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Easy model creation/reference in cucumber - optionally leveraging your factories/blueprints — Read more

  cancel

http://ianwhite.github.com/pickle

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

Tweaking garlic.rb 
ianwhite (author)
Sun Jan 03 06:02:31 -0800 2010
commit  24e9e58fb67daf6e1e6e137f5e543ed6cc7df686
tree    5ada5774c3e274a5f236fd56c8d22a74eab67396
parent  58d9004bf32af3d364f2c62cb38ca8b88a2db59c
pickle /
name age
history
message
file .gitignore Thu Oct 15 12:58:12 -0700 2009 Not bothering with rubyforge [ianwhite]
file History.txt Tue Dec 01 09:36:32 -0800 2009 Added nil as a possible field value [#14 state:... [ianwhite]
file License.txt Fri Jan 02 16:25:05 -0800 2009 Update License- Happy New Year! [ianwhite]
file README.rdoc Tue Nov 24 14:25:52 -0800 2009 Add gemcutter to the resources link [ianwhite]
file Rakefile Fri Jan 01 07:41:13 -0800 2010 Exclude OS X gems from rcov [Ian White]
file Todo.txt Tue Nov 24 14:22:29 -0800 2009 Updated Todo [ianwhite]
file VERSION Tue Dec 01 09:39:26 -0800 2009 Version bump to 0.2.1 [ianwhite]
directory features/ Fri Jan 01 10:17:07 -0800 2010 Changes in features for latest cucumber environ... [Ian White]
file garlic.rb Sun Jan 03 06:02:31 -0800 2010 Tweaking garlic.rb [ianwhite]
file init.rb Thu Oct 16 15:50:42 -0700 2008 Initial release of pickle (Expermental: in deve... [ianwhite]
directory lib/ Tue Dec 01 09:36:32 -0800 2009 Added nil as a possible field value [#14 state:... [ianwhite]
file pickle.gemspec Tue Dec 01 09:39:36 -0800 2009 Regenerated gemspec for version 0.2.1 [ianwhite]
directory rails_generators/ Tue Dec 01 07:36:30 -0800 2009 Fix typo [ianwhite]
directory spec/ Tue Dec 01 09:32:09 -0800 2009 Added feature and spec for having nil as field ... [ianwhite]
README.rdoc

pickle

Pickle gives you cucumber steps that create your models easily from factory-girl or machinist factories/blueprints. You can also just use ActiveRecord but it’s not as cool.

References to the models are stored in the current world, not necessarily for the purpose of checking the db (although you could use it for that), but for enabling easy reference to urls, and for building complex givens which require a bunch of models collaborating

Resources

Github for code: github.com/ianwhite/pickle

Gemcutter for the gem: gemcutter.org/gems/pickle

API docs: ianwhite.github.com/pickle/doc

Google group for questions: groups.google.com/group/pickle-cucumber

Lighthouse for bugs: ianwhite.lighthouseapp.com/projects/25941-pickle

Railscast presentation: railscasts.com/episodes/186-pickle-with-cucumber

Blog articles: dynamic50: Integration testing with cucumber and pickle, rubyflare: pickle my cucumber

Install

Install pickle either as a rails plugin, or a gem

  # gem from gemcutter
  sudo gem install pickle

  # gem dependency (in config/environments/cucumber.rb)
  config.gem 'pickle'

  # plugin
  script/plugin install git://github.com/ianwhite/pickle.git

  # or, plugin as submodule
  git submodule add git://github.com/ianwhite/pickle.git vendor/plugins/pickle

CI

It’s tested against all stable branches of 2.x rails, and edge, with the latest versions of rspec, cucumber, factory_girl, machinist.

Contributors

The following people have made Pickle better:

  • Nick Rutherford
  • Tobi Knaup
  • Michael MacDonald

Get Started

(you’d better install cucumber)

  script/generate pickle [paths] [email]

Now have a look at features/step_definitions/pickle_steps.rb

If you want path steps and email steps then just add ‘paths’ and/or ‘email’. The code/steps will be written to features/env/paths.rb and features/step_definitions/email_steps.rb respectively.

Using with plain ole Active Record

If you have an AR called ‘Post’, with required fields ‘title’, and ‘body’, then you can now write steps like this

  Given a post exists with title: "My Post", body: "My body"

Using with factory-girl or machinist

But you’re using Machinist or FactoryGirl right?! To leverage all of the factories/blueprints you’ve written, you can just do stuff like

  Given a user exists
  And another user exists with role: "admin"

  # later
  Then a user should exist with name: "Fred"
  And that user should be activated # this uses rspec predicate matchers

Machinst: require your blueprints and reset Shams

(The latest version of pickle supports multiple blueprints, for earlier versions of machinist use pickle <= 0.1.10)

In your features/support/env.rb add the following lines at the bottom

  require "#{Rails.root}/spec/blueprints" # or wherever they live
  Before { Sham.reset } # reset Shams in between scenarios

FactoryGirl: make sure factories are loaded

In your config/environments/cucumber.rb file, make sure the factory-girl gem is included (unless it’s installed as a plugin).

If that doesn’t solve loading issues then require your factories.rb file directly in a file called ‘features/support/factory_girl.rb’

  # example features/support/factory_girl.rb
  require File.dirname(__FILE__) + '/../../spec/factories'

Configuring Pickle

You can tell pickle to use another factory adapter (see Pickle::Adapter), or create mappings from english expressions to pickle model names. You can also override many of the options on the Pickle::Config object if you so choose.

In: features/support/pickle.rb

  require 'pickle/world'

  Pickle.configure do |config|
    config.adapters = [:machinist, YourOwnAdapterClass]
    config.map 'me', 'myself', 'my', 'I', :to => 'user: "me"'
  end

Out of the box pickle looks for machinist, then factory-girl, then finally active-record ‘factories’. If you find that your steps aren’t working with your factories, it’s probably the case that your factory setup is not being included in your cucumber environment (see comments above regarding machinist and factory-girl).

API

Steps

When you run script/generate pickle you get the following steps

Given steps

"Given a model exists", e.g.

  Given a user exists
  Given a user: "fred" exists
  Given the user exists

"Given a model exists with fields", e.g.

  Given a user exists with name: "Fred"
  Given a user exists with name: "Fred", activated: false

You can refer to other models in the fields

  Given a user exists
  And a post exists with author: the user

  Given a person: "fred" exists
  And a person: "ethel" exists
  And a fatherhood exists with parent: user "fred", child: user "ethel"

"Given n models exist", e.g.

  Given 10 users exist

"Given n models exist with fields", examples:

  Given 10 users exist with activated: false

Then steps

Asserting existence of models

"Then a model should exist", e.g.

  Then a user should exist

"Then a model should exist with fields", e.g.

  Then a user: "fred" should exist with name: "Fred" # we can label the found user for later use

You can use other models, booleans, numerics, and strings as fields

  Then a person should exist with child: person "ethel"
  Then a user should exist with activated: false
  Then a user should exist with activated: true, email: "fred@gmail.com"

"Then n models should exist", e.g.

  Then 10 events should exist

"Then n models should exist with fields", e.g.

  Then 2 people should exist with father: person "fred"
Asserting associations

One-to-one assocs: "Then a model should be other model’s association", e.g.

  Then the person: "fred" should be person: "ethel"'s father

Many-to-one assocs: "Then a model should be [in|one of] other model’s association", e.g.

  Then the person: "ethel" should be one of person: "fred"'s children
  Then the comment should be in the post's comments
Asserting predicate methods

"Then a model should [be|have] [a|an] predicate", e.g.

  Then the user should have a status # => user.status?.should == true
  Then the car: "batmobile" should be fast # => car.fast?.should == true

"Then a model should not [be|have] [a|an] predicate", e.g.

  Then person: "fred" should not be childless # => fred.childless?.should == false

Regexps for use in your own steps

By default you get some regexps available in the main namespace for use in creating your own steps: `capture_model`, `capture_fields`, and others (see lib/pickle.rb)

(You can use any of the regexps that Pickle uses by using the Pickle.parser namespace, see Pickle::Parser::Matchers for the methods available)

capture_model

  Given /^#{capture_model} exists$/ do |model_name|
    model(model_name).should_not == nil
  end

  Then /^I should be at the (.*?) page$/ |page|
    if page =~ /#{capture_model}'s/
      url_for(model($1))
    else
      # ...
    end
  end

  Then /^#{capture_model} should be one of #{capture_model}'s posts$/ do |post, forum|
    post = model!(post)
    forum = model!(forum)
    forum.posts.should include(post)
  end

capture_fields

This is useful for setting attributes, and knows about pickle model names so that you can build up composite objects with ease

  Given /^#{capture_model} exists with #{capture_fields}$/ do |model_name, fields|
    create_model(model_name, fields)
  end

  # example of use
  Given a user exists
  And a post exists with author: the user # this step will assign the above user as :author on the post
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server