You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please describe the expected behavior of the issue
Specs2 test example should fail when assertion is changed to be not true
Please provide a description of what actually happens
Hello - I'm new to the library and was experimenting with the example test cases provided:
when changing an assertion in OrderSpecification (to expect the mock to be called twice rather than once) a test failure wasn't reported (when running sbt "testOnly com.example.OrderSpecification")
adding a "Record-then-Verify style" test, I could write a test with a .verify that wouldn't report a failure when a different product name was provided
However, changing the test class to mix in IsolatedMockFactory (rather than using MockContext) caused the modified tests to fail (as desired).
Reproducible Test Case
packagecom.exampleimportorg.scalamock.specs2.MockContextimportorg.specs2.mutable.Specification/** * This is a demonstration and test of the Specs2 integration, using the example from * Martin Fowler's article Mocks Aren't Stubs http://martinfowler.com/articles/mocksArentStubs.html*/classOrderSpecificationextendsSpecification {
"An order" should {
"remove inventory when in stock" in newMockContext {
valmockWarehouse= mock[Warehouse]
inSequence {
(mockWarehouse.hasInventory _).expects("Talisker", 50).returning(true).once
(mockWarehouse.remove _).expects("Talisker", 50).once
}.twice //no failure reportedvalorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beTrue
}
"remove inventory (Record-then-Verify style)" in newMockContext {
valmockWarehouse= stub[Warehouse]
(mockWarehouse.hasInventory _).when("Talisker", 50).returns(true)
valorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
assert(order.isFilled)
(mockWarehouse.hasInventory _).verify("DifferentProduct", 50).once //no failure reported
(mockWarehouse.remove _).verify("DifferentProduct", 50).repeat(2) //no failure reported
}
"remove nothing when out of stock" in newMockContext {
valmockWarehouse= mock[Warehouse]
(mockWarehouse.hasInventory _).expects(*, *).returning(false).repeat(2) //no failure reportedvalorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beFalse
}
"remove nothing when out of stock (Record-then-Verify style)" in newMockContext {
valmockWarehouse= stub[Warehouse]
(mockWarehouse.hasInventory _).when(*, *).returns(false)
valorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beFalse
(mockWarehouse.hasInventory _).verify("DifferentProduct", *).once //no failure reported
}
}
}
Failures reported using IsolatedMockFactory
packagecom.exampleimportorg.scalamock.specs2.IsolatedMockFactoryimportorg.specs2.mutable.Specification/** * This is a demonstration and test of the Specs2 integration, using the example from * Martin Fowler's article Mocks Aren't Stubs http://martinfowler.com/articles/mocksArentStubs.html*/classOrderIsolatedSpecificationextendsSpecificationwithIsolatedMockFactory {
"An order" should {
"remove inventory when in stock" in {
valmockWarehouse= mock[Warehouse]
inSequence {
(mockWarehouse.hasInventory _).expects("Talisker", 50).returning(true).once
(mockWarehouse.remove _).expects("Talisker", 50).once
}.twice //failure reportedvalorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beTrue
}
"remove inventory (Record-then-Verify style)" in {
valmockWarehouse= stub[Warehouse]
(mockWarehouse.hasInventory _).when("Talisker", 50).returns(true)
valorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
assert(order.isFilled)
(mockWarehouse.hasInventory _).verify("DifferentProduct", 50).once //failure reported
(mockWarehouse.remove _).verify("DifferentProduct", 50).repeat(2) //failure reported
order.isFilled must beTrue //adding here so test compiles
}
"remove nothing when out of stock" in {
valmockWarehouse= mock[Warehouse]
(mockWarehouse.hasInventory _).expects(*, *).returning(false).repeat(2) //failure reportedvalorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beFalse
}
"remove nothing when out of stock (Record-then-Verify style)" in {
valmockWarehouse= stub[Warehouse]
(mockWarehouse.hasInventory _).when(*, *).returns(false)
valorder=newOrder("Talisker", 50)
order.fill(mockWarehouse)
order.isFilled must beFalse
(mockWarehouse.hasInventory _).verify("DifferentProduct", *).once //failure reported
order.isFilled must beFalse //adding here so test compiles
}
}
}
The text was updated successfully, but these errors were encountered:
ScalaMock Version (e.g. 3.5.0)
5.3.0-SNAPSHOT
Scala Version (e.g. 2.12)
2.13.6
Runtime (JVM or JS)
JVM
Please describe the expected behavior of the issue
Specs2 test example should fail when assertion is changed to be not true
Please provide a description of what actually happens
Hello - I'm new to the library and was experimenting with the example test cases provided:
OrderSpecification
(to expect the mock to be called twice rather than once) a test failure wasn't reported (when runningsbt "testOnly com.example.OrderSpecification"
).verify
that wouldn't report a failure when a different product name was providedHowever, changing the test class to mix in
IsolatedMockFactory
(rather than usingMockContext
) caused the modified tests to fail (as desired).Reproducible Test Case
Failures reported using
IsolatedMockFactory
The text was updated successfully, but these errors were encountered: