ruby on rails - Test failing when trying to run Rspec with Factory Girl -


I am running in an error while trying to add a factory girl to my project which I do not seem to solve Happen. I wrote a test that would check whether my user's first name was empty:

  # spec / models / user_spec.rb is required 'rails_helper' RSpec.describe user, : Type = & gt; : Models do this 'without first name is invalid' user = factorial Build (user, first_name: zero) is expected (user). (1) .Resource_on (: first_name) End end   

When I try to run this test with a failure, I get this error:

1) Without the first name the user is invalid Failure / Error: Expect (user). (1) .errors_on (: first_name) 1 errors are expected: first_name, found 2 # ./spec/models/user_spec.rb:7:in 'in block (2 level)' < P> Here's what my factories.rb file looks like:

  # spec / factories.rb factorygear.Define factory: first_name "John" Last_name "doe" sequence (: email) {| N | "Johndoe#{n}@example.com"} Password "Secret" End End   

If it helps everyone here how my gemfile is setup:

  group: development, test gem 'rspec-rails' gem 'rspec-collection_matchers' gem 'factory_girl_rails' end   

update

After checking my user model, I believe that the second error was by mistake setting the attendance verification twice in my model:

  Valid: first_name, : last_name ,: email,: password, presence: true va Lidates: first_name,: last_name, presence: true, format: {with: / \ A ([^ \ d \ W] | [-]) * \ z /, Message: 'can not contain any numbers or special characters '}   

I am surprised that there is no way for RSPC, in the way I am working for the errors that are told to me:

Expected 1 Errors: First_name, 2 found

It looks like your user has real 2 errors on first errors in Field

To be able to debug it you can just print the errors

  RSpec.describe user ,: type = & gt; : The model puts it user 'factorial.bild (user, first_name: zero) user' is invalid without 'first name' Errors Message [: First_name] Expected (user). (1) .rors_on (: first_name) and end    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -