I''m using datamapper and have two associated classes: - Org - has n, :users - User - belongs_to :org When I test the User object, I have been able to mock/stub methods of the Org object. Great! But - I still need to require ''org.rb'' to setup my user tests - otherwise Datamapper will complain: "Cannot find the parent_model Org for User in org (NameError)" Sure I can require the associated object in my test setup, but would love to avoid having to do this, as it increases complexity as the number of associated classes grows. Is there a way to mock the Org object, without having to require it in my test setup ??
David Chelimsky
2009-Nov-13 23:38 UTC
[rspec-users] Using Mock / Datamapper / Associations
On Fri, Nov 13, 2009 at 10:04 AM, Arco <akleak at gmail.com> wrote:> I''m using datamapper and have two associated classes: > - Org - has n, :users > - User - belongs_to :org > > When I test the User object, I have been able to mock/stub methods of > the Org object. Great! > > But - I still need to require ''org.rb'' to setup my user tests - > otherwise Datamapper will complain: "Cannot find the parent_model Org > for User in org (NameError)" > > Sure I can require the associated object in my test setup, but would > love to avoid having to do this, as it increases complexity as the > number of associated classes grows. > > Is there a way to mock the Org object, without having to require it in > my test setup ?? >I don''t know much about Datamapper, but if you''re referencing an Org object then it seems reasonable to me that you''d have to require that file. Why it''s not autoloaded I have no idea - have you tried a Datamapper list or IRC channel? -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20091113/e2f1c46f/attachment.html>
On Nov 13, 2009, at 6:04 pm, Arco wrote:> Is there a way to mock the Org object, without having to require it in > my test setup ??Hi Arco Are you running the spec through something that loads a code loader (eg: for my specs, spec_helper.rb starts Merb in the test environment), or just running that one file on its own? That''s the simplest way I can think this would be failing. Ashley -- http://www.patchspace.co.uk/ http://www.linkedin.com/in/ashleymoran