我正在通过第5章的Hartl's Rails教程,我正在为新的Users控制器创建集成测试。在创建了rspec测试之后,我似乎无法通过两个测试来检查内容和注册网页的标题。
我自己手动访问了网页,内容和标题都很好看。我还使用了水豚的save_and_open_page
来检查它看到了什么,它看起来和我访问网站没有css格式的情况完全相同。我也重新启动了rails和spork服务器,如果这有任何区别的话。
非常感谢任何帮助。
这是我的rspec测试user_pages_spec.rb
:
require 'spec_helper'
describe "UserPages" do
subject { page }
describe "Signup page" do
before { visit signup_path; save_and_open_page }
it { should have_content("Sign up") }
it { should have_title(full_title("Sign up")) }
end
end
测试结果:
Run options: include {:locations=>{"./spec/requests/user_pages_spec.rb"=>[7]}}
FF
Failures:
1) UserPages Signup page
Failure/Error: it { should have_content("Sign up") }
expected #has_content?("Sign up") to return true, got false
# ./spec/requests/user_pages_spec.rb:11:in `block (3 levels) in <top (required)>'
2) UserPages Signup page
Failure/Error: it { should have_title(full_title("Sign up")) }
expected #has_title?("Rails Sample App | Sign up") to return true, got false
# ./spec/requests/user_pages_spec.rb:12:in `block (3 levels) in <top (required)>'
Finished in 0.06667 seconds
2 examples, 2 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:11 # UserPages Signup page
rspec ./spec/requests/user_pages_spec.rb:12 # UserPages Signup page
Randomized with seed 30695
[Finished in 0.7s with exit code 1]
rake routes
Prefix Verb URI Pattern Controller#Action
root GET / static_pages#home
help GET /help(.:format) static_pages#help
about GET /about(.:format) static_pages#about
contact GET /contact(.:format) static_pages#contact
signup GET /signup(.:format) users#new
new.html.erb
<% provide(:title, "Sign Up") %>
<h1>Sign Up</h1>
<p>Find me in app/views/users/new.html.erb</p>
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
<%= csrf_meta_tags %>
<%= render 'layouts/shim' %>
</head>
<body>
<%= render 'layouts/header' %>
<div class="container">
<%= yield %>
<%= render 'layouts/footer' %>
</div>
</body>
</html>