`
dongbin
  • 浏览: 245608 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

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

    博客分类:
  • Ruby
阅读更多
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

分享到:
评论
2 楼 dongbin 2007-07-26  
对不起, 这是edge rails 才有的类
1 楼 dongbin 2007-07-25  
自己定义一个,不定义就是一个空Hash

相关推荐

Global site tag (gtag.js) - Google Analytics