The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

Title

Test::Mock::Mango

Synopsis

  # Using Test::More
  #
  use Test::More;
  use Test::Mock::Mango; # Stubs in effect!
  # ...
  done_testing();


  # Using Test::Spec (uses Test::Spec::Mocks)
  #
  use Test::Spec;

  describe "Whilst stubbing Mango" => {
    require Test::Mock::Mango; # Stubs in effect in scope!
    # ...
  };
  runtests unless caller;

Description

Simple stubbing of mango methods. Methods ignore actual queries being entered and simply return the data set in the FakeData object. To run a test you need to set up the data you expect back first - this module doesn't test your queries, it allows you to test around mango calls with known conditions.

Stubbed Methods

The following methods are available on each faked part of the mango. We describe here briefly how far each actually simulates the real method.

Each method supports blocking and non-blocking syntax if the original method does. Non-blocking ops are not actually non blocking but simply execute your callback straight away as there's nothing to actually go off and do on an event loop.

All methhods by default execute without error state.

Collection

Test::Mock::Mango::Collection

aggregate

Ignores query. Returns current collection documents to simulate an aggregated result.

create

Doesn't really do anything.

drop

Doesn't really do anything.

find_one

Ignores query. Returns the first document from the current fake collection given in Test::Mock::Mango::FakeData. Returns undef if the collection is empty.

find

Ignores query. Returns a new Test::Mock::Mango::Cursor instance.

full_name

Returns full name of the fake collection.

insert

Naively inserts the given doc(s) onto the end of the current fake collection.

Returns an oid for each inserted document. If an _id is specifiec in the inserted doc then it is returned, otherwise a random string is returned instead.

Cursor

Test::Mock::Mango::Cursor

all

Return array ref containing all the documents in the current fake collection.

next

Simulates a cursor by (beginning at zero) iterating through each document on successive calls. Won't reset itself. If you want to reset the cursor then set Test::Mock::Mango-index> to zero.

count

Returns the number of documents in the current fake collection.

backlog

Arbitarily returns '2'