Factory not registered: user
I have already fixed it. The solution was to change gem ‘factory_girl’ to gem ‘factory_girl_rails’ in my Gemfile.
I have already fixed it. The solution was to change gem ‘factory_girl’ to gem ‘factory_girl_rails’ in my Gemfile.
You can try something like this: (Factory.build :code).attributes.symbolize_keys Check this: http://groups.google.com/group/factory_girl/browse_thread/thread/a95071d66d97987e)
Add this line to your routes.rb # Devise routes devise_for :users # Or the name of your custom model
Ok so this is how I do, I don’t pretend to strictly follow the best practices, but I focus on precision of my tests, clarity of my code, and fast execution of my suite. So let take example of a UserController 1- I do not use FactoryGirl to define the attributes to post to my … Read more
Just call FactoryGirl.reload in your before/after callback. This is defined in the FactoryGirl codebase as: module FactoryGirl def self.reload self.factories.clear self.sequences.clear self.traits.clear self.find_definitions end end Calling FactoryGirl.sequences.clear is not sufficient for some reason. Doing a full reload might have some overhead, but when I tried with/without the callback, my tests took around 30 seconds to … Read more
You could think of a mock (or double) as a fake object. When you’re testing and need to work with an object that isn’t easily usable inside your test, you could use a mock as an approximation for how you expect that object to behave and work around it. Stubs can be used in a … Read more
Try something like this. You want to build a detail object and append it to the job’s detail association. When you use after_create, the created job will be yielded to the block. So you can use FactoryGirl to create a detail object, and add it to that job’s details directly. factory :job do … after_create … Read more
I would rather use FactoryBot’s after(:create) callback to create roles (also see this issue for Rolify). Furthermore the method has_role? is used to check if a user has a specific role, to set a specific role you should use the add_role method. FactoryBot.define do factory :user do name ‘Test User’ email ‘[email protected]’ password ‘please’ password_confirmation … Read more
You can declare the definitions of factories as follow: FactoryGirl.define do factory :task, class: ‘Task’ do shop currency value 10 end factory :counter_task, parent: :task, class: ‘CounterTask’ do end end And now you can test base class isolated from its own factory and the same for each inherited class.
Doh. Silly mistake here, running bundle exec rake spec instead of rake spec solved it. Also had to add require ‘factory_bot’ to the top of support/factory_bot.rb