jeudi 23 avril 2015

"Uninitialized constant User" for Factory_Girl Rspec

I am trying to set up my Factory Girl factory for my users model and I can't seem to get it without some sort of error appearing. The error I'm getting now is "uninitialized constant User"

spec/factories.rb

factory :user do |user|

user.name "John Doe"
user.admin false
user.created_at Time.now
user.updated_at Time.now
user.password_digest nil
user.remember_token nil
user.e_admin nil
user.t_admin true
user.d_admin false
user.activated false
user.activated_at Time.now
end

spec/spec_helper.rb

require 'rails/all'
require 'rspec/rails'
require 'factory_girl_rails'

RSpec.configure do |config|

  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end

  config.filter_run :focus
  config.run_all_when_everything_filtered = true

  config.disable_monkey_patching!
  config.warnings = true
  if config.files_to_run.one?
    config.default_formatter = 'doc'
  end

  config.profile_examples = 10

  config.order = :random
  Kernel.srand config.seed

  config.include FactoryGirl::Syntax::Methods

  FactoryGirl.definition_file_paths = [File.expand_path('../factories', __FILE__)]
  FactoryGirl.find_definitions

end

spec/user_spec.rb

require 'rspec'
require 'spec_helper'
require 'factory_girl_rails'


RSpec.describe 'Log In' do

  it 'should log user in' do

    var = create(:user)

    expect(var.valid?).to eql(true)
  end
 end

Does anyone know how I can resolve this error?

Aucun commentaire:

Enregistrer un commentaire