Spree集成测试登录失败

时间:2018-09-29 16:07:15

标签: ruby-on-rails rspec capybara spree

我正在尝试创建对管理面板的测试。但是在程序尝试登录时失败。

  

失败:

     

1)访问产品登录正常            失败/错误:expect(page).to have_content(“成功登录”)

     

预期在“登录\ n所有部门\ n家庭\ n购物车:(空)\ n \ n无效的电子邮件中找到文本”已成功登录”   密码。\ n以现有客户身份登录\ n记住我\也不创建新用户   帐号|忘记密码?”            #./spec/features/home_spec.rb:14:在'

中的“块(2个级别)”中

密码和电子邮件对于管理员是正确的。我在其他帖子中找到了解决方案,例如向水豚添加配置,但仍然失败。

spec_helper

require 'capybara/rspec'
require 'rails_helper'
require 'spree/testing_support/controller_requests'
require 'capybara/rails'

Capybara.app_host = "http://localhost:3000"
Capybara.server_host = "localhost"
Capybara.server_port = "3000"

_spec.rb

require "spec_helper"

RSpec.describe 'Visit products' do
    it 'login works correctly' do
        visit spree.admin_path
        fill_in "spree_user[email]", with: "piotr.wydrzycki@yahoo.com"
    fill_in "spree_user[password]", with: "password"
    click_button Spree.t(:login)
        expect(page).to have_content("Logged in successfully")
    end
end

1 个答案:

答案 0 :(得分:1)

由于页面显示“无效的电子邮件或密码”,因此电子邮件或密码不正确,或者测试用户未正确创建。由于您没有在测试中显示任何测试用户的创建,因此很可能没有任何用户。在测试模式下运行时,该应用程序不使用您的开发数据库,​​它拥有自己的数据库,您需要创建期望存在于测试中的所有对象(例如用户)。您可以通过使用固定装置或诸如factory_bot之类的工具在每次测试之前创建用户来实现此目的。

此外,您无需根据自己的情况设置server_hostserver_portapp_host