gpt4 book ai didi

ruby-on-rails - Rspec 期望 link_to 没有找到任何东西

转载 作者:行者123 更新时间:2023-12-04 06:07:36 26 4
gpt4 key购买 nike

![在此处输入图片描述][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>

最佳答案

您在 describe "edit"do 下缺少 subject { page }。这使您可以使用语法 it { should ...

关于ruby-on-rails - Rspec 期望 link_to 没有找到任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13204965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com