Skip to content

Commit

Permalink
Rename Predicate to Matcher (#7)
Browse files Browse the repository at this point in the history
* Bump version to 4.0 RC

* Rename Predicate to Matcher

* Fix version number

* Bump version to 4.0.0 release

* rename documentation

* Remove RC reference
  • Loading branch information
tahirmt authored Oct 10, 2023
1 parent 58cccd8 commit 0c603ba
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Example/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ target 'Nimble-SnapshotTesting_Example' do
pod 'SnapshotTesting'
pod 'Nimble-SnapshotTesting', :path => '../'
pod 'Quick', '~> 7'
pod 'Nimble', '~> 12'
pod 'Nimble', '~> 13.0.0'
end
end
20 changes: 10 additions & 10 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
PODS:
- Nimble (12.0.1)
- Nimble-SnapshotTesting (2.0.1):
- Nimble
- Nimble (13.0.0)
- Nimble-SnapshotTesting (4.0.0):
- Nimble (~> 13.0.0)
- SnapshotTesting
- Quick (7.0.2)
- Quick (7.3.0)
- SnapshotTesting (1.9.0)

DEPENDENCIES:
- Nimble (~> 12)
- Nimble (~> 13.0.0)
- Nimble-SnapshotTesting (from `../`)
- Quick (~> 7)
- SnapshotTesting
Expand All @@ -23,11 +23,11 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
Nimble: b279b3ca9e094508778aab5c76417be158d3ad04
Nimble-SnapshotTesting: 70787bbe3a271e94476a32a145209e0b53409b93
Quick: efab97aca76d60be86c15daa533b2cdfbe1a74d3
Nimble: 97d90931cca412a23224ff29e258809f75c258f7
Nimble-SnapshotTesting: 95c1ec69d0745dcb304b79d55ab38e6f5a781f0a
Quick: d32871931c05547cb4e0bc9009d66a18b50d8558
SnapshotTesting: 6141c48b6aa76ead61431ca665c14ab9a066c53b

PODFILE CHECKSUM: 0a0ba5d1feaf92d165e27cb7d51e9ba28caab8f8
PODFILE CHECKSUM: 9c17906356f55e47e846539957bc30659e660785

COCOAPODS: 1.12.1
COCOAPODS: 1.13.0
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gem "activesupport", "= 7.0.8"
gem 'cocoapods', '1.13.0'
95 changes: 95 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
GEM
specs:
CFPropertyList (3.0.6)
rexml
activesupport (7.0.8)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
addressable (2.8.5)
public_suffix (>= 2.0.2, < 6.0)
algoliasearch (1.27.5)
httpclient (~> 2.8, >= 2.8.3)
json (>= 1.5.1)
atomos (0.1.3)
claide (1.1.0)
cocoapods (1.13.0)
addressable (~> 2.8)
claide (>= 1.0.2, < 2.0)
cocoapods-core (= 1.13.0)
cocoapods-deintegrate (>= 1.0.3, < 2.0)
cocoapods-downloader (>= 1.6.0, < 2.0)
cocoapods-plugins (>= 1.0.0, < 2.0)
cocoapods-search (>= 1.0.0, < 2.0)
cocoapods-trunk (>= 1.6.0, < 2.0)
cocoapods-try (>= 1.1.0, < 2.0)
colored2 (~> 3.1)
escape (~> 0.0.4)
fourflusher (>= 2.3.0, < 3.0)
gh_inspector (~> 1.0)
molinillo (~> 0.8.0)
nap (~> 1.0)
ruby-macho (>= 2.3.0, < 3.0)
xcodeproj (>= 1.23.0, < 2.0)
cocoapods-core (1.13.0)
activesupport (>= 5.0, < 8)
addressable (~> 2.8)
algoliasearch (~> 1.0)
concurrent-ruby (~> 1.1)
fuzzy_match (~> 2.0.4)
nap (~> 1.0)
netrc (~> 0.11)
public_suffix (~> 4.0)
typhoeus (~> 1.0)
cocoapods-deintegrate (1.0.5)
cocoapods-downloader (1.6.3)
cocoapods-plugins (1.0.0)
nap
cocoapods-search (1.0.1)
cocoapods-trunk (1.6.0)
nap (>= 0.8, < 2.0)
netrc (~> 0.11)
cocoapods-try (1.2.0)
colored2 (3.1.2)
concurrent-ruby (1.2.2)
escape (0.0.4)
ethon (0.16.0)
ffi (>= 1.15.0)
ffi (1.16.3)
fourflusher (2.3.1)
fuzzy_match (2.0.4)
gh_inspector (1.1.3)
httpclient (2.8.3)
i18n (1.14.1)
concurrent-ruby (~> 1.0)
json (2.6.3)
minitest (5.20.0)
molinillo (0.8.0)
nanaimo (0.3.0)
nap (1.1.0)
netrc (0.11.0)
public_suffix (4.0.7)
rexml (3.2.6)
ruby-macho (2.5.1)
typhoeus (1.4.0)
ethon (>= 0.9.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
xcodeproj (1.23.0)
CFPropertyList (>= 2.3.3, < 4.0)
atomos (~> 0.1.3)
claide (>= 1.0.2, < 2.0)
colored2 (~> 3.1)
nanaimo (~> 0.3.0)
rexml (~> 3.2.4)

PLATFORMS
arm64-darwin-22

DEPENDENCIES
activesupport (= 7.0.8)
cocoapods (= 1.13.0)

BUNDLED WITH
2.4.13
4 changes: 2 additions & 2 deletions Nimble-SnapshotTesting.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Nimble-SnapshotTesting'
s.version = '3.0.0'
s.version = '4.0.0'
s.summary = 'A Nimble matcher for snapshot testing'
s.description = <<-DESC
A Nimble matcher for snapshot testing library.
Expand All @@ -13,7 +13,7 @@ Pod::Spec.new do |s|

s.frameworks = "Foundation", "XCTest", "UIKit"
s.dependency "SnapshotTesting"
s.dependency "Nimble"
s.dependency "Nimble", '~> 13.0.0'

s.ios.deployment_target = '13.0'
s.swift_versions = [5.0, 5.1, 5.2, 5.3, 5.4]
Expand Down
42 changes: 21 additions & 21 deletions Nimble-SnapshotTesting/Classes/HaveValidSnapshot.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private enum Counter {
/// - testName: The name of the test in which failure occurred. Defaults to a sanitized name based on the quick context.
/// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
/// - function: The function name. This is used as a fallback if the currently running test is not found
/// - Returns: A predicate to use in Nimble
/// - Returns: A matcher to use in Nimble
public func haveValidSnapshot<Value, Format>(
as strategy: Snapshotting<Value, Format>,
named name: String? = nil,
Expand All @@ -58,7 +58,7 @@ public func haveValidSnapshot<Value, Format>(
testName: String? = nil,
line: UInt = #line,
function: String = #function
) -> Predicate<Value> {
) -> Matcher<Value> {
haveValidSnapshot(as: [strategy],
named: name,
record: record,
Expand All @@ -82,7 +82,7 @@ public func haveValidSnapshot<Value, Format>(
/// - testName: The name of the test in which failure occurred. Defaults to a sanitized name based on the quick context.
/// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
/// - function: The function name. This is used as a fallback if the currently running test is not found
/// - Returns: A predicate to use in Nimble
/// - Returns: A matcher to use in Nimble
public func haveValidSnapshot<Value, Format>(
as strategies: [Snapshotting<Value, Format>],
named name: String? = nil,
Expand All @@ -93,10 +93,10 @@ public func haveValidSnapshot<Value, Format>(
testName: String? = nil,
line: UInt = #line,
function: String = #function
) -> Predicate<Value> {
return Predicate { actualExpression in
) -> Matcher<Value> {
return Matcher { actualExpression in
guard let value = try actualExpression.evaluate() else {
return PredicateResult(status: .fail, message: .fail("have valid snapshot"))
return MatcherResult(status: .fail, message: .fail("have valid snapshot"))
}

let testName = testName ?? CurrentTestCaseTracker.shared.currentTestCase?.sanitizedName ?? function
Expand All @@ -117,7 +117,7 @@ public func haveValidSnapshot<Value, Format>(
}
}

return PredicateResult(
return MatcherResult(
bool: failureMessages.isEmpty,
message: .fail(failureMessages.joined(separator: ",\n"))
)
Expand All @@ -132,40 +132,40 @@ public extension PollingDefaults {
}

public extension SyncExpectation {
/// Uses `toEventually` to test the predicate only if the snapshot global recording mode is turned off. If the recording mode is on it will use a `to` expectation with the `recordingDelay`.
/// Uses `toEventually` to test the matcher only if the snapshot global recording mode is turned off. If the recording mode is on it will use a `to` expectation with the `recordingDelay`.
/// - Parameters:
/// - predicate: The predicate to evaluate. Ideally, we should only use the `haveValidSnapshot` predicate here with a `recordingDelay`
/// - matcher: The matcher to evaluate. Ideally, we should only use the `haveValidSnapshot` matcher here with a `recordingDelay`
/// - timeout: The timeout for the test
/// - pollInterval: The polling interval for the test. It uses `AsyncDefaults.snapshotPollInterval` as the default
/// - description: Additional description for the test
@available(*, noasync, message: "the sync version of `toEventuallyIfTestingSnapshots` does not work in async contexts. Use the async version with the same name as a drop-in replacement")
func toEventuallyIfTestingSnapshots(_ predicate: Predicate<Value>,
func toEventuallyIfTestingSnapshots(_ matcher: Matcher<Value>,
timeout: NimbleTimeInterval = PollingDefaults.timeout,
pollInterval: NimbleTimeInterval = PollingDefaults.snapshotPollInterval,
description: String? = nil) {
if isRecordingSnapshots {
to(predicate, description: description)
to(matcher, description: description)
}
else {
toEventually(predicate, timeout: timeout, pollInterval: pollInterval, description: description)
toEventually(matcher, timeout: timeout, pollInterval: pollInterval, description: description)
}
}

/// Uses `toEventually` to test the predicate only if the snapshot global recording mode is turned off. If the recording mode is on it will use a `to` expectation with the `recordingDelay`.
/// Uses `toEventually` to test the matcher only if the snapshot global recording mode is turned off. If the recording mode is on it will use a `to` expectation with the `recordingDelay`.
/// - Parameters:
/// - predicate: The predicate to evaluate. Ideally, we should only use the `haveValidSnapshot` predicate here with a `recordingDelay`
/// - matcher: The matcher to evaluate. Ideally, we should only use the `haveValidSnapshot` matcher here with a `recordingDelay`
/// - timeout: The timeout for the test
/// - pollInterval: The polling interval for the test. It uses `AsyncDefaults.snapshotPollInterval` as the default
/// - description: Additional description for the test
func toEventuallyIfTestingSnapshots(_ predicate: Predicate<Value>,
func toEventuallyIfTestingSnapshots(_ matcher: Matcher<Value>,
timeout: NimbleTimeInterval = PollingDefaults.timeout,
pollInterval: NimbleTimeInterval = PollingDefaults.snapshotPollInterval,
description: String? = nil) async {
if isRecordingSnapshots {
to(predicate, description: description)
to(matcher, description: description)
}
else {
await toEventually(predicate, timeout: timeout, pollInterval: pollInterval, description: description)
await toEventually(matcher, timeout: timeout, pollInterval: pollInterval, description: description)
}
}
}
Expand All @@ -181,7 +181,7 @@ public extension SyncExpectation {
/// - testName: The name of the test in which failure occurred. Defaults to a sanitized name based on the quick context.
/// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
/// - function: The function name. This is used as a fallback if the currently running test is not found
/// - Returns: A predicate to use in Nimble
/// - Returns: A matcher to use in Nimble
public func haveValidSnapshot<Value, Format>(
as strategy: Snapshotting<Value, Format>,
named name: String? = nil,
Expand All @@ -193,7 +193,7 @@ public func haveValidSnapshot<Value, Format>(
testName: String? = nil,
line: UInt = #line,
function: String = #function
) -> Predicate<Value> {
) -> Matcher<Value> {
haveValidSnapshot(as: [strategy],
named: name,
record: record,
Expand Down Expand Up @@ -245,7 +245,7 @@ private func testCaseIdentifier(line: UInt) -> String {
/// - testName: The name of the test in which failure occurred. Defaults to a sanitized name based on the quick context.
/// - line: The line number on which failure occurred. Defaults to the line number on which this function was called.
/// - function: The function name. This is used as a fallback if the currently running test is not found
/// - Returns: A predicate to use in Nimble
/// - Returns: A matcher to use in Nimble
public func haveValidSnapshot<Value, Format>(
as strategies: [Snapshotting<Value, Format>],
named name: String? = nil,
Expand All @@ -257,7 +257,7 @@ public func haveValidSnapshot<Value, Format>(
testName: String? = nil,
line: UInt = #line,
function: String = #function
) -> Predicate<Value> {
) -> Matcher<Value> {
if SnapshotTesting.isRecording || record {
return haveValidSnapshot(as: strategies.map { .wait(for: recordDelay, on: $0) },
named: name,
Expand Down

0 comments on commit 0c603ba

Please sign in to comment.