i will use RSpec with Factory girl in my Rails3 Project. I have installed factory girl but it don't find the factorys i have this error
Failure/Error: Factory.build(:user).should_be valid
No such factory: user
spec/factories/user_factory.rb :
Factory.define :user do |u|
u.username 'otto'
end
spec/spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'factory_girl'
Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
RSpec.configure do |config|
config.mock_with :rspec
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true
end
Gemfile:
group :development, :test do
gem 'webrat'
gem "cucumber-rails"
gem "rspec-rails"
gem "rspec"
gem "autotest"
gem 'factory_girl'
end
Thanks
Do you have the following lines in your config\application.rb
:
# Configure generators values.
config.generators do |g|
g.test_framework :rspec, :fixture => true
g.fixture_replacement :factory_girl, :dir=>"spec/factories"
end
Add the 'factory_girl_rails" gem to your Gemfile under your :test, :development groups, as follows:
group :development, :test do
gem 'webrat'
gem "cucumber-rails"
gem "rspec-rails"
gem "rspec"
gem "autotest"
gem 'factory_girl'
gem 'factory_girl_rails'
end
In Rails 3, you need to add that gem to make it work. Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With