
A new release, and a great addition.
For starters, assert_select will now work with both HTML and RJS outputs. So if your code does:
if xhr?
render :update do |page|
page.replace "message", "<p>Hi there</p>"
end
else
render :text=>"<p>Hi there</p>"
end
You can test it with:
assert_select "p", "Hi there"
I have a lot of actions that do smart updates using RJS, but degrade nicely to update the entire page when JavaScript is disabled. An easy way to test both:
test = lambda do
assert_select "div#post-1" do
assert_select "p:first-child", /Your post has been updated/
assert_select "p:last-child", /Click here to see/
end
end
post :update, :id=>1
test.call
xhr :post, :update, :id=>1
test.call
You can also test for RJS statements that update specific elements:
assert_select_rjs "post-1" do assert_select "p:first-child", /Your post has been updated/ assert_select "p:last-child", /Click here to see/ end
And even assert whether RJS is doing an update or an insert, and what type of insertion:
assert_select_rjs :update, "notice" do assert_select "*", /Please enter your e-mail address/ end assert_select_rjs :insert, :top do assert_select "div#?", /item-\d+/ end
To install the assert_select plugin:
./script/plugin install http://labnotes.org/svn/public/ruby/rails_plugins/assert_select
Labnotes » Blog Archive » assert_select plugin for Rails