I’d like to make each of my functional tests automatically test various formats. It seems like the way to achieve this is to wrap up the ‘test’ method in my own class method:
def self.test_all_formats(name)
[ "xml", "json" ].each do |fmt|
test "#{name} #{fmt}" do
yield(format)
end
end
end
test_all_formats "index" do |fmt|
get :index, { :format => fmt }
assert_response :ok
end
Unfortunately, each test results in the following error raised:
NoMethodError: undefined method `get’ for AccountsControllerTest:Class.
Although execution of the block is deferred until execution of the test, it’s trying to run the block in the context of the class rather than instance.
Is there a way to achieve this automated testing?
The following worked for me: