"Uninitialized constant Faker" with FactoryGirl

Hello!

I’m writing the tests to my rails application and I’m facing some
problems
to integrate Faker with FactoryGirl.

I’ve put both in Gemfile, section development and test, as below:

  • group :development, :test do # <<<< :development*
  • gem ‘sqlite3’*
  • gem ‘factory_girl_rails’*
  • gem ‘ffaker’*
  • end*

All my tests are written under test/ directory.

In test/, I’ve created a factories/ folder with my user factory, as
below:

FactoryGirl.define do

  • factory :user do*

  • first_name { Faker::Name.first_name }*

  • last_name { Faker::Name.last_name }*

  • email { Faker::Internet.email }*

  • password { Faker::Interner.password }*

  • user_type { Faker::Number.positive(from=1, to=3) }*

  • trait :empty do*

  •  first_name nil*
    
  •  last_name nil*
    
  •  email nil*
    
  •  password nil*
    
  •  user_type nil*
    
  • end*

  • trait :no_name do*

  •  first_name nil*
    
  •  last_name nil*
    
  • end*

  • trait :no_email do*

  •  email nil*
    
  • end*

  • trait :invalid_email do*

  •  email "abcdef"*
    
  • end*

  • trait :no_password do*

  •  password nil*
    
  • end*

  • trait :no_usertype do*

  •  user_type nil*
    
  • end*

  • trait :invalid_usertype do*

  •  user_type 50*
    
  • end*

  • end*

end

In my models test, I’m using FactoryGirl as usual (Example):

test “should not create a new user without email and password” do
user = build(:user, :empty)
assert_not user.save, “Created the user without email and password”
end

However, when I run the tests, I’m receiving the following error:
NameError: uninitialized constant Faker

I’ve already tried to add:
require ‘ffaker’

In both factory and model test files, but the problem persists.

Could someone please help me to figure out where the problem is?!

Thanks in advance for the support!

On Fri, Mar 20, 2015 at 9:21 AM, Mauricio Klein
[email protected] wrote:

I’m writing the tests to my rails application and I’m facing some problems
to integrate Faker with FactoryGirl.

The Gemfile entry below says you’re not.

group :development, :test do # <<<< :development
gem ‘ffaker’
end

FFaker != Faker


Hassan S. ------------------------ [email protected]
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs