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
誰かがメタプログラミングについて少し教えてくれますか/これをどのように行うか?