rspec, 水豚 javascript driver
rspec, capybara javascript driver
我的测试中有这个:
let!(:user) { create(:user) }
当我 运行 测试时没有 :js
def create
11: byebug
=> 12: if @user = login(params[:email], params[:password])
13: logger.info "--------------"
14: logger.info "found user"
15: redirect_back_or_to root_path, notice: t(:log_in_is_successful_notice)
16: else
(byebug) User.all
#<ActiveRecord::Relation [#<User id: 291, email: "test@test.com", crypted_password: "a$rOKscDDidaf93p/e9IOceOCGozns5AJ2zSLMO68jRZO...", created_at: "2016-06-22 20:15:55", updated_at: "2016-06-22 20:15:55", salt: "qpSR5US81thfoTn8pphQ", remember_me_token: nil, remember_me_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, current_block_id: nil, locale: "ru">]>
但是当我 运行 这个测试 :js
时,我得到了这个:
11: byebug
=> 12: if @user = login(params[:email], params[:password])
13: logger.info "--------------"
14: logger.info "found user"
15: redirect_back_or_to root_path, notice: t(:log_in_is_successful_notice)
16: else
(byebug) User.all
#<ActiveRecord::Relation []>
(byebug) User.all.take
nil
我正在使用 webkit
作为 js driver:
Capybara.javascript_driver = :webkit
您没有禁用事务测试,因此在您的测试线程中创建的对象在您的应用程序线程中不可见。您需要阅读 Transactions and Database Setup section of the Capybara README, and then configure something like database_cleaner 来为您处理切换数据库策略
我的测试中有这个:
let!(:user) { create(:user) }
当我 运行 测试时没有 :js
def create
11: byebug
=> 12: if @user = login(params[:email], params[:password])
13: logger.info "--------------"
14: logger.info "found user"
15: redirect_back_or_to root_path, notice: t(:log_in_is_successful_notice)
16: else
(byebug) User.all
#<ActiveRecord::Relation [#<User id: 291, email: "test@test.com", crypted_password: "a$rOKscDDidaf93p/e9IOceOCGozns5AJ2zSLMO68jRZO...", created_at: "2016-06-22 20:15:55", updated_at: "2016-06-22 20:15:55", salt: "qpSR5US81thfoTn8pphQ", remember_me_token: nil, remember_me_token_expires_at: nil, reset_password_token: nil, reset_password_token_expires_at: nil, reset_password_email_sent_at: nil, current_block_id: nil, locale: "ru">]>
但是当我 运行 这个测试 :js
时,我得到了这个:
11: byebug
=> 12: if @user = login(params[:email], params[:password])
13: logger.info "--------------"
14: logger.info "found user"
15: redirect_back_or_to root_path, notice: t(:log_in_is_successful_notice)
16: else
(byebug) User.all
#<ActiveRecord::Relation []>
(byebug) User.all.take
nil
我正在使用 webkit
作为 js driver:
Capybara.javascript_driver = :webkit
您没有禁用事务测试,因此在您的测试线程中创建的对象在您的应用程序线程中不可见。您需要阅读 Transactions and Database Setup section of the Capybara README, and then configure something like database_cleaner 来为您处理切换数据库策略