简体   繁体   中英

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}

This is the code for page, so when you click on a row in the table table , then it should jump another page which is the details about this row. detail page And here are my test code.

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

When I run and printed out the page, it appears it's still on the table page, which means it does not jumped to the details page.

As pointed out by @Daniel, your context line doesn't have any description text in it. This means :js => true will be taken as the name of the context block and not used as metadata to switch to the JS capable driver. This should have been noticeable from the name of the failed test which would have been something like accounts {:js=>true} Account Page can visit account page . To fix you should just need to include descriptive text in the context call

context "something", js: true

or just dump the context block and apply the metadata to whichever of the other blocks makes sense

describe 'Account Page can', js: true do
  ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM