Skip to content

Commit 5416afd

Browse files
committed
Formatting update
1 parent 2362dcb commit 5416afd

File tree

2 files changed

+125
-142
lines changed

2 files changed

+125
-142
lines changed

README.md

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ mach = require 'mach'
1010

1111
local f = mach.mock_function()
1212

13-
f:should_be_called():
14-
when(function() f() end)
13+
f:should_be_called():when(
14+
function() f()
15+
end)
1516
```
1617

1718
## Mocking a Method
@@ -22,8 +23,9 @@ mach = require 'mach'
2223
local o = {}
2324
o.m = mach.mach_method()
2425

25-
m:should_be_called():
26-
when(function() o:m() end)
26+
m:should_be_called():when(
27+
function() o:m()
28+
end)
2729
```
2830

2931
## Mocking a Table
@@ -38,8 +40,9 @@ local some_table = {
3840

3941
mocked_table = mach.mockTable(some_table)
4042

41-
mocked_table.foo:should_be_called():
42-
when(function() mocked_table.foo() end)
43+
mocked_table.foo:should_be_called():when(
44+
function() mocked_table.foo()
45+
end)
4346
```
4447

4548
## Mocking an Object
@@ -53,8 +56,9 @@ function some_object:bar() end
5356

5457
mocked_object = mach.mock_object(some_object)
5558

56-
mocked_object.foo:should_be_called():
57-
when(function() mocked_object:foo() end)
59+
mocked_object.foo:should_be_called():when(function()
60+
mocked_object:foo()
61+
end)
5862
```
5963

6064
## Multiple Expectations
@@ -66,8 +70,11 @@ local f1 = mach.mock_function()
6670
local f2 = mach.mock_function()
6771

6872
f1:should_be_called():
69-
and_also(f2:should_be_called()):
70-
when(function() f1(); f2() end)
73+
and_also(f2:should_be_called()):
74+
when(function()
75+
f1()
76+
f2()
77+
end)
7178
```
7279

7380
## Optional Expectations
@@ -77,8 +84,7 @@ mach = require 'mach'
7784

7885
local f = mach.mock_function()
7986

80-
f:mayBeCalled():
81-
when(function() end)
87+
f:mayBeCalled():when(function() end)
8288
```
8389

8490
## Optional Ordering
@@ -90,19 +96,19 @@ local f = mach.mock_function()
9096

9197
-- Use and_also when order is important
9298
f:should_be_called_with(1):
93-
and_then(f:should_be_called_with(2)):
94-
when(function()
95-
f(2) -- Error, out of order call
96-
f(1)
97-
end)
99+
and_then(f:should_be_called_with(2)):
100+
when(function()
101+
f(2) -- Error, out of order call
102+
f(1)
103+
end)
98104

99105
-- Use and_also when order is unimportant
100106
f:should_be_called_with(1):
101-
and_also(f:should_be_called_with(2)):
102-
when(function()
103-
f(2) -- No error, order is not fixed when 'and_also' is used
104-
f(1)
105-
end)
107+
and_also(f:should_be_called_with(2)):
108+
when(function()
109+
f(2) -- No error, order is not fixed when 'and_also' is used
110+
f(1)
111+
end)
106112
```
107113

108114
## Mixed Ordering
@@ -113,15 +119,15 @@ mach = require 'mach'
113119
local f = mach.mock_function()
114120

115121
f:should_be_called_with(1):
116-
and_also(f:should_be_called_with(2)):
117-
and_then(f:should_be_called_with(3)):
118-
and_also(f:should_be_called_with(4)):
119-
when(function()
120-
f(2)
121-
f(1)
122-
f(4)
123-
f(3)
124-
end)
122+
and_also(f:should_be_called_with(2)):
123+
and_then(f:should_be_called_with(3)):
124+
and_also(f:should_be_called_with(4)):
125+
when(function()
126+
f(2)
127+
f(1)
128+
f(4)
129+
f(3)
130+
end)
125131
```
126132

127133
## Flexible Syntax
@@ -147,6 +153,6 @@ end
147153

148154
-- Actual test:
149155
something_should_happen():
150-
and_also(another_thing_should_happen()):
151-
when(the_code_under_test_runs)
156+
and_also(another_thing_should_happen()):
157+
when(the_code_under_test_runs)
152158
```

0 commit comments

Comments
 (0)