[rspec-users] How to spec error_messages_for

Ashley Moran work at ashleymoran.me.uk
Fri Mar 23 06:37:50 EDT 2007

On 22 Mar 2007, at 17:52, David Chelimsky wrote:

> This is an interesting case because the behaviour you want to describe
> is no longer in your app - it's actually new behaviour in Rails itself
> (in your patch of rails).

Well I added the code to ApplicationHelper, so I guess the tests  
still belong in my app, even if they override some Rails magic  
(actually, maybe the thing I need to test is that it DOES override  
the Rails magic but let's not go there...)

> Rails is all about opacity. I re-learn that lesson nearly every day.

Within Rails, there is a much smaller and cleaner framework  
struggling to get out?

> Well, it doesn't make me want to jump for joy, but I might choose to
> do it this way anyhow. Lesser of many evils and all.

Eventually I gave up and did this.  I added the following to my  
controller spec:

     context "ASSUMPTION (about the next spec): the controller" do
       specify "should have respond to template and return a template  
that responds to error_messages_for" do
         @controller.should respond_to(:template)
         @controller.template.should respond_to(:error_messages_for)

     context "A rendered calculate_quote view with an invalid form" do
       specify "should render the error messages" do
('form', :anything).and_return("<div>ERRORS</div>")
         render 'gap/calculate_quote'
         response.should have_tag("div", :text => "ERRORS")

Which I think catches it.  I don't think given the current Rails  
architecture that there's a cleaner way.


More information about the rspec-users mailing list