Ruby on Rails
Friday, March 20, 2015
Hello!
I'm writing the tests to my rails application and I'm facing some problems to integrate Faker with FactoryGirl.
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 FakerI'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!
Thanks in advance for the support!
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/76263a20-d318-4616-b6de-9970dcbbb79c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment