how do I test controller method using rspec?
controller, methods, rspec, ruby-on-rails, testing
Solution
I think the correct way is this:
describe GamesController do
it 'should return 99 if large' do
controller.testme(1000).should == 99
end
end
In a rails controller spec, when you put the controller class in `describe`, you can use `controller` method to get an instance :P Obviously, if `testme` method is private, you still have to use `controller.send :testme`
Problem
I'm trying to learn rspec. I can't seem to test a rails controller method. When I call the method in the test, rspec just returns an undefined method error. Here is my test example ``` it 'should return 99 if large' do GamesController.testme(1000).should == 99 end ``` and here is the error: ``` Failure/Error: GamesController.testme(1000).should == 99 NoMethodError: undefined method `testme' for GamesController:Class ``` I do have a testme method in the GamesController. I don't understand why the test code cannot see my methods. Any help is appreciated.