Skip to content

Instantly share code, notes, and snippets.

View Andrea-Scuderi's full-sized avatar

Andrea Scuderi Andrea-Scuderi

View GitHub Profile
@Andrea-Scuderi
Andrea-Scuderi / .swift
Last active September 3, 2019 11:24
URLProtocolMock
import Foundation
//References:
// --: https://www.hackingwithswift.com/articles/153/how-to-test-ios-networking-code-the-easy-way
// --: https://nshipster.com/nsurlprotocol/
@objc class URLProtocolMock: URLProtocol {
// this dictionary maps URLs to test data
static var testURLs = [URL?: Data]()
static var response: URLResponse?
@Andrea-Scuderi
Andrea-Scuderi / .swift
Created September 3, 2019 12:37
XCTTest Publisher utils
func evalValidResponseTest<T:Publisher>(publisher: T?) -> (expectations:[XCTestExpectation], cancellable: AnyCancellable?) {
XCTAssertNotNil(publisher)
let expectationFinished = expectation(description: "finished")
let expectationReceive = expectation(description: "receiveValue")
let expectationFailure = expectation(description: "failure")
expectationFailure.isInverted = true
let cancellable = publisher?.sink (receiveCompletion: { (completion) in
switch completion {
@Andrea-Scuderi
Andrea-Scuderi / .swift
Created September 3, 2019 12:46
Create XCTest
func testCreate() {
//Setup fixture
let usersURL = URL(string: APIDemo.baseURL + "/users")
URLProtocolMock.testURLs = [usersURL: Data(Fixtures.createUserResponse.utf8)]
//1) When is valid
APIDemo.publisher = customPublisher
URLProtocolMock.response = mocks.validResponse
let publisher = APIDemo.create(user: self.mocks.user)
@Andrea-Scuderi
Andrea-Scuderi / .swift
Created September 3, 2019 12:49
CombineAPIDemoTests
import XCTest
import Foundation
import Combine
@testable import CombineAPIDemo
class Mocks {
let user = User(name: "name",
email: "email",
password: "password",
@Andrea-Scuderi
Andrea-Scuderi / Dockerfile.emerge
Last active January 15, 2022 13:31
Dockerfile-emerge
FROM python:3.9.9-slim-buster
RUN apt-get -qq update
RUN apt-get install -qqy graphviz graphviz-dev gcc
RUN rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip
RUN pip install emerge-viz
@Andrea-Scuderi
Andrea-Scuderi / Makefile.emerge
Last active January 15, 2022 13:34
Makefile.emerge
MOUNT_ROOT=$(shell pwd)
DOCKER_TAG=emerge:1.0.0
docker_build:
docker build --tag $(DOCKER_TAG) .
docker_bash:
docker run \
-it \
--rm \