Skip to content

Commit 6230ab6

Browse files
committed
Renamed everything to use generic 'mock'
1 parent a120ea1 commit 6230ab6

File tree

2 files changed

+46
-50
lines changed

2 files changed

+46
-50
lines changed

mock.lua

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@ end
122122

123123

124124

125-
local function mock(m)
126-
return MockExpectation:new(m)
127-
end
128-
129125
local function createMockFunction()
130126
local f
131127

@@ -172,13 +168,13 @@ local function createMockObject(o)
172168
return mocked
173169
end
174170

175-
moq = {
171+
mock = {
176172
createMockFunction = createMockFunction,
177173
createMockTable = createMockTable,
178174
createMockMethod = createMockMethod,
179175
createMockObject = createMockObject
180176
}
181177

182-
setmetatable(moq, {__call = function(_, ...) return mock(...) end})
178+
setmetatable(mock, {__call = function(_, ...) return MockExpectation:new(...) end})
183179

184-
return moq
180+
return mock

spec/mock_spec.lua

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
describe('The mock library', function()
2-
moq = require 'moq'
2+
mock = require 'mock'
33

44
local function shouldFail(test)
55
if pcall(test) then
@@ -8,68 +8,68 @@ describe('The mock library', function()
88
end
99

1010
it('should allow you to verify that a function is called', function()
11-
local m = moq.createMockFunction()
11+
local m = mock.createMockFunction()
1212

13-
moq(m):shouldBeCalled():
13+
mock(m):shouldBeCalled():
1414
when(function() m() end)
1515
end)
1616

1717
it('should alert you when a function is not called', function()
18-
local m = moq.createMockFunction()
18+
local m = mock.createMockFunction()
1919

2020
shouldFail(function()
21-
moq(m):shouldBeCalled():
21+
mock(m):shouldBeCalled():
2222
when(function() end)
2323
end)
2424
end)
2525

2626
it('should alert you when the wrong function is called', function()
27-
local m1 = moq.createMockFunction()
28-
local m2 = moq.createMockFunction()
27+
local m1 = mock.createMockFunction()
28+
local m2 = mock.createMockFunction()
2929

3030
shouldFail(function()
31-
moq(m1):shouldBeCalled():
31+
mock(m1):shouldBeCalled():
3232
when(function() m2() end)
3333
end)
3434
end)
3535

3636
it('should alert you when a function is called unexpectedly', function()
37-
local m = moq.createMockFunction()
37+
local m = mock.createMockFunction()
3838

3939
shouldFail(function()
4040
m()
4141
end)
4242
end)
4343

4444
it('should allow you to verify that a function has been called with the correct arguments', function()
45-
local m = moq.createMockFunction()
45+
local m = mock.createMockFunction()
4646

47-
moq(m):shouldBeCalledWith(1, '2'):
47+
mock(m):shouldBeCalledWith(1, '2'):
4848
when(function() m(1, '2') end)
4949
end)
5050

5151
it('should alert you when a function has been called with incorrect arguments', function()
52-
local m = moq.createMockFunction()
52+
local m = mock.createMockFunction()
5353

5454
shouldFail(function()
55-
moq(m):shouldBeCalledWith(1, '2'):
55+
mock(m):shouldBeCalledWith(1, '2'):
5656
when(function() m(1, '3') end)
5757
end)
5858
end)
5959

6060
it('should allow you to specify the return value of a mocked function', function()
61-
local m = moq.createMockFunction()
61+
local m = mock.createMockFunction()
6262

63-
moq(m):shouldBeCalled():andWillReturn(4):
63+
mock(m):shouldBeCalled():andWillReturn(4):
6464
when(function()
6565
assert.is.equal(m(), 4)
6666
end)
6767
end)
6868

6969
it('should allow you to specify multiple return values for a mocked function', function()
70-
local m = moq.createMockFunction()
70+
local m = mock.createMockFunction()
7171

72-
moq(m):shouldBeCalled():andWillReturn(1, 2):
72+
mock(m):shouldBeCalled():andWillReturn(1, 2):
7373
when(function()
7474
r1, r2 = m()
7575
assert.is.equal(r1, 1)
@@ -78,35 +78,35 @@ describe('The mock library', function()
7878
end)
7979

8080
it('should allow you to check that a function has been called multiple times', function()
81-
local m = moq.createMockFunction()
81+
local m = mock.createMockFunction()
8282

83-
moq(m):shouldBeCalled():
84-
andAlso(moq(m):shouldBeCalledWith(1, 2, 3)):
83+
mock(m):shouldBeCalled():
84+
andAlso(mock(m):shouldBeCalledWith(1, 2, 3)):
8585
when(function()
8686
m()
8787
m(1, 2, 3)
8888
end)
8989
end)
9090

9191
it('should allow you to check that multiple functions are called', function()
92-
local m1 = moq.createMockFunction()
93-
local m2 = moq.createMockFunction()
92+
local m1 = mock.createMockFunction()
93+
local m2 = mock.createMockFunction()
9494

95-
moq(m1):shouldBeCalled():
96-
andAlso(moq(m2):shouldBeCalledWith(1, 2, 3)):
95+
mock(m1):shouldBeCalled():
96+
andAlso(mock(m2):shouldBeCalledWith(1, 2, 3)):
9797
when(function()
9898
m1()
9999
m2(1, 2, 3)
100100
end)
101101
end)
102102

103103
it('should allow you to mix and match call types', function()
104-
local m1 = moq.createMockFunction()
105-
local m2 = moq.createMockFunction()
104+
local m1 = mock.createMockFunction()
105+
local m2 = mock.createMockFunction()
106106

107-
moq(m1):shouldBeCalled():
108-
andAlso(moq(m2):shouldBeCalledWith(1, 2, 3)):
109-
andThen(moq(m2):shouldBeCalledWith(1):andWillReturn(4)):
107+
mock(m1):shouldBeCalled():
108+
andAlso(mock(m2):shouldBeCalledWith(1, 2, 3)):
109+
andThen(mock(m2):shouldBeCalledWith(1):andWillReturn(4)):
110110
when(function()
111111
m1()
112112
m2(1, 2, 3)
@@ -115,15 +115,15 @@ describe('The mock library', function()
115115
end)
116116

117117
it('should allow functions to be used to improve readability', function()
118-
local m1 = moq.createMockFunction()
119-
local m2 = moq.createMockFunction()
118+
local m1 = mock.createMockFunction()
119+
local m2 = mock.createMockFunction()
120120

121121
function somethingShouldHappen()
122-
return moq(m1):shouldBeCalled()
122+
return mock(m1):shouldBeCalled()
123123
end
124124

125125
function anotherThingShouldHappen()
126-
return moq(m2):shouldBeCalledWith(1, 2, 3)
126+
return mock(m2):shouldBeCalledWith(1, 2, 3)
127127
end
128128

129129
function codeUnderTestRuns()
@@ -142,10 +142,10 @@ describe('The mock library', function()
142142
bar = function() end
143143
}
144144

145-
mockedTable = moq.createMockTable(someTable)
145+
mockedTable = mock.createMockTable(someTable)
146146

147-
moq(mockedTable.foo):shouldBeCalledWith(1):andWillReturn(2):
148-
andAlso(moq(mockedTable.bar):shouldBeCalled()):
147+
mock(mockedTable.foo):shouldBeCalledWith(1):andWillReturn(2):
148+
andAlso(mock(mockedTable.bar):shouldBeCalled()):
149149
when(function()
150150
mockedTable.foo(1)
151151
mockedTable.bar()
@@ -158,9 +158,9 @@ describe('The mock library', function()
158158
foo = function() end
159159
}
160160

161-
mockedTable = moq.createMockTable(someTable)
161+
mockedTable = mock.createMockTable(someTable)
162162

163-
moq(mockedTable.foo):shouldBeCalledWith(1):andWillReturn(2):
163+
mock(mockedTable.foo):shouldBeCalledWith(1):andWillReturn(2):
164164
when(function()
165165
mockedTable:foo(1)
166166
end)
@@ -173,10 +173,10 @@ describe('The mock library', function()
173173
function someObject:foo() end
174174
function someObject:bar() end
175175

176-
mockedObject = moq.createMockObject(someObject)
176+
mockedObject = mock.createMockObject(someObject)
177177

178-
moq(mockedObject.foo):shouldBeCalledWith(1):andWillReturn(2):
179-
andAlso(moq(mockedObject.bar):shouldBeCalled()):
178+
mock(mockedObject.foo):shouldBeCalledWith(1):andWillReturn(2):
179+
andAlso(mock(mockedObject.bar):shouldBeCalled()):
180180
when(function()
181181
mockedObject:foo(1)
182182
mockedObject:bar()
@@ -189,9 +189,9 @@ describe('The mock library', function()
189189

190190
function someObject:foo() end
191191

192-
mockedObject = moq.createMockObject(someObject)
192+
mockedObject = mock.createMockObject(someObject)
193193

194-
moq(mockedObject.foo):shouldBeCalledWith(1):andWillReturn(2):
194+
mock(mockedObject.foo):shouldBeCalledWith(1):andWillReturn(2):
195195
when(function()
196196
mockedObject.foo(1)
197197
end)

0 commit comments

Comments
 (0)