Hi, I have an error of undefined method. can anyone help me to solve it. I follow the tutorial to practicing testing controller of rails, and now i got stuck with the error.. plz help error: undefined method `post'' for #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> undefined method `assigns'' for #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> Test file describe "GET Index" do def mock_product(stubs={}) @mock_user ||= mock_model(User, stubs).as_null_object end def setup @user = User.new end it "assigns all users as @users" do @user.stub(:all){[mock_user]} post ''index'' assigns(:users).should eq([mock_user]) end end please give me some help .. thanks Yennie -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 6, 3:19 pm, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have an error of undefined method. > can anyone help me to solve it. > I follow the tutorial to practicing testing controller of rails, and > now i got stuck with the error.. plz help > > error: > undefined method `post'' for > #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> > undefined method `assigns'' for > #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> > > Test file > > describe "GET Index" do > def mock_product(stubs={}) > @mock_user ||= mock_model(User, stubs).as_null_object > end > > def setup > @user = User.new > end > > it "assigns all users as @users" do > @user.stub(:all){[mock_user]} > post ''index''I change it as get ''index'' it still gives me undefined method> assigns(:users).should eq([mock_user]) > end > end > > please give me some help .. > > thanks > Yennie-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 6, 8:19 pm, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > I have an error of undefined method. > can anyone help me to solve it. > I follow the tutorial to practicing testing controller of rails, and > now i got stuck with the error.. plz help >rspec probably doesn''t understand that you''re testing a controller. if your spec file looks like require ''spec_helper'' describe SomeController do ... end then it should detect that you''re speccing a controller Fred> error: > undefined method `post'' for > #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> > undefined method `assigns'' for > #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> > > Test file > > describe "GET Index" do > def mock_product(stubs={}) > @mock_user ||= mock_model(User, stubs).as_null_object > end > > def setup > @user = User.new > end > > it "assigns all users as @users" do > @user.stub(:all){[mock_user]} > post ''index'' > assigns(:users).should eq([mock_user]) > end > end > > please give me some help .. > > thanks > Yennie-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 6, 3:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 6, 8:19 pm, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I have an error of undefined method. > > can anyone help me to solve it. > > I follow the tutorial to practicing testing controller of rails, and > > now i got stuck with the error.. plz help > > rspec probably doesn''t understand that you''re testing a controller. > > if your spec file looks like > > require ''spec_helper'' > > describe SomeController do > ... > endI did like that require ''spec_helper'' describe "UserController" do describe "GET index" do it "should be successful" do get ''index'' response.should be_success end it "render the index template" do get :index response.should render_template(''index'') end it "assigns all users as @users" do u = Factory(:user) get :index assigns[:users].should == [p] end end end it gives the the require error. However. I have a spec_helper.rb in the spec dicrectory.. kind of confusing plz help me> > then it should detect that you''re speccing a controller > Fred > > > > > > > > > error: > > undefined method `post'' for > > #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> > > undefined method `assigns'' for > > #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> > > > Test file > > > describe "GET Index" do > > def mock_product(stubs={}) > > @mock_user ||= mock_model(User, stubs).as_null_object > > end > > > def setup > > @user = User.new > > end > > > it "assigns all users as @users" do > > @user.stub(:all){[mock_user]} > > post ''index'' > > assigns(:users).should eq([mock_user]) > > end > > end > > > please give me some help .. > > > thanks > > Yennie-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 6, 3:34 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jul 6, 8:19 pm, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi, > > > I have an error of undefined method. > > can anyone help me to solve it. > > I follow the tutorial to practicing testing controller of rails, and > > now i got stuck with the error.. plz help > > rspec probably doesn''t understand that you''re testing a controller. > > if your spec file looks like > > require ''spec_helper'' > > describe SomeController do > ... > endI did like that require ''spec_helper'' describe "UserController" do describe "GET index" do it "should be successful" do get ''index'' response.should be_success end it "render the index template" do get :index response.should render_template(''index'') end it "assigns all users as @users" do u = Factory(:user) get :index assigns[:users].should == [p] end end end but i gives me error of require (first line), However I have spec_helper.rb in spec directory plzz help> > then it should detect that you''re speccing a controller > Fred > > > > > > > > > error: > > undefined method `post'' for > > #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> > > undefined method `assigns'' for > > #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> > > > Test file > > > describe "GET Index" do > > def mock_product(stubs={}) > > @mock_user ||= mock_model(User, stubs).as_null_object > > end > > > def setup > > @user = User.new > > end > > > it "assigns all users as @users" do > > @user.stub(:all){[mock_user]} > > post ''index'' > > assigns(:users).should eq([mock_user]) > > end > > end > > > please give me some help .. > > > thanks > > Yennie-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Jul 6, 9:18 pm, Yennie <joanne0...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I did like that > > require ''spec_helper'' > > describe "UserController" do > describe "GET index" do > it "should be successful" do > get ''index'' > response.should be_success > end > > it "render the index template" do > get :index > response.should render_template(''index'') > end > > it "assigns all users as @users" do > u = Factory(:user) > get :index > assigns[:users].should == [p] > end > > end > end > > but i gives me error of require (first line), However I have > spec_helper.rb in spec directoryHow are you running the spec ? either the rake task or running rspec spec/.../my_spec.rb should setup the load path correctly for you Fred> > plzz help > > > > > > > then it should detect that you''re speccing a controller > > Fred > > > > error: > > > undefined method `post'' for > > > #<Spec::Example::ExampleGroup::Subclass_1:0xb7754114> > > > undefined method `assigns'' for > > > #<Spec::Example::ExampleGroup::Subclass_1:0xb785d1b4> > > > > Test file > > > > describe "GET Index" do > > > def mock_product(stubs={}) > > > @mock_user ||= mock_model(User, stubs).as_null_object > > > end > > > > def setup > > > @user = User.new > > > end > > > > it "assigns all users as @users" do > > > @user.stub(:all){[mock_user]} > > > post ''index'' > > > assigns(:users).should eq([mock_user]) > > > end > > > end > > > > please give me some help .. > > > > thanks > > > Yennie-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.