[rspec-users] Mocking/Stubbing help with subdomain as account key

Ryan Heneise lists at artofmission.com
Thu Oct 25 10:23:52 EDT 2007

My app uses account_location to set up subdomains as account keys. In  
my controllers, all my model operations are scoped through the  
@current_person object.

The question is: How do I test this with RSpec's mocking and  
stubbing? Basically, I need to test that @current_person.things is  
getting the find message and returning @thing. I've tried stubbing  
and mocking @current_person.things a number of different ways with no  
luck. Here's my latest attempt:

# things_controller_spec.rb
before do
   @request.host = "subdomain.test.host"
   @thing = mock_model(Thing)
   @current_person = mock("person")      # <= THE MOCKS IN QUESTION

def do_get
   get :show, :id => "1"

it "should find the donation requested" do
   # Thing.should_receive(:find).with("1").and_return(@thing)

# things_controller.rb
def index
   @things = @current_person.things

def show
   @thing = @current_person.things.find(params[:id])

Thanks for your help.

P.S. Sorry if this is answered elsewhere - I did a lot of googling  
and finally decided to ask the group!

More information about the rspec-users mailing list