GithubHelp home page GithubHelp logo

bitcababy / cucumber_factory Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makandra/cucumber_factory

1.0 2.0 0.0 137 KB

Create records from Cucumber features without writing step definitions.

Home Page: http://makandra.com/

License: MIT License

cucumber_factory's Introduction

Cucumber Factory - create ActiveRecord objects without step definitions

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

Examples

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"

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"

Setting associations

You can set belongs_to associations by referring to the last created record of a kind by saying “above”:

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

The example above also shows how to set has_many associations - you simply set the belongs_to association on the other side.

You can also set associations by referring to any string attribute used previously:

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

You can also explicitly give a record a name and use it to set a belongs_to association below:

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

Note that in the example above, “Before Sunrise” is only a name you can use to refer to the record. The name is not actually used for the movie title, or any other attribute value.

Fixture factory support

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 there is a movie (comedy) with the title "Groundhog Day"

Overriding factory steps

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.

Installation and setup

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)

Rails 3 compatibility

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

Credits

Henning Koch

makandra.com

gem-session.com

cucumber_factory's People

Contributors

triskweline avatar kratob avatar kraatob avatar

Stargazers

Meredith avatar

Watchers

Meredith avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.