Testing RSpec views: the index action; is my methodology flawed?

10 προβολές
Παράβλεψη και μετάβαση στο πρώτο μη αναγνωσμένο μήνυμα

David Zhang

μη αναγνωσμένη,
30 Ιουν 2011, 3:01:14 μ.μ.30/6/11
ως rubyonra...@googlegroups.com
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?

David Chelimsky

μη αναγνωσμένη,
30 Ιουν 2011, 3:29:10 μ.μ.30/6/11
ως Ruby on Rails: Talk


On Jun 30, 2:01 pm, David Zhang <dzhan...@gmail.com> 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

David Zhang

μη αναγνωσμένη,
30 Ιουν 2011, 5:21:13 μ.μ.30/6/11
ως rubyonra...@googlegroups.com
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?
Απάντηση σε όλους
Απάντηση στον συντάκτη
Προώθηση
0 νέα μηνύματα