[rspec-users] Using mocks in classes

Guff gareth.howell at gmail.com
Mon Oct 8 10:37:32 EDT 2007


I am mocking a rails model that hasn't been implemented and belongs_to a
model that I am developing with rspec.
The model in development, Audit, has_many AuditItems which is being mocked.
When created, Audit creates the first instance of AuditItem.
To enable me to mock AuditItem I have created a factory method in Audit to
create the AuditItem, rather than  creating it in the initialize method;
that way I can defined a new class MockAudit and overide the
create_audit_item method.

It looks like
class MockAudit < Audit
def initialize
@auditItem[0] = mockAuditItem
end

The question is, where do I define mockAuditItem. If it inside the describe
block, MockAudit cannot see it. If I define mockAuditItem =
mock("AuditItem") inside the def for MockAudit then mock isn't defined.
Should I just mixin the Mock class?

Guff
-- 
View this message in context: http://www.nabble.com/Using-mocks-in-classes-tf4588595.html#a13097948
Sent from the rspec-users mailing list archive at Nabble.com.



More information about the rspec-users mailing list