Stubbing controller methods in a helper test
I hadn’t created any tests of helper methods in Rspec 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 was that the context of the controller in a helper test is self.
self.stub!(:logged_in?).and_return(false)
More of my rantings
These might also interest you
- In which I lose twelve ping pong games in a row (Brainfuel)
- In which a woman criticizes me (Brainfuel)
- Bambi 2: In which Bambi discovers a nuclear bomb hidden in a mine shaft (Brainfuel)