我正在使用rspec,capybara测试我的rails应用程序。测试工作正常,可以登录。 登录后我试图访问一些链接,我也可以去链接,但之后它又回到登录页面。我不确定我的代码有什么问题。请帮我弄清楚问题。
我的测试规范文件。
require 'spec_helper'
describe "User Login",:js => true do
let(:user) { FactoryGirl.create(:user)}
before(:each) do
visit login_path
fill_in "email", with: user.email
fill_in "password", with: user.password
click_button "Sign in"
end
describe "after login" do
it "should show the left navigation on the dashboard" do
visit "/todos"
visit employees_dashboard_path
page.should have_link('Todo', href: todos_path)
click_link "Todo"
end
end
end
describe "Display the todos list" do
let(:todo) { FactoryGirl.create(:todo)}
it "should disply no todos if the todos are nil" do
expect(Todo.count).to eq(0)
visit "/todos" # I could come till here.
expect(page).to have_content("Todos")
end
end
在观看" / todos"我应该看到" Todos"作为页面上的内容,而是再次重新登录登录页面。
我的测试跟踪错误:
Display the todos list should disply no todos if the todos are nil
Failure/Error: expect(page).to have_content("Todos")
expected to find text "Todos" in "Please login to access the page Log In
Sign in Forgot Password Close Forgot Password Close"
所以我又回到了登录页面。请告诉我为什么我的代码中发生了这种意外行为。
谢谢。
答案 0 :(得分:1)
在"显示待办事项列表"阻止您没有登录:您需要具有与"用户登录"中相似的before(:each)
。阻止或移动整个"显示待办事项"阻止"用户登录"块。