Comments (3)
Postponing - will not be part of 2.0.0
from swiftymocky.
@Przemyslaw-Wosko I'm finishing PR for sequencing. It got a bit bigger than I thought, as I also added policies for better mock control.
let mock = SimpleProtocolWithMethodsMock()
Given(mock, .simpleMehtodThatReturns(willReturn: 1,2,3))
while true {
mock.simpleMehtodThatReturns()
}
// 1, 2, 3, 1, 2, 3, 1, 2, 3, ...
Similar for errors:
let mock = ProtocolWithThrowingMethodsMock()
Given(mock, .methodThatThrows(willThrow: TestError.first, TestError.second, TestError.third))
while true {
try? mock.methodThatThrows()
}
// throwing TestError.first, TestError.second, ...
Also, as we might want to mix the stuff, new Given option is created:
let mock = ProtocolWithThrowingMethodsMock()
Given(mock, .methodThatReturnsAndThrows(param: .any, willProduce: { make in
make.throw(TestError.first)
make.throw(TestError.second)
make.throw(TestError.third)
make.return(true)
make.return(true)
make.return(true)
make.return(true)
}))
while true {
try? mock.methodThatReturnsAndThrows(param: 0)
}
// TestError.first, TestError.second, TestError.third, true, true, true , true, ...
// (go back to the beginning of sequence)
Need some feedback about that part.
As for policies, I'm proposing two:
- StubbingPolicy defined for mock in general, and per method stub in particular (if not defined, using mock default value)
- default - it's default :) use mock default policy
- wrap - default one, iterate over sequence of return values indefinetely
- drop - every returned/throw value is being consumed, so it will not be reused again.
- SequencingPolicy - in what order should we process Given's.
- lastWrittenResolvedFirst - default, same behaviour as SwiftyMocky have now. We process givens from most specific ones to most general, and if they are same, last written hides previous one.
- inWritingOrder - We process givens from most specific ones to most general, and if they are same, we process them in writing order
Simple examples:
// Default policy is drop, so if not specified differently, every given return/throw value
// will be consumed once
let mock = ProtocolWithThrowingMethodsMock(sequencing: .inWritingOrder, stubbing: .drop)
Given(mock, .methodThatReturnsAndThrows(param: .any, willThrow: TestError.first))
Given(mock, .methodThatReturnsAndThrows(param: .any, willThrow: TestError.second))
Given(mock, .methodThatReturnsAndThrows(param: .any, willThrow: TestError.third))
Given(mock, .methodThatReturnsAndThrows(param: .any, willReturn: true), .wrap)
// TestError.first, .second, .third, true, true, true .... (forever, as the last given has policy wrap)
let mock = SimpleProtocolWithMethodsMock()
mock.stubbingPolicy = .drop
Given(mock, .simpleMehtodThatReturns(willReturn: 5))
Given(mock, .simpleMehtodThatReturns(willReturn: 1,2,3))
while true {
mock.simpleMehtodThatReturns()
}
// 1, 2, 3, 5, [fatal error] - no stubs defined for method ...
For these I'll also need some feedback.
from swiftymocky.
v3.0.0
from swiftymocky.
Related Issues (20)
- Compilation Performance Issues HOT 2
- Mock generation failure for Swift Package when using actor objects in package HOT 3
- Feature Request: View controller and view mocking support.
- Missing parenthesis optional existential type (any ProtocolName) properties
- Mock a protocol in an SPM dependency framework.
- Feature request: Allow partial mocks for testable subclasses
- Stubber with factory behavior
- Invalid redeclaration error in .generated file while using tuples with typealias
- Can't Download CLI tool
- generate command fails on xcode cloud HOT 1
- Use XCTestDynamicOverlay
- _InternalSwiftSyntaxParser is missing again HOT 2
- Issue with ShellOut dependency with SPM HOT 1
- How to add generated file with swiftlint rules in version 4.2.0 with new Mockfile format HOT 1
- There is no fallback data, if no 'Given` method provided. HOT 1
- How to include swift package file in mockfile
- cannot decode object of class (SwiftActor) for key (NS.objects) because no class named "SwiftActor" was found HOT 2
- outdated Sourcery version (1.8.0) doesn't build on macos ventura (apple silicon)
- Conflict with swift-openapi-generator
- Mocked return value is different for different cases
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swiftymocky.