Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Cleaning up Zombie.wants in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
assaf committed Dec 20, 2010
1 parent 1ca0d11 commit 6146fbb
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 40 deletions.
2 changes: 1 addition & 1 deletion spec/browser-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ vows.describe("Browser").addBatch(

"click link":
zombie.wants "http://localhost:3003/living"
ready: (browser)->
topic: (browser)->
browser.clickLink "Kill", @callback
"should change location": (browser)-> assert.equal browser.location, "http://localhost:3003/dead"
"should run all events": (browser)-> assert.equal browser.document.title, "The Dead"
Expand Down
14 changes: 7 additions & 7 deletions spec/eventloop-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ vows.describe("EventLoop").addBatch(
"setTimeout":
"no wait":
zombie.wants "http://localhost:3003/timeout"
ready: (browser)->
topic: (browser)->
browser.clock = 0
browser.window.setTimeout (-> @document.title += " Two"), 1000
@callback null, browser
"should not fire any timeout events": (browser)-> assert.equal browser.document.title, "One"
"should not change clock": (browser) -> assert.equal browser.clock, 0
"wait for all":
zombie.wants "http://localhost:3003/timeout"
ready: (browser)->
topic: (browser)->
browser.clock = 0
browser.window.setTimeout (-> @document.title += " Two"), 3000
browser.window.setTimeout (-> @document.title += " Three"), 5000
Expand All @@ -38,7 +38,7 @@ vows.describe("EventLoop").addBatch(
"should move clock forward": (browser) -> assert.equal browser.clock, 5000
"cancel timeout":
zombie.wants "http://localhost:3003/timeout"
ready: (browser)->
topic: (browser)->
browser.clock = 0
first = browser.window.setTimeout (-> @document.title += " Two"), 3000
second = browser.window.setTimeout (-> @document.title += " Three"), 5000
Expand All @@ -53,15 +53,15 @@ vows.describe("EventLoop").addBatch(
"setInterval":
"no wait":
zombie.wants "http://localhost:3003/interval"
ready: (browser)->
topic: (browser)->
browser.clock = 0
browser.window.setInterval (-> @document.title += "."), 1000
@callback null, browser
"should not fire any timeout events": (browser)-> assert.equal browser.document.title, ""
"should not change clock": (browser) -> assert.equal browser.clock, 0
"wait once":
zombie.wants "http://localhost:3003/interval"
ready: (browser)->
topic: (browser)->
browser.clock = 0
browser.window.setInterval (-> @document.title += "."), 1000
browser.wait @callback
Expand All @@ -70,7 +70,7 @@ vows.describe("EventLoop").addBatch(
assert.equal browser.clock, 1000
"wait three times":
zombie.wants "http://localhost:3003/interval"
ready: (browser)->
topic: (browser)->
browser.clock = 0
browser.window.setInterval (-> @document.title += "."), 1000
browser.wait 5, =>
Expand All @@ -80,7 +80,7 @@ vows.describe("EventLoop").addBatch(
"should move clock forward": (browser) -> assert.equal browser.clock, 3000
"cancel interval":
zombie.wants "http://localhost:3003/interval"
ready: (browser)->
topic: (browser)->
browser.clock = 0
interval = browser.window.setInterval (-> @document.title += "."), 1000
browser.wait =>
Expand Down
22 changes: 11 additions & 11 deletions spec/forms-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ brains.post "/submit", (req, res)-> res.send """
vows.describe("Forms").addBatch(
"fill field":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
for field in ["email", "likes", "name", "password"]
browser.find("#field-#{field}")[0].addEventListener "change", -> browser["#{field}Changed"] = true
@callback null, browser
Expand All @@ -83,7 +83,7 @@ vows.describe("Forms").addBatch(

"check box":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
for field in ["hungry", "brains", "green"]
browser.find("#field-#{field}")[0].addEventListener "click", -> browser["#{field}Clicked"] = true
browser.find("#field-#{field}")[0].addEventListener "click", -> browser["#{field}Changed"] = true
Expand All @@ -109,7 +109,7 @@ vows.describe("Forms").addBatch(

"radio buttons":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
for field in ["scary", "notscary"]
browser.find("#field-#{field}")[0].addEventListener "click", -> browser["#{field}Clicked"] = true
browser.find("#field-#{field}")[0].addEventListener "click", -> browser["#{field}Changed"] = true
Expand All @@ -130,7 +130,7 @@ vows.describe("Forms").addBatch(

"select option":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
for field in ["looks", "state"]
browser.find("#field-#{field}")[0].addEventListener "change", -> browser["#{field}Changed"] = true
@callback null, browser
Expand All @@ -154,7 +154,7 @@ vows.describe("Forms").addBatch(
"reset form":
"by calling reset":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
check("Hungry").choose("Scary").select("state", "dead")
browser.find("form")[0].reset()
Expand All @@ -168,21 +168,21 @@ vows.describe("Forms").addBatch(
"should reset select to original option": (browser)-> assert.equal browser.find("#field-state")[0].value, "alive"
"with event handler":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.find("form :reset")[0].addEventListener "click", (event)=> @callback null, event
browser.find("form :reset")[0].click()
"should fire click event": (event)-> assert.equal event.type, "click"
"with preventDefault":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter")
browser.find("form :reset")[0].addEventListener "click", (event)-> event.preventDefault()
browser.find("form :reset")[0].click()
@callback null, browser
"should not reset input field": (browser)-> assert.equal browser.find("#field-name")[0].value, "ArmBiter"
"by clicking reset input":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter")
browser.find("form :reset")[0].click()
@callback null, browser
Expand All @@ -191,7 +191,7 @@ vows.describe("Forms").addBatch(
"submit form":
"by calling submit":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
check("Hungry").choose("Scary").select("state", "dead")
browser.find("form")[0].submit()
Expand All @@ -205,7 +205,7 @@ vows.describe("Forms").addBatch(
"should send selected option to server": (browser)-> assert.equal browser.text("#state"), "dead"
"by clicking button":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
pressButton "Hit Me", @callback
"should open new page": (browser)-> assert.equal browser.location, "http://localhost:3003/submit"
Expand All @@ -216,7 +216,7 @@ vows.describe("Forms").addBatch(
assert.equal browser.text("#likes"), "Arm Biting"
"by clicking input":
zombie.wants "http://localhost:3003/form"
ready: (browser)->
topic: (browser)->
browser.fill("Name", "ArmBiter").fill("likes", "Arm Biting").
pressButton "Submit", @callback
"should open new page": (browser)-> assert.equal browser.location, "http://localhost:3003/submit"
Expand Down
15 changes: 6 additions & 9 deletions spec/helpers.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,13 @@ brains.ready = (callback)->
# However, you can (and often need to) supply a ready function that will be
# called with err and window; the ready function can then call this.callback.
zombie.wants = (url, context)->
context ||= {}
topic = context.topic
context.topic = ->
ready = context.ready
delete context.ready
brains.ready =>
zombie.visit url, (err, browser)=>
if ready
ready.call this, browser, browser.window
else
browser.wait @callback
new zombie.Browser().wants url, (err, browser)=>
if topic
topic.call this, browser, browser.window
else
browser.wait @callback
return
return context

Expand Down
18 changes: 9 additions & 9 deletions spec/history-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ vows.describe("History").addBatch(
"history":
"pushState":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.history.pushState { is: "start" }, null, "/start"
browser.window.history.pushState { is: "end" }, null, "/end"
@callback null, browser.window
Expand All @@ -47,7 +47,7 @@ vows.describe("History").addBatch(
"should include state": (evt)-> assert.equal evt.state.is, "start"
"go forwards":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.history.pushState { is: "start" }, null, "/start"
browser.window.history.pushState { is: "end" }, null, "/end"
browser.window.history.back()
Expand All @@ -57,7 +57,7 @@ vows.describe("History").addBatch(
"should include state": (evt)-> assert.equal evt.state.is, "end"
"replaceState":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.history.pushState { is: "start" }, null, "/start"
browser.window.history.replaceState { is: "end" }, null, "/end"
@callback null, browser.window
Expand All @@ -82,23 +82,23 @@ vows.describe("History").addBatch(
"should set document location": (browser)-> assert.equal browser.document.location.href, "http://localhost:3003/"
"change location":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.location = "http://localhost:3003/boo"
browser.window.document.addEventListener "DOMContentLoaded", => @callback null, browser
"should add page to history": (browser)-> assert.length browser.window.history, 2
"should change location URL": (browser)-> assert.equal browser.location, "http://localhost:3003/boo"
"should load document": (browser)-> assert.match browser.html(), /Eeek!/
"change pathname":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.location.pathname = "/boo"
browser.window.document.addEventListener "DOMContentLoaded", => @callback null, browser
"should add page to history": (browser)-> assert.length browser.window.history, 2
"should change location URL": (browser)-> assert.equal browser.location, "http://localhost:3003/boo"
"should load document": (browser)-> assert.match browser.html(), /Eeek!/
"change hash":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.document.innerHTML = "Wolf"
browser.window.addEventListener "hashchange", => @callback null, browser
browser.window.location.hash = "boo"
Expand All @@ -107,23 +107,23 @@ vows.describe("History").addBatch(
"should not reload document": (browser)-> assert.match browser.document.innerHTML, /Wolf/
"assign":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.location.assign "http://localhost:3003/boo"
browser.document.addEventListener "DOMContentLoaded", => @callback null, browser
"should add page to history": (browser)-> assert.length browser.window.history, 2
"should change location URL": (browser)-> assert.equal browser.location, "http://localhost:3003/boo"
"should load document": (browser)-> assert.match browser.html(), /Eeek!/
"replace":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.location.replace "http://localhost:3003/boo"
browser.window.document.addEventListener "DOMContentLoaded", => @callback null, browser
"should not add page to history": (browser)-> assert.length browser.window.history, 1
"should change location URL": (browser)-> assert.equal browser.location, "http://localhost:3003/boo"
"should load document": (browser)-> assert.match browser.html(), /Eeek!/
"reload":
zombie.wants "http://localhost:3003/"
ready: (browser)->
topic: (browser)->
browser.window.document.innerHTML = "Wolf"
browser.window.location.reload()
browser.window.document.addEventListener "DOMContentLoaded", => @callback null, browser
Expand Down
6 changes: 3 additions & 3 deletions spec/storage-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ vows.describe("Storage").addBatch(
"should not change other values": (storage)-> assert.equal storage.getItem("wants"), "brains"
"remove an item":
withStorage
ready: (storage)->
topic: (storage)->
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
storage.removeItem "is"
Expand All @@ -58,7 +58,7 @@ vows.describe("Storage").addBatch(
assert.equal storage.getItem("wants"), "brains"
"clean all items":
withStorage
ready: (storage)->
topic: (storage)->
storage.setItem "is", "hungry"
storage.setItem "wants", "brains"
storage.clear()
Expand All @@ -70,7 +70,7 @@ vows.describe("Storage").addBatch(
assert.isUndefined storage.getItem("wants")
"store null":
withStorage
ready: (storage)->
topic: (storage)->
storage.setItem "null", null
"should store that item": (storage)-> assert.length storage, 1
"should return null for key": (storage)-> assert.isNull storage.getItem("null")
Expand Down

0 comments on commit 6146fbb

Please sign in to comment.