前提・実現したいこと
Ruby on Railsで詳細ページにEditとBackのリンクを作ったのですがRSpecでは表示もリンクも無いとエラーで出てきてしまいます
発生している問題・エラーメッセージ
エラーメッセージ 1) 投稿のテスト 詳細画面のテスト 表示の確認 Editリンクが表示される Failure/Error: expect(edit_link.native.inner_text).to match(/edit/i) expected "hoge" to match /edit/i Diff: @@ -1 +1 @@ -/edit/i +"hoge" # ./spec/system/books_spec.rb:92:in `block (4 levels) in <main>' 2) 投稿のテスト 詳細画面のテスト 表示の確認 Backリンクが表示される Failure/Error: expect(back_link.native.inner_text).to match(/back/i) expected "body" to match /back/i Diff: @@ -1 +1 @@ -/back/i +"body" # ./spec/system/books_spec.rb:96:in `block (4 levels) in <main>' 3) 投稿のテスト 詳細画面のテスト リンクの遷移先の確認 Editの遷移先は編集画面か Failure/Error: expect(current_path).to eq('/books/' + book.id.to_s + '/edit') expected: "/books/1/edit" got: "/books/1" (compared using ==) # ./spec/system/books_spec.rb:103:in `block (4 levels) in <main>' 4) 投稿のテスト 詳細画面のテスト リンクの遷移先の確認 Backの遷移先は一覧画面か Failure/Error: expect(page).to have_current_path books_path expected "/books/1" to equal "/books" # ./spec/system/books_spec.rb:108:in `block (4 levels) in <main>'
該当のソースコード
routes.rb Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html resources :books root to: 'books#top' end books_controller.rb class BooksController < ApplicationController def top end def index @books = Book.all @book = Book.new end def show @book = Book.find(params[:id]) end def create @book = Book.new(book_params) if @book.save flash[:notice] = "successfully" redirect_to book_path(@book) else @books = Book.all render :index end end def edit @book = Book.find(params[:id]) end def update @book = Book.find(params[:id]) if @book.update(book_params) flash[:notice] = "successfully" redirect_to book_path(@book) else render :edit end end def destroy book = Book.find(params[:id]) book.destroy flash[:notice] = "successfully" redirect_to books_path end private def book_params params.require(:book).permit(:title, :body) end end show.html.erb <% if flash[:notice] %> <div class="flash"> <%= flash[:notice] %> </div> <% end %> <p><strong>Title:</strong> <a><%= @book.title %></a> </p> <p><strong>Body:</strong> <a><%= @book.body %></a> </p> <%= link_to"Edit",edit_book_path %> | <%= link_to"Back",books_path %> $ rails routes Prefix Verb URI Pattern Controller#Action books GET /books(.:format) books#index POST /books(.:format) books#create new_book GET /books/new(.:format) books#new edit_book GET /books/:id/edit(.:format) books#edit book GET /books/:id(.:format) books#show PATCH /books/:id(.:format) books#update PUT /books/:id(.:format) books#update DELETE /books/:id(.:format) books#destroy root GET / books#top 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) active_storage/direct_uploads#create
試したこと
pathのidなど変更したりしましたが結果は変わらないです
補足情報(FW/ツールのバージョンなど)
Rails 5.2.6
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。