Skip to content

Commit

Permalink
Replace Context("when...") with new When("...") synonym
Browse files Browse the repository at this point in the history
  • Loading branch information
ansd committed Jan 8, 2020
1 parent 57e46f2 commit ced742a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 34 deletions.
22 changes: 11 additions & 11 deletions account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ var _ = Describe("Account", func() {
})

Describe("Accounts()", func() {
Context("when server returns blob", func() {
When("server returns blob", func() {
var rsp string
JustBeforeEach(func() {
server.AppendHandlers(
Expand All @@ -61,7 +61,7 @@ var _ = Describe("Account", func() {
),
)
})
Context("when accounts including secure notes are returned", func() {
When("accounts including secure notes are returned", func() {
BeforeEach(func() {
rsp = readFile("blob-3accts.txt")
})
Expand Down Expand Up @@ -95,7 +95,7 @@ var _ = Describe("Account", func() {
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
})
Context("when group accounts are returned", func() {
When("group accounts are returned", func() {
BeforeEach(func() {
rsp = readFile("blob-groupaccount.txt")
})
Expand All @@ -107,7 +107,7 @@ var _ = Describe("Account", func() {
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
})
Context("when shared folders exist whose sharing key is AES encrypted with user's encryption key", func() {
When("shared folders exist whose sharing key is AES encrypted with user's encryption key", func() {
BeforeEach(func() {
rsp = readFile("blob-sharedaccounts.txt")
})
Expand Down Expand Up @@ -156,7 +156,7 @@ var _ = Describe("Account", func() {
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
})
Context("when shared folder exists whose sharing key needs to be decrypted with user's RSA private key", func() {
When("shared folder exists whose sharing key needs to be decrypted with user's RSA private key", func() {
BeforeEach(func() {
rsp = readFile("blob-sharingkeyrsaencrypted.txt")
})
Expand All @@ -178,7 +178,7 @@ var _ = Describe("Account", func() {
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
})
Context("when an account is AES 256 ECB encrypted", func() {
When("an account is AES 256 ECB encrypted", func() {
BeforeEach(func() {
rsp = readFile("blob-ecb.txt")
})
Expand All @@ -200,7 +200,7 @@ var _ = Describe("Account", func() {
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
})
Context("when blob is not base 64 encoded", func() {
When("blob is not base 64 encoded", func() {
BeforeEach(func() {
rsp = "!! blob not base64 encoded !!"
})
Expand All @@ -210,7 +210,7 @@ var _ = Describe("Account", func() {
Expect(ok).To(BeTrue())
})
})
Context("when blob is empty", func() {
When("blob is empty", func() {
BeforeEach(func() {
rsp = ""
})
Expand All @@ -219,7 +219,7 @@ var _ = Describe("Account", func() {
Expect(err).To(MatchError("blob is truncated"))
})
})
Context("when blob is truncated and therefore chunk cannot be extracted", func() {
When("blob is truncated and therefore chunk cannot be extracted", func() {
BeforeEach(func() {
// 8 base64 digits (each 6 bit) = 48 bits = 6 bytes
// chunk contains 4-byte ID, 4-byte size and payload of that size
Expand All @@ -232,7 +232,7 @@ var _ = Describe("Account", func() {
})
})
})
Context("when request gets canceled", func() {
When("request gets canceled", func() {
var ctx context.Context
BeforeEach(func() {
var cancel context.CancelFunc
Expand All @@ -244,7 +244,7 @@ var _ = Describe("Account", func() {
Expect(err).To(MatchError(MatchRegexp("context canceled")))
})
})
Context("when HTTP error response", func() {
When("HTTP error response", func() {
BeforeEach(func() {
server.AppendHandlers(
ghttp.CombineHandlers(
Expand Down
42 changes: 21 additions & 21 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ var _ = Describe("Client", func() {
})
}

Context("when Client never logged in", func() {
When("Client never logged in", func() {
BeforeEach(func() {
client = &Client{}
})
AssertUnauthenticatedBehavior()
})

Context("when NewClient()", func() {
When("NewClient()", func() {
var loginForm url.Values
var user, passwd, passwdIterations string
contentTypeVerifier := ghttp.VerifyContentType("application/x-www-form-urlencoded")
Expand All @@ -97,13 +97,13 @@ var _ = Describe("Client", func() {
loginForm.Set("username", user)
})

Context("when username is empty", func() {
When("username is empty", func() {
It("returns a descriptive error", func() {
_, err := NewClient(context.Background(), "", passwd, WithBaseURL(server.URL()))
Expect(err).To(MatchError("username must not be empty"))
})
})
Context("when password is empty", func() {
When("password is empty", func() {
It("returns a descriptive error", func() {
_, err := NewClient(context.Background(), user, "", WithBaseURL(server.URL()))
Expect(err).To(MatchError("masterPassword must not be empty"))
Expand Down Expand Up @@ -173,7 +173,7 @@ var _ = Describe("Client", func() {
)
})

Context("when authentication fails", func() {
When("authentication fails", func() {
var cause string
var msg string
var rsp string
Expand Down Expand Up @@ -244,7 +244,7 @@ var _ = Describe("Client", func() {
Expect(server.ReceivedRequests()).To(HaveLen(2 + MaxLoginRetries))
})
})
Context("when re-trying due to unknown error", func() {
When("re-trying due to unknown error", func() {
var retryCause, retryMsg string
JustBeforeEach(func() {
retryMsg = "unknown"
Expand All @@ -270,7 +270,7 @@ var _ = Describe("Client", func() {
})
})

Context("when NewClient() succeeds", func() {
When("NewClient() succeeds", func() {
var form url.Values
const token = "fakeToken"
const otp = "654321"
Expand Down Expand Up @@ -298,7 +298,7 @@ var _ = Describe("Client", func() {
Expect(server.ReceivedRequests()).To(HaveLen(2))
})
})
Context("when session is live", func() {
When("session is live", func() {
rsp := `<response> <ok accts_version="111"/> </response>`
BeforeEach(func() {
server.AppendHandlers(
Expand All @@ -308,7 +308,7 @@ var _ = Describe("Client", func() {
),
)
})
Context("when successfully operating on a single account", func() {
When("successfully operating on a single account", func() {
var rspMsg string
JustBeforeEach(func() {
server.AppendHandlers(
Expand All @@ -327,7 +327,7 @@ var _ = Describe("Client", func() {
// /iterations.php, /login.php, /login_check.php, /show_website.php
Expect(server.ReceivedRequests()).To(HaveLen(4))
})
Context("when upserting", func() {
When("upserting", func() {
BeforeEach(func() {
form = url.Values{}
form.Set("method", "cli")
Expand All @@ -340,7 +340,7 @@ var _ = Describe("Client", func() {
BeforeEach(func() {
form.Set("aid", "0")
})
Context("when server returns 'accountadded'", func() {
When("server returns 'accountadded'", func() {
BeforeEach(func() {
rspMsg = "accountadded"
})
Expand All @@ -350,7 +350,7 @@ var _ = Describe("Client", func() {
Expect(acct.ID).To(Equal("test ID"))
})
})
Context("when server does not return 'accountadded'", func() {
When("server does not return 'accountadded'", func() {
BeforeEach(func() {
rspMsg = "not added"
})
Expand All @@ -363,15 +363,15 @@ var _ = Describe("Client", func() {
BeforeEach(func() {
form.Set("aid", acct.ID)
})
Context("when server returns 'accountupdated'", func() {
When("server returns 'accountupdated'", func() {
BeforeEach(func() {
rspMsg = "accountupdated"
})
It("requests /show_website.php with correct aid", func() {
Expect(client.Update(context.Background(), acct)).To(Succeed())
})
})
Context("when server does not return 'accountupdated'", func() {
When("server does not return 'accountupdated'", func() {
BeforeEach(func() {
rspMsg = "not updated"
})
Expand All @@ -390,15 +390,15 @@ var _ = Describe("Client", func() {
form.Set("token", token)
form.Set("aid", acct.ID)
})
Context("when server returns 'accountdeleted'", func() {
When("server returns 'accountdeleted'", func() {
BeforeEach(func() {
rspMsg = "accountdeleted"
})
It("requests /show_website.php with correct aid and delete=1", func() {
Expect(client.Delete(context.Background(), acct.ID)).To(Succeed())
})
})
Context("when server does not return 'accountdeleted'", func() {
When("server does not return 'accountdeleted'", func() {
BeforeEach(func() {
rspMsg = "not deleted"
})
Expand All @@ -409,7 +409,7 @@ var _ = Describe("Client", func() {
})
})
})
Context("when account does not exist", func() {
When("account does not exist", func() {
BeforeEach(func() {
header := http.Header{}
header.Set("Content-Length", "0")
Expand Down Expand Up @@ -437,7 +437,7 @@ var _ = Describe("Client", func() {
})
})

Context("when HTTP error response", func() {
When("HTTP error response", func() {
var err error
var path string
BeforeEach(func() {
Expand Down Expand Up @@ -476,7 +476,7 @@ var _ = Describe("Client", func() {
})
})
})
Context("when Client Logout()", func() {
When("Client Logout()", func() {
BeforeEach(func() {
form = url.Values{}
form.Set("method", "cli")
Expand All @@ -499,7 +499,7 @@ var _ = Describe("Client", func() {
AssertUnauthenticatedBehavior()
})
})
Context("when session becomes dead (e.g. when session cookie expires)", func() {
When("session becomes dead (e.g. when session cookie expires)", func() {
rsp := `<?xml version="1.0" encoding="UTF-8"?>
<response>
<error silent="1" from="session is not live"/>
Expand All @@ -522,7 +522,7 @@ var _ = Describe("Client", func() {
})
})
Describe("Add()", func() {
Context("when account.Name is empty", func() {
When("account.Name is empty", func() {
BeforeEach(func() {
client = &Client{}
acct.Name = ""
Expand Down
4 changes: 2 additions & 2 deletions test/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

var _ = Describe("Integration", func() {
Context("when account exists", func() {
When("account exists", func() {
var newAcct *Account

BeforeEach(func() {
Expand Down Expand Up @@ -68,7 +68,7 @@ var _ = Describe("Integration", func() {
})
})

Context("when accout does not exist", func() {
When("accout does not exist", func() {
id := "nonExistingID"
Describe("Update()", func() {
It("returns AccountNotFoundError", func() {
Expand Down

0 comments on commit ced742a

Please sign in to comment.