RoR Rspec tags with have_selector
EDIT: Figured it out. I should be doing ("span.age", :content => ...)
I am getting the 开发者_Python百科following error when I run this rspec test
response.should have_selector("span.age", :age => work1.age.to_s):
Failure/Error: response.should have_selector("span.age", :age => work1.age.to_s)
expected following output to contain a
<span.age age='15'/> tag
Output
....
<td class="work">
<span class="age">15</span><br><span class="content">B.1</span>
</td>
Running the same test on the span.content tag with
response.should have_selector("span.content", :content => work1.content)
yields no mistakes. However, if I purposefully make a mistake in that tag, I get the same output but a different expectation:
<span.content>B.1</span.content>
The only thing different between content and age is that age is an integer and content is a string. I am unsure why this is happening. Thanks for the help.
Oh, also, this doesnt happen in dev setting, only in test.
The answer, I believe, lies in your choice of the symbol ":content" for your second try. To correct your original test, change it to response.should have_selector("span.age", :content => work1.age.to_s)
This is because the key ":content" refers to the contents of the "span" element, so you are saying: "the response should have a "span.age" selector whose contents equals the result of evaluating the expression "work1.age.to_s". Your original test was looking for a "span.age" element with the attribute "age" equal to that.
精彩评论