所以,我測試我的Ruby on Rails項目,但我有一個數據庫的問題。RSpec,水豚,JavaScript測試不正確回滾數據庫
我正在使用Stripe,並且正在爲用戶的購買體驗中的每個頁面運行集成測試。但是,在完成測試後,我的數據庫不會回滾,不過!
這非常令人沮喪,因爲在每次測試後我都需要運行rake db:test:prepare
,這會讓我放慢腳步。
下面是我的規格代碼:
require 'spec_helper'
describe "Subscription Pages" do
subject { page }
...
describe "purchase page" do
...
describe "when not signed in" do
it { should have_field "Email" }
it { should have_field "Full Name" }
it { should have_field "Password" }
it { should have_field "Confirmation" }
describe "and fills in the provided sign-up form as new user" do
let(:some_user){ FactoryGirl.build(:user) }
before do
fill_in "Full Name", with: some_user.name
fill_in "Email", with: some_user.email
fill_in "Password", with: some_user.password
fill_in "Confirmation", with: some_user.password
fill_in "card_number", with: "4242424242424242"
fill_in "card_code", with: "123"
select "January", from: "card_month"
select (Date.today.year+1).to_s, from: "card_year"
end
...
describe "and submits with valid information", js: true do
before do
click_button submit
sleep 5
end
it { should have_selector('div.alert.alert-success', text: 'Thank you for purchasing!') }
it { should have_field "Words" } # because its the new puzzle page.
it { should_not have_link "Buy Now!", href: plans_path }
describe "and then tries to revisit the purchase page", js: true do
before do
visit purchase_path
end
# Should redirect to account screen with an alert
# These tests pass when I do them myself but don't know why they are failing here
specify { User.find_by_email(some_user.email).subscription.paid_user?.should be_true }
it { should have_selector('title', text: "Account") }
it { should_not have_field "card_number" }
it { should have_selector('div.alert.alert-notify') }
it { should_not have_link "Buy Now!", href: plans_path }
end
end
end
end
end
末
如果我通過運行rake db:test:prepare
啓動,然後運行我的測試中,一切都很好。但是,當我再次運行測試時,由於數據庫未回滾,因此我的用戶模型中出現「已發送電子郵件」驗證錯誤。
我在做什麼錯,在這裏?
你正在使用哪種水豚驅動程序? –
我相信它的硒 - 但我該如何檢查確定?我不知道100%,並不知道在哪裏檢查... – csalvato
Capybara.current_session.driver(在一個規格內)會告訴你目前的驅動程序是什麼 –