【问题标题】:RSpec td tag not returning dataRSpec td标签不返回数据
【发布时间】:2012-07-05 09:16:35
【问题描述】:

我正在使用一个表格来表示一个列表,我想使用 RSpec 来测试日期是否出现:

 describe "Checking the rota" do

    let(:service){ FactoryGirl.create(:service)}
    before{ visit root_path } #this is where the rota is displayed
    it{ should have_selector('td', date: service.date) }

  end

据我所知,应用程序本身运行良好,因为当我自己访问该页面时轮播表显示完美。我很好奇为什么测试失败了。我使用的工厂脚本是:

factory :service do
    date Date.today
    leader "Bob"
    singers "Mr T"
    soundAM "Thor"
    soundPM "Wobbles"
  end     

最后是我用来渲染轮播的存根:

<% if(service.date < Date.today) %>
  <% service.destroy %>
<% end %>
<tr>
    <td><%=link_to service.date, edit_service_path(service.id) %></td>
    <td><%= service.leader %></td>

    ...</tr>

提前感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

    我认为正确的行是:

    it{ should have_selector('td', text: service.date) }
    

    取决于你使用的是 Capybara 还是 Webrat

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-07
      • 2012-06-24
      • 1970-01-01
      • 2012-06-26
      • 1970-01-01
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多