Michael Johnston
2006-Nov-30 08:48 UTC
[rspec-users] response is null when using should_render_rjs
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 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
Mathias Biilmann Christensen
2006-Nov-30 10:04 UTC
[rspec-users] response is null when using should_render_rjs
And a response to my own question :) : I put this in the end of my view spec: module ViewSpecsHelper def current_user nil end end and then used render => ''controller/template'', :helper => :view_specs That worked - should be easy to use something similar to that to mock error_messages_for as well Regards, Mathias On Nov 30, 2006, at 10:37 AM, Mathias Biilmann Christensen wrote:> Thanks a lot - that helped a great deal. > > I still seem to have problems with helper methods that are not > defined in a helper module. In my Application controller I have a > current_user method and then uses " helper_method :current_user" > to be make it usable for my views. Any way to stub that method in > a view test? (I suspect a way to do this would also solve Michael > Johnston''s error_messages_for problem) > > Regards, > Mathias > > > On Nov 30, 2006, at 1:05 AM, David Chelimsky wrote: > >> On 11/29/06, Mathias Biilmann Christensen <info at mathias- >> biilmann.net> wrote: >>> Great to finally having view specs work with edge rails! >>> >>> To bad I can''t actually use them, since I use helper methods in my >>> views. Has anybody gotten calls to helper methods to work in view >>> tests under Rails 1.2 RC1? >>> >>> Currently I get "undefined method `crumbs'' for #<#<Class:0x340b70c>: >>> 0x340ab40>" when the view is calling the crumbs helper (<%= crumbs >>> (@var) %>) >>> >>> Hope there''s a solution out there! >> >> There IS!!!!! Incomplete though they are, the specs are the best >> source of documentation for questions like this. Take a look at >> vendor/plugins/rspec/spec/view_spec_spec. It has the answer to your >> question. I''ll give you the highlights, but check out the spec if >> you''re unsure of anything: >> >> context "/some/template" do >> setup do >> render ''/some/template'', :helper => :some_other #_helper will >> get appended >> end >> ... >> end >> >> OR, if you need more than one: >> >> context "/some/template" do >> setup do >> render ''/some/template'', :helpers => >> [:one, :another, :yet_another] >> end >> ... >> end >> >> Cheers, >> David >> >>> >>> Regards, >>> Mathias >>> >>> >>> On Nov 29, 2006, at 7:35 AM, David Chelimsky wrote: >>> >>>> On 11/28/06, Micah Martin <micah at 8thlight.com> wrote: >>>>> That did the trick. Thanks Pat. >>>>> >>>>> >>>>> Micah Martin >>>>> >>>>> On Nov 28, 2006, at 5:40 PM, Pat Maddox wrote: >>>>> >>>>> Basically in the mean time, just do >>>>> render :partial => "controller_name/partial_name" >>>>> >>>>> So like if the partial is named "person" and it''s under the >>>>> "people" >>>>> views dir, it''d be >>>>> render :partial => "people/person" >>>>> >>>>> That''ll work until we get it fixed in the plugin. >>>> >>>> We got it fixed in the plugin. In trunk (rev 1174). >>>> >>>> Cheers, >>>> David >>>> >>>>> >>>>> _______________________________________________ >>>>> rspec-users mailing list >>>>> rspec-users at rubyforge.org >>>>> http://rubyforge.org/mailman/listinfo/rspec-users >>>>> >>>>> >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-users at rubyforge.org >>>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-users at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >>> >> _______________________________________________ >> rspec-users mailing list >> rspec-users at rubyforge.org >> http://rubyforge.org/mailman/listinfo/rspec-users >
David Chelimsky
2006-Nov-30 12:19 UTC
[rspec-users] response is null when using should_render_rjs
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'' > endUsing :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 >
Michael Johnston
2006-Nov-30 13:07 UTC
[rspec-users] response is null when using should_render_rjs
I had tried it without :page and got the same error, and I also switched to the syntax you suggested but still get the same error. So something else is going on there. When I have time I''ll sandbox it and try to track it down. For now unfortunately I have to switch from my newly burgeoning BDD mode to my tried-and-true SSCT* mode. Thanks, Michael *show something [to the] client tomorrow On 30-Nov-06, at 4:19 AM, David Chelimsky wrote:> 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
David Chelimsky
2006-Dec-01 09:37 UTC
[rspec-users] response is null when using should_render_rjs
On 11/30/06, Mathias Biilmann Christensen <info at mathias-biilmann.net> wrote:> And a response to my own question :) : > > I put this in the end of my view spec: > > module ViewSpecsHelper > def current_user > nil > end > end > > and then used render => ''controller/template'', :helper => :view_specsCool! Nice solution. David> > That worked - should be easy to use something similar to that to mock > error_messages_for as well > > Regards, > Mathias > > > > On Nov 30, 2006, at 10:37 AM, Mathias Biilmann Christensen wrote: > > Thanks a lot - that helped a great deal. > > > > I still seem to have problems with helper methods that are not > > defined in a helper module. In my Application controller I have a > > current_user method and then uses " helper_method :current_user" > > to be make it usable for my views. Any way to stub that method in > > a view test? (I suspect a way to do this would also solve Michael > > Johnston''s error_messages_for problem) > > > > Regards, > > Mathias > > > > > > On Nov 30, 2006, at 1:05 AM, David Chelimsky wrote: > > > >> On 11/29/06, Mathias Biilmann Christensen <info at mathias- > >> biilmann.net> wrote: > >>> Great to finally having view specs work with edge rails! > >>> > >>> To bad I can''t actually use them, since I use helper methods in my > >>> views. Has anybody gotten calls to helper methods to work in view > >>> tests under Rails 1.2 RC1? > >>> > >>> Currently I get "undefined method `crumbs'' for #<#<Class:0x340b70c>: > >>> 0x340ab40>" when the view is calling the crumbs helper (<%= crumbs > >>> (@var) %>) > >>> > >>> Hope there''s a solution out there! > >> > >> There IS!!!!! Incomplete though they are, the specs are the best > >> source of documentation for questions like this. Take a look at > >> vendor/plugins/rspec/spec/view_spec_spec. It has the answer to your > >> question. I''ll give you the highlights, but check out the spec if > >> you''re unsure of anything: > >> > >> context "/some/template" do > >> setup do > >> render ''/some/template'', :helper => :some_other #_helper will > >> get appended > >> end > >> ... > >> end > >> > >> OR, if you need more than one: > >> > >> context "/some/template" do > >> setup do > >> render ''/some/template'', :helpers => > >> [:one, :another, :yet_another] > >> end > >> ... > >> end > >> > >> Cheers, > >> David > >> > >>> > >>> Regards, > >>> Mathias > >>> > >>> > >>> On Nov 29, 2006, at 7:35 AM, David Chelimsky wrote: > >>> > >>>> On 11/28/06, Micah Martin <micah at 8thlight.com> wrote: > >>>>> That did the trick. Thanks Pat. > >>>>> > >>>>> > >>>>> Micah Martin > >>>>> > >>>>> On Nov 28, 2006, at 5:40 PM, Pat Maddox wrote: > >>>>> > >>>>> Basically in the mean time, just do > >>>>> render :partial => "controller_name/partial_name" > >>>>> > >>>>> So like if the partial is named "person" and it''s under the > >>>>> "people" > >>>>> views dir, it''d be > >>>>> render :partial => "people/person" > >>>>> > >>>>> That''ll work until we get it fixed in the plugin. > >>>> > >>>> We got it fixed in the plugin. In trunk (rev 1174). > >>>> > >>>> Cheers, > >>>> David > >>>> > >>>>> > >>>>> _______________________________________________ > >>>>> rspec-users mailing list > >>>>> rspec-users at rubyforge.org > >>>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>>>> > >>>>> > >>>> _______________________________________________ > >>>> rspec-users mailing list > >>>> rspec-users at rubyforge.org > >>>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >>> _______________________________________________ > >>> rspec-users mailing list > >>> rspec-users at rubyforge.org > >>> http://rubyforge.org/mailman/listinfo/rspec-users > >>> > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-users at rubyforge.org > >> http://rubyforge.org/mailman/listinfo/rspec-users > > > > > > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users >