代码之家  ›  专栏  ›  技术社区  ›  Maayan Naveh

rspec+capybara作用域返回意外结果

  •  0
  • Maayan Naveh  · 技术社区  · 6 年前

    我有两个表:建议和关键字。 我正在尝试从关键字中删除项目(这会自动将其放入建议中)。

    这是我的测试:

    it "removes a chosen keyword" do
      page.first(:link, "Add").click
      within(:css, "#keywords") do
        find('li:nth-child(1)').click_link('X')
        expect(page).to have_no_content(item.search.term)
      end
    end
    

    结果是:

      1) New collection Suggestions removes a chosen keyword
         Failure/Error: expect(page).to have_no_content(item.search.term)
           expected not to find text "Gift for her" in "Keywords\nGift for her X"
         # ./spec/features/collections_spec.rb:60:in `block (4 levels) in <top (required)>'
         # ./spec/features/collections_spec.rb:53:in `block (3 levels) in <top (required)>'
    

    这是body元素的印刷体:

      <div class="col-lg-5 col-md-6 mb-4" id="suggestions">
        <div class="card h-100">
          <div class="card-body">
            <h4 class="card-title">Suggestions</h4>
            <p class="card-text"> 
              <ul class="list-group list-group-flush" id="suggestion-list">
                    <li class="list-group-item">
                      Gift for her
                      <a class="btn btn-primary" rel="nofollow" data-method="post" href="/collections/1/item/choose.1">Add</a><a class="btn btn-primary" rel="nofollow" data-method="post" href="/collections/1/item/destroy.1">X</a><br>
                    </li>
              </ul>
            </p>
          </div>
        </div>
      </div>
    
    <div class="col-lg-5 col-md-6 mb-4" id="keywords">
        <div class="card h-100">
          <div class="card-body">
            <h4 class="card-title">Keywords</h4>
            <p class="card-text">                     
              <ul class="list-group list-group-flush" id="keyword-list">
              </ul>
            </p>
          </div>
        </div>
      </div>
    

    还有我的 show.html.erb 文件:

      <div class="col-lg-5 col-md-6 mb-4" id="suggestions">
        <div class="card h-100">
          <div class="card-body">
            <h4 class="card-title">Suggestions</h4>
            <p class="card-text"> 
              <ul class="list-group list-group-flush" id="suggestion-list">
                <% if @suggestions %>
                    <% @suggestions.each do |s| %>
                    <li class="list-group-item">
                      <%= Hpricot.uxs s.search.term %>
                      <%= link_to 'Add', collection_item_choose_path(@collection, s),{  method: :post, class: "btn btn-primary" } %><%= link_to 'X', collection_item_destroy_path(@collection, s),{  method: :post, class: "btn btn-primary" } %><br>
                    </li>
                  <% end %>
                <% end %>
              </ul>
            </p>
          </div>
        </div>
      </div>
    
    <div class="col-lg-5 col-md-6 mb-4" id="keywords">
        <div class="card h-100">
          <div class="card-body">
            <h4 class="card-title">Keywords</h4>
            <p class="card-text">                     
              <ul class="list-group list-group-flush" id="keyword-list">
                <% if @keywords %>
                  <% @keywords.each do |s| %>
                    <li class="list-group-item">
                      <%= Hpricot.uxs s.search.term %>
                      <%= link_to 'X', collection_item_remove_path(@collection, s),{  method: :post, class: "btn btn-primary" } %><br>
                    </li>
                  <% end %>
                <% end %>
              </ul>
            </p>
          </div>
        </div>
      </div>
    

    在我看来,作用域好像被关闭了,尽管我检查了并且链接确实点击了(你可以在puts page.body中看到)。有什么想法吗? 事先谢谢!

    1 回复  |  直到 6 年前
        1
  •  1
  •   Thomas Walpole    6 年前

    Capybara.default_max_wait_time test.log save_and_open_screenshot

    capybara/rails