vveare138
vveare138

Reputation: 347

Rspec.Undefined method `valid?' for :user:Symbol

I try to create test for users-factories.But when I running test, 'rspec' show me an error

Failure/Error: expect(:user).to be_valid
 NoMethodError:
   undefined method `valid?' for :user:Symbol

this is my user_spec.rb

require 'rails_helper'

RSpec.describe do
  it "has a valid factory" do
    user = FactoryGirl.create(:user)
    expect(:user).to be_valid
  end
end

and this is users-factories(with 'faker' gem)

FactoryGirl.define do

  factory :user do
    email Faker::Internet.email
    password Faker::Internet.password(8)
  end

end

how fix and why this method don't work?

sorry for my bad English

Upvotes: 0

Views: 1820

Answers (1)

Arup Rakshit
Arup Rakshit

Reputation: 118271

Here is a fix :

RSpec.describe do
  it "has a valid factory" do
    user = FactoryGirl.create(:user)
    expect(user).to be_valid
  end
end

You passed the symbol :user as an argument to the expect(:user), which you shouldn't. You should pass the local variable user, you have created, and passed to it expect(user).

Upvotes: 3

Related Questions