Skip to content

Instantly share code, notes, and snippets.

@pedrommcarrasco
Last active January 7, 2019 11:16
Show Gist options
  • Save pedrommcarrasco/d8108a5519e9ee4fee1965d8cb0671f9 to your computer and use it in GitHub Desktop.
Save pedrommcarrasco/d8108a5519e9ee4fee1965d8cb0671f9 to your computer and use it in GitHub Desktop.
Let's Talk About: Double Standards - Copy-Pastability (before)
private enum Constant {
static let scenarioAFile = "screenScenarioA"
static let scenarioBFile = "screenScenarioB"
}
func testScenarioA() {
// Arrange
guard let filePath = Bundle(for: type(of: self)).path(forResource: Constant.scenarioAFile, ofType: FileType.json),
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: .allowFragments),
else { return XCTFail("Failed to load JSON") }
// Act
screenStructureManager.update(with: jsonObject)
let result = screenStructureManager.current
let expectedResult: [Component] = [.header, .products]
// Assert
XCTAssertEqual(result, expectedResult)
}
func testScenarioB() {
// Arrange
guard let filePath = Bundle(for: type(of: self)).path(forResource: Constant.scenarioBFile, ofType: FileType.json),
let data = try? Data(contentsOf: URL(fileURLWithPath: filePath)),
let jsonObject = try? JSONSerialization.jsonObject(with: data, options: .allowFragments),
else { return XCTFail("Failed to load JSON") }
// Act
screenStructureManager.update(with: jsonObject)
let result = screenStructureManager.current
let expectedResult: [Component] = [.header, .promoBanner, .products, .footer]
// Assert
XCTAssertEqual(result, expectedResult)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment