Skip to content

Commit

Permalink
Add with_result as an alias for and_will_return
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanplusplus committed Feb 22, 2019
1 parent cdee93b commit 1f7706d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ local f = mach.mock_function('f')
f.should_be_called().and_will_return(1, 4).when(function()
local x, y = f()
end)

f.should_be_called().with_result(1, 4).when(function()
local x, y = f()
end)
```

## Raising Errors
Expand Down
33 changes: 33 additions & 0 deletions rockspecs/mach-5.1-0.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package = 'mach'
version = '5.1-0'
source = {
url = 'https://github.com/ryanplusplus/mach.lua/archive/v5.1-0.tar.gz',
dir = 'mach.lua-5.1-0/src'
}
description = {
summary = 'Simple mocking framework for Lua inspired by CppUMock and designed for readability.',
homepage = 'https://github.com/ryanplusplus/mach.lua/',
license = 'MIT <http://opensource.org/licenses/MIT>'
}
dependencies = {
'lua >= 5.1'
}
build = {
type = 'builtin',
modules = {
['mach'] = 'mach.lua',
['mach.Expectation'] = 'mach/Expectation.lua',
['mach.ExpectedCall'] = 'mach/ExpectedCall.lua',
['mach.CompletedCall'] = 'mach/CompletedCall.lua',
['mach.unexpected_call_error'] = 'mach/unexpected_call_error.lua',
['mach.unexpected_args_error'] = 'mach/unexpected_args_error.lua',
['mach.out_of_order_call_error'] = 'mach/out_of_order_call_error.lua',
['mach.not_all_calls_occurred_error'] ='mach/not_all_calls_occurred_error.lua',
['mach.format_call_status'] = 'mach/format_call_status.lua',
['mach.format_arguments'] = 'mach/format_arguments.lua',
['mach.format_value'] = 'mach/format_value.lua',
['mach.deep_compare_matcher'] = 'mach/deep_compare_matcher.lua',
['mach.match'] = 'mach/match.lua',
['mach.any'] = 'mach/any.lua',
}
}
4 changes: 4 additions & 0 deletions spec/mach_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ describe('The mach library', function()
f.should_be_called().and_will_return(4).when(function()
assert.is.equal(f(), 4)
end)

f.should_be_called().with_result(4).when(function()
assert.is.equal(f(), 4)
end)
end)

it('should allow you to specify multiple return values for a mocked function', function()
Expand Down
2 changes: 2 additions & 0 deletions src/mach/Expectation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ return function(handle_mock_calls, m)
return o
end)

o.with_result = o.and_will_return

o.and_will_raise_error = wrap(function(...)
if not call_specified then
error('cannot set error for an unspecified call', 2)
Expand Down

0 comments on commit 1f7706d

Please sign in to comment.