David Chelimsky
2010-Jun-11 07:08 UTC
[rspec-users] undefined local variable or method `assigns''
On Thu, Jun 10, 2010 at 4:41 PM, <jfrankov at gmail.com> wrote:> I might be missing something basic here, but I''m stumped on this > error: > > model code: > > class CachedStat < ActiveRecord::Base > ? ?def self.create_stats_days_ago(days_ago, human_id) > ? ?d = Date.today - days_ago.day > ? ?@prs = PageRequest.find(:all, :conditions => [ "owner_type > ''Human'' and owner_id = ? and created_at = ?", human_id, d] ) > ?end > end > > > spec code: > > ?it "should create stats for the specified number of days in the > past" do > ? ?CachedStat.create_stats_days_ago(1, Human.first.id) > ? ?assigns[:prs].should eql("foo") > ?end > > > The error is: undefined local variable or method `assigns'' for > #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> > > > I feel like I''m overlooking something obvious but it''s invisible to > me. Any suggestions?assigns is for controller and view specs, not model specs. What is it you''re trying to specify here?
Kristian Mandrup
2010-Jun-13 10:49 UTC
[rspec-users] undefined local variable or method `assigns''
assigns(:message).should eq(@message) assign(:message, stub("Message", :text => "Hello world!")) Hmm, so ''assign'' to assign a variable and ''assigns'' to read an assigned variable? We need to update the RSpec 2 wiki or somewhere with all these API changes so it is clear to everyone. On Jun 11, 9:08?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Thu, Jun 10, 2010 at 4:41 PM, <jfran... at gmail.com> wrote: > > I might be missing something basic here, but I''m stumped on this > > error: > > > model code: > > > class CachedStat < ActiveRecord::Base > > ? ?def self.create_stats_days_ago(days_ago, human_id) > > ? ?d = Date.today - days_ago.day > > ? ?@prs = PageRequest.find(:all, :conditions => [ "owner_type > > ''Human'' and owner_id = ? and created_at = ?", human_id, d] ) > > ?end > > end > > > spec code: > > > ?it "should create stats for the specified number of days in the > > past" do > > ? ?CachedStat.create_stats_days_ago(1, Human.first.id) > > ? ?assigns[:prs].should eql("foo") > > ?end > > > The error is: undefined local variable or method `assigns'' for > > #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> > > > I feel like I''m overlooking something obvious but it''s invisible to > > me. Any suggestions? > > assigns is for controller and view specs, not model specs. What is it > you''re trying to specify here? > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2010-Jun-13 13:29 UTC
[rspec-users] undefined local variable or method `assigns''
On Jun 13, 2010, at 6:49 AM, Kristian Mandrup wrote:> assigns(:message).should eq(@message) > > assign(:message, stub("Message", :text => "Hello world!")) > > Hmm, so ''assign'' to assign a variable and ''assigns'' to read an > assigned variable? > We need to update the RSpec 2 wiki or somewhere with all these API > changes so it is clear to everyone.There''s already info about assign(key, val) on the rspec-rails readme: http://github.com/rspec/rspec-rails. I''ll add something about assigns(:key) as well. Keep in mind that assign(k,v) is used in view specs to provide data to the view, whereas assigns(key) is used in controller specs to express expectations about what the controller does. As for the wiki, let''s hold off on that for now. There is currently insufficient documentation in too many places, and the wiki has, at times, caused more confusion than benefit. I''ve got a few thoughts rolling around about how to best address this, and I''ll follow up on that in a separate thread in the next couple of days. Cheers, David> On Jun 11, 9:08 am, David Chelimsky <dchelim... at gmail.com> wrote: >> On Thu, Jun 10, 2010 at 4:41 PM, <jfran... at gmail.com> wrote: >>> I might be missing something basic here, but I''m stumped on this >>> error: >> >>> model code: >> >>> class CachedStat < ActiveRecord::Base >>> def self.create_stats_days_ago(days_ago, human_id) >>> d = Date.today - days_ago.day >>> @prs = PageRequest.find(:all, :conditions => [ "owner_type >>> ''Human'' and owner_id = ? and created_at = ?", human_id, d] ) >>> end >>> end >> >>> spec code: >> >>> it "should create stats for the specified number of days in the >>> past" do >>> CachedStat.create_stats_days_ago(1, Human.first.id) >>> assigns[:prs].should eql("foo") >>> end >> >>> The error is: undefined local variable or method `assigns'' for >>> #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> >> >>> I feel like I''m overlooking something obvious but it''s invisible to >>> me. Any suggestions? >> >> assigns is for controller and view specs, not model specs. What is it >> you''re trying to specify here? >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Kristian Mandrup
2010-Jun-13 20:35 UTC
[rspec-users] undefined local variable or method `assigns''
Hi David, Sounds great! Looking forward to more documentation :) I have now gone through all the examples in the RSpec book and got them working with the latest version of RSpec 2 and Rails 3 beta4. I only have one loose end: shared_examples_for "a template that renders the messages/form partial" do it "renders the messages/form partial" do template.should_receive(:render).with( :partial => "form", :locals => { :message => assigns[:message] } ) render end end undefined local variable or method `template'' for #<RSpec::Core::ExampleGroup::Nested_8:0x00000100e019a0> Changing template to _view as you instructed previously (I think) _view.should_receive(:render).with( :partial => "form", :locals => { :message => assigns[:message] } ) #<ActionView::Base:0x00000100e98c88> received :render with unexpected arguments expected: ({:partial=>"form", :locals=>{:message=>nil}}) got: ({:template=>"messages/edit.html.erb"}, {}) But this is my edit.html <%= render "form", :message => @message %> So _view only contains info on the view. How do I get info on the templates called as part of the rendering process? On Jun 13, 3:29?pm, David Chelimsky <dchelim... at gmail.com> wrote:> On Jun 13, 2010, at 6:49 AM, Kristian Mandrup wrote: > > > assigns(:message).should eq(@message) > > > assign(:message, stub("Message", :text => "Hello world!")) > > > Hmm, so ''assign'' to assign a variable and ''assigns'' to read an > > assigned variable? > > We need to update the RSpec 2 wiki or somewhere with all these API > > changes so it is clear to everyone. > > There''s already info about assign(key, val) on the rspec-rails readme:http://github.com/rspec/rspec-rails. I''ll add something about assigns(:key) as well. > > Keep in mind that assign(k,v) is used in view specs to provide data to the view, whereas assigns(key) is used in controller specs to express expectations about what the controller does. > > As for the wiki, let''s hold off on that for now. There is currently insufficient ?documentation in too many places, and the wiki has, at times, caused more confusion than benefit. I''ve got a few thoughts rolling around about how to best address this, and I''ll follow up on that in a separate thread in the next couple of days. > > Cheers, > David > > > > > On Jun 11, 9:08 am, David Chelimsky <dchelim... at gmail.com> wrote: > >> On Thu, Jun 10, 2010 at 4:41 PM, <jfran... at gmail.com> wrote: > >>> I might be missing something basic here, but I''m stumped on this > >>> error: > > >>> model code: > > >>> class CachedStat < ActiveRecord::Base > >>> ? ?def self.create_stats_days_ago(days_ago, human_id) > >>> ? ?d = Date.today - days_ago.day > >>> ? ?@prs = PageRequest.find(:all, :conditions => [ "owner_type > >>> ''Human'' and owner_id = ? and created_at = ?", human_id, d] ) > >>> ?end > >>> end > > >>> spec code: > > >>> ?it "should create stats for the specified number of days in the > >>> past" do > >>> ? ?CachedStat.create_stats_days_ago(1, Human.first.id) > >>> ? ?assigns[:prs].should eql("foo") > >>> ?end > > >>> The error is: undefined local variable or method `assigns'' for > >>> #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> > > >>> I feel like I''m overlooking something obvious but it''s invisible to > >>> me. Any suggestions? > > >> assigns is for controller and view specs, not model specs. What is it > >> you''re trying to specify here? > >> _______________________________________________ > >> rspec-users mailing list > >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > > rspec-users mailing list > > rspec-us... at rubyforge.org > >http://rubyforge.org/mailman/listinfo/rspec-users > > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users
David Chelimsky
2010-Jun-13 20:48 UTC
[rspec-users] undefined local variable or method `assigns''
On Jun 13, 2010, at 4:35 PM, Kristian Mandrup wrote:> Hi David, > > Sounds great! Looking forward to more documentation :) > I have now gone through all the examples in the RSpec book and got > them working with the latest version of RSpec 2 and Rails 3 beta4. > I only have one loose end: > > shared_examples_for "a template that renders the messages/form > partial" do > it "renders the messages/form partial" do > template.should_receive(:render).with( > :partial => "form", > :locals => { :message => assigns[:message] } > ) > render > end > end > > undefined local variable or method `template'' for > #<RSpec::Core::ExampleGroup::Nested_8:0x00000100e019a0> > > Changing template to _view as you instructed previously (I think) > > _view.should_receive(:render).with( > :partial => "form", > :locals => { :message => assigns[:message] } > ) > > #<ActionView::Base:0x00000100e98c88> received :render with unexpected > arguments > expected: ({:partial=>"form", :locals=>{:message=>nil}}) > got: ({:template=>"messages/edit.html.erb"}, {}) > > But this is my edit.html > > <%= render "form", :message => @message %> > > So _view only contains info on the view. How do I get info on the > templates called as part of the rendering process?See the bit on View Specs on http://github.com/rspec/rspec-rails/blob/master/Upgrade.markdown> > > On Jun 13, 3:29 pm, David Chelimsky <dchelim... at gmail.com> wrote: >> On Jun 13, 2010, at 6:49 AM, Kristian Mandrup wrote: >> >>> assigns(:message).should eq(@message) >> >>> assign(:message, stub("Message", :text => "Hello world!")) >> >>> Hmm, so ''assign'' to assign a variable and ''assigns'' to read an >>> assigned variable? >>> We need to update the RSpec 2 wiki or somewhere with all these API >>> changes so it is clear to everyone. >> >> There''s already info about assign(key, val) on the rspec-rails readme:http://github.com/rspec/rspec-rails. I''ll add something about assigns(:key) as well. >> >> Keep in mind that assign(k,v) is used in view specs to provide data to the view, whereas assigns(key) is used in controller specs to express expectations about what the controller does. >> >> As for the wiki, let''s hold off on that for now. There is currently insufficient documentation in too many places, and the wiki has, at times, caused more confusion than benefit. I''ve got a few thoughts rolling around about how to best address this, and I''ll follow up on that in a separate thread in the next couple of days. >> >> Cheers, >> David >> >> >> >>> On Jun 11, 9:08 am, David Chelimsky <dchelim... at gmail.com> wrote: >>>> On Thu, Jun 10, 2010 at 4:41 PM, <jfran... at gmail.com> wrote: >>>>> I might be missing something basic here, but I''m stumped on this >>>>> error: >> >>>>> model code: >> >>>>> class CachedStat < ActiveRecord::Base >>>>> def self.create_stats_days_ago(days_ago, human_id) >>>>> d = Date.today - days_ago.day >>>>> @prs = PageRequest.find(:all, :conditions => [ "owner_type >>>>> ''Human'' and owner_id = ? and created_at = ?", human_id, d] ) >>>>> end >>>>> end >> >>>>> spec code: >> >>>>> it "should create stats for the specified number of days in the >>>>> past" do >>>>> CachedStat.create_stats_days_ago(1, Human.first.id) >>>>> assigns[:prs].should eql("foo") >>>>> end >> >>>>> The error is: undefined local variable or method `assigns'' for >>>>> #<Spec::Rails::Example::ModelExampleGroup::Subclass_1:0x2fbac28> >> >>>>> I feel like I''m overlooking something obvious but it''s invisible to >>>>> me. Any suggestions? >> >>>> assigns is for controller and view specs, not model specs. What is it >>>> you''re trying to specify here? >>>> _______________________________________________ >>>> rspec-users mailing list >>>> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users >>> _______________________________________________ >>> rspec-users mailing list >>> rspec-us... at rubyforge.org >>> http://rubyforge.org/mailman/listinfo/rspec-users >> >> _______________________________________________ >> rspec-users mailing list >> rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ > rspec-users mailing list > rspec-users at rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users
Kristian Mandrup
2010-Jun-13 22:16 UTC
[rspec-users] undefined local variable or method `assigns''
Thanks! Just what I needed :)
Kristian Mandrup
2010-Jun-13 22:32 UTC
[rspec-users] undefined local variable or method `assigns''
shared_examples_for "a template that renders the messages/form partial" do it "renders the messages/form partial" do view.should_receive(:_render_partial). with(hash_including(:partial => "form")) render end end # new.html.erb <%= render "sidebar", :recent_messages => @recent_messages %> <%= render "form", :message => @message %> 7) messages/new.html.erb renders the messages/form partial Failure/Error: Unable to find matching line from backtrace #<ActionView::Base:0x000001014fbc88> received :_render_partial with unexpected arguments expected: (hash_including(:partial=>"form")) got: ({:partial=>"sidebar", :locals=>{:recent_messages=>[]}}) So what to do if I call multiple partials from my view?
David Chelimsky
2010-Jun-14 00:30 UTC
[rspec-users] undefined local variable or method `assigns''
On Jun 13, 2010, at 5:32 PM, Kristian Mandrup <kmandrup at gmail.com> wrote:> shared_examples_for "a template that renders the messages/form > partial" do > it "renders the messages/form partial" do > view.should_receive(:_render_partial). > with(hash_including(:partial => "form")) > render > end > end > > # new.html.erb > > <%= render "sidebar", :recent_messages => @recent_messages %> > <%= render "form", :message => @message %> > > 7) messages/new.html.erb renders the messages/form partial > Failure/Error: Unable to find matching line from backtrace > #<ActionView::Base:0x000001014fbc88> received :_render_partial > with unexpected arguments > expected: (hash_including(:partial=>"form")) > got: > ({:partial=>"sidebar", :locals=>{:recent_messages=>[]}}) > > So what to do if I call multiple partials from my view?view.stub(:_render_partial) before view.should_receive(:_render_partial)
Kristian Mandrup
2010-Jun-15 05:17 UTC
[rspec-users] undefined local variable or method `assigns''
Thanks again David :) Pure magic to me, I don''t really understand how/ why that makes it work. But it does! On Jun 14, 2:30?am, David Chelimsky <dchelim... at gmail.com> wrote:> On Jun 13, 2010, at 5:32 PM, Kristian Mandrup <kmand... at gmail.com> ? > wrote: > > > > > shared_examples_for "a template that renders the messages/form > > partial" do > > ?it "renders the messages/form partial" do > > ? ?view.should_receive(:_render_partial). > > ? ? ?with(hash_including(:partial => "form")) > > ? ?render > > ?end > > end > > > # new.html.erb > > > <%= render "sidebar", :recent_messages => @recent_messages %> > > <%= render "form", :message => @message %> > > > 7) messages/new.html.erb renders the messages/form partial > > ? ?Failure/Error: Unable to find matching line from backtrace > > ? ?#<ActionView::Base:0x000001014fbc88> received :_render_partial > > with unexpected arguments > > ? ? ?expected: (hash_including(:partial=>"form")) > > ? ? ? ? ? got: > > ({:partial=>"sidebar", :locals=>{:recent_messages=>[]}}) > > > So what to do if I call multiple partials from my view? > > view.stub(:_render_partial) before view.should_receive(:_render_partial) > _______________________________________________ > rspec-users mailing list > rspec-us... at rubyforge.orghttp://rubyforge.org/mailman/listinfo/rspec-users