Skip to content

Commit

Permalink
Adds withArgument: arg as a shortcut for withArguments: [arg].
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed Jan 4, 2010
1 parent 00d96d4 commit 66b6cea
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions dist/moksi.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,11 @@ Moksi.Expectations.Expectation = Class.create({

var result, invocationCount, messageParts = [];

if (options.withArgument) {
options.withArguments = [options.withArgument];
delete options['withArgument'];
}

invocationCount = Moksi.Invocations.invocationCount(subject, method, options.withArguments)

if (options.times) {
Expand Down
2 changes: 1 addition & 1 deletion examples/expected_invocation_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Moksi.describe('Updater', {

'fetches book information from the correct URL': function() {
expects(Ajax).receives('get', {
withArguments: ['http://example.com/books/12.json'],
withArgument: 'http://example.com/books/12.json',
returns: { title: 'The Haunter of the Dark' }
});
this.suite.updater.run();
Expand Down
5 changes: 5 additions & 0 deletions src/moksi/expectations.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ Moksi.Expectations.Expectation = Class.create({

var result, invocationCount, messageParts = [];

if (options.withArgument) {
options.withArguments = [options.withArgument];
delete options['withArgument'];
}

invocationCount = Moksi.Invocations.invocationCount(subject, method, options.withArguments)

if (options.times) {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/expectations_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,11 @@ Moksi.describe('Moksi.Expectations.Expectation, concerning receives', Object.ext
expects(this.suite.resolver.results[0].message).equals('expected ‘[object Object]’ to not receive ‘hasFriend(Manfred)’ 2 times, but was 2 times');
},

'uses withArgument: arg as a shortcut for withArguments: [arg]': function() {
expects(Person).receives('hasFriend', { withArgument: 'Manfred' });
Person.hasFriend('Manfred');
},

'returns no value from the stubbed function': function() {
var expectation = new Moksi.Expectations.Expectation(Person, true, this.suite.resolver);
expectation.receives('name');
Expand Down

0 comments on commit 66b6cea

Please sign in to comment.