Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions DVR/Cassette.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension Cassette {
var dictionary: [String: AnyObject] {
return [
"name": name,
"interactions": interactions.map() { $0.dictionary }
"interactions": interactions.map { $0.dictionary }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh who knew?! Is this new?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I've been using this since day 1. I love trailing closure syntax. 🎉

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Didn't realize the () were optional if you did that. So great.

]
}

Expand All @@ -36,14 +36,10 @@ extension Cassette {

self.name = name

var interactions = [Interaction]()
if let array = dictionary["interactions"] as? [[String: AnyObject]] {
for dictionary in array {
if let interaction = Interaction(dictionary: dictionary) {
interactions.append(interaction)
}
}
interactions = array.flatMap { Interaction(dictionary: $0) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What?! Heck yes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm going to use this everywhere. Amazing.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

this is very great !

} else {
interactions = []
}
self.interactions = interactions
}
}
6 changes: 2 additions & 4 deletions DVR/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class Session: NSURLSession {

public var outputDirectory: String
public let cassetteName: String
public var recordingEnabled: Bool = true
public var recordingEnabled = true
private let testBundle: NSBundle


Expand Down Expand Up @@ -39,9 +39,7 @@ public class Session: NSURLSession {
if let json = try NSJSONSerialization.JSONObjectWithData(data, options: []) as? [String: AnyObject] {
return Cassette(dictionary: json)
}
} catch {
return nil
}
} catch {}
return nil
}
}
12 changes: 4 additions & 8 deletions DVR/SessionDataTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ class SessionDataTask: NSURLSessionDataTask {
}

if cassette != nil {
print("[DVR] Invalid request. The request was not found in the cassette.")
abort()
fatalError("[DVR] Invalid request. The request was not found in the cassette.")
}

// Cassette is missing. Record.
if session.recordingEnabled == false {
print("[DVR] Recording is disabled.")
abort()
fatalError("[DVR] Recording is disabled.")
}

// Create directory
Expand All @@ -60,14 +58,12 @@ class SessionDataTask: NSURLSessionDataTask {
let outputPath = outputDirectory.stringByAppendingPathComponent(self.session.cassetteName).stringByAppendingPathExtension("json")!
let data = try NSJSONSerialization.dataWithJSONObject(cassette.dictionary, options: [.PrettyPrinted])
data.writeToFile(outputPath, atomically: true)
print("[DVR] Persisted cassette at \(outputPath). Please add this file to your test target")
abort()
fatalError("[DVR] Persisted cassette at \(outputPath). Please add this file to your test target")
} catch {
// Do nothing
}

print("[DVR] Failed to persist cassette.")
abort()
fatalError("[DVR] Failed to persist cassette.")
}
task?.resume()
}
Expand Down
6 changes: 2 additions & 4 deletions DVR/URLResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ class URLResonse: NSURLResponse {

extension NSURLResponse {
var dictionary: [String: AnyObject] {
var dictionary = [String: AnyObject]()

if let url = URL?.absoluteString {
dictionary["url"] = url
return ["url": url]
}

return dictionary
return [:]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a little weird, but I'm into it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍 I love how you love Swifts quirky features.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Just to clarify, what exactly is this, return [:], returning?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Assuming it's [String: AnyObject]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ok. Great! Thanks for clarifying.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@natebird [:] is just an empty dictionary literal. The function signature allows the underlying type to be inferred.

}
}

Expand Down