Skip to content

Commit

Permalink
Inject calendar to make tests reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
ullas-jain committed Nov 21, 2023
1 parent bd099f5 commit 112bc3a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions EssentialFeedTests/Helpers/SharedTestHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ extension Date {
return self + seconds
}

func adding(minutes: Int) -> Date {
return Calendar(identifier: .gregorian).date(byAdding: .minute, value: minutes, to: self)!
func adding(minutes: Int, calendar: Calendar = Calendar(identifier: .gregorian)) -> Date {
return calendar.date(byAdding: .minute, value: minutes, to: self)!
}

func adding(days: Int) -> Date {
return Calendar(identifier: .gregorian).date(byAdding: .day, value: days, to: self)!
func adding(days: Int, calendar: Calendar = Calendar(identifier: .gregorian)) -> Date {
return calendar.date(byAdding: .day, value: days, to: self)!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ class ImageCommentsPresenterTests: XCTestCase {
ImageComment(
id: UUID(),
message: "a message",
createdAt: now.adding(minutes: -5),
createdAt: now.adding(minutes: -5, calendar: calendar),
username: "a username"
),
ImageComment(
id: UUID(),
message: "another message",
createdAt: now.adding(days: -1),
createdAt: now.adding(days: -1, calendar: calendar),
username: "another username"
),
]
Expand Down

0 comments on commit 112bc3a

Please sign in to comment.