私は Hartl の Rails チュートリアルに取り組んでおり、9.1.1 の一部として最初のテストで行き詰まっています。user_pages_spec.rb、users_controller.rb、routes.rb、edit.html.erb、および application_controller.rb ファイルを調べましたが、何が問題なのかわかりません。
ターミナルで次の 3 つのエラーが発生します。
Ryans-MacBook-Air-3:tutorialapp rlhinchey$ bundle exec rspec spec/requests/user_pages_spec.rb -e "edit page"
Run options: include {:full_description=>/edit\ page/}
FFF
Failures:
1) signup edit page
Failure/Error: it { should have_selector('h1', text: "Update your profile") }
expected css "h1" with text "Update your profile" to return something
# ./spec/requests/user_pages_spec.rb:37:in `block (4 levels) in <top (required)>'
2) signup edit page
Failure/Error: it { should have_link('change', href: 'http://gravatar.com/emails') }
expected link "change" to return something
# ./spec/requests/user_pages_spec.rb:39:in `block (4 levels) in <top (required)>'
3) signup edit page
Failure/Error: it { should have_selector('title', text: "Edit user") }
expected css "title" with text "Edit user" to return something
# ./spec/requests/user_pages_spec.rb:38:in `block (4 levels) in <top (required)>'
Finished in 0.31167 seconds
3 examples, 3 failures
Failed examples:
rspec ./spec/requests/user_pages_spec.rb:37 # signup edit page
rspec ./spec/requests/user_pages_spec.rb:39 # signup edit page
rspec ./spec/requests/user_pages_spec.rb:38 # signup edit page
Randomized with seed 20756
テストが edit.html.erb ファイルを認識していないように見えますか? 私はこれに慣れていないので、おそらく完全に間違っています。どんな助けでも大歓迎です!
user_pages_spec.rb ファイル
require 'spec_helper'
describe "User pages" do
subject { page }
describe "profile page" do
let(:user) { FactoryGirl.create(:user) }
before { visit user_path(user) }
it { should have_selector('h1', text: user.name) }
it { should have_selector('title', text: user.name) }
end
describe "signup page" do
before { visit signup_path }
it { should have_selector('h1', text: 'Sign up') }
it { should have_selector('title', text: full_title('Sign up')) }
end
end
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 "edit" do
let(:user) { FactoryGirl.create(:user) }
before { visit edit_user_path(user) }
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 invalid information" do
before { click_button "Save changes" }
it { should have_content('error') }
end
end
describe "with valid information" do
before do
fill_in "Name", with: "Example User"
fill_in "Email", with: "user@example.com"
fill_in "Password", with: "foobar"
fill_in "Confirmation", with: "foobar"
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
end
describe "after saving the user" do
it { should have_link("Sign out") }
end
end
end
end
users_controller.rb
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
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
def edit
@user = User.find(params[:id])
end
end
edit.html.erb:
<% 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>
application_controller.rb:
class ApplicationController < ActionController::Base
protect_from_forgery
include SessionsHelper
#force signout to prevent CSRF attacks
def handle_unverified_request
sign_out
super
end
end
ルート.rb
Tutorialapp::Application.routes.draw do
resources :users
resources :sessions, only: [:new, :create, :destroy]
root to: 'static_pages#home'
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
match '/signup', to: 'users#new'
match '/signin', to: 'sessions#new'
match '/signout', to: 'sessions#destroy', via: :delete