I'm using minitest with rails 3.2. I want to define my own "test" function that does some special stuff, then proceeds as normal.
Normally, you define tests like this:
class MyControllertest < ActionController::TestCase
test "should note have defined x" do
assert(!(defined? x))
get :index
assert_response :success
end
end
I would like to be able to do the following
class MyControllerTest < ActionController::TestCase
special_test "should define X" do
assert(defined? x)
get :index
assert_response :success
end
end
So, I tried the following in a test helper that I include
class ActiveSupport::TestCase
def self.special_test(name)
self.test(name) do
x=1
yield
end
end
end
But, I get
undefined method `get' for MyControllerTest:Class
Can someone help teach me a little about metaprogramming / how to go about this?
在测试示例中这很奇怪,原因是您正在测试哪个子控件ActionController::TestCase
但是要在ActiveSupport::TestCase
中定义您的方法,如果需要,请在ActionController::TestCase
定义您的自定义方法。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.