factory_girl_rspec

Build Status

Integrate FactoryBot fixture initialization into the RSpec DSL.

Features

Usage

Basic usage:

# spec/models/user_spec.rb
describe User do
  context 'basic user' do
    # instantiate FactoryBot :user fixture
    with :user
    it { user.should be_inactive }
    it { user.should_not be_happy }
  end
end

Advanced usage:

# spec/models/user_spec.rb
describe User do
  context 'when user.first_name == nil' do
    # instantiate FactoryBot :user fixture with custom options
    with :user, :first_name => nil
    it { user.should be_inactive }
    it { user.should_not be_happy }
  end

  context 'when user is inactive' do
    # instantiate FactoryBot :user fixture with custom traits
    with :user, :when_inactive
    it { user_when_inactive.should be_inactive }
  end
end

Installation

# Bundler Gemfile
gem 'factory_girl_rspec'

Contributing

  • Fork the project
  • Fix the issue
  • Add unit tests
  • Submit pull request on github

Original implementation described on Ryan Sonnek's blog

See CONTRIBUTORS.txt for list of project contributors

Copyright (c) 2011 Ryan Sonnek See LICENSE.txt for further details.