[rspec-users] Problems translating should_render from 0.8.2 to 1.0.5

David Chelimsky dchelimsky at gmail.com
Thu Jun 28 09:09:05 EDT 2007


On 6/26/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> On 6/26/07, Jake Scruggs <JScruggs at thoughtworks.com> wrote:
> >
> > -----rspec-users-bounces at rubyforge.org wrote: -----
> >
> > >To: rspec-users <rspec-users at rubyforge.org>
> > >From: "David Chelimsky" <dchelimsky at gmail.com>
> > >Sent by: rspec-users-bounces at rubyforge.org
> > >Date: 06/22/2007 09:54AM
> > >Subject: Re: [rspec-users] Problems translating should_render from
> > >0.8.2 to 1.0.5
> >
> > >
> > >On 6/19/07, Jake Scruggs <JScruggs at thoughtworks.com> wrote:
> > >> I'm working on a large Rails site and we want to move from RSpec
> > >0.8.2 to
> > >> the latest and greatest.  So we ran the translator and yet we're
> > >having a
> > >> lot of trouble translating should_render.
> > >>
> > >> I found this on the web:
> > >>
> > >> We will NOT be supporting the following in the
> > new syntax:
> > >>   controller.should_render
> > >>   controller.should_redirect_to
> > >>
> > >> You will be able to use instead:
> > >>   response.should render_template
> > >>   response.should render_text
> > >>   response.should redirect_to
> > >>
> > >> But the problem I have is that render_template
> > doesn't have the
> > >> functionality that we used in lots of our should_render
> > >expectations.  A lot
> > >> of our should renders specify an action and and a controller, so
> > >now the
> > >> change over is slow (we have to figure out which file is being
> > >rendered
> > >> instead), but the big problem is that when testing actions that
> > >render a
> > >> partial (mostly for ajax calls) we need to test the locals that get
> > >passed
> > >> into the template.
> > >>
> > >> here's a typical spec:
> > >>   specify "the :start_date should equal the date
> > passed in" do
> > >>     @mock_event_calendar_data = mock('Mock
> > event_calendar_data')
> > >>
> > >>
> > >EventCalendarData.should_receive(:new).and_return(@mock_event_calenda
> > >r_data)
> > >>     date = Date.today
> > >>     controller.should_render :partial => 'calendar', :locals =>
> > >{:start_date
> > >> => date, :event_calendar_data =>
> > @mock_event_calendar_data}
> > >>     get 'ajax_calendar', :date =>
> > Date.today.strftime("%B-%d-%Y")
> > >>   end
> > >>
> > >> here's another expectation I don't know how to
> > translate:
> > >> controller.should_render({:controller=>:content_item,
> > >:layout=>"frame",
> > >> :action=>:upload_image})
> > >>
> > >> Does anybody have any ideas about how to get these things working
> > >in the new
> > >> RSpec?
> > >
> > >Sorry for not responding sooner. This was functionality we yanked
> > >when
> > >we went from should_render to should render_template.
> > To keep the
> > >matchers simple, I'd suggest we add another matcher named
> > >render_action that looked at the hash, or
> > render_with_options. WDYT?
> >
> > That would be cool, because right now we have a lot of tests/specs/examples
> > that do things just like the examples I gave and the time involved in
> > converting all these of them means that we probably won't leave RSpec 0.82
> > anytime soon (if at all).  If there was a render_action, then the conversion
> > would be more of a simple mapping and might only take a day -- and I'm
> > pretty sure I could  convince the business to give up a day.
> >
> > maybe we could pair on it?,
>
> That'd be great!

So Jake came by last night and we paired on this and got it solved.
You can read about the solution here:

http://blog.davidchelimsky.net/articles/2007/06/28/template-expects_render

Cheers,
David

>
> > -Jake Scruggs
> >
> > _______________________________________________
> > rspec-users mailing list
> > rspec-users at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/rspec-users
> >
>


More information about the rspec-users mailing list