質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

0回答

1458閲覧

ruby on rails RSpecでテストを抜けられない

megaichi

総合スコア4

RSpec

RSpecはRuby用のBDD(behaviour-driven development)フレームワークです。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2020/04/18 16:40

編集2020/04/19 18:18

site_layout_specテスト作成後
下記エラーが発生しましたエラー文だけではどこに問題があるのか
全くわからず苦戦中です。

ファイルが多いため
必要なファイルは適時表示していきますのでよろしくお願いいたします。

site_layout_spec

require 'rails_helper' RSpec.describe "SiteLayouts", type: :system do describe "home layout" do it "contains root link" do visit root_path expect(page).to have_link nil, href: root_path, count: 2 end it "contains login link" do visit root_path expect(page).to have_link 'Login', href: login_path end # 中略 end end

エラー

Failures: 1) SiteLayouts home layout contains root link Failure/Error: expect(page).to have_link nil, href: root_path, count: 2 expected to find link nil with href "/" 2 times but there were no matches [Screenshot]: tmp/screenshots/failures_r_spec_example_groups_site_layouts_home_layout_contains_root_link_850.png # ./spec/systems/site_layout_spec.rb:7:in `block (3 levels) in <main>' 2) SiteLayouts home layout contains login link Failure/Error: expect(page).to have_link 'Login', href: login_path NameError: undefined local variable or method `login_path' for #<RSpec::ExampleGroups::SiteLayouts::HomeLayout:0x00007f842ea10d60> [Screenshot]: tmp/screenshots/failures_r_spec_example_groups_site_layouts_home_layout_contains_login_link_530.png # ./spec/systems/site_layout_spec.rb:12:in `block (3 levels) in <main>' Finished in 5.32 seconds (files took 2.81 seconds to load) 4 examples, 2 failures Failed examples: rspec ./spec/systems/site_layout_spec.rb:5 # SiteLayouts home layout contains root link rspec ./spec/systems/site_layout_spec.rb:10 # SiteLayouts home layout contains login link /Users/megataichi/.rbenv/versions/2.7.0/bin/ruby -I/Users/megataichi/portfolio/lantern_app/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.9.1/lib:/Users/megataichi/portfolio/lantern_app/vendor/bundle/ruby/2.7.0/gems/rspec-support-3.9.2/lib /Users/megataichi/portfolio/lantern_app/vendor/bundle/ruby/2.7.0/gems/rspec-core-3.9.1/exe/rspec --pattern spec/**\{,/*/**\}/*_spec.rb failed

追記分

① app/views/static_pages/home.html.erb

<% provide(:title, "Home") %> <h1>Sample App</h1> <p> This is the home page for the <a href="https://railstutorial.jp/">Ruby on Rails Tutorial</a> sample application. </p>

② bundle exec rake routes の実行結果

/Users/megataichi/portfolio/lantern_app/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.4.2/lib/action_dispatch/middleware/stack.rb:37: warning: Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call /Users/megataichi/portfolio/lantern_app/vendor/bundle/ruby/2.7.0/gems/actionpack-5.2.4.2/lib/action_dispatch/middleware/static.rb:111: warning: The called method `initialize' is defined here Prefix Verb URI Pattern Controller#Action static_pages_home GET /static_pages/home(.:format) static_pages#home static_pages_about GET /static_pages/about(.:format) static_pages#about root GET / static_pages#home about GET /about(.:format) static_pages#about rails_service_blob GET /rails/active_storage/blobs/:signed_id/*filename(.:format) active_storage/blobs#show rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update rails_direct_uploads POST /rails/active_storage/direct_uploads(.:format)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

siruku6

2020/04/19 01:49 編集

まずは、次の二つの情報が質問文内に追記されているとよいと思います ①home layoutにアクセスしたときに使用されるviewファイル ②bundle exec rake routes の実行結果全て
megaichi

2020/04/19 18:21

ご返信ありがとうございます!資料追加してみました! 足りますでしょうか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問