Skip to content

Commit

Permalink
Better docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhasenan committed May 21, 2011
1 parent b5313a8 commit d2b800e
Showing 1 changed file with 26 additions and 26 deletions.
52 changes: 26 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
MaryJane
========
A mock objects library for javascript.

Platform Support
================
I don't intend to exclude any platforms, but my development is all on Linux with Node.js. I will accept patches to fix broken functionality in any other environment, if they don't break Node.js.

I might extend platform support in the future, with the next likely target being Jurassic, but this is far from guaranteed.

Despite these warnings about platform support, there shouldn't be anything strange about MaryJane that would prevent you from using it in any reasonably compliant environment.

A Note on Types
===============
MaryJane takes a rather strong stance toward types. Specifically, you should deal with types that exist. If you dynamically add methods to your type, this should be accomplished in some global setup.

Regardless, there's almost no way to properly mock an object method that will be assigned during the course of a test. (Implementing that would eliminate any chance of multiplatform support.) So just don't, kay?
A mock objects library for javascript, inspired heavily by Mockito. It uses the Arrange-Act-Assert pattern.

Usage
=====
Expand Down Expand Up @@ -79,8 +65,8 @@ Here's what you can do with the mock options:

You can even chain these together:

when(mock).frob(14)
.thenReturn('ya think?')
when(turret).encounter(weightedCompanionCube)
.thenReturn('Who are you?')
.thenThrow(new Error('Divide by Cucumber Exception'))
.thenDo(function() { assert.fail(); });

Expand All @@ -90,23 +76,23 @@ Okay, now you know how to set up a result. What about verifying that something h

Just use the same process, but with `verify` rather than `when`:

verify(well).consume(apple);
verify(materialEmancipationGrid).consume(weightedCompanionCube); // NOOOOOOOOOOOO!

This will require that someone called `well.consume(apple)` at some point.

You can also verify the number of times something should be called:

verify(well, never).consume(apple);
verify(well, once).consume(apple);
verify(well, times(17)).consume(apple);
verify(well, atLeast(17)).consume(apple);
verify(well, atMost(3)).consume(apple);
verify(well, between(3, 7)).consume(apple);
verify(murkyWater, never).consume(weightedCompanionCube);
verify(lazor, once).fry(weightedStorageCube); // we also have 'twice' and 'thrice'
verify(turret1, times(17)).fallThrough(orangePortal);
verify(turret2, atLeast(17)).fallThrough(bluePortal);
verify(plasmaBallOfDeath, atMost(3)).bounceOff(wall1);
verify(redirectionCube, between(3, 7)).fry(unfortunateTurret);

If you want to check that you've covered all the cases, or that a particular mock hasn't been used in this case:

verifyNoMoreInteractions(well1, well2);
verifyZeroInteractions(well3, well4);
verifyNoMoreInteractions(weightedStorageSphere);
verifyZeroInteractions(turret3);

Both of these ignore anything you did in the Arrange phase. For example, the following test will pass:

Expand All @@ -130,6 +116,20 @@ Consider:

This will replace the `add` function on `math` with one that returns the bitwise XOR of its operands. All the usual mock object accounting will hold, but the function you supply will be executed.

A Note on Types
===============
MaryJane takes a rather strong stance toward types. Specifically, you should deal with types that exist and are relatively static. If you dynamically add methods to your type, this should be accomplished in some global setup.

Regardless, there's almost no way to properly mock an object method that will be assigned during the course of a test. (I could probably do it, but not in JavaScript; I'd need to write a Node plugin.) So just don't, kay?

Platform Support
================
I don't intend to exclude any platforms, but my development is all on Linux with Node.js. I will accept patches to fix broken functionality in any other environment, if they don't break Node.js.

I might extend platform support in the future, with the next likely target being Jurassic, but this is far from guaranteed.

Despite these warnings about platform support, there shouldn't be anything strange about MaryJane that would prevent you from using it in any reasonably compliant environment.

TODO
====
* Ordering
Expand Down

0 comments on commit d2b800e

Please sign in to comment.