Skip to content

Commit

Permalink
Rename a describe-level variable called name
Browse files Browse the repository at this point in the history
The motivation for this change is that it’s groundwork for removing the
Quick testing framework using an automated migrator tool (#1201). The
migrator that I’m writing will pull all `spec` / `describe` / `context`
level local variables outside of the class declaration and into
fileprivate global variables. But if we let the migrator hoist this
particular variable to a global with the same name, then it’ll be
shadowed by XCTestCase’s `name` property, which we don’t want.
  • Loading branch information
lawrence-forooghian committed Nov 29, 2021
1 parent 6d4fdd1 commit f4c0e1f
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions Spec/RestClientChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ class RestClientChannel: QuickSpec {

// RSL1
describe("publish") {
let name = "foo"
let data = "bar"
struct PublishArgs {
static let name = "foo"
static let data = "bar"
}

// RSL1b
context("with name and data arguments") {
it("publishes the message and invokes callback with success") {
var publishError: ARTErrorInfo? = ARTErrorInfo.create(from: NSError(domain: "", code: -1, userInfo: nil))
var publishedMessage: ARTMessage?

channel.publish(name, data: data) { error in
channel.publish(PublishArgs.name, data: PublishArgs.data) { error in
publishError = error
channel.history { result, _ in
publishedMessage = result?.items.first
}
}

expect(publishError).toEventually(beNil(), timeout: testTimeout)
expect(publishedMessage?.name).toEventually(equal(name), timeout: testTimeout)
expect(publishedMessage?.data as? String).toEventually(equal(data), timeout: testTimeout)
expect(publishedMessage?.name).toEventually(equal(PublishArgs.name), timeout: testTimeout)
expect(publishedMessage?.data as? String).toEventually(equal(PublishArgs.data), timeout: testTimeout)
}
}

Expand All @@ -47,15 +49,15 @@ class RestClientChannel: QuickSpec {
var publishError: ARTErrorInfo? = ARTErrorInfo.create(from: NSError(domain: "io.ably.XCTest", code: -1, userInfo: nil))
var publishedMessage: ARTMessage?

channel.publish(name, data: nil) { error in
channel.publish(PublishArgs.name, data: nil) { error in
publishError = error
channel.history { result, _ in
publishedMessage = result?.items.first
}
}

expect(publishError).toEventually(beNil(), timeout: testTimeout)
expect(publishedMessage?.name).toEventually(equal(name), timeout: testTimeout)
expect(publishedMessage?.name).toEventually(equal(PublishArgs.name), timeout: testTimeout)
expect(publishedMessage?.data).toEventually(beNil(), timeout: testTimeout)
}
}
Expand All @@ -66,7 +68,7 @@ class RestClientChannel: QuickSpec {
var publishError: ARTErrorInfo? = ARTErrorInfo.create(from: NSError(domain: "", code: -1, userInfo: nil))
var publishedMessage: ARTMessage?

channel.publish(nil, data: data) { error in
channel.publish(nil, data: PublishArgs.data) { error in
publishError = error
channel.history { result, _ in
publishedMessage = result?.items.first
Expand All @@ -75,7 +77,7 @@ class RestClientChannel: QuickSpec {

expect(publishError).toEventually(beNil(), timeout: testTimeout)
expect(publishedMessage?.name).toEventually(beNil(), timeout: testTimeout)
expect(publishedMessage?.data as? String).toEventually(equal(data), timeout: testTimeout)
expect(publishedMessage?.data as? String).toEventually(equal(PublishArgs.data), timeout: testTimeout)
}
}

Expand Down Expand Up @@ -107,7 +109,7 @@ class RestClientChannel: QuickSpec {
var publishedMessage: ARTMessage?

waitUntil(timeout: testTimeout) { done in
channel.publish([ARTMessage(name: name, data: data)]) { error in
channel.publish([ARTMessage(name: PublishArgs.name, data: PublishArgs.data)]) { error in
publishError = error
channel.history { result, _ in
publishedMessage = result?.items.first
Expand All @@ -117,8 +119,8 @@ class RestClientChannel: QuickSpec {
}

expect(publishError).to(beNil())
expect(publishedMessage?.name).to(equal(name))
expect(publishedMessage?.data as? String).to(equal(data))
expect(publishedMessage?.name).to(equal(PublishArgs.name))
expect(publishedMessage?.data as? String).to(equal(PublishArgs.data))
}
}

Expand Down

0 comments on commit f4c0e1f

Please sign in to comment.