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. Advertisements

  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. Advertisements

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. Ken
    Replies:
    0
    Views:
    474
  2. John J. Lee

    Mock object creation by example?

    John J. Lee, Jul 9, 2003, in forum: Python
    Replies:
    0
    Views:
    563
    John J. Lee
    Jul 9, 2003
  3. John J. Lee
    Replies:
    4
    Views:
    526
    John J. Lee
    Nov 8, 2003
  4. Remy Blank
    Replies:
    3
    Views:
    1,142
    Lothar Scholz
    Mar 6, 2004
  5. mfaine
    Replies:
    0
    Views:
    400
    mfaine
    Aug 23, 2007
  6. Matthew Wilson
    Replies:
    1
    Views:
    324
    Gabriel Genellina
    Oct 18, 2007
  7. Nietz
    Replies:
    0
    Views:
    473
    Nietz
    Jan 6, 2008
  8. Emil Sandin

    Problem using mocha with Test::Unit

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