https://github.com/codebrahma/factory_group
An abstraction on top of factory girl
https://github.com/codebrahma/factory_group
Last synced: 5 months ago
JSON representation
An abstraction on top of factory girl
- Host: GitHub
- URL: https://github.com/codebrahma/factory_group
- Owner: Codebrahma
- License: mit
- Created: 2014-09-12T14:49:06.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-10-26T08:17:14.000Z (over 11 years ago)
- Last Synced: 2025-08-27T14:47:55.528Z (6 months ago)
- Language: Ruby
- Homepage:
- Size: 1.35 MB
- Stars: 0
- Watchers: 26
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# FactoryGroup
[](http://badge.fury.io/rb/factory_group)
[](https://travis-ci.org/Codebrahma/factory_group)
[](https://codeclimate.com/github/Codebrahma/factory_group)
[](https://gemnasium.com/Codebrahma/factory_group)
[](https://codeclimate.com/github/Codebrahma/factory_group)
By [CodeBrahma](http://codebrahma.com).
FactoryGroup provides an abstraction on top of factory_girl, which will help you create reusable groups of factories which can be used across test cases.
For now we support only rails applications.
## Installation
Add this line to your application's Gemfile:
gem 'factory_group', :group => :test
And then execute:
$ bundle
Or install it yourself as:
$ gem install factory_group
## Usage
Define a factory group
```ruby
# spec/factory_groups/user_group.rb
FactoryGroup.define :user_group do
user FactoryGirl.create(:user, :name => "Rajinikant")
end
```
Next require the factory_groups folder from the spec_helper
```ruby
# spec/spec_helper.rb
Dir["spec/factory_groups/**/*.rb"].each { |f| require File.expand_path(f) }
```
Now from your spec call ```FactoryGroup.create(:user_group)```
```ruby
# spec/user_spec.rb
describe User do
let(:user_group) { FactoryGroup.create(:user_group) }
context "#name" do
it "returns Rajinikant" do
expect(user_group.user.name).to eq "Rajinikant"
end
end
end
```
## Contributing
1. Fork it ( https://github.com/[my-github-username]/factory_group/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request