Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Tests for multiple headers #5

Merged
merged 2 commits into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 8, 2012
  1. @jeromegn
  2. @jeromegn

    added request package

    jeromegn authored
This page is out of date. Refresh to see the latest.
Showing with 50 additions and 2 deletions.
  1. +2 −1  package.json
  2. +5 −0 test/helpers.coffee
  3. +43 −1 test/replay_test.coffee
View
3  package.json
@@ -21,7 +21,8 @@
"coffee-script": "~1.3.1",
"express": "~2.5.9",
"mocha": "~1.0.2",
- "async": "~0.1.18"
+ "async": "~0.1.18",
+ "request": "~2.9.202"
},
"repository": {
"type": "git",
View
5 test/helpers.coffee
@@ -37,6 +37,11 @@ server.get "/404", (req, res)->
# Internal error
server.get "/500", (req, res)->
res.send 500, "Boom!"
+# Multiple set-cookie headers
+server.get "/set-cookie", (req, res)->
+ res.cookie "c1", "v1"
+ res.cookie "c2", "v2"
+ res.send 200
# SSL Server
View
44 test/replay_test.coffee
@@ -1,4 +1,6 @@
-{ assert, HTTP, HTTPS, Replay } = require("./helpers")
+{ assert, setup, HTTP, HTTPS, Replay } = require("./helpers")
+File = require("fs")
+Request = require("request")
# Test replaying results from fixtures in spec/fixtures.
@@ -106,6 +108,46 @@ describe "Replay", ->
assert.equal body, "Aregexp2"
+ describe "recording multiple of the same header", ->
+
+ fixture_path = null
+
+ before setup
+
+ before ->
+ Replay.mode = "record"
+
+ before (done)->
+ request = HTTP.get(hostname: "127.0.0.1", port: 3001, path: "/set-cookie", (response)->
+ response.on "end", done
+ )
+ request.on "error", done
+
+ it "should create a fixture with multiple set-cookie headers", ->
+ fixture_path = "#{__dirname}/fixtures/127.0.0.1:3001/#{File.readdirSync("#{__dirname}/fixtures/127.0.0.1:3001")[0]}"
+ fixture = File.readFileSync(fixture_path, "utf8")
+ set_cookie_count = 0
+ for line in fixture.split("\n")
+ set_cookie_count++ if /set-cookie: c\d=v\d/.test(line)
+ assert.equal set_cookie_count, 2
+
+ describe "replaying multiple headers", ->
+
+ headers = null
+
+ before (done)->
+ Request.get "http://127.0.0.1:3001/set-cookie", (err, resp)->
+ headers = resp.headers
+ done()
+
+ it "should have both set-cookie headers", ->
+ assert.equal headers["set-cookie"][0], "c1=v1"
+ assert.equal headers["set-cookie"][1], "c2=v2"
+
+ after ->
+ File.unlinkSync(fixture_path)
+
+
# Send responses to non-existent server on port 3002. No matching fixture for that path, expect a 404.
describe "undefined path", ->
error = null
Something went wrong with that request. Please try again.