[rspec-users] Just a quick question on David's new-controller-examples

Shane Mingins smingins at elctech.com
Wed Oct 15 13:58:40 EDT 2008

Hi Mark

Yeah I was looking at that later on too.  And yes if you use in a  
'before' it does.  Only setting in an 'it' block is ok.

I was using this as a quick test as we are on an older version of  
rspec and I was checking if it may have changed but this fails on 1.1.8

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe PersonController do

   def mock_person(stubs={})
     @person ||= mock_model(Person, stubs)

   describe "GET" do

     before(:each) do
       mock_person(:name => "fred")

     it "should have name fred" do
       @person.name.should == "fred"

     it "should have name steve" do
       mock_person(:name => "steve")
       @person.name.should == "steve"


   describe "POST" do

     it "should have name steve" do
       mock_person(:name => "steve")
       @person.name.should == "steve"

     it "should have name bob" do
       mock_person(:name => "bob")
       @person.name.should == "bob"



'PersonController GET should have name steve' FAILED
expected: "steve",
      got: "fred" (using ==)

Finished in 0.295898 seconds

6 examples, 1 failure

On 16/10/2008, at 6:26 AM, Mark Wilden wrote:

> I have a different question about the article (pity comments are  
> closed).
> def mock_account(stubs={})
>     stubs = {
>       :save => true,
>       :update_attributes => true,
>       :destroy => true,
>       :to_xml => ''
>     }.merge(stubs)
>     @mock_account ||= mock_model(Account, stubs)
>   end
> With this helper, doesn't @mock_account only get set once inside its  
> 'describe' block? Any future tests would use the same @mock_account,  
> even if other stubs were designated.
> I'm probably missing something very obvious.
> ///ark
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

Shane Mingins
ELC Technologies (TM)
1921 State Street
Santa Barbara, CA 93101

Phone: +64 4 568 6684
Mobile: +64 21 435 586
Email:  smingins at elctech.com
AIM:     ShaneMingins
Skype: shane.mingins

(866) 863-7365 Tel - Santa Barbara Office
(866) 893-1902 Fax - Santa Barbara Office

+44 020 7504 1346 Tel - London Office
+44 020 7504 1347 Fax - London Office


Privacy and Confidentiality Notice:
The information contained in this electronic mail message is intended  
for the named recipient(s) only. It may contain privileged and  
confidential information. If you are not an intended recipient, you  
must not copy, forward, distribute or take any action in reliance on  
it. If you have received this electronic mail message in

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4000 bytes
Desc: not available
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081016/3fce215d/attachment.bin>

More information about the rspec-users mailing list