From 2c45e925fb9bebac0a81820240d6f6a5aa6ff971 Mon Sep 17 00:00:00 2001 From: Denis Kudriashov Date: Mon, 13 May 2019 21:47:50 +0100 Subject: [PATCH] SpecOfExpectedObjectSender is fixed for case when object was returned from multiple senders --- ...epMessageSendWhichWasAlsoReturnedFromSender.st | 11 +++++++++++ .../monticello.meta/categories.st | 2 +- .../instance/testMatchesMultipleSenders.st | 13 +++++++++++++ .../testSucceedValidationOfMultipleSenders.st | 15 +++++++++++++++ .../monticello.meta/categories.st | 2 +- .../instance/basicMatches..st | 8 +++----- .../instance/validate..st | 13 ++++++------- 7 files changed, 50 insertions(+), 14 deletions(-) create mode 100644 Mocketry-Domain-Tests.package/MockAcceptanceTests.class/instance/testValidationThatObjectIsResultOfDeepMessageSendWhichWasAlsoReturnedFromSender.st create mode 100644 Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testMatchesMultipleSenders.st create mode 100644 Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testSucceedValidationOfMultipleSenders.st diff --git a/Mocketry-Domain-Tests.package/MockAcceptanceTests.class/instance/testValidationThatObjectIsResultOfDeepMessageSendWhichWasAlsoReturnedFromSender.st b/Mocketry-Domain-Tests.package/MockAcceptanceTests.class/instance/testValidationThatObjectIsResultOfDeepMessageSendWhichWasAlsoReturnedFromSender.st new file mode 100644 index 0000000..6e0bad4 --- /dev/null +++ b/Mocketry-Domain-Tests.package/MockAcceptanceTests.class/instance/testValidationThatObjectIsResultOfDeepMessageSendWhichWasAlsoReturnedFromSender.st @@ -0,0 +1,11 @@ +tests +testValidationThatObjectIsResultOfDeepMessageSendWhichWasAlsoReturnedFromSender + + | result rect | + rect := 0@0 corner: mock. + rect stub. + + result := rect right. + + result should beReturnedFrom: [mock x]. + result should beReturnedFrom: [rect right]. \ No newline at end of file diff --git a/Mocketry-Domain-Tests.package/monticello.meta/categories.st b/Mocketry-Domain-Tests.package/monticello.meta/categories.st index 34843da..97b294a 100644 --- a/Mocketry-Domain-Tests.package/monticello.meta/categories.st +++ b/Mocketry-Domain-Tests.package/monticello.meta/categories.st @@ -1 +1 @@ -SystemOrganization addCategory: 'Mocketry-Domain-Tests'! +SystemOrganization addCategory: #'Mocketry-Domain-Tests'! diff --git a/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testMatchesMultipleSenders.st b/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testMatchesMultipleSenders.st new file mode 100644 index 0000000..4ced999 --- /dev/null +++ b/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testMatchesMultipleSenders.st @@ -0,0 +1,13 @@ +tests +testMatchesMultipleSenders + + | spec expectedSenderMessage anotherSenderMessage | + spec := SpecOfExpectedObjectSender for: #object returnedFrom: ( + SpecOfExpectedMessage from: (MockOccurredMessage receiver: #receiver selector: #selector)). + + expectedSenderMessage := MockOccurredMessage receiver: #receiver selector: #selector. + expectedSenderMessage result: #object asOccurredMessageResult. + anotherSenderMessage := MockOccurredMessage receiver: #receiver selector: #anotherSelector. + anotherSenderMessage result: #object asOccurredMessageResult. + + spec should be matches: {anotherSenderMessage. expectedSenderMessage} \ No newline at end of file diff --git a/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testSucceedValidationOfMultipleSenders.st b/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testSucceedValidationOfMultipleSenders.st new file mode 100644 index 0000000..7d4af9e --- /dev/null +++ b/Mocketry-Specs-Tests.package/SpecOfExpectedObjectSenderTests.class/instance/testSucceedValidationOfMultipleSenders.st @@ -0,0 +1,15 @@ +tests +testSucceedValidationOfMultipleSenders + + | spec result expectedSenderMessage anotherSenderMessage | + spec := SpecOfExpectedObjectSender for: #object returnedFrom: ( + SpecOfExpectedMessage from: (MockOccurredMessage receiver: #receiver selector: #selector)). + + expectedSenderMessage := MockOccurredMessage receiver: #receiver selector: #selector. + expectedSenderMessage result: #object asOccurredMessageResult. + anotherSenderMessage := MockOccurredMessage receiver: #receiver selector: #anotherSelector. + anotherSenderMessage result: #object asOccurredMessageResult. + + result := spec validate: { anotherSenderMessage. expectedSenderMessage }. + + result should be: SpecOfValidationResult success \ No newline at end of file diff --git a/Mocketry-Specs-Tests.package/monticello.meta/categories.st b/Mocketry-Specs-Tests.package/monticello.meta/categories.st index c2252fe..36f63b3 100644 --- a/Mocketry-Specs-Tests.package/monticello.meta/categories.st +++ b/Mocketry-Specs-Tests.package/monticello.meta/categories.st @@ -1 +1 @@ -SystemOrganization addCategory: 'Mocketry-Specs-Tests'! +SystemOrganization addCategory: #'Mocketry-Specs-Tests'! diff --git a/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/basicMatches..st b/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/basicMatches..st index f5c3a58..2a23dad 100644 --- a/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/basicMatches..st +++ b/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/basicMatches..st @@ -1,9 +1,7 @@ testing basicMatches: occurredMessages - | actualSender | - actualSender := occurredMessages - detect: [:each | each hasReturnedValueLike: object] - ifNone: [^false]. + | actualSenders | + actualSenders := occurredMessages select: [:each | each hasReturnedValueLike: object]. - ^requiredSender basicMatches: { actualSender } \ No newline at end of file + ^requiredSender basicMatches: actualSenders \ No newline at end of file diff --git a/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/validate..st b/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/validate..st index df7b3d9..30d903a 100644 --- a/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/validate..st +++ b/Mocketry-Specs.package/SpecOfExpectedObjectSender.class/instance/validate..st @@ -1,11 +1,10 @@ validation validate: occurredMessages - | actualSender success | - actualSender := occurredMessages - detect: [ :each | each hasReturnedValueLike: object ] - ifNone: [ ^ self validateRequiredSenderFor: occurredMessages ]. - - success := requiredSender matches: {actualSender}. + | actualSenders success | + actualSenders := occurredMessages select: [ :each | each hasReturnedValueLike: object ]. + actualSenders ifEmpty: [ ^ self validateRequiredSenderFor: occurredMessages ]. + + success := requiredSender matches: actualSenders. success ifTrue: [ ^ SpecOfValidationResult success ]. - ^ SpecOfWrongObjectSender spec: self for: occurredMessages wrongSender: actualSender \ No newline at end of file + ^ SpecOfWrongObjectSender spec: self for: occurredMessages wrongSender: actualSenders last \ No newline at end of file