[rspec-users] would I stub an existing class method out or use fixtures in this scenario?
greg.hauptmann.ruby at gmail.com
Mon Oct 6 00:26:06 EDT 2008
I'll try to put some clarifying comments here re my question:
(a) "any_instance.stubs" - this already exists in Mocha
(b) where I had "do people normal use the "any_instance.stubs"
approach to stub out existing classes already developed" - this should
have read for "an existing method in an existing class". In my case
I had a method in the BankAccount model which requires "bankaccounts"
table rows to be populated, so I was asking re stubbing this out.
(c) as a quick overview of the key elements of my question, I have:
* "recurrings" table - has details of recurring items (e.g. food,
$200, every week). Has foreign key to BankAccount re where the expense
is likely to turn up against.
* "transactions" table - has actual plus future projected
transactions. Has BankAccount foreign key.
* "bank_accounts" table - ID and name for each bank account
* BankAccount model - Has method "balance?(date=Today.now.to_date)
which gets balance for that bank account for that date (by looking at
the transactions table)
* "populate_projections" method - this is what I want to test. It basically:
- reads input from "recurrings" table
- creates "transactions" table rows
- during the process calls BankAccount.balance? method
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 feedback welcome on what the best practice would be here.
More information about the rspec-users