Skip to content

Create records from Cucumber features without writing step definitions.

License

Notifications You must be signed in to change notification settings

mthelander/cucumber_factory

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cucumber Factory allows you to create ActiveRecord objects directly from your Cucumber features. No step definitions required.

The following will call Movie.make, Factory.create(:movie), Movie.create! or Movie.new, depending on what’s available:

Given there is a movie

To create a new record with attributes set, you can say:

Given there is a movie with the title "Sunshine" and the year "2007"

The following will also store the created record in @sunshine:

Given "Sunshine" is a movie with the title "Sunshine" and the year "2007"

To set associations you can refer to other records by name:

Given "Before Sunrise" is a movie
And "Before Sunset" is a movie with the prequel "Before Sunrise"

You can also refer to the last created object of a kind by saying “above”:

Given there is a movie with the title "Before Sunrise"
And "Before Sunset" is a movie with the prequel above

Boolean attributes can be set by appending “which”, “that” or “who” at the end:

Given there is a movie which is awesome
And there is a movie with the name "Sunshine" that is not a comedy
And there is a director who is popular

Instead of “and” you can also use “but” and commas to join sentences:

Given there is a movie which is awesome, popular and successful but not science fiction
And there is a director with the income "500000" but with the account balance "-30000"

Machinist blueprints and factory_girl factories will be used when available.

You can use named Machinist blueprint such as Movie.blueprint(:comedy) like this:

Given a movie (comedy) with the title "Groundhog Day"

If you want to override a factory step with your own version, just do so:

Given /^there is a movie with good actors$/ do
  movie = Movie.make
  movie.actors << Actor.make(:name => 'Clive Owen')
  movie.actors << Actor.make(:name => 'Denzel Washington')
end

Custom steps will always be preferred over factory steps. Also Cucumber will not raise a warning about ambiguous steps if the only other matching step is a factory step.

Cucumber Factory is a gem, which you can install with

sudo gem install cucumber_factory

In Rails 2, add the following to your environment.rb:

config.gem 'cucumber_factory'

In Rails 3, add the following to your Gemfile:

gem 'cucumber_factory'

Finally, create a file features/step_definitions/factory_steps.rb, which just says

Cucumber::Factory.add_steps(self)

We cannot guarantee Rails 3 compatibility at this point, but we will upgrade the gem when Rails 3 is released.

Henning Koch

makandra.com

gem-session.com

About

Create records from Cucumber features without writing step definitions.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%