-
-
Notifications
You must be signed in to change notification settings - Fork 348
/
ReShouldSendSuperTearDownAsLastMessage.class.st
57 lines (45 loc) · 1.64 KB
/
ReShouldSendSuperTearDownAsLastMessage.class.st
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
"
In a test case the tearDown method should call super tearDown as last message
"
Class {
#name : 'ReShouldSendSuperTearDownAsLastMessage',
#superclass : 'ReAbstractRule',
#traits : 'ReTSUnitGroupedRule',
#classTraits : 'ReTSUnitGroupedRule classTrait',
#category : 'SUnit-Rules-Base',
#package : 'SUnit-Rules',
#tag : 'Base'
}
{ #category : 'testing - interest' }
ReShouldSendSuperTearDownAsLastMessage class >> checksMethod [
^ true
]
{ #category : 'utilities' }
ReShouldSendSuperTearDownAsLastMessage class >> parseTreeSearcher [
^ RBParseTreeSearcher new
]
{ #category : 'utilities' }
ReShouldSendSuperTearDownAsLastMessage class >> superTearDownNotCalledLastIn: aCompiledMethod [
"Return true if the method is a tearDown method and a call to super tearDown is not the last message send."
| searcher |
searcher := self parseTreeSearcher
matchesAnyMethodOf:
#('tearDown `.@any. super tearDown' 'tearDown | `@temps | `.@any. super tearDown')
do: [ :node :answer | true ];
yourself.
^ (searcher
executeTree: aCompiledMethod ast
initialAnswer: false) not
]
{ #category : 'running' }
ReShouldSendSuperTearDownAsLastMessage >> basicCheck: aMethod [
^ (self isClassToCheck: aMethod methodClass) and: [ aMethod selector = #tearDown and: [ self class superTearDownNotCalledLastIn: aMethod ] ]
]
{ #category : 'testing' }
ReShouldSendSuperTearDownAsLastMessage >> isClassToCheck: aClass [
^ { TestCase. TestResource } anySatisfy: [:each | aClass inheritsFrom: each ]
]
{ #category : 'accessing' }
ReShouldSendSuperTearDownAsLastMessage >> name [
^ 'Provide a call to super tearDown as the last message in the tearDown method'
]