fix url fetcher tests so they exit correctly
This commit is contained in:
@@ -17,8 +17,8 @@ describe "UrlFetcher", ->
|
|||||||
@defaults.calledWith(jar: false)
|
@defaults.calledWith(jar: false)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "_pipeUrlToFile", ->
|
describe "pipeUrlToFile", ->
|
||||||
beforeEach ->
|
beforeEach (done)->
|
||||||
@path = "/path/to/file/on/disk"
|
@path = "/path/to/file/on/disk"
|
||||||
@request.get = sinon.stub().returns(@urlStream = new EventEmitter)
|
@request.get = sinon.stub().returns(@urlStream = new EventEmitter)
|
||||||
@urlStream.pipe = sinon.stub()
|
@urlStream.pipe = sinon.stub()
|
||||||
@@ -26,21 +26,24 @@ describe "UrlFetcher", ->
|
|||||||
@urlStream.resume = sinon.stub()
|
@urlStream.resume = sinon.stub()
|
||||||
@fs.createWriteStream = sinon.stub().returns(@fileStream = new EventEmitter)
|
@fs.createWriteStream = sinon.stub().returns(@fileStream = new EventEmitter)
|
||||||
@fs.unlink = (file, callback) -> callback()
|
@fs.unlink = (file, callback) -> callback()
|
||||||
@UrlFetcher.pipeUrlToFile(@url, @path, @callback)
|
done()
|
||||||
|
|
||||||
|
describe "successfully", ->
|
||||||
|
beforeEach (done)->
|
||||||
|
@UrlFetcher.pipeUrlToFile @url, @path, =>
|
||||||
|
@callback()
|
||||||
|
done()
|
||||||
|
@res = statusCode: 200
|
||||||
|
@urlStream.emit "response", @res
|
||||||
|
@urlStream.emit "end"
|
||||||
|
@fileStream.emit "finish"
|
||||||
|
|
||||||
|
|
||||||
it "should request the URL", ->
|
it "should request the URL", ->
|
||||||
@request.get
|
@request.get
|
||||||
.calledWith(sinon.match {"url": @url})
|
.calledWith(sinon.match {"url": @url})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
|
|
||||||
describe "successfully", ->
|
|
||||||
beforeEach ->
|
|
||||||
@res = statusCode: 200
|
|
||||||
@urlStream.emit "response", @res
|
|
||||||
@urlStream.emit "end"
|
|
||||||
@fileStream.emit "finish"
|
|
||||||
|
|
||||||
it "should open the file for writing", ->
|
it "should open the file for writing", ->
|
||||||
@fs.createWriteStream
|
@fs.createWriteStream
|
||||||
.calledWith(@path)
|
.calledWith(@path)
|
||||||
@@ -55,7 +58,10 @@ describe "UrlFetcher", ->
|
|||||||
@callback.called.should.equal true
|
@callback.called.should.equal true
|
||||||
|
|
||||||
describe "with non success status code", ->
|
describe "with non success status code", ->
|
||||||
beforeEach ->
|
beforeEach (done)->
|
||||||
|
@UrlFetcher.pipeUrlToFile @url, @path, (err)=>
|
||||||
|
@callback(err)
|
||||||
|
done()
|
||||||
@res = statusCode: 404
|
@res = statusCode: 404
|
||||||
@urlStream.emit "response", @res
|
@urlStream.emit "response", @res
|
||||||
@urlStream.emit "end"
|
@urlStream.emit "end"
|
||||||
@@ -66,7 +72,10 @@ describe "UrlFetcher", ->
|
|||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "with error", ->
|
describe "with error", ->
|
||||||
beforeEach ->
|
beforeEach (done)->
|
||||||
|
@UrlFetcher.pipeUrlToFile @url, @path, (err)=>
|
||||||
|
@callback(err)
|
||||||
|
done()
|
||||||
@urlStream.emit "error", @error = new Error("something went wrong")
|
@urlStream.emit "error", @error = new Error("something went wrong")
|
||||||
|
|
||||||
it "should call the callback with the error", ->
|
it "should call the callback with the error", ->
|
||||||
|
|||||||
Reference in New Issue
Block a user