In my application I'm using devise for authentication and rspec, capybara for testing. Here are my files
new_student_spec.rb
require_relative '../support/new_student_form_spec'
require_relative '../support/login_form_spec'
feature 'New Student', type: :feature do
let(:login_form) { LoginForm.new }
let(:new_student) { NewStudentForm.new }
let(:user) { FactoryGirl.create(:user) }
login_form.visit_login_form.fill_form_as(user)
scenario 'fill new student details' do
new_student.visit_dashboard_page
new_student_form_spec.rb
fill_in('Email', with: user.email)
fill_in('Password', with: user.password)
sequence(:email) { |n| "email#{n}@example.tld" }
password_confirmation 'sceretsceret'
before(:create) do |user, evaluator|
user.skip_confirmation! if evaluator.skip_confirmation
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
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)>'