失败的Rspec / Capybara“link_to”测试虽然链接出现在网站上

时间:2013-04-25 17:00:19

标签: ruby-on-rails testing rspec integration capybara

我正在编写一个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

0 个答案:

没有答案