Rspecでのエラーが自分の力じゃ解決できないので質問させて頂きます。
現在RailsでWebアプリの開発を行っています。
現在トップページを作っているのですが、そこでエラーが出ます。
ruby
12019-07-15 20:29:29 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chro 2me::Service#driver_path= instead. 32019-07-15 20:29:30 WARN Selenium [DEPRECATION] Selenium::WebDriver::Chrome#driver_path= is deprecated. Use Selenium::WebDriver::Chro 4me::Service#driver_path= instead. 5F 6 7Failures: 8 9 1) StaticPageController GET / returns http success 10 Failure/Error: <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 11 ActionView::Template::Error: 12 undefined method `[]' for nil:NilClass 13 # ./app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__1867907516391797567_70197030160940' 14 # ./spec/controllers/static_page_controller_spec.rb:9:in `block (3 levels) in <top (required)>' 15 # ------------------ 16 # --- Caused by: --- 17 # NoMethodError: 18 # undefined method `[]' for nil:NilClass 19 # ./app/views/layouts/application.html.erb:8:in `_app_views_layouts_application_html_erb__1867907516391797567_70197030160940'
対応するコードは以下のようになっています。
application.html.erb
ruby
1<!DOCTYPE html> 2<html> 3 <head> 4 <title><%= yield(:title) %></title> 5 <%= csrf_meta_tags %> 6 <%= csp_meta_tag %> 7 8 <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> 9 <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %> 10 </head> 11 12 <body> 13 <header> 14 <div class="container"> 15 <div class="header"> 16 <div class="title"> 17 <h1>Cities</h1> 18 </div> 19 <div class="link"> 20 <%= link_to 'log in', '#' %> 21 </div> 22 </div> 23 </div> 24 </header> 25 <%= yield %> 26 </body> 27</html> 28コード
rspec
ruby
1require 'rails_helper' 2 3RSpec.describe StaticPageController, type: :controller do 4 5 describe "GET /" do 6 render_views 7 8 it "returns http success" do 9 get :home 10 expect(response).to have_http_status 200 11 assert_select "title", "Cities" 12 # should have_link 'Sign up', href: '#' 13 end 14 end 15end
試したこと
erbファイルのapplicationと記載されているところをdefaultに変えたり、coffee-script-sourceをインストールしましたが解決しませんでした。
環境
mac
ruby 2.6.3
rails 5.2.3
よろしくお願い致します。
あなたの回答
tips
プレビュー