gpt4 book ai didi

javascript - 使用 Rails 5.1 和 Vue.js 进行 Flaky 系统测试

转载 作者:行者123 更新时间:2023-12-01 17:29:03 26 4
gpt4 key购买 nike

几天来我一直在尝试对此进行调试,只是无法弄清楚问题出在哪里。我最初认为这是一个顺序依赖,但我不再这么认为了,所以 rspec --bisect=verbose

我现在倾向于 Devise/Warden 助手无法正常工作,我没有正确设置 capybara /网络驱动程序或其他原因。

这个测试有时会失败:

  1. 在重定向时,当从菜单中选择项目以重定向到另一个页面时。例如,在按下“帐户设置”后重定向到“帐户设置”页面。这是我责怪 Devise 助手的地方,因为当我登陆主页时我已经登录,但是当我进入帐户设置时 current_user 返回 nil,因此示例失败它被重定向到登录页面。

这也是特定于测试的,实时代码可以正常运行数月。

系统测试

require 'rails_helper'

RSpec.describe 'home page', type: :system do
before(:context) do
WebMock.disable_net_connect!(allow_localhost: true)
end

after(:each) do
Warden.test_reset!
end

context 'when not logged in' do
it 'displays login with discord button' do
visit '/'

expect(page).to have_content 'Login with Discord'
end

it 'logs in with discord after clicking Login with Discord' do
OmniAuth.config.test_mode = true

visit '/'

click_on 'Login with Discord'

expect(page).to_not have_content 'Login with Discord'

find('.profile-menu').hover

expect(page).to have_content 'Account Settings'
expect(page).to have_content 'Event Calendar'
expect(page).to have_content 'Logout'
end
end

context 'when logged in' do
context 'as an average user' do
before do
@user = build(:user, confirmed_at: Time.now)
create(:profile, user: @user)

login_as(@user, scope: :user)
end

it 'shows profile menu' do
visit '/'

find('.profile-menu').hover

expect(page).to have_content 'Account Settings'
expect(page).to have_content 'Event Calendar'
expect(page).to have_content 'Logout'
end

it 'logs user out after pressing Logout' do
visit '/'

find('.profile-menu').hover
find('.logout').click

expect(page).to have_content 'Login with Discord'
end

it 'redirects to Events page after pressing Event Calendar' do
event = create(:event)

visit '/'

find('.profile-menu').hover
find('.event-calendar').click

expect(page).to have_content event.title
end

it 'redirects to Account Settings page after pressing Account Settings' do
visit '/'

find('.profile-menu').hover
find('.settings').click

expect(page).to have_content 'Account Settings'
end
end

context 'as an organiser' do
before do
@user = build(:user, confirmed_at: Time.now, role: :organiser)
create(:profile, user: @user)

login_as(@user, scope: :user)
end

it 'shows profile menu with Organiser Dashboard link' do
visit '/'

find('.profile-menu').hover

expect(page).to have_content 'Organiser Dashboard'
end

it 'redirects to Organiser Dashboard page after pressing Organiser Dashboard' do
visit '/'

find('.profile-menu').hover
find('.organiser-dashboard').click

expect(page).to have_content 'Create Event'
end
end
end
end

设计配置

require 'devise'

RSpec.configure do |config|
config.include Warden::Test::Helpers
end

Javascript 驱动菜单重定向

handleCommand(command) {
if (command === "logout") {
Rails.ajax({
url: "/sign_out",
type: "DELETE",
dataType: "json",
success: (signed_in_status) => {
this.$store.commit('authenticate', false)
this.$message.success('You logged out');
location.href = "/";
},
error: (signed_in_status) => {
this.$store.commit('authenticate', true)
this.$message.error('Something went wrong');
}
})
}
else if (command === "settings") {
location.href = "/users/edit";
}
else if (command === "events") {
location.href = "/events";
}
else if (command === "organiser") {
location.href = "/admin/events";
}
}

最佳答案

我似乎已经解决了这个问题。我已经尝试了这个 SO 答案中提到的几件事。据我所知,修复它的是什么修复了我的配置:

 RSpec.configure do |config|
config.include Warden::Test::Helpers
end

 RSpec.configure do |config|
config.include Devise::Test::IntegrationHelpers, type: :system
end

这也让我放弃了:

  after(:each) do
Warden.test_reset!
end

在我所有的测试中。我已经运行了很多测试,它们不再失败,所以我现在假设这个问题确实已经修复。

关于javascript - 使用 Rails 5.1 和 Vue.js 进行 Flaky 系统测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49967944/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com