Skip to content

Commit 23037ba

Browse files
committed
Test that mocked tables are named (explicitly or implicitly). Closes #1.
1 parent 8d9d396 commit 23037ba

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

spec/mach_spec.lua

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ describe('The mach library', function()
146146
bar = function() end
147147
}
148148

149-
mocked_table = mach.mock_table(some_table, 'some_table')
149+
mocked_table = mach.mock_table(some_table)
150150

151151
mocked_table.foo:should_be_called_with(1):and_will_return(2):
152152
and_also(mocked_table.bar:should_be_called()):
@@ -156,14 +156,30 @@ describe('The mach library', function()
156156
end)
157157
end)
158158

159+
it('should allow a mocked table to be named', function()
160+
mocked_table = mach.mock_table({ foo = function() end }, 'some_table')
161+
162+
should_fail_with('unexpected function call some_table.foo()', function()
163+
mocked_table.foo()
164+
end)
165+
end)
166+
167+
it('should give mocked tables a default name when none is provided', function()
168+
mocked_table = mach.mock_table({ foo = function() end })
169+
170+
should_fail_with('unexpected function call <anonymous>.foo()', function()
171+
mocked_table.foo()
172+
end)
173+
end)
174+
159175
it('should fail when a function is incorrectly used as a method', function()
160-
should_fail(function()
161-
local some_table = {
162-
foo = function() end
163-
}
176+
local some_table = {
177+
foo = function() end
178+
}
164179

165-
mocked_table = mach.mock_table(some_table)
180+
mocked_table = mach.mock_table(some_table)
166181

182+
should_fail(function()
167183
mocked_table.foo:should_be_called_with(1):and_will_return(2):when(function()
168184
mocked_table:foo(1)
169185
end)

0 commit comments

Comments
 (0)