Ruby on Rails
Tuesday, June 21, 2016
In my application I'm using devise for authentication and rspec, capybara for testing. Here are my files
1) New Student fill new student details
Failure/Error: let(:user) { FactoryGirl.create(:user) }
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
# ./spec/features/new_students_spec.rb:9:in `block (2 levels) in <top (required)>'
# ./spec/features/new_students_spec.rb:12:in `block (2 levels) in <top (required)>'
--
-- new_student_spec.rb
require 'rails_helper'require_relative '../support/new_student_form_spec'require_relative '../support/login_form_spec'feature 'New Student', type: :feature dolet(:login_form) { LoginForm.new }let(:new_student) { NewStudentForm.new }let(:user) { FactoryGirl.create(:user) }background dologin_form.visit_login_form.fill_form_as(user)endscenario 'fill new student details' donew_student.visit_dashboard_pageendend
new_student_form_spec.rb
class NewStudentForminclude Capybara::DSLdef visit_dashboard_pagevisit('/dashboard')selfendend
login_form_spec.rb
class LoginForminclude Capybara::DSLdef visit_login_formvisit('/users/sign_in')selfenddef fill_form_as(user)fill_in('Email', with: user.email)fill_in('Password', with: user.password)click_on('Submit')selfendend
Factory (users.rb)
FactoryGirl.define dofactory :user dotransient doskip_confirmation trueendsequence(:email) { |n| "email#{n}@example.tld" }password 'sceretsceret'password_confirmation 'sceretsceret'before(:create) do |user, evaluator|user.skip_confirmation! if evaluator.skip_confirmationendendend
Whenever I run 'bin/rspec' on above test it passes true only for one time. If I tried to run it one more time it generate following error
Failure/Error: let(:user) { FactoryGirl.create(:user) }
ActiveRecord::RecordInvalid:
Validation failed: Email has already been taken
# ./spec/features/new_students_spec.rb:9:in `block (2 levels) in <top (required)>'
# ./spec/features/new_students_spec.rb:12:in `block (2 levels) in <top (required)>'
# -e:1:in `<main>'
Where I'm going wrong?
Cheers!
Deepak Kumar Sharma
Guru Nanak Dev Engineering College
India!
Blog: http://deekysharma.wordpress.com
Deepak Kumar Sharma
Guru Nanak Dev Engineering College
India!
Blog: http://deekysharma.wordpress.com
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CALDHwN7gWjss41tGmbS%3DJkRojXKUriBS5gkXvNwF_d8%3DUX%2Bj%3Dw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment