[rspec-users] response is null when using should_render_rjs

David Chelimsky dchelimsky at gmail.com
Thu Nov 30 07:19:21 EST 2006


On 11/30/06, Michael Johnston <lastobelus at mac.com> wrote:
> I'm trying to use rspec to test a controller that has ajax.
>
> I have the following action:
>
>    def change_ad_type_form
>      render :update do |page|
>        page.replace_html 'ad_sub_form', :partial => 'text'
>      end
>    end
>
> and the following spec:
>
>    specify "should return Text subform on AJAX request to
> change_ad_type_form" do
>      controller.should_render_rjs :page,
> 'ad_sub_form', :replace_html, 'stuff'
>      get 'change_ad_type_form'
>    end

Using :page in the should_render_rjs call is specifically for elements
accessed via page[:element_name]. You need to either remove :page from
your spec or change the implementation to read:

page[:ad_sub_form].replace_html :partial => 'text'

Cheers,
David
>
> which result is the following:
>
> 1)
> NoMethodError in 'When creating a new ad, the ad_controller should
> return Text subform on AJAX request to change_ad_type_form'
> nil does not respond to `rjs' or `has_rjs?'
> /Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/
> rails/render_matcher.rb:61:in `should_render_rjs'
> /Users/lasto/clients/ibc/project_n/vendor/plugins/rspec/lib/spec/
> rails/context/controller.rb:63:in `should_render_rjs'
> ./spec/controllers/ad_controller_spec.rb:75
>
> (because response is null when it gets to render_matcher)
>
> What am I doing wrong?
>
>
> Cheers,
> Michael
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>


More information about the rspec-users mailing list