とRailsの-チュートリアルを実行している間、私は第5章でテストを失敗した理由を理解していません。この本は最小のフレームワークを使用しましたが、私はRSpecを使うことにしました。これを行うために、私はテストフォルダを削除し、私のGemfileにrspec-rails
を含めると、バンドルインストールを実行し、rails g rspec:install
はスペックフォルダを生成します。しかし、static_pages_controller_spec.rbファイルには、assert_select
などの最小限の構文で便利に動作すると感じるテストがいくつかあります。ここに私のspecファイルがどのように見えるかです:未定義のメソッド「文書」:NilClassは、私は<code>railstutorial by Michael Hartl</code>次午前
require "rails_helper"
RSpec.describe StaticPagesController, type: :controller do
describe "GET #home" do
it "returns http success" do
get :home
expect(response).to have_http_status(:success)
end
it "should have the right title" do
get :home
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
end
describe "GET #help" do
it "returns http success" do
get :help
expect(response).to have_http_status(:success)
end
it "should have the right title" do
get :help
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
end
end
describe "GET #about" do
it "returns http success" do
get :about
expect(response).to have_http_status(:success)
end
it "should have the right title" do
get "about"
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end
end
end
私はRSpecのでテストを実行すると、これは私が失敗のエラーとして得るものです:
StaticPagesController GET #home should have the right title
Failure/Error: assert_select "title", "Ruby on Rails Tutorial Sample App"
NoMethodError:
undefined method `document' for nil:NilClass
# ./spec/controllers/static_pages_controller_spec.rb:11:in `block (3 levels)
in <top (required)>'
同じエラーメッセージ(No Method error)
がそれぞれに表示されます失敗したテスト。
どうすれば修正できますか?私が間違っていることがありますか?