Skip to content

Commit a19735d

Browse files
committed
state specs underway
1 parent 823bd50 commit a19735d

File tree

2 files changed

+30
-31
lines changed

2 files changed

+30
-31
lines changed

Chapters/Mocking/SimpleMock.pillar

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,17 +147,17 @@ aMock on: #messageToBeMocked:withArguments:
147147
[[[
148148
aMock
149149
on: #messageToBeMocked:withArguments:
150-
with: 1
151-
with: 'two'
150+
with: 1
151+
with: 'two'
152152
]]]
153153

154154
!!!! Partial match
155155

156156
[[[
157157
aMock
158158
on: #messageToBeMocked:withArguments:
159-
with: MockObject any
160-
with: 'two'
159+
with: MockObject any
160+
with: 'two'
161161
]]]
162162

163163
The above training methods are to be used when we don't care about the behaviour when mocking, but only that the message is sent.

Chapters/Mocking/StateSpecs.pillar

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -104,64 +104,60 @@ Equal to: 10.0123 within: 0.01.
104104

105105

106106
!!! Should expressions
107-
107+
Should expressions were created with the goal to replace SUnit assertions (==self assert: a equals: b)==.
108108
The implementation of should expression creates specific specifications and it verifies that receiver satisfies it.
109109
When an object is not valid, a should expression signals ==SpecOfFailed== error.
110110
Such validation error can be inspected in the debugger to analyze and understand the reason.
111111

112-
Sending a ==not== message to a ==should== expression inverts the logic of following expression:
112+
Sending a ==not== message to a ==should== expression negates the logic of following expression:
113113

114114
[[[
115115
3 should not equal: 3.
116116
>>> fail with message: Got '3' but it should not equal '3'
117117
]]]
118118

119-
Should expressions were created with the goal to replace SUnit assertions (self assert: a = b).
119+
120120

121121
To explore complete set of expressions look at the class ==SpecOfShouldExpression==.
122122
It is also place where to extend them. The test class ==SpecOfShouldExpressionTests== describes them using tests.
123123

124124
!!!! Specification of object identity
125125

126-
The message ==be:== is used to verify that receiver is identical to given argument:
126+
The message ==be:== is used to verify that receiver is identical to a given argument:
127+
The following two expressions will fail, obviously.
127128

128129
[[[
129130
1 should be: 2.
130-
]]]
131-
132-
It fails with message: Got "1" but it should be "2".
133-
134-
[[[
135131
1 should not be: 1.
136132
]]]
137133

138-
It fails with message: Got "1" but it should not be "1".
139-
140134
!!!! Specification of object equality
141135

142-
==#equal:== message is used to verify that receiver is equivalent to given argument:
136+
The ==equal:== message is used to verify that receiver is equivalent to given argument:
137+
The following two expressions will fail, obviously.
143138

144139
[[[
145140
3 should equal: 2.
141+
3 should not equal: 3.
146142
]]]
147143

148-
It fails with message: Got "3" but it should equal "2".
149144

150-
[[[
151-
3 should not equal: 3.
152-
]]]
153145

154-
It fails with message: Got "3" but it should not equal "3"
155146

147+
!!! About equality for specification
156148

157-
Language equality operation #= is redefined by many classes according to domain logic. Sometimes they check a lot of conditions to compare objects.
158-
Problem that it can be not suitable from the point of view of specification. Imaging that we want compare two collection of different type:
149+
Language equality operation ==\=== is redefined by many classes according to their domain logic.
150+
Sometimes they check many conditions.
151+
This is a problem that it can be not suitable from the point of view of specification.
152+
Imagine that we want compare two collections of different types:
159153

160154
[[[
161-
#(1 2 3) asOrderedCollection = #(1 2 3). "==>false"
155+
#(1 2 3) asOrderedCollection = #(1 2 3).
156+
>>> false
162157
]]]
163158

164-
It returns false which is correct from the point of view of collection library. But what we would expect from specification?
159+
It returns false which is correct from the point of view of collection library.
160+
But what we would expect from specification?
165161

166162
[[[
167163
#(1 2 3) asOrderedCollection should equal: #(1 2 3).
@@ -170,9 +166,10 @@ It returns false which is correct from the point of view of collection library.
170166
It would be not suitable to fail because it will force us to always think about collection type when we would like assert their equality.
171167
In fact we are supposed to assert collection items with this expression and not instances of collections.
172168

169+
So this expression will not fail in StateSpecs. And to achieve its equality specification uses specific message ==#checkStateSpecsEqualityTo:== instead of standart #=.
173170

174-
So this expression will not fail in StateSpecs. And to achieve it equality specification uses specific message ==#checkStateSpecsEqualityTo:== instead of standart #=.
175-
Default Object implementation calls #=. But some classes redefine it with appropriate logic to provide as less restrictive behaviour as possible.
171+
Default Object implementation calls #=.
172+
But some classes redefine it with appropriate logic to provide as less restrictive behaviour as possible.
176173

177174
Idea is that general equality specification should be as much simple equality as possible with enough restrictions. And if you want some extra details you should use different explicit specification which describes them.
178175
In case of collections you should check for collection class explicitly if it is important for your business case where you use specification:
@@ -188,17 +185,19 @@ actual should equal: expected.
188185
Following this logic StateSpecs do not check order when compare basic collection classes:
189186

190187
[[[
191-
#(1 2 3) should equal: #(2 1 3). "will not fail"
192-
#(1 2 3) asSet should equal: #(2 1 3). "will not fail"
188+
#(1 2 3) should equal: #(2 1 3).
189+
>>> true
190+
#(1 2 3) asSet should equal: #(2 1 3).
191+
>>> true
193192
]]]
194193

195-
When order is important use different message ==#equalInOrder:==:
194+
When the order is important, use the message ==equalInOrder:==:
196195

197196
[[[
198197
#(1 2 3) asOrderedCollection should equalInOrder: #(2 1 3).
198+
>>> Fails #(1 2 3)" but it should equal in order to "#(2 1 3)
199199
]]]
200200

201-
It fails with message: Got "#(1 2 3)" but it should equal in order to "#(2 1 3)".
202201

203202

204203
There are collection classes like String or ByteArray which are supposed to be in order and which type is important. For them theses properties are always taken into account for equality comparison:

0 commit comments

Comments
 (0)