[rspec-users] would I stub an existing class method out or use fixtures in this scenario?

Mark Wilden mark at mwilden.com
Mon Oct 6 13:50:46 EDT 2008

On Sun, Oct 5, 2008 at 9:26 PM, Greg Hauptmann <
greg.hauptmann.ruby at gmail.com> wrote:

> So overall I'm pondering how to test my "populate_projections" method
> in a manner that minimises the amount of dynamically generated
> fixtures I have to create (currently I create recurring items &
> bank_accounts), and also the reliance on the BankAccount.balance?
> method (and it's correct operation).  My specific question was about
> how to stub out the already existing BankAccount.balance? method using
> "any_instance.stubs".

In general, I do something like

bank_account = mock_model(BankAccount, :balance => 12)
BankAccount.stub!(:find).with(bank_account.id).and_return bank_account

Is that what you're talking about? As opposed to

bank_account = BankAcount.create!
Transaction.create!(:back_account_id => bank_account.id, :amount => 12)

Are you asking which one is better, or am I totally off on the wrong track?
:) Otherwise, I'd pick the first approach, because it's faster.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081006/06bead3b/attachment.html>

More information about the rspec-users mailing list