# Rails Testing Tips: Stubbing controller methods in a helper test

> In RSpec helper tests, the controller context is self -- use self.stub! to mock controller methods

- Author: Curtis Miller
- Published: 2007-08-21
- Categories: rails, testing, how-to
- Canonical URL: https://millarian.com/posts/stubbing-controller-methods-in-a-helper-test/

I hadn't created any tests of helper methods in Rspec (dead link: http://rspec.rubyforge.org) until last week. Doing so I found that one of my helpers was invoking the restful\_authentication `logged_in?` method. This probably isn't a big thing, but I was unsure how to stub the `logged_in?` method, that is, how to get the controller context to be able to invoke the `stub!` method. What I learned from [a colleague](http://heidmotron.com) was that the context of the controller in a helper test is self.

```ruby
self.stub!(:logged_in?).and_return(false)
```
