Topic: Testing Views that Presume a Controller

I'm sorry to ask so many questions but I feel Test::Rails is a valuable firewall against breakage, but the methodology and documentation is hard to find. Here's the current dilemma:

I have a view that lists affiliates. Each is rendered by a partial. There is an administrative and a user view. The view, then interrogates the controller to ask for the action_name, which clues it in to what it's supposed to render, especially on Ajax searches.

Using Test::Rails to test this view, I don't have a controller. Is there some best practice for this?

By the way, I'd like to write all this stuff down and post it if I can collect enough information. I think rcov, autotest and Test::Rails are great but people aren't making the kind of use of them they might if there were more nuts and bolts information available.


Re: Testing Views that Presume a Controller

Is it possible to have the controllers that render the view under test to set an @action_name instance variable instead of having the view callback to the controller? This would make it easier to test and would probably lead to a better decoupled design, even if you have to remember to manually set the action_name.

I agree with your goal of trying to build up a library of guidelines, extensions, etc for helping all the good tools to work well together.  I was groping towards that in my blog, but haven't had a chance to start really synthesising stuff, or even updating it much recently.

My RoR journey  -- thoughts on learning RoR and lessons learned in applying TDD and agile practices.

Re: Testing Views that Presume a Controller

I was leaning toward doing this, but because it's an Ajax action that depends on this info, I decided to just interrogate the controller directly. I think you're right about decoupling and I'll relook this.