test_helpful released -- A plugin on rails to make test easier

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_helpful

And 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值