Skip to content

Instantly share code, notes, and snippets.

@karledurante
Created January 3, 2012 15:51
Show Gist options
  • Save karledurante/1555451 to your computer and use it in GitHub Desktop.
Save karledurante/1555451 to your computer and use it in GitHub Desktop.
Rails 3 Functional Test: assert_select finds nothing on XHR requests
setup do
xhr :post, :summarize
end
should "find a tag" do
# FAILS in Rails3, SUCCEEDS in Rails2
assert_select :span, :text => "some content"
# SUCCEEDS in Rails3 & Rails2
assert_match /\<span\>some content<\/span\>/, @response.body
end
@sethvargo
Copy link

assert_select will look at the Content-Type before actually testing. If it sees xhr/js, it will assume the response is rjs. That being said, I don't have a solution. I supposed you could extract the regexs from assert_select and write a test helper on your own?

@karledurante
Copy link
Author

Yeah, I'm using assert_match for now. Honestly, I don't like functional tests that expect certain tags to be in place, especially something as generic as span. I think just matching the content is sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment