【发布时间】:2013-04-14 02:50:51
【问题描述】:
我终其一生都无法弄清楚为什么这些测试会失败。
当用户输入他们的电子邮件/密码并点击登录按钮时,他们将被重定向到他们的个人资料页面,该页面将他们的名字放在标题中并在页面上显示他们的名字。它还显示了指向其个人资料的链接和退出链接。当我在浏览器中完成这些步骤时,一切都在它应该在的地方,但是当 rspec 运行时它继续失败。
我发现真正奇怪的是,当我运行一个 user_page_spec 测试来测试相同的元素时,这些都通过了。
我认为它与控制器中的 click_button 部分或“redirect_to 用户”有关,但我们将不胜感激。
这里是测试-
通过 user_pages_spec.rb- 中的测试
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.firstName) }
it { should have_selector('title', text: user.firstName) }
end
authentication_pages_spec.rb 中的测试失败 - 需要'spec_helper'
describe "Authentication" do
describe "sign in" do
.
.
.
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email
fill_in "Password", with: user.password
click_button "Log in"
end
it { should have_selector('title', text:user.firstName) }
it { should have_link('Profile', href: user_path(user)) }
it { should have_link('Sign out', href: signout_path) }
describe "followed by signout" do
before { click_link "Sign out" }
it { should have_link('Home') }
end
end
end
end
【问题讨论】:
标签: ruby-on-rails testing rspec tdd