Skip to content

Commit

Permalink
change span mocking after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
philprime committed Feb 26, 2025
1 parent 52336a6 commit 79576cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
12 changes: 4 additions & 8 deletions SentryTestUtils/Mocks/MockSentryScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,14 @@ public class MockSentryScope: Scope, SentryMockable {
// MARK: - Mock Helpers

public func clearAllMocks() {
mockUseSpan.clear()
// replace me
}

// MARK: - Mock Functions

public var mockUseSpan = MockFunction1<Void, SentrySpanCallback>()
// replace me

// MARK: - Overridden Functions
// MARK: - Override Functions

public override func useSpan(_ callback: @escaping SentrySpanCallback) {
mockUseSpan.call(callback, default: { arg1 in
super.useSpan(arg1)
})
}
// replace me
}
4 changes: 4 additions & 0 deletions SentryTestUtils/Mocks/MockSentrySpan.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import SentryTestMock
/// - Warning: It might be incomplete, so make sure to implement the necessary methods when writing tests.
public class MockSentrySpan: SentrySpan, SentryMockable {
public init() {
#if SENTRY_HAS_UIKIT
super.init(context: MockSpanContext())
#else
super.init(context: MockSpanContext(), framesTracker: nil)

Check failure on line 12 in SentryTestUtils/Mocks/MockSentrySpan.swift

View workflow job for this annotation

GitHub Actions / Unit macOS - Xcode 15.4 - OS latest Sentry

'nil' requires a contextual type

Check failure on line 12 in SentryTestUtils/Mocks/MockSentrySpan.swift

View workflow job for this annotation

GitHub Actions / Unit macOS - Xcode 16.2 - OS latest Sentry

'nil' requires a contextual type
#endif
}

// MARK: - Mock Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ class DataSentryTracingTests: XCTestCase {

let mockParentSpan = MockSentrySpan()
mockParentSpan.mockStartChildWithOperationDescription.returnValue(ioSpan)
mockedSentryScope.mockUseSpan.useImplementation { callback in
callback(mockParentSpan)
}
mockedSentryScope.span = mockParentSpan

fileIOTracker.enable()

Expand All @@ -90,7 +88,6 @@ class DataSentryTracingTests: XCTestCase {
XCTAssertEqual(ioSpan.startTimestamp, expectedStartTimestamp)
XCTAssertEqual(ioSpan.timestamp, expectedEndTimestamp)

sentryExpect(mockedSentryScope.mockUseSpan).toHaveBeenCalled()
sentryExpect(mockParentSpan.mockStartChildWithOperationDescription)
.toHaveBeenCalledWith(
SentrySpanOperation.fileRead,
Expand Down

0 comments on commit 79576cd

Please sign in to comment.