如何在Rails中的集成测试中访问View helper?

时间:2016-03-07 06:41:44

标签: ruby-on-rails unit-testing view font-awesome

我的Rails视图中有以下代码

 <li><span class="list-group-item-bullet"><%= icon('eye') %></span>

生成以下HTML:

<li><span class="list-group-item-bullet"><i class="fa fa-eye"></i></span>

我想在集成测试中验证这个问题,并且我使用以下代码生成错误

 assert_select 'li' do
   assert_select 'span.list-group-item-bullet', 'i.fa fa-eye'
 end

如何在集成测试中验证它?

1 个答案:

答案 0 :(得分:3)

以下似乎有效:

assert_select 'li' do
  assert_select 'span.list-group-item-bullet' do
    assert_select 'i.fa.fa-eye'
  end
end

或者更简洁,

assert_select 'li span.list-group-item-bullet i.fa.fa-eye'

Taglia是正确的,你需要&#39; i.fa.fa-eye&#39; b / c&#39; i.fa fa-eye&#39;查找带有fa类和后代fa-eye标签的i标签。