[rspec-users] When to send "post" and "get" in blocks.

Mike Schiller mike.sch.list at gmail.com
Fri Jun 6 23:46:58 EDT 2008


Hi,
I'm new to RSpec. I have a question about how to write controller specs.

Here's a code generated by scaffolding (with Rspec).

    def do_get
      get :index
    end

    it "should be successful" do
      do_get
      response.should be_success
    end

    it "should render index template" do
      do_get
      response.should render_template('index')
    end

    it "should find all books" do
      Book.should_receive(:find).with(:all).and_return([@book])
      do_get
    end

    it "should assign the found books for the view" do
      do_get
      assigns[:books].should == [@book]
    end
  end

###################

What I don't understand is that, sometimes, "get" is done before an
expectation(i.e., a line that contains "should"), but other times, the order
is the opposite.

In the third spec above, the sentence that has "should" comes first and
do_get later. In my view, "get :index" needs to be done first to trigger
"index" action. And the "index" action should trigger
"Book.should_receive(:find).....". I'm a bit confused about all of this.

Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20080607/f9da2fb7/attachment.html>


More information about the rspec-users mailing list