#はじめに
Railsチュートリアル第6版のテストをRSpecで書き直していく。
###目次
#Minitest
####StaticPagesコントローラーのテスト
test/controllers/static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionDispatch::IntegrationTest
def setup
@base_title = "Ruby on Rails Tutorial Sample App"
end
test "should get home" do
static_pages_home_url
assert_response :success
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
test "should get help" do
static_pages_help_url
assert_response :success
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
end
test "should get about" do
static_pages_about_url
assert_response :success
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end
end
#RSpec
####StaticPagesコントローラーのテスト
spec/requests/static_pages.rb
require 'rails_helper'
RSpec.describe "StaticPages", type: :request do
let(:base_title) { "Ruby on Rails Tutorial Sample App" }
describe "GET /home" do
it "returns http success" do
get "/home"
expect(response).to have_http_status(:success)
assert_select "title", "#{base_title}"
end
end
describe "GET /help" do
it "returns http success" do
get "/help"
expect(response).to have_http_status(:success)
assert_select "title", "Help | #{base_title}"
end
end
describe "GET /about" do
it "returns http success" do
get "/about"
expect(response).to have_http_status(:success)
assert_select "title", "About | #{base_title}"
end
end
end
/home
で基本タイトルのみを表示するよう変更。