Plugins - test_helpful
Add to favoritesTestHelpful
=====
Note: This plugin can only work with edge rails(Rails 2.0)
This plugin provide the following helper method for test
# Functional Matrix Test support
To knowlearn about it: http://www.infoq.com/news/2007/04/matrix-your-tests This plugin modify the matrix test code of ZenTest and add some new feature.
- You need not to define matrix_init_xxx method, but init with block:
In your test case:
def setup
init(:logined){ login_as :dongbin}
end
then "login_as :dongbin" will be called when setup include "logined"
- Reuse your test with after_filter
In your test case
after_filter :render_form, :new, :edit
def matrix_test_render_form
assert_response :success assert assigns(:job) assert_form(assigns(:job), *@@job_default_attr.keys)
end
def matrix_test_new
assert_template 'new'
end
def matrix_test_edit
assert_template 'edit'
end
Then matrix_test_render_form will be called after matrix_test_new or matrix_test_edit
# assert_form
assert_form(@user, :email, :password)
equals to
assert_select("form[action=/users]") do
assert_select("#user_email[name=?]", "user[email]")
assert_select("#user_password[name=?]", "user[password]")
assert_select("input[type=submit]")
end
# Add a method named "create" for unit tests and functional tests
- For Unit Test
in UserTest
create(:name => 'dongbin')
equals to
User.create(@@user_default_attr.merge(:name => 'dongbin')
If @@user_default_attr not defined, then it is an empty {}
- For functional test
In UserControllerTest
create(:name => 'dongbin')
equals to
post :create, :user => @@user_default_attr.merge(:name => 'dongbin')
If @@user_default_attr not defined, then it is an empty {}
Example
http://railsjob.googlecode.com/svn/trunk/test/functional/jobs_controller_test.rb
Copyright © 2007 Bin Dong, released under the MIT license
