David Zhang
2011-Jun-30 19:01 UTC
Testing RSpec views: the index action; is my methodology flawed?
This is my organizations_controller_spec.rb: require ''spec_helper'' describe Superadmin::OrganizationsController do describe "GET index" do it "shows a list of all organizations" do #pending "don''t know why this doesn''t work" Organization.should_receive(:all) end end end =========== This is my controllers/superadmin/organizations_controller.rb: class Superadmin::OrganizationsController < ApplicationController def index @organizations = Organization.all end end Oddly, this doesn''t pass: 1) Superadmin::OrganizationsController GET index shows a list of all organizations Failure/Error: Organization.should_receive(:all) (<Organization(id: integer, name: string, created_at: datetime, updated_at: datetime) (class)>).all(any args) expected: 1 time received: 0 times Is my methodology incorrect? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SNSqbTDWQhQJ. 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.
David Chelimsky
2011-Jun-30 19:29 UTC
Re: Testing RSpec views: the index action; is my methodology flawed?
On Jun 30, 2:01 pm, David Zhang <dzhan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> This is my organizations_controller_spec.rb: > > require ''spec_helper'' > > describe Superadmin::OrganizationsController do > describe "GET index" do > it "shows a list of all organizations" do > #pending "don''t know why this doesn''t work" > Organization.should_receive(:all)You''ve got to actually invoke the action here: get :index HTH, David> end > end > > end > > ===========> > This is my controllers/superadmin/organizations_controller.rb: > > class Superadmin::OrganizationsController < ApplicationController > def index > @organizations = Organization.all > end > end > > Oddly, this doesn''t pass: > > 1) Superadmin::OrganizationsController GET index shows a list of all > organizations > Failure/Error: Organization.should_receive(:all) > (<Organization(id: integer, name: string, created_at: datetime, > updated_at: datetime) (class)>).all(any args) > expected: 1 time > received: 0 times > > Is my methodology incorrect?-- 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.
David Zhang
2011-Jun-30 21:21 UTC
Re: Testing RSpec views: the index action; is my methodology flawed?
Oh, of course... thank you. How silly of me. Question: Do you recommend stubbing/mocking models? Or could I just specify the real model as I did here? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/-_6G3GeDCg0J. 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.