Ruby on Rails
Tuesday, June 21, 2016
Your test database isn't being cleared after each test run. Normally this problem is solved by running each test in a transaction which is rolled back at the completion of each test. You can enable this in RSpec with the use_transactional_fixtures option.
-- Alternatively, check out the database_cleaner gem.
On Tuesday, June 21, 2016 at 12:21:51 PM UTC-4, Deepak Sharma wrote:
On Tuesday, June 21, 2016 at 12:21:51 PM UTC-4, Deepak Sharma wrote:
In my application I'm using devise for authentication and rspec, capybara for testing. Here are my filesnew_student_spec.rbrequire '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_page endendnew_student_form_spec.rbclass NewStudentForminclude Capybara::DSLdef visit_dashboard_pagevisit('/dashboard')selfendendlogin_form_spec.rbclass 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')selfendendFactory (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_confirmationendendend1) New Student fill new student detailsWhenever 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
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/833dd08a-e5ad-4d13-9ffd-bf0900d4d0c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment