Forum: Radiant CMS stubbing objects in Radiant

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
0218fde3a78fadbadb566bdb40d7b0dd?d=identicon&s=25 Barry Hess (Guest)
on 2007-07-18 15:33
(Received via mailing list)
Hi,

Currently I'm writing some tests for a front end shopping cart extension
I
wrote for a client.  Of course, for the functional testing I'd like to
stub
out some models to verify proper methods are being called by my
controller.
Unfortunately this doesn't appear to be "just working" under the
extension
model like it does in Rails.

In fact, it doesn't appear that my stub objects in
extension/test/mocks/test/ are even being loaded.  I realize it may be
that
the load path in a Radiant environment does not even bother looking for
stubs first.

Is anyone aware of a way to stub models in Radiant extension testing?
Is
anyone aware of the load path ordering in Radiant?

Any help or insight is appreciated!
--
Barry Hess
barry@bjhess.com
http://www.bjhess.com
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-07-18 15:42
(Received via mailing list)
I don't believe test/mocks/test is included in the load path, as we've
never had anyone using mocks in extensions yet. In
extension/test/test_helper.rb, you should probably require them
specifically, or in the individual tests. If there is a canonical way
(i.e. the Rails way) that they are loaded, any info about that would be
appreciated.

Honestly, I've fallen in love with RSpec lately and appreciate the power
of mocks and stubs... good call.

Sean
Bdf2290f0b1d87cb0853966e7e51606b?d=identicon&s=25 Andrew O'Brien (Guest)
on 2007-07-18 15:50
(Received via mailing list)
I've been using Mocha in my extensions for a little while now.  All I do
is
require 'rubygems' (unnecessary I know, but it's habit) and 'mocha'.
I guess RSpec is getting closer to stable, so maybe it's time for a
second
look.


-Andrew
0218fde3a78fadbadb566bdb40d7b0dd?d=identicon&s=25 Barry Hess (Guest)
on 2007-07-18 21:24
(Received via mailing list)
Thanks for the hints, Sean.

In extensions/shopping_cart/test/test_helper.rb I required the stub/mock
model object:

  require File.dirname(__FILE__) + "/mocks/test/order_mailer"

In extensions/shopping_cart/test/mocks/test/order_mailer.rb I required
the
original model object:

  require File.dirname(__FILE__) + '/../../../app/models/order_mailer'

I imagine there's a way to require all stub files in the mocks/test
directory.  Unfortunately I'm not rockstar enough to know how off the
top of
my head.

(Andrew, I decided against Mocha simply because I haven't used it
before,
nor has the contracting group I'm working with.  I just didn't want to
add
another moving piece.  I definitely will look into it in the future,
though.)

~Barry


On 7/18/07, Sean Cribbs <seancribbs@gmail.com> wrote:
>
> controller.
> > Is anyone aware of a way to stub models in Radiant extension
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>



--
Barry Hess
barry@bjhess.com
http://www.bjhess.com
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (Guest)
on 2007-07-18 21:28
(Received via mailing list)
Barry Hess wrote:
> Thanks for the hints, Sean.
>
> In extensions/shopping_cart/test/test_helper.rb I required the stub/mock
> model object:
>
>   require File.dirname(__FILE__) + "/mocks/test/order_mailer"
>
Dir-glob to the rescue! Try this:

Dir[File.dirname(__FILE__) + "/mocks/test/*.rb].each do |file|
  require file
end

That will load all of your mocks in the test helper.

Sean
0218fde3a78fadbadb566bdb40d7b0dd?d=identicon&s=25 Barry Hess (Guest)
on 2007-07-18 21:37
(Received via mailing list)
Thanks, Sean.

Another note.  If you have any unit tests relating to the model that's
been
stubbed, you'll need to explicitly require the real model.  Something
like:

  require File.dirname(__FILE__) + '/../../app/models/order_mailer'


~Barry



On 7/18/07, Sean Cribbs <seancribbs@gmail.com> wrote:
>
> Search: http://radiantcms.org/mailing-list/search/
> Site:   http://lists.radiantcms.org/mailman/listinfo/radiant
>



--
Barry Hess
barry@bjhess.com
http://www.bjhess.com
This topic is locked and can not be replied to.