在rspec测试中,have_selector太字面了吗?

时间:2013-06-10 07:13:45

标签: ruby-on-rails-3 rspec

不确定这里的问题是什么,因为我在其他测试中使用相同的语法。我有一个表,我正在检查表头中的内容。这是我的测试:

before(:each) do
  @index = get :index, id: @user, user_id: @user.id
end

it "should be successful" do
   @index
   response.should be_success
 end

it "should have the right title" do
   @index
   response.should have_selector('title', content: "All classes")
 end

it "should have an element for each class" do
   @index
   @student_groups.each do |student_group|
     response.should have_selector('th', content: student_group.name)
   end
end

这是response.body:

<th><a href="/classes.2">Class 2</a></th>

这是自动测试中出现的错误:

     Failure/Error: response.should have_selector('th', content: student_group.name)
   expected following output to contain a <th>class 2</th> tag

那么为什么这么读懂呢?标签内的student_group.name IS ......

1 个答案:

答案 0 :(得分:1)

这里的问题应该是显而易见的:

测试期待:

<th>class 2</th>

它得到了:

<th>Class 2</th>

因此,在评论中提及Narfanator时,问题是这是区分大小写的。 Woops!