0

我正在编写一个 Ruby on Rails 应用程序来管理图书馆记录。该网站位于 grinnelllendinglibrary.herokuapp.com 我想测试一下,当经理登录时,他们可以在每本书记录旁边看到指向“结帐”操作的链接。我的问题是这个 Cabybara/Rspec 测试失败了,我不知道为什么。

describe "on the index page" do
  before(:each) do
    click_link "Index"
  end
 ....

  it "should have a checkout link" do
    page.should have_link("Checkout")

    # I've also tried a bunch of other tests; these also failed:
    #page.should have_content "Checkout"
    #find('div').should have_link('Checkout')
    #find_link('Checkout').visible? == 'true'
  end
 .....
end

错误信息是:

 Failure/Error: page.should have_link("Checkout")
   expected link "Checkout" to return something
 # ./spec/requests/layout_links_spec.rb:172

我已经检查了几件事:1)这不是由于登录失败;同一块中的其他测试正确地在标题中找到仅在经理登录时可见的链接;只有部分书中的链接没有找到。2)链接显示在网站本身,它只是失败的测试。

本书部分代码:

  <div class="book">
    <div class="title"> 
      <%= book.name %>
    </div>
    <% if signed_in? and is_manager? %>
    <%= link_to "Entry", book%>
    <%= link_to "Delete", book, :method => :delete, :confirm => "Are you
    sure?", :title => "Delete #{book.name}" %> 
    <%= link_to "Checkin", checkin_book_path(book), :method => :put%>
    <%= link_to "Checkout", checkout_book_path(book), :method => :put%>
    <% end %>
    <br>
    <p class="moreinfo">
      Authors(s): <%= book.authors %><br>
      <% if book.edition != nil %>
      Edition: <%= book.edition %>
      <% else %>
      Edition: N/A
      <% end %>
      <br>
      Copies available: <%= book.avail_copies
                            %>/<%= book.total_num_copies %>
    </p>
  </div>

我正在使用 Rails 3.2.12、rspec-rails 2.8.1 和 capybara 1.1.2

4

0 回答 0