Skip to content

Commit

Permalink
updated readme
Browse files Browse the repository at this point in the history
  • Loading branch information
andykent committed May 19, 2009
1 parent 21fdfbc commit 9c16495
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 9 additions & 2 deletions README.markdown
@@ -1,6 +1,6 @@
Smoke Smoke
===== =====
Smoke is a JavaScript mocking and stubbing framework. It has a familiar RSpec style interface and whilst it is perfectly capable of being used as a free-standing tool it is currently most useful when used in conjunction with the screw-unit testing framework. Smoke is a JavaScript mocking and stubbing framework. It has a familiar RSpec style interface and whilst it is perfectly capable of being used as a free-standing tool it is totally usable as a free standing tool but comes complete with a plugin for the screw-unit testing framework.


Getting Started (With Screw.Unit) Getting Started (With Screw.Unit)
--------------------------------- ---------------------------------
Expand All @@ -15,6 +15,12 @@ but you will need to include the Smoke files and you can get straight to work us
myMock.should_receive('foo').at_least('once').and_return('hello'); myMock.should_receive('foo').at_least('once').and_return('hello');
expect(foo.baz).to(equal, 'hi!'); expect(foo.baz).to(equal, 'hi!');


Additionally Smoke now has a macro for mocking anonymous functions this is great for mocking and stubbing closures...

f = mock_function(function () { return 'Hi!' });
f.should_be_invoked().exactly('once');
expect(f()).to(equal, 'hi!');

Getting Started (Free Standing) Getting Started (Free Standing)
------------------------------- -------------------------------
Include the library files in your document... Include the library files in your document...
Expand All @@ -32,6 +38,7 @@ Create your stubs...
Create your mocks... Create your mocks...


var myMock = Smoke.Mock(); var myMock = Smoke.Mock();
var myMockFunction = Smoke.MockFunction();


Create your expectations... Create your expectations...


Expand All @@ -48,7 +55,7 @@ Mocks are the main part of the Smoke framework. But Smoke.Mock() has a bit of a
1. *without any arguments* it will return a fresh Mock with no more than default Object methods. You will need to mock all your interactions and check all your expectations. 1. *without any arguments* it will return a fresh Mock with no more than default Object methods. You will need to mock all your interactions and check all your expectations.
2. *with an argument* it will return a 'Mocked' version of the object that was passed in. This is very useful if you just want to mock a single method on your object whilst leaving the rest intact. It's especially helpful for just carrying out expectations on existing objects without any mocking at all. 2. *with an argument* it will return a 'Mocked' version of the object that was passed in. This is very useful if you just want to mock a single method on your object whilst leaving the rest intact. It's especially helpful for just carrying out expectations on existing objects without any mocking at all.


Smoke expectations are non-destructive meaning that if you add an expectation but don't specify a return value then the previous method will still be invoked (if one exists) and it's result will be returned. Smoke expectations are non-destructive meaning that if you add an expectation then the previous method will still be invoked (if one exists) and it's result will be returned (unless you specify otherwise). If you really don't want the original to be called then you should use .stub() to stub it out.


Known Issues Known Issues
------------ ------------
Expand Down
8 changes: 7 additions & 1 deletion spec/mock_spec.js
Expand Up @@ -57,7 +57,13 @@ Screw.Unit(function() {
m.bar(); m.bar();
m.bar(); m.bar();
}); });


it("should allow stubbing on mocks", function() {
var m = mock({foo: function() { throw('I should not have been called!')}});
m.should_receive('foo').stub.and_return('hello');
m.foo();
});

it("should allow return values directly from mocks",function() { it("should allow return values directly from mocks",function() {
var m = mock() var m = mock()
m.should_receive('bar').exactly('once').and_return('hello'); m.should_receive('bar').exactly('once').and_return('hello');
Expand Down

0 comments on commit 9c16495

Please sign in to comment.