1.テストを書く(RED)
spec/requests/****_spec.rb
describe "Contact page" do
it "should have the content 'Contact'" do
visit '/static_pages/contact' expect(page).to have_content('Contact')
end
it "should have the title 'Contact'" do
visit '/static_pages/contact' expect(page).to have_title("Ruby on Rails Tutorial Sample App | Contact")
end
end
実行(RED)
bundle exec rspec spec/requests/****_spec.rb
2.ルートを追加する
config/routes.rb
SampleApp::Application.routes.draw do
get "static_pages/home"
get "static_pages/help"
get "static_pages/about"
get "static_pages/contact" <<===
end
3.コントローラーにアクションを追加
app/controllers/*****_controller.rb
class StaticPagesController < ApplicationController
def contact #ページファイル名
end
end
4.ファイルにHTML / ERBを書く
app/views/static_pages/****.html.erb
class StaticPagesController < ApplicationController
def contact #ページファイル名
end
end
5.テストをする(GREEN)
bundle exec rspec spec/requests/****_spec.rb