Coder Social home page Coder Social logo

backyard's Introduction

Backyard

Build Status Code Climate

this project is in a 'work in progress' state. The object creation currently only works with factory_girl.

Installation

in your Gemfile:

gem 'backyard'

to configure backyard, you need to create a backyard.rb file in your features/support directory:

require 'backyard/cucumber'

Backyard.configure do
  # application specific configuration
  name_attribute :username, :for => :user
  name_attribute :title, :for => [:post, :comment]
end

Usage

Backyard provides a simple dsl to name the models in your cucumber scenarios.

put_model(:post, 'How to use Backyard') # create and store a new Post model named 'How to use Backyard'
put_model(:post, 'I am published', {:published => true}) # you can pass additional options for the factory

my_comment = Comment.first
put_model(my_comment, 'My Comment') # you can also store existing models

Backyard keeps track of your saved models and you can access them from all the step definitions:

get_model(:post, 'How to use Backyard') # returns the stored post instance

If you want to write step definitions, which do not care if the model you are referencing exists then you can use the `model´ method. It will check if the model with the given name exists and if not, it will create a new model for you.

model(:user, 'Tester') # this will return the user called 'Tester' if one has been crated, otherwise it will create a new model for you
model(:user, 'Gardener', {:approved => true})  # you can also pass additional attributes for the factories

Examples

The best way, to get an idea of backyard in action, is to peek inside the cucumber features.

Configuration

Backyard needs to know how to name your models correctly. You can define the rules using the Backyard.configure method:

Backyard.configure do
  name_attribute :title, :for => :article
end

# Examples
put_model(:article, 'Getting Started with Rails') # this creates an Article instance with the titel: 'Getting Started with Rails'
model(:article, 'Getting Started with Rails') # returns the article created above
model(:article, 'Upgrading to Rails 3') # since no article with the given name has been created it will create one.

There are situations when the name of your model is not as simple as setting an attribute. In these circumstances you can register a block to set the name of your model accordingly:

Backyard.configure do
  name_for :owner do |name|
    { :user => model(:user, name, {:username => name}) }
  end
end

If all users in your system are named with the username attribute you could use the following configuration:

Backyard.configure do
  name_attribute :username, :for => :user

  name_for :owner do |name|
    { :user => model(:user, name) }
  end
end

# Examples
put_model(:user, 'John') # creates a User with username: 'John'
put_model(:owner, 'Jane') # creates a Owner with an associated User, which has the username: 'Jane'

This will still create Owner models with an associated user, where the username is set to the name of the created Owner model. This configuration has the advantage, that the username is also beeing set if you just create a User model.

Community

Got a question?

Just send me a message and I'll try to get to you as soon as possible.

Found a bug?

Please register a new issue.

Fixed something?

  1. Fork backyard
  2. Create a topic branch - git checkout -b my_branch
  3. Make your changes and update the History.txt file
  4. Push to your branch - git push origin my_branch
  5. Send me a pull-request for your topic branch
  6. That's it!

backyard's People

Contributors

danielfrey avatar senny avatar stellard avatar

Watchers

 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.