Commit 10920fec authored by Vaz Allen's avatar Vaz Allen

Add FactoryGirl and Faker

parent 4780cc6c
......@@ -16,6 +16,8 @@ group :development, :test do
gem 'pry'
gem 'shotgun'
gem 'sqlite3'
gem 'factory_girl'
gem 'faker'
end
# bundle install --without test --without development
......
......@@ -29,6 +29,10 @@ GEM
coderay (1.1.0)
database_cleaner (1.3.0)
diff-lcs (1.2.5)
factory_girl (4.7.0)
activesupport (>= 3.0.0)
faker (1.6.3)
i18n (~> 0.5)
i18n (0.7.0)
json (1.8.3)
method_source (0.8.2)
......@@ -110,6 +114,8 @@ DEPENDENCIES
activesupport
capybara
database_cleaner
factory_girl
faker
pg
pry
puma
......
You can add FactoryGirl factories in this directory and they'll
be automatically available in your tests. For example:
# spec/factories/user_factory.rb
FactoryGirl.define do
# basic factory for class User, just fill any required attributes
factory :user do
name Faker::Name.name
# factory that inherits from :user and customizes it
factory :admin_user, class: User do
is_admin true
end
end
end
Using it in a test:
# spec/models/user_spec.rb
describe User do
let(:user) { build(:user) } # instantiate a User but don't save it
let(:user2) { create(:user) } # instantiate and save a User
let(:user3) { create(:user, name: 'Vaz') } # override attribute
# ...
end
For more information see:
- [FactoryGirl GETTING STARTED guide](http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md)
- [Faker README](https://github.com/stympy/faker)
......@@ -5,10 +5,17 @@ require_relative '../config/environment'
require 'rspec'
require 'capybara/rspec' # capybara will be loaded for tests tagged :feature
require 'database_cleaner'
require 'factory_girl'
require 'faker'
Capybara.app = Sinatra::Application
RSpec.configure do |config|
# make the factory_girl methods available in our tests and find factories
# in spec/factories/*.rb
config.include FactoryGirl::Syntax::Methods
config.before(:suite) { FactoryGirl.find_definitions }
# All of the following just ensures the database is wiped
# before every single test:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment