![在这里输入图像描述] [1]我一直在阅读Michael Hartl的RoR教程书,我在Rspec上遇到了7次失败。我一直在寻找3个小时来找到错误,但我找不到它。错误说我没有link_to注销(一个来自用户页面,一个来自编辑页面),link_to更改,以及一堆have_selector错误。这是rspec user_pages_spec.rb。我几乎是肯定的edit.html.erb和header.html很好,但如果没有人看到这个rspec有什么不对,那就不好发布了
describe "edit" do
let(:user) { FactoryGirl.create(:user) }
before do
sign_in user
visit edit_user_path(user)
end
describe "page" do
it { should have_selector('h1', text: "Update your profile") }
it { should have_selector('title', text: "Edit user") }
it { should have_link('change', href: 'http://gravatar.com/emails') }
end
describe "with valid information" do
let(:new_name) { "New Name" }
let(:new_email) { "new@example.com" }
before do
fill_in "Name", with: new_name
fill_in "Email", with: new_email
fill_in "Password", with: user.password
fill_in "Confirm Password", with: user.password
click_button "Save changes"
end
it { should have_selector('title', text: new_name) }
it { should have_selector('div.alert.alert-success') }
it { should have_link('Sign out', href: signout_path) }
specify { user.reload.name.should == new_name }
specify { user.reload.email.should == new_email }
end
端
这里是错误以及与之相关的其他文件
Failures:
1) User pages signup with valid information after saving the user
←[31mFailure/Error:←[0m ←[31mit { should have_link('Sign out') }←[0m
←[31mexpected link "Sign out" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:30:in `block (5 levels) in <top (
required)>'←[0m
2) User pages edit page
←[31mFailure/Error:←[0m ←[31mit { should have_link('change', href: 'http://
gravatar.com/emails') }←[0m
←[31mexpected link "change" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:134:in `block (4 levels) in <top
(required)>'←[0m
3) User pages edit page
←[31mFailure/Error:←[0m ←[31mit { should have_selector('title', text: "Edit
user") }←[0m
←[31mexpected css "title" with text "Edit user" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:133:in `block (4 levels) in <top
(required)>'←[0m
4) User pages edit page
←[31mFailure/Error:←[0m ←[31mit { should have_selector('h1', text: "Upda
te your profile") }←[0m
←[31mexpected css "h1" with text "Update your profile" to return somethin
g←[0m
←[36m # ./spec/requests/user_pages_spec.rb:132:in `block (4 levels) in <top
(required)>'←[0m
5) User pages edit with valid information
←[31mFailure/Error:←[0m ←[31mit { should have_selector('div.alert.alert-suc
cess') }←[0m
←[31mexpected css "div.alert.alert-success" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:149:in `block (4 levels) in <top
(required)>'←[0m
6) User pages edit with valid information
←[31mFailure/Error:←[0m ←[31mit { should have_selector('title', text: new_n
ame) }←[0m
←[31mexpected css "title" with text "New Name" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:148:in `block (4 levels) in <top
(required)>'←[0m
7) User pages edit with valid information
←[31mFailure/Error:←[0m ←[31mit { should have_link('Sign out', href: signou
t_path) }←[0m
←[31mexpected link "Sign out" to return something←[0m
←[36m # ./spec/requests/user_pages_spec.rb:150:in `block (4 levels) in <top
(required)>'←[0m
<% provide(:title, "Edit user") %>
<h1>Update your profile</h1>
<div class="row">
<div class="span6 offset3">
<%= form_for(@user) do |f| %>
<% render 'shared/error_messages' %>
<%= f.label :name %>
<%= f.text_field :name %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :password %>
<%= f.password_field :password %>
<%= f.label :password_confirmation, "Confirm Password" %>
<%= f.password_field :password_confirmation %>
<%= f.submit "Save changes", class: "btn btn-large btn-primary" %>
<% end %>
<%= gravatar_for @user %>
<a href="http://gravatar.com/emails">change</a>
</div>
</div>
<header class="navbar navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<%= link_to "Anime Ranting", root_path, id: "logo" %>
<nav>
<ul class="nav pull-right">
<li><%= link_to "Home", root_path %></li>
<li><%= link_to "Help", help_path %></li>
<% if signed_in? %>
<li><%= link_to "Users", '#' %></li>
<li id="fat-menu" class="dropdown">
<a href-"#" class="dropdown-toggle" data-toggle="dropdown">
Account <b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", edit_user_path(current_user) %></li>
<li class="divier"></li>
<li><%= link_to "Sign out", signout_path, method: "delete" %></li>
</ul>
</li>
<% else %>
<li><%= link_to "Sign in", signin_path %></li>
<% end %>
</ul>
</nav>
</div>
</div>
</header>
答案 0 :(得分:1)
你在subject { page }
下面遗漏了describe "edit" do
。这允许您使用语法it { should ...
。