I extract the plugin from a real project
http://code.google.com/p/railsjob/ to make test easier.
I submit it to
http://agilewebdevelopment.com/plugins/test_helpfulAnd write a short document -- sorry for my ugly English. :p
TestHelpful
===========
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
Note: This method can only work with edge rails(Rails 2.0)
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 (c) 2007 Bin Dong<dongbin.cn@gmail.com>, released under the MIT license
分享到:
相关推荐
RenPyPlugin-8.0.3_7.5.3_009-patreon-release .apk
资源分类:Python库 所属语言:Python 资源全名:nonebot_plugin_shindan-0.2.2-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
axis2-idea-plugin-1.7.9
pillow_avif_plugin-1.2.0-pp37-pypy37_pp73-win_amd64
python库。 资源全名:opensesame_plugin_-_radboudbox-1.0.9.tar.gz
python库。 资源全名:opensesame_plugin_-_radboudbox-1.0.2.tar.gz
资源分类:Python库 所属语言:Python 使用前提:需要解压 资源全名:nonebot_plugin_cocdicer-0.2.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
windows下esp32编译链,2020r3版本 使用说明参考:https://blog.csdn.net/p1279030826/article/details/111665788
资源分类:Python库 所属语言:Python 资源全名:nonebot_plugin_puppet-0.1.4-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源分类:Python库 所属语言:Python 资源全名:pybpod_gui_plugin_soundcard-0.1.1-py3-none-any.whl 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
ManusVR Unity 插件 ManusVR_Unity-Plugin-for-Apollo_1.0.0
资源来自pypi官网,解压后可用。 资源全名:mkdocs_print_site_plugin-2.2-py3-none-any.whl
资源分类:Python库 所属语言:Python 资源全名:netbox_plugin_test-0.4-py3.7.egg 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
python库。 资源全名:nonebot_plugin_russian-0.1.2-py3-none-any.whl
资源来自pypi官网。 资源全名:avocado_framework_plugin_i2n-77.0-py3-none-any.whl
python库。 资源全名:opensesame_plugin_Pulse_EVT2-0.0.6-py3-none-any.whl
Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) on project