Archive for the 'software' Category

assert_select Plugin Allows you to Run Funtional Tests on your .rhtml

assert_select picture

Ruby Inside just posted an interesting tidbit about the assert_select plugin written by Assaf Arkin. This is a cool little plugin which allows you to run functional tests on your .rhtml pages.

I wasn’t aware of a previous method to run functionjal tests on HTML elements, but I guess that *should* be a valuable part of our testing cycle.

Anyways, this is a cool little plugin. I think it will soon be added into some of my personal projects. Here are some code examples for it:

def test_login_form_has_all_fields
get :login
assert_select "form[action=http://myapp/login] input" do |inputs|
assert_equal 3, inputs.size
assert_select inputs[0], "input[type=name][name=username]"
assert_select inputs[1], "input[type=password][name=password]"
assert_select inputs[2], "input[type=submit][value=Login]"
end
end

And another one….

# Form includes four input fields
assert_select "form input", 4

# Page does not have any forms in it.
assert_select "form", false, "Page must contain no forms"

# Page has one link back to user's page.
assert_select "a[href=?]", url_for(:controller=>"user", :id=>user_id),
:count=>1, :text=>"Back to page"

19 Rails Tricks Most Rails Coders Don’t Know

MVC: The Most Vexing Conundrum

TextMate Cheat Sheet for Ruby and Rails Developers

« Previous Page