I’m writing a test for some existing Ruby code which looks something like
module Foo
module Bar
private
def function_i_want_to_test (a, b)
if controller.is_something? a, b
puts a
else
puts b
end
end
end
end
The varaible controller magically inserted into the function from somewhere else. To access this function from my tests, I can do include Foo::Bar in my test class and call the function normally afterwards. Unfortunately this doesn’t work as controller isn’t set. Any ideas how I could set the controller variable from my test?
The module seems to assume “controller” is available in the class/module it’s being included into. Perhaps it’s for inclusion in Rails ActionController classes? Also, it’s probably meant to be a method call, not a local variable. So, do something like this:
For a test, you can also use Mocha (or other mocking libs) to make the process a little less verbose.