Hartl Rails教程(3.2)8.2.5 Rspec失败
问题描述:
更新:Hartl Rails教程(3.2)8.2.5 Rspec失败
我的测试没有提交用户信息。该初步认识代码是在前面的章节的练习:
describe "after saving user" do
before { click_button submit }
let(:user) { User.find_by_email('[email protected]') }
it { should have_selector('title', text: user.name) }
it { should have_selector('div.alert.alert-success', text: 'Welcome') }
it { should have_link('Profile') }
end
/UPDATE
我已经完成了第8.2.5节(在注册时签到)和精确描述的应用程序的行为:
- 用户在注册后登录
- 然后重定向到其配置文件页面
- 其中标题已更改为包括“退出”链接。
但我的'退出'链接测试失败。这里是我的代码,从教程全部复制:
相关的控制器代码(users_controller.rb):
def create
@user = User.new(params[:user])
if @user.save
sign_in @user
flash[:success] = "Welcome to the Sample App!"
redirect_to @user
else
render 'new'
end
end
相关的视图代码(_header.html.erb):
<ul class="dropdown-menu">
<li><%= link_to "Profile", current_user %></li>
<li><%= link_to "Settings", '#' %></li>
<li class="divider"></li>
<li>
<%= link_to "Sign out", signout_path, method: "delete" %>
</li>
</ul>
相关测试代码(user_pages_spec.rb):
describe "signup" do
before { visit signup_path }
let(:submit) { "Create my account" }
describe "with invalid information" do
it "should not create a user" do
expect { click_button submit }.not_to change(User, :count)
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "[email protected]"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving user" do
it { should have_link('Profile') }
end
end
end
的错误是rspec ./spec/requests/user_pages_spec.rb:47 # User pages signup with valid information after saving user
谢谢!
答
我认为最后的“描述”块应该是这样的:
describe "after saving user" do
before { click_button submit }
it { should have_content('Profile') }
end
测试错过了一下检查,如果有一个页面上相应的内容之前,“提交”按钮。
啊哈 - 不要忘记做测试点击提交: – rda3000 2012-04-17 21:00:04