Coder Social home page Coder Social logo

mocknetworking's People

Contributors

machx avatar

Watchers

 avatar  avatar  avatar

mocknetworking's Issues

Change URLPropertyStore to something else

URLPropertyStore sounds too official and doesn't sound like something from this package. I'd like to find a name that sounds more like it fits in with the expected naming style from this project.

URLResponse custom isEqual func for or custom XCTAssert for unit tests

URLResponse considers fields that MockNetworking doesn't care about such as mime type in the equality comparison. For unit test purposes only a better equality method/assertion should be made using 1 of 2 methods

  1. Make a XCTAsser func that works better for URLResponse
  2. Make a better (for unit tests) equal func for comparison of 2 responses

Implement Cancel request

Currently there is an API

public override func stopLoading() {
	//
}

this should probably operate like NSOperation's cancel where you make a private variable and then just check it during the course of the load logic

Review why 2 responses coming back in http response test weren't equal

In the test

func testHTTPResponse() throws {
		let url = try XCTUnwrap(URL(string: "https://wwww.apple.com"))
		let response = try XCTUnwrap(HTTPURLResponse(url: url,
									   statusCode: 200,
									   httpVersion: HTTPURLResponse.HTTP_1_1,
									   headerFields: ["thing180":"thing2"]))
		
		MockURLProtocol.register(response: response, for: url)
		defer {
			MockURLProtocol.unregister()
		}
		
		var receivedResponse: URLResponse?
		let expectation = XCTestExpectation()
		URLSession.sessionWith(.ephemeral).downloadTask(with: url) { (url, response, error) in
			receivedResponse = response
			expectation.fulfill()
		}.resume()
		
		wait(for: [expectation], timeout: 5.0)
		
		XCTAssertNotNil(receivedResponse)
		guard let receivedHTTPResponse = receivedResponse as? HTTPURLResponse else {
			XCTFail("Could not convert Response to HTTPURLResponse type")
			return
		}
		XCTAssertEqual(response.url, receivedHTTPResponse.url)
		XCTAssertEqual(response.statusCode, receivedHTTPResponse.statusCode)
		XCTAssertEqual(response.allStringHTTPHeaders(), receivedHTTPResponse.allStringHTTPHeaders())
	}

if you straight ask for the 2 http responses being equal, you will get a negative response back. I suspect that the 2nd response (having gone through URLProtocol) has more fields in it than the one we supplied it to begin with. Should quickly evaluate this and see if a better equality method can be made for the unit test.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.