![]() | have_selector question |
|
26 Mar 2009, 17:37
Gregory Moeck (7 posts) |
It seems like have_selector isn’t functioning quite right in my code, but I’m sure it’s something that I’m doing. The following is one of my tests: @user is defined above, and is loading fine. I then get the following output: What seems weird to me is that the submit input clearly is there, but it isn’t recognizing it? Any help would be appreciated. |
|
26 Mar 2009, 17:39
Gregory Moeck (7 posts) |
This is lifted almost exactly from the code on page 240. When I change it to be have_tag by the way, it does pass. |
|
27 Mar 2009, 09:33
Vladimir Klyushnikov (1 post) |
This is an interesting question for me too. I’ve read a book chapter, tried have_selector and got the same issue. However there is a trick that will work:
Seems a bit verbose, but there is no other way to spec view semantics with have_selector. |
|
11 Apr 2009, 16:23
Martin Stingl (16 posts) |
I ran in a similar problem. But I’m not shure if it’s a rspec problem. I use haml. My page renders to correct xhtml code. But when I’m testing a partial (as described on chapter 20.4) I get a similar error message (see http://pastie.org/443746). But the error message told me rspec is looking for (with trailing slash) and only found (without trailing slash). Maybe it’s a haml problem? When using the above mentioned form.inner_html.should way, the test passes. When running the test with the debugger and I inspect the response the body contains the xhtml input-tag. So I’m really confused about the output rspec gives when failing the test … |
|
11 Apr 2009, 21:51
Martin Stingl (16 posts) |
I digged in a little bit deeper. So it seems to me the problem is caused by the to_xhtml method of Nokogiri. When using libxml2 version 2.6.* the trailing slash is missing (see http://rubyforge.org/pipermail/nokogiri-talk/20…). When using version 2.7.* to_xhtml produces the way of correct xhtml. But this doesn’t help because rspec (or webrat?) expects the short version. |
|
05 May 2009, 18:10
Thomas Jack (1 post) |
This is a webrat bug. https://webrat.lighthouseapp.com/projects/10503… is another interesting have_selector bug to watch out for. Also, never trust the failure messages for have_selector. This is generated separately from the matching code, and is often wrong. It’ll say, for example, that it was looking for |
| You must be logged in to comment |

