How to get a handle/reference to the current controller object inside a rails functional test?
Posted
by Dave Paroulek
on Stack Overflow
See other posts from Stack Overflow
or by Dave Paroulek
Published on 2010-03-24T13:48:49Z
Indexed on
2010/03/24
18:53 UTC
Read the original article
Hit count: 382
I must be missing something very simple, but can't find the answer to this. I have a method named foo
inside bar_controller
. I simply want to call that method from inside a functional test.
Here's my controller:
class BarsController < ApplicationController
def foo
# does stuff
end
end
Here's my functional test:
class BarsControllerTest << ActionController::TestCase
def "test foo" do
# run foo
foo
# assert stuff
end
end
When I run the test I get:
NameError: undefined local variable or method `foo' for #<BarsControllerTest:0x102f2eab0>
All the documentation on functional tests describe how to simulate a http get request to the bar_controller which then runs the method. But I'd just like to run the method without hitting it with an http get or post request. Is that possible?
There must be a reference to the controller object inside the functional test, but I'm still learning ruby and rails so need some help.
© Stack Overflow or respective owner