Commit 1858da0

mo khan <mo@mokhan.ca>
2015-01-20 04:44:18
add factory girl and faker to generate test data.
1 parent 7800d33
spec/factories/users.rb
@@ -0,0 +1,7 @@
+FactoryGirl.define do
+  factory :user do
+    username Faker::Internet.user_name
+    email Faker::Internet.email
+    terms_and_conditions true
+  end
+end
spec/features/registrations_spec.rb
@@ -17,7 +17,7 @@ feature "Registrations", type: :feature do
     end
 
     context "when the username is taken" do
-      let!(:user) { User.create!(username: 'mo', email: 'mo@example.com', terms_and_conditions: true) }
+      let!(:user) { create(:user) }
 
       it 'displays an error' do
         visit root_path
spec/rails_helper.rb
@@ -29,6 +29,7 @@ Capybara.javascript_driver = :poltergeist
 RSpec.configure do |config|
   # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
   config.fixture_path = "#{::Rails.root}/spec/fixtures"
+  config.include FactoryGirl::Syntax::Methods
 
   # If you're not using ActiveRecord, or you'd prefer not to run each of your
   # examples within a transaction, remove the following line or assign false
Gemfile
@@ -47,5 +47,7 @@ group :development, :test do
   gem 'foreman'
   gem 'i18n-tasks'
   gem 'poltergeist'
+  gem 'factory_girl_rails'
+  gem 'ffaker'
 end
 
Gemfile.lock
@@ -71,6 +71,12 @@ GEM
       activemodel
     erubis (2.7.0)
     execjs (2.2.2)
+    factory_girl (4.5.0)
+      activesupport (>= 3.0.0)
+    factory_girl_rails (4.5.0)
+      factory_girl (~> 4.5.0)
+      railties (>= 3.0.0)
+    ffaker (1.31.0)
     foreman (0.76.0)
       dotenv (~> 1.0.2)
       thor (~> 0.19.1)
@@ -221,6 +227,8 @@ DEPENDENCIES
   byebug
   coffee-rails (~> 4.1.0)
   email_validator
+  factory_girl_rails
+  ffaker
   foreman
   foundation-rails
   i18n-tasks