1
我正在使用minitest與rails 3.2。我想定義我自己的「測試」功能,做一些特殊的事情,然後正常進行。包裝minitest測試塊
通常情況下,你定義的測試是這樣的:
class MyControllertest < ActionController::TestCase
test "should note have defined x" do
assert(!(defined? x))
get :index
assert_response :success
end
end
我想能夠做到以下
class MyControllerTest < ActionController::TestCase
special_test "should define X" do
assert(defined? x)
get :index
assert_response :success
end
end
所以,我想在一個測試助手,我包括
以下class ActiveSupport::TestCase
def self.special_test(name)
self.test(name) do
x=1
yield
end
end
end
但是,我得到
undefined method `get' for MyControllerTest:Class
有人可以幫助教我一些關於元編程/如何去做這件事嗎?
https://github.com/seattlerb/minitest
優秀!謝謝 – spike