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

David Chelimsky dchelimsky at gmail.com
Fri Jun 22 10:54:44 EDT 2007

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_calendar_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?

More information about the rspec-users mailing list