mimus-swift / mimus Goto Github PK
View Code? Open in Web Editor NEWSwift Mocking Library
License: MIT License
Swift Mocking Library
License: MIT License
Right now if we get arguments mismatch Mimus will print out
failed - Call with identifier x was recorded, but arguments didn't match
Which is a bit too cryptic, we could use Swifts CustomStringConvertible
and String(describing: )
to display captured and expected values, this would be helpful when debugging failures.
Edit: OCMockito has an amazing reporting similar to what we want to achieve here:
Argument(s) are different!
Wanted: start:"Fixture App Center Identifier" withServices:<(
)>
Actual invocation has different arguments:
start:@"Fixture App Center Identifier" withServices:@[MSAnalytics, MSCrashes]
Mismatch in 2nd argument. Expected <(
)>, but was <(
MSAnalytics,
MSCrashes
)>
MyApp -[AppConfigurator configureAppWithConfiguration:] + 397
Looks like we've also missed this one!
Right now custom matchers might require complicated logic as they cannot leverage internal components of Mimus.
For instance, consider following scenario. We're trying to write a custom matcher for URLRequest
. In that matcher we need to compare URL?
and [String: String]?
.
That means we need to do the usual dance of unwrapping, checking for equality etc:
public func equalTo(other: MockEquatable?) -> Bool {
if let otherURLRequest = other as? URLRequest {
var urlsMatch = false
var headersMatch = false
if self.url == nil, otherURLRequest.url == nil {
urlsMatch = true
} else {
if let actualURL = otherURLRequest.url, let expectedURL = self.url {
urlsMatch = actualURL == expectedURL
}
}
if self.allHTTPHeaderFields == nil, otherURLRequest.allHTTPHeaderFields == nil {
headersMatch = true
} else {
if let actualHeaders = otherURLRequest.allHTTPHeaderFields, let expectedHeaders = self.allHTTPHeaderFields {
headersMatch = actualHeaders == expectedHeaders
}
}
//TODO: Move this to Mimus? Find a way we can leverage Mimus.Matcher
return urlsMatch && headersMatch
}
return false
}
This could be greatly simplified by using Mimus Matcher
class:
public func equalTo(other: MockEquatable?) -> Bool {
if let otherURLRequest = other as? URLRequest {
let matcher: Mimus.Matcher = // Get the matcher from somewhere?
return matcher.match(expected: [self.url, self.allHTTPHeaderFields], actual: [otherURLRequest.url, otherURLRequest.allHTTPHeaderFields])
}
return false
}
Right now there's no way to easily say "for these set or arguments return this value". We already have infrastructure for recording calls, matchers and matching arguments so this should not be that complicated (albeit this sounds like famous last words).
Basically for following scenario there is a usability issue:
In this case the message will be Call with identifier xyz was recorded 1 times, but expected at least 2
. Would be nice to handle this so the the programmer knows 1 call matches, but there's another one with different arguments.
Somewhat related to #13.
Right now you need to pass exact argument count:
object.verifyCall(withIdentifier: "identifier", arguments: [AnyMatcher(), AnyMatcher()])
Would be nice to specify this as any matcher in general:
object.verifyCall(withIdentifier: "identifier", arguments: .any])
We could leverage ExpressibleByArrayLiteral
for this.
Expected message:
Arguments didn't match
Actual:
Attempted to compare unsupported dictionary types. Values should conform to MockEquatable
class InstanceOf<T>: MockEquatable {
func equalTo(other: MockEquatable?) -> Bool {
return other is T
}
}
We will need to make minor adjustments to how types are hold though.
Looks like we've forgot to add support for Swift URL type. Might be a good idea to throw in support for NSURL
as well.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.