Created
September 20, 2011 23:22
-
-
Save zealoushacker/1230723 to your computer and use it in GitHub Desktop.
Model mocks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # a typical controller spec | |
| require 'spec_helper' | |
| describe PaymentsController do | |
| # A typical model mock object (with memoization ftw): | |
| def mock_customer_user(stubs={}) | |
| @mock_customer_user ||= mock_model(CustomerUser, stubs).as_null_object | |
| end | |
| describe "when passed a customer user id" do | |
| before(:each) do | |
| # Here we go, having our find method return a mock_customer_user | |
| CustomerUser.stub(:find) {mock_customer_user} | |
| get :new, :customer_user_id => 7 | |
| end | |
| end | |
| it "should be successful" do | |
| response.should be_success | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment