Skip to content

Commit

Permalink
Improved some messages. Added shortcut for a single assertion.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcotelli committed Jan 26, 2017
1 parent ebc5c96 commit d1b0be2
Show file tree
Hide file tree
Showing 51 changed files with 201 additions and 117 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I'm a test case for Assertion Checker Builder
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
initialization
setUp

checkerBuilder := AssertionCheckerBuilder new
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests
testConditionalChecking

| explanation rowCount |

explanation := 'A row count must be positive'.
rowCount := -15.

checkerBuilder
checking: [ :asserter | asserter affirm: [ rowCount notNil ] because: [ self fail ] onSuccess: [ :successAsserter | successAsserter affirm: [ rowCount positive ] because: [ explanation ] ] ].

self
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: explanation;
assertCollection: exception failures hasSameElements: {explanation} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
tests
testConditionalCheckingWhenFirstConditionFails

| explanation rowCount |

explanation := 'A row count must be positive'.
rowCount := -15.

checkerBuilder checking: [ :asserter | asserter affirm: [ rowCount positive ] because: explanation onSuccess: [ :successAsserter | self fail ] ].

self
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: explanation;
assertCollection: exception failures hasSameElements: {explanation} ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testFailFast
| mathFailureExplanation |

mathFailureExplanation := 'An obvious math error'.
checker
checkerBuilder
failFast;
checking: [ :asserter |
asserter
Expand All @@ -13,9 +13,9 @@ testFailFast
affirm: [ self fail ] because: [ self fail ] ].

self
should: [ checker check ]
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: mathFailureExplanation;
assert: exception failures size equals: 1 ]
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testFailFastInConditional
| mathFailureExplanation |

mathFailureExplanation := 'An obvious math error'.
checker
checkerBuilder
failFast;
checking: [ :asserter |
asserter
Expand All @@ -13,9 +13,9 @@ testFailFastInConditional
affirm: [ self fail ] because: [ self fail ] ].

self
should: [ checker check ]
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: mathFailureExplanation;
assert: exception failures size equals: 1 ]
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ testFailFastPassingSomeConditions
| failureExplanation |

failureExplanation := 'An obvious math error'.
checker
checkerBuilder
failFast;
checking: [ :asserter |
asserter
Expand All @@ -13,9 +13,9 @@ testFailFastPassingSomeConditions
affirm: [ self fail ] because: [ self fail ] ].

self
should: [ checker check ]
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: failureExplanation;
assert: exception failures size equals: 1 ]
assertCollection: exception failures hasSameElements: {failureExplanation} ]
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ testSeveralConditionsButOnlyOneFailed
| mathFailureExplanation |

mathFailureExplanation := 'An obvious math error'.
checker
checkerBuilder
checking: [ :asserter |
asserter
affirm: [ 4 > 3 ] because: [ self fail ];
affirm: [ 1 > 2 ] because: mathFailureExplanation;
affirm: [ #() isEmpty ] because: [ self fail ] ].
self
should: [ checker check ]
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: mathFailureExplanation;
assert: exception failures size equals: 1 ]
assertCollection: exception failures hasSameElements: {mathFailureExplanation} ]
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
tests
testSeveralConditionsFailed

| mathFailureExplanation collectionSizeFailureExplanation |
| mathFailureExplanation collectionSizeFailureExplanation |

mathFailureExplanation := 'An obvious math error'.
collectionSizeFailureExplanation := 'An empty collection was not expected'.
checker
checkerBuilder
checking: [ :asserter |
asserter
affirm: [ 1 > 2 ] because: mathFailureExplanation;
affirm: [ #() notEmpty ] because: collectionSizeFailureExplanation ].
self
should: [ checker check ]
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: ('<1s>. <2s>' expandMacrosWith: mathFailureExplanation with: collectionSizeFailureExplanation);
assert: exception failures size equals: 2 ]
assertCollection: exception failures
hasSameElements:
{mathFailureExplanation.
collectionSizeFailureExplanation} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
tests
testSingleConditionFailure

| explanation |

explanation := 'An obvious math error'.
checkerBuilder checking: [ :asserter | asserter affirm: [ 1 > 2 ] because: explanation ].
self
should: [ checkerBuilder buildAndCheck ]
raise: AssertionFailed
withExceptionDo: [ :exception |
self
assert: exception messageText equals: explanation;
assertCollection: exception failures hasSameElements: {explanation} ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests
testWithoutChecks

self shouldnt: [ checkerBuilder buildAndCheck ] raise: AssertionFailed
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tests
testWithoutFailures

checker
checkerBuilder
checking: [ :asserter |
asserter
affirm: [ true ] because: [ self fail ];
affirm: [ 1 positive ] because: [ self fail ] ].

self shouldnt: [ checker check ] raise: AssertionFailed
self shouldnt: [ checkerBuilder buildAndCheck ] raise: AssertionFailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"instance" : {
"testWithoutFailures" : "GabrielOmarCotelli 1/25/2017 21:28",
"testConditionalChecking" : "GabrielOmarCotelli 1/25/2017 21:33",
"testConditionalCheckingWhenFirstConditionFails" : "GabrielOmarCotelli 1/25/2017 21:34",
"testSeveralConditionsButOnlyOneFailed" : "GabrielOmarCotelli 1/25/2017 21:36",
"testSingleConditionFailure" : "GabrielOmarCotelli 1/25/2017 21:39",
"testFailFastPassingSomeConditions" : "GabrielOmarCotelli 1/25/2017 21:35",
"testFailFastInConditional" : "GabrielOmarCotelli 1/25/2017 21:34",
"testFailFast" : "GabrielOmarCotelli 1/25/2017 21:34",
"testWithoutChecks" : "GabrielOmarCotelli 1/25/2017 21:28",
"testSeveralConditionsFailed" : "GabrielOmarCotelli 1/25/2017 21:36",
"setUp" : "GabrielOmarCotelli 1/25/2017 21:27"
},
"class" : { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"commentStamp" : "GabrielOmarCotelli 1/25/2017 21:30",
"super" : "TestCase",
"category" : "Pharo-Kernel-Extensions-Tests-Assertions",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"checkerBuilder"
],
"name" : "AssertionCheckerBuilderTest",
"type" : "normal"
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I'm a test case for Assertion Checker
I'm a test case for Assertion Checker

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
tests
testJustCheckOneFactFailing

| explanation |

explanation := 'A false statement'.
self should: [ AssertionChecker justCheck: [ false ] because: explanation ] raise: AssertionFailed withExceptionDo: [ :exception | self assert: exception messageText equals: explanation ]
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tests
testJustCheckOneFactNotFailing

self shouldnt: [ AssertionChecker justCheck: [ true ] because: [ self fail ] ] raise: AssertionFailed

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
{
"instance" : {
"testWithoutFailures" : "GabrielOmarCotelli 1/24/2017 21:49",
"testConditionalChecking" : "GabrielOmarCotelli 1/24/2017 21:48",
"testConditionalCheckingWhenFirstConditionFails" : "GabrielOmarCotelli 1/24/2017 21:44",
"testSeveralConditionsButOnlyOneFailed" : "GabrielOmarCotelli 1/24/2017 21:51",
"testSingleConditionFailure" : "GabrielOmarCotelli 1/23/2017 18:59",
"testFailFastPassingSomeConditions" : "GabrielOmarCotelli 1/24/2017 21:51",
"testFailFastInConditional" : "GabrielOmarCotelli 1/24/2017 21:52",
"testFailFast" : "GabrielOmarCotelli 1/24/2017 21:52",
"testWithoutChecks" : "GabrielOmarCotelli 1/23/2017 18:58",
"testSeveralConditionsFailed" : "GabrielOmarCotelli 1/23/2017 18:59",
"setUp" : "GabrielOmarCotelli 1/23/2017 18:58"
"testJustCheckOneFactFailing" : "GabrielOmarCotelli 1/25/2017 22:01",
"testJustCheckOneFactNotFailing" : "GabrielOmarCotelli 1/25/2017 22:00"
},
"class" : { }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"commentStamp" : "GabrielOmarCotelli 1/23/2017 17:01",
"commentStamp" : "GabrielOmarCotelli 1/25/2017 21:55",
"super" : "TestCase",
"category" : "Pharo-Kernel-Extensions-Tests-Assertions",
"classinstvars" : [ ],
"pools" : [ ],
"classvars" : [ ],
"instvars" : [
"checker"
],
"instvars" : [ ],
"name" : "AssertionCheckerTest",
"type" : "normal"
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ testSignalAll
withExceptionDo: [ :exception |
self
assert: exception messageText equals: ('<1s>. <2s>' expandMacrosWith: firstExplanation with: secondExplanation);
assert: exception failures size equals: 2;
assert: exception failures first equals: firstExplanation;
assert: exception failures last equals: secondExplanation ]
assertCollection: exception failures
hasSameElements:
{firstExplanation.
secondExplanation} ]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"instance" : {
"testFailures" : "GabrielOmarCotelli 1/24/2017 20:01",
"testSignalAll" : "GabrielOmarCotelli 1/24/2017 20:17"
"testSignalAll" : "GabrielOmarCotelli 1/25/2017 21:33"
},
"class" : { }
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(name 'Pharo-Kernel-Extensions-Tests-GabrielOmarCotelli.2' message 'First iteration on assertion model ' id '5f4e6cd7-d444-40b4-9453-b2405bd0d5c2' date '24 January 2017' time '9:54:05.93826 pm' author 'GabrielOmarCotelli' ancestors ((name 'Pharo-Kernel-Extensions-Tests-GabrielOmarCotelli.1' message 'Package rename' id '6cf484ad-1744-434f-8da5-2ad346e54527' date '5 January 2017' time '3:02:49.284866 pm' author 'GabrielOmarCotelli' ancestors () stepChildren ())) stepChildren ())
(name 'Pharo-Kernel-Extensions-Tests-GabrielOmarCotelli.3' message 'Improved some messages. Added shortcut for a single assertion.' id 'feea69b2-0d07-40ad-ac34-426acb8e2c75' date '25 January 2017' time '10:02:37.949731 pm' author 'GabrielOmarCotelli' ancestors ((name 'Pharo-Kernel-Extensions-Tests-GabrielOmarCotelli.2' message 'First iteration on assertion model ' id '5f4e6cd7-d444-40b4-9453-b2405bd0d5c2' date '24 January 2017' time '9:54:05.93826 pm' author 'GabrielOmarCotelli' ancestors ((name 'Pharo-Kernel-Extensions-Tests-GabrielOmarCotelli.1' message 'Package rename' id '6cf484ad-1744-434f-8da5-2ad346e54527' date '5 January 2017' time '3:02:49.284866 pm' author 'GabrielOmarCotelli' ancestors () stepChildren ())) stepChildren ())) stepChildren ())
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
configuring
affirm: aFact because: aStringOrBlock

conditions add: (AssertionCheck checking: aFact onFailure: aStringOrBlock)
checks add: (AssertionCheck checking: aFact onFailure: aStringOrBlock)
Loading

0 comments on commit d1b0be2

Please sign in to comment.