Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added tests for Single+Response and refactored Shared Test Helpers #1229

Merged
merged 8 commits into from
Aug 17, 2017

Conversation

freak4pc
Copy link
Member

@freak4pc freak4pc commented Aug 16, 2017

This PR adds tests for Single+Response (for RxMoya), fixing issue #1227.

This PR also:

  • Wraps Test Helpers converting Response to Single/Observable under RxTestHelpers.swift.
  • Moves Test Helpers related to generating Test Images to TestHelpers.swift.
  • Reorganize TestHelpers.swift with some MARKs and sectioning of helper methods / classes.

@freak4pc freak4pc changed the base branch from master to 9.0.0-dev August 16, 2017 19:43
@MoyaBot
Copy link

MoyaBot commented Aug 16, 2017

SwiftLint found issues

Warnings

File Line Reason
TestHelpers.swift 3 Limit vertical whitespace to a single empty line. Currently 2.
Single+MoyaSpec.swift 258 Lines should not have trailing whitespace.

Generated by 🚫 Danger

Changelog.md Outdated
@@ -1,4 +1,5 @@
# Next
- Added tests for Single+Response and refactored Shared Test Helpers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if adding tests needs a CHANGELOG entry but we usually list all API breaking changes first.

Copy link
Member Author

@freak4pc freak4pc Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind removing this, I just saw a line saying
"Moved tests to Moya.xcodeproj." so wasn't sure if you usually include this sort of stuff there.

Should I move it to the bottom of breaking or get rid of it completely ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving it to the bottom would be great. Right under where we mention adding Single<Response>.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me ! 👍

@freak4pc
Copy link
Member Author

Updated the Changelog and also did a "Build without Cache" for good luck 🍀

@SD10
Copy link
Member

SD10 commented Aug 16, 2017

@freak4pc I just cleared the cache and triggered a rebuild.
Anyways, thanks for taking care of this so Swiftly 😆 There's some nice cleanup in there.

@freak4pc
Copy link
Member Author

Thanks for the review! @SD10
I'll wait for CI to clear and @sunshinejr to review this and feel free to merge whenever 👍

@freak4pc
Copy link
Member Author

By the way this "cache" issue is probably the fault of scripts/bootstrap-if-needed.sh ...

#if os(OSX)
import AppKit
#else
import Foundation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@freak4pc I think we have to import UIKit to use CGFloat 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was never there AFAIK. I think we need to import Foundation regardless of OS here.

Copy link
Member Author

@freak4pc freak4pc Aug 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also didn't know the tests run on Xcode 9 / iOS 11 :) Haven't tried this locally. Will do a quick test and push a fix for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/Users/distiller/Moya/Tests/TestHelpers.swift:174:50: use of undeclared type 'CGFloat'; did you mean to use 'CGFloat'? -- This is such a weird CI error.

I learned yesterday that CGFloat is not declared in Foundation. It's part of UIKit 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL, perfect error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SD10 GCFloat is actually imported in CoreGraphics, which in turn is not included in Foundation, but is included in UIKit. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BasThomas I came to that realization after awhile! I have to stop thinking in the extreme that everything not in UIKit is Foundation. I originally thought that Foundation imported CoreGraphics because they have an Int.init(CGFloat)... Stopping to think -- it's actually more likely that CoreGraphics extends Foundation with this initializer... I'm such a noob 😆

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://developer.apple.com/documentation/swift/int/1455396-init
->
Framework
Core Graphics

Documentation is* awesome. 😬

* And with is, I mean can be.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that sort of is implicated in the "CG" prefix :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the way this is an even more interesting thing to know:
https://developer.apple.com/documentation/coregraphics/cgfloat/nativetype

@codecov-io
Copy link

codecov-io commented Aug 16, 2017

Codecov Report

Merging #1229 into 9.0.0-dev will increase coverage by 2.75%.
The diff coverage is n/a.

Impacted file tree graph

@@              Coverage Diff              @@
##           9.0.0-dev    #1229      +/-   ##
=============================================
+ Coverage       76.4%   79.16%   +2.75%     
=============================================
  Files             24       24              
  Lines            763      763              
=============================================
+ Hits             583      604      +21     
+ Misses           180      159      -21
Impacted Files Coverage Δ
Sources/RxMoya/Single+Response.swift 100% <0%> (+100%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5cb8f6...96479a2. Read the comment docs.

Changelog.md Outdated
@@ -3,6 +3,7 @@
- **Breaking Change** Flattened `UploadType` and `DownloadType` into `Task` cases.
- Added Swift 4.0 support.
- Added all the `filter`/`map` operators that were available for `Observable<Response>` to `Single<Response>` as well.
- Added tests for Single+Response and refactored Shared Test Helpers.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just:

Added tests for Single<Response> operators.

The refactor part might not be as important in my opinion.

it("maps data representing an image to an image") {
let image = Image.testPNGImage(named: "testImage")
guard let data = image.asJPEGRepresentation(0.75) else {
fail("Failed creating Data from Image")
Copy link
Member

@sunshinejr sunshinejr Aug 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that fatalError might better here, as it is not a failed test, but rather an error in preparation (this one is in few more places as well)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually had fatalError there and changed it to fail "on the last minute". I actually think both are fine but i'll change :)

return self.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
}
}
#if os(OSX)
Copy link
Member

@sunshinejr sunshinejr Aug 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may want to stick to more verbose conditional statements (as we had before):

  #if os(iOS) || os(watchOS) || os(tvOS)
    ...
  #elseif os(OSX)
    ...
  #endif

return Image(contentsOfFile: path!)!
}

#if os(iOS) || os(watchOS) || os(tvOS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we have here 😄

@freak4pc freak4pc force-pushed the feature/rxmoya-single-tests branch 2 times, most recently from 7362f04 to 0b8c3c6 Compare August 17, 2017 16:53
Changelog.md Outdated
@@ -7,6 +7,7 @@
- Added Swift 4.0 support.
- Added all the `filter`/`map` operators that were available for `Observable<Response>` to `Single<Response>` as well.
- Added `AuthorizationType` to `AccessTokenAuthorizable` representing request headers of `.none`, `.basic`, and `.bearer`.
- Added tests for Single<Response> operators.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a minor one, but you forgot backticks around Single<Response> 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough ;)

Copy link
Member

@sunshinejr sunshinejr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for these, @freak4pc 🎉

@sunshinejr sunshinejr merged commit 486a933 into 9.0.0-dev Aug 17, 2017
@sunshinejr sunshinejr deleted the feature/rxmoya-single-tests branch August 17, 2017 17:21
@sunshinejr sunshinejr mentioned this pull request Sep 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants