fluentnode
Version:
Fluent apis for node (based on the concepts used in C#'s FluentSharp
327 lines (223 loc) • 11 kB
HTML
<html>
<head>
<title>http.test.coffee</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, target-densitydpi=160dpi, initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">
<link rel="stylesheet" media="all" href="docco.css" />
</head>
<body>
<div id="container">
<div id="background"></div>
<ul id="jump_to">
<li>
<a class="large" href="javascript:void(0);">Jump To …</a>
<a class="small" href="javascript:void(0);">+</a>
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="Array.html">
Array.litcoffee
</a>
<a class="source" href="Boolean.html">
Boolean.litcoffee
</a>
<a class="source" href="Function.html">
Function.litcoffee
</a>
<a class="source" href="Number.html">
Number.litcoffee
</a>
<a class="source" href="Object.html">
Object.litcoffee
</a>
<a class="source" href="String.html">
String.litcoffee
</a>
<a class="source" href="_register.html">
_register.js
</a>
<a class="source" href="_to_map_and_write_Tests.html">
_to_map_and_write_Tests.litcoffee
</a>
<a class="source" href="assert_Array.html">
assert_Array.litcoffee
</a>
<a class="source" href="assert_Boolean.html">
assert_Boolean.litcoffee
</a>
<a class="source" href="assert_Function.html">
assert_Function.litcoffee
</a>
<a class="source" href="assert_Number.html">
assert_Number.litcoffee
</a>
<a class="source" href="assert_Object.html">
assert_Object.litcoffee
</a>
<a class="source" href="assert_String.html">
assert_String.litcoffee
</a>
<a class="source" href="console.html">
console.litcoffee
</a>
<a class="source" href="fs.html">
fs.litcoffee
</a>
<a class="source" href="globals.html">
globals.litcoffee
</a>
<a class="source" href="http.html">
http.litcoffee
</a>
<a class="source" href="index.html">
index.md
</a>
<a class="source" href="path.html">
path.litcoffee
</a>
<a class="source" href="process.html">
process.litcoffee
</a>
<a class="source" href="Array.test.html">
Array.test.coffee
</a>
<a class="source" href="Boolean.test.html">
Boolean.test.coffee
</a>
<a class="source" href="Function.test.html">
Function.test.coffee
</a>
<a class="source" href="Number.test.html">
Number.test.coffee
</a>
<a class="source" href="Object.test.html">
Object.test.coffee
</a>
<a class="source" href="String.test.html">
String.test.coffee
</a>
<a class="source" href="Array.test.html">
Array.test.coffee
</a>
<a class="source" href="Boolean.test.html">
Boolean.test.coffee
</a>
<a class="source" href="Function.test.html">
Function.test.coffee
</a>
<a class="source" href="Number.test.html">
Number.test.coffee
</a>
<a class="source" href="Object.test.html">
Object.test.coffee
</a>
<a class="source" href="String.test.html">
String.test.coffee
</a>
<a class="source" href="console.test.html">
console.test.coffee
</a>
<a class="source" href="fs.test.html">
fs.test.coffee
</a>
<a class="source" href="globals.test.html">
globals.test.coffee
</a>
<a class="source" href="http.test.html">
http.test.coffee
</a>
<a class="source" href="path.test.html">
path.test.coffee
</a>
<a class="source" href="process.test.html">
process.test.coffee
</a>
</div>
</li>
</ul>
<ul class="sections">
<li id="title">
<div class="annotation">
<h1>http.test.coffee</h1>
</div>
</li>
<li id="section-1">
<div class="annotation">
<div class="pilwrap ">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</div>
<div class="content"><div class='highlight'><pre><span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/http'</span>)
<span class="hljs-built_in">require</span>(<span class="hljs-string">'../src/Number'</span>)
http = <span class="hljs-built_in">require</span> <span class="hljs-string">'http'</span>
describe <span class="hljs-string">'http'</span>,<span class="hljs-function">-></span>
test_Port = <span class="hljs-number">45566</span> + Math.floor((Math.random() * <span class="hljs-number">100</span>) + <span class="hljs-number">1</span>)
test_Ip = <span class="hljs-string">'127.0.0.1'</span>
test_Data = <span class="hljs-string">'hello from web'</span>
url = <span class="hljs-string">"http://<span class="hljs-subst">#{test_Ip}</span>:<span class="hljs-subst">#{test_Port}</span>"</span>
server = <span class="hljs-literal">null</span>
before (done)->
url.assert_Contains(test_Ip).assert_Contains(test_Port)
server = http.createServer(<span class="hljs-literal">null</span>)
server.listen_OnPort_Saying test_Port, test_Data, <span class="hljs-function"><span class="hljs-params">()</span>=></span>
done()
after (done)->
server.close_And_Destroy_Sockets ()->
assert_Is_Null(server._handle)
assert_Is_Null(server.address())
server._sockets.keys().assert_Is_Array().assert_Size_Is(<span class="hljs-number">0</span>)
done()
it <span class="hljs-string">'createServer_OnPort_Saying'</span>,<span class="hljs-function"><span class="hljs-params">()</span>-></span>
server.listen_OnPort_Saying.assert_Is_Function()
server .assert_Instance_Of(http.Server)
server._handle .assert_Is_Not_Null()
server.address().port .assert_Is test_Port
server.address().address.assert_Is test_Ip
server._sockets .assert_Is_Object()
server._sockets.keys() .assert_Is_Array().assert_Size_Is(<span class="hljs-number">0</span>)
server._socket_Count .assert_Is(<span class="hljs-number">0</span>)
it <span class="hljs-string">'respond_With_Object_As_Json'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-></span>
server.respond_With_Object_As_Json.assert_Is_Function()
test_Object = { a : <span class="hljs-number">123</span> , b : <span class="hljs-number">456</span>}
server.respond_With_Object_As_Json(test_Object)
url.GET (json) ->
json.assert_Is(JSON.stringify(test_Object))
test_Object.a=<span class="hljs-string">'abc'</span>
url.GET_Json (value) ->
value.a.assert_Is(<span class="hljs-string">'abc'</span>)
value.b.assert_Is(<span class="hljs-number">456</span>)
done()
it <span class="hljs-string">'respond_With_String_As_Text'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-></span>
text = (<span class="hljs-number">20</span>).random_Letters()
server.respond_With_String_As_Text(text)
url.GET (value) ->
value.assert_Is(text)
server.respond_With_String_As_Text(test_Data)
url.GET (value) ->
value.assert_Is(test_Data)
done()
it <span class="hljs-string">'http_Status'</span>, <span class="hljs-function"><span class="hljs-params">(done)</span>-></span>
<span class="hljs-string">''</span>.http_Status.assert_Is_Function()
url.http_Status (status)->
status.assert_Is(<span class="hljs-number">200</span>)
done()
it <span class="hljs-string">'http_GET'</span> , <span class="hljs-function"><span class="hljs-params">(done)</span>-></span>
<span class="hljs-string">''</span>.http_Status.assert_Is_Function()
req = url.http_GET (err, data, res)->
assert_Is_Null(err)
data.assert_Is_String()
req.assert_Instance_Of(http.ClientRequest)
res.assert_Instance_Of(http.IncomingMessage)
data.assert_Is(test_Data)
done()
it <span class="hljs-string">'http_GET bad port)'</span> , <span class="hljs-function"><span class="hljs-params">(done)</span>-></span>
url.append(<span class="hljs-number">1</span>).http_GET (err, data, res)->
assert_Is_Not_Null(err).code.assert_Is(<span class="hljs-string">'ECONNREFUSED'</span>)
assert_Is_Null(data)
assert_Is_Null(res)
done()</pre></div></div>
</li>
</ul>
</div>
</body>
</html>