尝试 运行 ruby rails 测试
Trying to run a ruby on rails test
%table.table-hover{}
%thead
%tr
%th Registration NO.
%th Name
%th Tier
%th Email
%tbody
- @accounts.each do |user|
%tr{:onclick => "window.location='/accounts/#{user[:id]}';"}
%td #{user.id}
%td #{user.givenname}
- if user.admin?
%td Admin
- elsif user.tech?
%td Technician
- else
%td User
%td #{user.email}
这是页面的代码,因此当您单击 table 中的一行时
table, then it should jump another page which is the details about this row.detail page
这是我的测试代码。
require 'rails_helper'
RSpec.describe 'accounts' do
context :js => true do
before do
@testAdmin = FactoryGirl.create(:admin)
end
describe 'Account Page can' do
before do
login_as(@testAdmin, :scope => :account)
visit '/accounts'
end
specify "visit account page" do
page.find(:xpath, "//table/tbody/tr").click
expect(page).to have_content 'Account: testAdmin'
end
end
end
end
当我运行打印出来的时候,好像还在table页面,也就是说没有跳转到详情页。
正如@Daniel 所指出的,您的 context
行中没有任何描述文本。这意味着 :js => true
将被视为上下文块的名称,而不是用作元数据以切换到支持 JS 的驱动程序。从失败测试的名称中应该可以看出这一点,该名称类似于 accounts {:js=>true} Account Page can visit account page
。要修复,您只需要在 context
调用
中包含描述性文本
context "something", js: true
或者只是转储上下文块并将元数据应用于其他任何有意义的块
describe 'Account Page can', js: true do
...
%table.table-hover{}
%thead
%tr
%th Registration NO.
%th Name
%th Tier
%th Email
%tbody
- @accounts.each do |user|
%tr{:onclick => "window.location='/accounts/#{user[:id]}';"}
%td #{user.id}
%td #{user.givenname}
- if user.admin?
%td Admin
- elsif user.tech?
%td Technician
- else
%td User
%td #{user.email}
这是页面的代码,因此当您单击 table 中的一行时 table, then it should jump another page which is the details about this row.detail page 这是我的测试代码。
require 'rails_helper'
RSpec.describe 'accounts' do
context :js => true do
before do
@testAdmin = FactoryGirl.create(:admin)
end
describe 'Account Page can' do
before do
login_as(@testAdmin, :scope => :account)
visit '/accounts'
end
specify "visit account page" do
page.find(:xpath, "//table/tbody/tr").click
expect(page).to have_content 'Account: testAdmin'
end
end
end
end
当我运行打印出来的时候,好像还在table页面,也就是说没有跳转到详情页。
正如@Daniel 所指出的,您的 context
行中没有任何描述文本。这意味着 :js => true
将被视为上下文块的名称,而不是用作元数据以切换到支持 JS 的驱动程序。从失败测试的名称中应该可以看出这一点,该名称类似于 accounts {:js=>true} Account Page can visit account page
。要修复,您只需要在 context
调用
context "something", js: true
或者只是转储上下文块并将元数据应用于其他任何有意义的块
describe 'Account Page can', js: true do
...