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

brightbox / object-factory

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 8
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (3)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (1)
    • master ✓
  • Tags (0)
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.

A simple object factory that assists with creating valid model objects when writing specifications — Read more

  cancel

http://www.brightbox.co.uk/

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

This URL has Read+Write access

updated version to 0.2.4 
rahoulb (author)
Mon Feb 08 13:09:18 -0800 2010
commit  6be635624eee6336ad3a914412f3fe00da6b5ad7
tree    04a22d2c6c74df27cf43fd84811bd49b069e3c12
parent  75408cfbe488a9fedef8b16e7a079a352e5ff0d6
object-factory /
name age
history
message
file .gitignore Thu May 21 02:41:35 -0700 2009 trying again with the gem build [rahoulb]
file CHANGELOG Mon Feb 08 13:07:51 -0800 2010 updated version to 0.2.4 [rahoulb]
file Manifest Mon Feb 08 13:09:18 -0800 2010 updated version to 0.2.4 [rahoulb]
file README.rdoc Tue Nov 10 03:50:37 -0800 2009 pushed to rubyforge and gemcutter [rahoulb]
file Rakefile Mon Feb 08 13:09:18 -0800 2010 updated version to 0.2.4 [rahoulb]
file github.rb Thu May 21 02:36:28 -0700 2009 bumped version to 0.2.1 as the Gem setting had ... [rahoulb]
file init.rb Fri Nov 28 06:39:36 -0800 2008 added print_configuration method and added an i... [rahoulb]
directory lib/ Mon Feb 08 13:07:03 -0800 2010 changed so that clean_up => true is the default [rahoulb]
directory spec/ Wed May 20 14:00:53 -0700 2009 added the clean up option [rahoulb]
directory tasks/ Mon Nov 24 09:19:37 -0800 2008 reworked to use echoe instead of bones [rahoulb]
README.rdoc

Object-factory

A ruby gem designed to make it simple to create test objects within your test framework, so you don’t need to use nasty fixtures.

If you don’t use the a_saved method then it should work with any type of model, if you do use a_saved then it will work with any model that has a save method (that returns false on failure - so ActiveRecord and DataMapper should be OK).

Install

  gem install object-factory

Usage

See the wiki page at github.com/brightbox/object-factory/wikis/home for the latest docs. In particular, wiki.github.com/brightbox/object-factory/usage-with-rails-rspec-and-cucumber is a pretty good example of how to get started.

However, it works something like this:

  when_creating_a Person, :auto_generate => :employee_code

  @person = a Person, :first_name => 'John', :last_name => 'Smith'
  puts @person.employee_code # will show a unique auto-generated value

And your options are:

  • :auto_generate => [:field1, :field2]: generates a unique string value for the given field name or array of field names
  • :auto_confirm => :password: generates a unique string value for the given field name or array of field names and also sets field_name_confirmation to the same value
  • :generate_email_address => :email: generates a randomised email address for the given field name or array of field names
  • :generate_ip_address => :ip: generates a randomised ip address for the given field name or array of field names
  • :set => { :field3 => ‘value3’, :field4 => ‘value4’ }: sets the given fields to the supplied static values
  • :generate => { :field5 => lambda { Date.today } }: sets the given fields to the supplied dynamic values

If you want to generate a unique value yourself, you can use Object::Factory’s next_number call (which has a simple shortcut a_number).

  :generate => { :field => "unique-value-#{a_number}" }

Cleaning up

(currently only for ActiveRecord)

If you register your (ActiveRecord) class with the clean_up option, then the factory can ensure that all instances are deleted. This is useful if you cannot use transactional_fixtures (for example using Watir or Culerity in your test suite).

Add a clean_up parameter when registering your classes:

  when_creating_a Person, :auto_generate => [:first_name, :last_name], :clean_up => true

Then in your "after" section call:

  Object.factory.clean_up

This will call delete_all on any registered classes (hence it is currently ActiveRecord only).

Rails

To use this with rails, stick the following in your +environment.rb+:

  config.gem "object-factory"

Also check out wiki.github.com/brightbox/object-factory/usage-with-rails-rspec-and-cucumber for more information on integrating Object-Factory with your application.

Released under the MIT Licence

Copyright © 2008 Brightbox Systems Ltd

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

  • The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

See www.brightbox.co.uk/ for contact details.

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