RSpec水豚have_selector测试不工作
问题描述:
我有一个非常简单的RSpec水豚have_selector(),似乎并没有工作,我无法弄清楚为什么......但可能是简单的东西。RSpec水豚have_selector测试不工作
这里的RSpec的要求测试:
describe 'with valid information'
let(:user) { FactoryGirl.create(:user) }
before do
fill_in 'Email', with: user.email
fill_in 'Password, with: user.password
click_button 'Login'
end
it { should have_selector('p', text: user.first_name) }
...
end
在new.html.erb
的会议,我只是有这样的事情:
<% if logged_in? %>
<p><%= current_user.first_name %></p>
<% else %>
<%= form_for(:session, url: sessions_path) do |f| %>
...
<% end %>
登录表单完全在浏览器session#new
作品。我可以很好地登录,并能够在p
标签中查看名字。问题似乎是水豚部分,因为其他it
测试检查页面上的h1
标记(无论登录是否存在)都可以正常工作。
有谁知道这个问题可能是什么?
在此先感谢您的帮助!
答
由于某种原因,您的登录失败的可能性很大。
更改您的测试看起来像这样:
it "should show me my first name" do
save_and_open_page
should have_selector('p', text: user.first_name)
end
,将打开你的浏览器,并显示你的页面作为测试浏览器目前看到它。 (您可能需要将launchy
宝石添加到您的Gemfile。)
还有一些其他的诊断,这将有助于,例如,添加测试或puts
,检查你降落在哪个页面,如:
it "redirects to the home page after log in" do
current_path.should == root_path
end
答
fill_in 'Password, with: user.password
不是那样的。您应该使用此行,
fill_in 'Password', with: user.password
+0
对不起,是的,这是我的错误,但不是在应用程序中。 – Justin
您是否检查过呈现的HTML? –