diff --git a/README.md b/README.md index 17e833f..6ecde07 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/rockspecs/mach-5.1-0.rockspec b/rockspecs/mach-5.1-0.rockspec new file mode 100644 index 0000000..00daf34 --- /dev/null +++ b/rockspecs/mach-5.1-0.rockspec @@ -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 ' +} +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', + } +} diff --git a/spec/mach_spec.lua b/spec/mach_spec.lua index 6dbaae7..d1f8202 100644 --- a/spec/mach_spec.lua +++ b/spec/mach_spec.lua @@ -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() diff --git a/src/mach/Expectation.lua b/src/mach/Expectation.lua index 37393db..5f8ab1e 100644 --- a/src/mach/Expectation.lua +++ b/src/mach/Expectation.lua @@ -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)