Using Mocha to mock an object

Discussion in 'Ruby' started by Joe Van Dyk, Oct 20, 2006.

  1. Joe Van Dyk

    Joe Van Dyk Guest

    Hi,

    I have:
    class Order
    def self.export_unshipped_orders
    # returns a string
    end
    end

    I want to use Mocha (http://mocha.rubyforge.org/) to fake the return
    of Order.export_unshipped_orders. How can I do that?

    Thanks,
    Joe
    Joe Van Dyk, Oct 20, 2006
    #1
    1. Advertising

  2. Joe Van Dyk

    Joe Van Dyk Guest

    On 10/20/06, Joe Van Dyk <> wrote:
    > Hi,
    >
    > I have:
    > class Order
    > def self.export_unshipped_orders
    > # returns a string
    > end
    > end
    >
    > I want to use Mocha (http://mocha.rubyforge.org/) to fake the return
    > of Order.export_unshipped_orders. How can I do that?


    Got it:

    Order.stubs:)export_unshipped_orders).returns("what's going on?")

    Easy enough!
    Joe Van Dyk, Oct 21, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    13,435
  2. James Mead
    Replies:
    0
    Views:
    99
    James Mead
    Jul 19, 2006
  3. J. B. Rainsberger

    Mocha and ActiveRecord

    J. B. Rainsberger, Nov 28, 2006, in forum: Ruby
    Replies:
    1
    Views:
    127
    J. B. Rainsberger
    Dec 2, 2006
  4. Raymond O'Connor
    Replies:
    1
    Views:
    137
    Raymond O'Connor
    Mar 8, 2007
  5. Emil Sandin

    Problem using mocha with Test::Unit

    Emil Sandin, Aug 20, 2009, in forum: Ruby
    Replies:
    2
    Views:
    104
    Emil Sandin
    Aug 24, 2009
Loading...

Share This Page