RE: [Rails] Stubbing an ApplicationController before_filter

Hi,

The RSpec Book (Pragmatic Bookshelf: By Developers, For Developers) just added a new chapter about testing controllers, within which is an example of testing a before filter. You might find it of use.

Brandon

Fernando Perez wrote: [...]

I stopped using RSpec,

Just for this issue? If so, there was no need. I use controller.stub!(:filter).return(@whatever) regularly with RSpec. It works fine.

and switched back to Test::Unit, the Agile Web dev with Rails has a good intro chapter and I was able to solve my problem.

How were you able to solve the problem? It will help others if you post your solution.

Best,

Just for this issue? If so, there was no need.

Not just for that issue, and Brandon probably assumed I was using rspec, but it pissed me off some time ago.

Each time I would hit a wall with RSpec and have to search for hours how to solve it. With Test::Unit for some reason, I don't have as many little annoying troubles, and when I do, I find a solution whether on my own or by reading stuff online very quickly. I am having a much better testing experience with Test::Unit.

How were you able to solve the problem? It will help others if you post your solution.

Well I can't directly stub a controller instance method. So I stubbed the Model class method that the instance variable will be set to.

From: rubyonrails-talk@googlegroups.com [mailto:rubyonrails- talk@googlegroups.com] On Behalf Of Fernando Perez Sent: Friday, April 17, 2009 9:30 AM To: rubyonrails-talk@googlegroups.com Subject: [Rails] Re: Stubbing an ApplicationController before_filter

> Just for this issue? If so, there was no need. Not just for that issue, and Brandon probably assumed I was using rspec,

Only because I could have sworn I saw you posting over on that mailing list just the other day.

Brandon

Only because I could have sworn I saw you posting over on that mailing list just the other day.

I didn't fully transition to test::unit yet, so I still use RSpec's ML from time to time.