我遇到了一些奇怪的RSpec行为。
我在application.html.erb中有以下代码:
<% if signed_in? %>
<%= link_to "Profile", current_user %>
<%= link_to "Sign out", signout_path, method: "delete" %>
<% else %>
<%= link_to "Sign in", signin_path %>
<% end %>
我正在测试:
require 'spec_helper'
describe "Authentication" do
subject { page }
describe "signin" do
before { visit signin_path }
describe "with valid information" do
let(:user) { FactoryGirl.create(:user) }
before do
fill_in "Email", with: user.email.upcase
fill_in "Password", with: user.password
click_button "Acceder"
end
it { should have_title(user.name) }
it { should have_link("Mi Perfil", href: user_path(user)) }
it { should have_link("Desconectar", href: signout_path) }
it { should_not have_link('Acceder', href: signin_path) }
end
end
end
那些测试失败了。但是当我在HTML中添加一些字符时,就像这样:
<% if signed_in? %>
HELLO
<%= link_to "Profile", current_user %>
<%= link_to "Sign out", signout_path, method: "delete" %>
<% else %>
HELLO
<%= link_to "Sign in", signin_path %>
<% end %>
测试通过。这是为什么?我可以在不添加字符的情况下解决这个问题吗?
谢谢!