Skip to content

Commit

Permalink
Merge 938fcfb into acf97c6
Browse files Browse the repository at this point in the history
  • Loading branch information
jecisc committed Apr 24, 2020
2 parents acf97c6 + 938fcfb commit d5676c9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
4 changes: 2 additions & 2 deletions resources/doc/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,10 @@ Chanel rename each test case ending with `Tests` te end with `Test` since this i
*Conditions for the cleanings to by applied:*
- The class needs to be a subclass of TestCase.
- The class name needs to end with `Tests`.
- The system should not contain a class with the same name without the final `s`.

*Warnings:*
This might cause trouble if you have a test case end with `Test` and another class with the same name ending with `Tests`.
This cleaning should not have any counter indication.

### Ensure right super are call

Expand Down Expand Up @@ -208,7 +209,6 @@ Remove each methods only doing a super call. This does not remove methods with p
- The method should not have any pragma.

*Warnings:*

This might remove methods added just to add comments in a subclass.

### Remove unread temporaries
Expand Down
15 changes: 15 additions & 0 deletions src/Chanel-Tests/ChanelTestCaseNameCleanerTest.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ ChanelTestCaseNameCleanerTest >> testRenameTestCaseEndingWithTestsUpdateReferenc
ifAbsent: [ self fail ]
]

{ #category : #tests }
ChanelTestCaseNameCleanerTest >> testShouldNotRenameIfTheNewClassNameAlreadyExistsInTheSystem [
"/!\ /!\ We use #asSymbol instead of writing symbols because the renaming will update the references in the image, thus, it will rename the symbols in the test. /!\ /!\ "

self createTestCaseNamed: 'ChanelMockTests' asSymbol.
self createTestCaseNamed: 'ChanelMockTest' asSymbol.

"The class should not be renamed since the right name already exists in the system."

self shouldnt: [ self runCleaner ] raise: Error.

self class environment at: 'ChanelMockTest' asSymbol ifAbsent: [ self fail ].
self class environment at: 'ChanelMockTests' asSymbol ifAbsent: [ self fail ]
]

{ #category : #tests }
ChanelTestCaseNameCleanerTest >> testShouldNotRenameNonTestCaseEndingWithTest [
"/!\ /!\ We use #asSymbol instead of writing symbols because the renaming will update the references in the image, thus, it will rename the symbols in the test. /!\ /!\ "
Expand Down
15 changes: 10 additions & 5 deletions src/Chanel/ChanelTestCaseNameCleaner.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ ChanelTestCaseNameCleaner class >> priority [

{ #category : #cleaning }
ChanelTestCaseNameCleaner >> clean [
self configuration definedTestCases
select: [ :class | class name endsWith: 'Tests' ]
thenDo: [ :class |
('Renaming ' , class name , ' to ' , class name allButLast) record.
(RBRenameClassRefactoring rename: class to: class name allButLast) execute ]
self configuration definedTestCases iterator
| [ :class | class name endsWith: 'Tests' ] selectIt
| [ :class | self class environment hasClassNamed: class name allButLast ] rejectIt
> [ :class | self rename: class as: class name allButLast ] doIt
]

{ #category : #cleaning }
ChanelTestCaseNameCleaner >> rename: class as: aString [
('Renaming ' , class name , ' to ' , aString) record.
(RBRenameClassRefactoring rename: class to: aString) execute
]

0 comments on commit d5676c9

Please sign in to comment.