dax
dax

Reputation: 10997

have_selector is too literal in rspec test?

Not sure what the issue here is as I have the same syntax in other tests. I have a table, and I'm checking that content in is in the table header. here's my test:

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

Here's the response.body:

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

And here's the error autotest is throwing:

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

So why is this getting read so literally? the student_group.name IS inside of the tags...

Upvotes: 1

Views: 285

Answers (1)

dax
dax

Reputation: 10997

The issue here should have been obvious:

The test was expecting:

<th>class 2</th>

And it was getting:

<th>Class 2</th>

So as Narfanator mentioned in the comments, the problem was that this is case sensitive. Woops!

Upvotes: 1

Related Questions