I want to go through the system spec.

Asked 1 years ago, Updated 1 years ago, 440 views

■Background
I'm working on an assignment at a certain school.
There is a time limit, but the school mentor's response is late, so please let me ask you a question.

■What you want to achieve
I want to pass this test code as systemspec

■Current state
Rspec wants to pass, but it doesn't.Let me ask you the following questions.
The following error occurs when running bundle exec rspec:

US>Error Messages
Capybara::ElementNotFound:
Unable to find link

Enter a description of the image here

■ What you actually tried
Search by error message and
I tried adding an id to the link with reference to the following, but it failed (and it got worse because I couldn't pass the test I was taking so far).
https://www.halu.dev/entry/2015/11/17/210904

Enter a description of the image here
Enter a description of the image here

■Other reference images
spec_helper
Enter a description of the image here
rails_helper
Enter a description of the image here

■ Code
HTML Code

<%provide(:title,@product.name)%>
<div class="main-wrapper">
  <section class="lightSection clearfix pageHeader">
    <div class="container">
      <div class="row">
        <div class="col-xs-6">
          <div class="page-title">
            <h2><%[email protected]%></h2>
          </div>
        </div>
        <div class="col-xs-6">
          <ol class="breadcrumb pull-right">
            <li><%=link_to 'Home', potpan_path%>/li>                          
            <lic class="active">%[email protected]%>/li>
          </ol>
        </div>
      </div>
    </div>
  </section>     
  <section class="mainContent clearfix">
    <div class="container">
      <div class="row singleProduct">
        <div class="col-xs-12">
          <div class="media">
            <div class="media-left productSlider">
              <divid="carousel" class="carousel slide" data-ride="carousel">
                <div class="carousel-inner">
                  <%@product.images.each_with_index do | image, i | %>
                    <div class="item<%="active" if i.zero?%>">
                      <%=image_tag(image.attachment(:large))%>
                    </div>
                  <%end%>
                </div>
              </div>
              <div class="clearfix">
                <divid="thumbcarousel" class="carousel slide" data-interval="false">
                  <div class="carousel-inner">
                    <%@product.images.each_with_index do | image, i | %>
                      <div data-target="#carousel"data-slide-to="<%=i%>"class="thumb">
                        <%=image_tag(image.attachment(:small))%>
                      </div>
                    <%end%>
                  </div>
                  <a class="left carousel-control" href="#thumbcarousel" role="button" data-slide="prev">
                    <span class="glyphicon glyphicon-chevron-left">/span>
                  </a>
                  <a class="right carousel-control" href="#thumbcarousel" role="button" data-slide="next">
                    <span class="glyphicon glyphicon-chevron-right">/span>
                  </a>
                </div>
              </div>
            </div>
            <div class="media-body">
              <ul class="list-inline">
                <li>
                  <%=link_to potapan_category_path(@product.taxons.first.id)do%>
                    <ic class="fa fa-reply" aria-hidden="true"></i> Back to List Page
                  <%end%>
                </li>
              </ul>
              <h2><%[email protected]%></h2>
              <h3><%[email protected]_price%>/h3>
              <p><%[email protected]%>/p>
              <span class="quick-drop">
                <select name="guiest_id3" id="guest_id3" class="select-drop">
                  <option value="0">S</option>
                  <option value="1">M</option>
                  <option value="2">L</option>
                  <option value="3">XL</option>
                </select>
              </span>
              <span class="quick-drop resizeWidth">
                <select name="guiest_id4" id="guest_id4" class="select-drop">
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                </select>
              </span>
              <div class="btn-area">
                <a href="cart_page.html" class="btn btn-primary btn-block" <i class="fa fa-angle-right" aria-hidden="true" </i><a>
              </div>
            </div>
          </div>
        </div>
      </div>

rspec Code

require 'rails_helper'

RSpec.describe "Products", type: :system do
  include Rails.application.routes.url_helpers
  describe "GET #show" do
    let(:image) {create(:image)}
    let(:product){create(:product,taxons:[taxon])}
    let(:taxonomy) {create(:taxonomy)}
    let(:taxon) {create(:taxon,taxonomy:taxonomy)}
    
    before do
      product.images<<image
      get potpan_product_path(product.id)
      # Addressing issues where image URL acquisition is not successful
      # # https://mng-camp.potepan.com/curriculums/document-for-final-task-2#notes-of-image-test
      ActiveStorage:: Current.host=request.base_url
    end

    "It ""Click ""Back to List Page"" to access the product category page"" do
      click_link('my_id')
      expect(current_path).to eq potepan_category_path(taxons.id)
    end

    "it" page must be displayed" do
      expect(response).to have_http_status(:success)
    end

    it "The name of the item must be displayed" do
      expect(response.body).to include product.name
    end

    it "The price of the item must be displayed" do
      expect(response.body).to include product.display_price.to_s
    end

    it "Product description is displayed" do
      expect(response.body).to include product.description
    end
  end
end


ruby-on-rails

2023-01-11 09:35

1 Answers

Self-resolved.

visit affected path

passed the test in


2023-01-11 09:59

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.