375 lines
18 KiB
HTML
375 lines
18 KiB
HTML
|
<?xml version="1.0" encoding="utf-8"?>
|
||
|
<!DOCTYPE html
|
||
|
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||
|
|
||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||
|
<head>
|
||
|
<title>Class: Rack::MockRequest</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
||
|
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
||
|
<script type="text/javascript">
|
||
|
// <![CDATA[
|
||
|
|
||
|
function popupCode( url ) {
|
||
|
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
||
|
}
|
||
|
|
||
|
function toggleCode( id ) {
|
||
|
if ( document.getElementById )
|
||
|
elem = document.getElementById( id );
|
||
|
else if ( document.all )
|
||
|
elem = eval( "document.all." + id );
|
||
|
else
|
||
|
return false;
|
||
|
|
||
|
elemStyle = elem.style;
|
||
|
|
||
|
if ( elemStyle.display != "block" ) {
|
||
|
elemStyle.display = "block"
|
||
|
} else {
|
||
|
elemStyle.display = "none"
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
// Make codeblocks hidden by default
|
||
|
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
||
|
|
||
|
// ]]>
|
||
|
</script>
|
||
|
|
||
|
</head>
|
||
|
<body>
|
||
|
|
||
|
|
||
|
|
||
|
<div id="classHeader">
|
||
|
<table class="header-table">
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Class</strong></td>
|
||
|
<td class="class-name-in-header">Rack::MockRequest</td>
|
||
|
</tr>
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>In:</strong></td>
|
||
|
<td>
|
||
|
<a href="../../files/lib/rack/mock_rb.html">
|
||
|
lib/rack/mock.rb
|
||
|
</a>
|
||
|
<br />
|
||
|
</td>
|
||
|
</tr>
|
||
|
|
||
|
<tr class="top-aligned-row">
|
||
|
<td><strong>Parent:</strong></td>
|
||
|
<td>
|
||
|
Object
|
||
|
</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
<!-- banner header -->
|
||
|
|
||
|
<div id="bodyContent">
|
||
|
|
||
|
|
||
|
|
||
|
<div id="contextContent">
|
||
|
|
||
|
<div id="description">
|
||
|
<p>
|
||
|
<a href="MockRequest.html">Rack::MockRequest</a> helps testing your <a
|
||
|
href="../Rack.html">Rack</a> application without actually using HTTP.
|
||
|
</p>
|
||
|
<p>
|
||
|
After performing a <a href="MockRequest.html#M000119">request</a> on a URL
|
||
|
with get/post/put/delete, it returns a <a
|
||
|
href="MockResponse.html">MockResponse</a> with useful helper methods for
|
||
|
effective testing.
|
||
|
</p>
|
||
|
<p>
|
||
|
You can pass a hash with additional configuration to the
|
||
|
get/post/put/delete.
|
||
|
</p>
|
||
|
<table>
|
||
|
<tr><td valign="top"><tt>:input</tt>:</td><td>A String or IO-like to be used as rack.input.
|
||
|
|
||
|
</td></tr>
|
||
|
<tr><td valign="top"><tt>:fatal</tt>:</td><td>Raise a <a href="MockRequest/FatalWarning.html">FatalWarning</a> if the app
|
||
|
writes to rack.errors.
|
||
|
|
||
|
</td></tr>
|
||
|
<tr><td valign="top"><tt>:lint</tt>:</td><td>If true, wrap the application in a <a href="Lint.html">Rack::Lint</a>.
|
||
|
|
||
|
</td></tr>
|
||
|
</table>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div id="method-list">
|
||
|
<h3 class="section-bar">Methods</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<a href="#M000118">delete</a>
|
||
|
<a href="#M000120">env_for</a>
|
||
|
<a href="#M000115">get</a>
|
||
|
<a href="#M000114">new</a>
|
||
|
<a href="#M000116">post</a>
|
||
|
<a href="#M000117">put</a>
|
||
|
<a href="#M000119">request</a>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<!-- if includes -->
|
||
|
|
||
|
<div id="section">
|
||
|
|
||
|
<div id="class-list">
|
||
|
<h3 class="section-bar">Classes and Modules</h3>
|
||
|
|
||
|
Class <a href="MockRequest/FatalWarner.html" class="link">Rack::MockRequest::FatalWarner</a><br />
|
||
|
Class <a href="MockRequest/FatalWarning.html" class="link">Rack::MockRequest::FatalWarning</a><br />
|
||
|
|
||
|
</div>
|
||
|
|
||
|
<div id="constants-list">
|
||
|
<h3 class="section-bar">Constants</h3>
|
||
|
|
||
|
<div class="name-list">
|
||
|
<table summary="Constants">
|
||
|
<tr class="top-aligned-row context-row">
|
||
|
<td class="context-item-name">DEFAULT_ENV</td>
|
||
|
<td>=</td>
|
||
|
<td class="context-item-value">{ "rack.version" => [0,1], "rack.input" => StringIO.new, "rack.errors" => StringIO.new, "rack.multithread" => true, "rack.multiprocess" => true, "rack.run_once" => false, }</td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
<!-- if method_list -->
|
||
|
<div id="methods">
|
||
|
<h3 class="section-bar">Public Class methods</h3>
|
||
|
|
||
|
<div id="method-M000120" class="method-detail">
|
||
|
<a name="M000120"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000120" class="method-signature">
|
||
|
<span class="method-name">env_for</span><span class="method-args">(uri="", opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p>
|
||
|
Return the <a href="../Rack.html">Rack</a> environment used for a <a
|
||
|
href="MockRequest.html#M000119">request</a> to <tt>uri</tt>.
|
||
|
</p>
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000120-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000120-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 74</span>
|
||
|
74: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">env_for</span>(<span class="ruby-identifier">uri</span>=<span class="ruby-value str">""</span>, <span class="ruby-identifier">opts</span>={})
|
||
|
75: <span class="ruby-identifier">uri</span> = <span class="ruby-constant">URI</span>(<span class="ruby-identifier">uri</span>)
|
||
|
76: <span class="ruby-identifier">env</span> = <span class="ruby-constant">DEFAULT_ENV</span>.<span class="ruby-identifier">dup</span>
|
||
|
77:
|
||
|
78: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"REQUEST_METHOD"</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:method</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">"GET"</span>
|
||
|
79: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SERVER_NAME"</span>] = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">host</span> <span class="ruby-operator">||</span> <span class="ruby-value str">"example.org"</span>
|
||
|
80: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SERVER_PORT"</span>] = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span> <span class="ruby-value">? </span><span class="ruby-identifier">uri</span>.<span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">:</span> <span class="ruby-value str">"80"</span>
|
||
|
81: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"QUERY_STRING"</span>] = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">query</span>.<span class="ruby-identifier">to_s</span>
|
||
|
82: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"PATH_INFO"</span>] = (<span class="ruby-operator">!</span><span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>.<span class="ruby-identifier">empty?</span>) <span class="ruby-operator">?</span> <span class="ruby-value str">"/"</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">path</span>
|
||
|
83: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.url_scheme"</span>] = <span class="ruby-identifier">uri</span>.<span class="ruby-identifier">scheme</span> <span class="ruby-operator">||</span> <span class="ruby-value str">"http"</span>
|
||
|
84:
|
||
|
85: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"SCRIPT_NAME"</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:script_name</span>] <span class="ruby-operator">||</span> <span class="ruby-value str">""</span>
|
||
|
86:
|
||
|
87: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:fatal</span>]
|
||
|
88: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.errors"</span>] = <span class="ruby-constant">FatalWarner</span>.<span class="ruby-identifier">new</span>
|
||
|
89: <span class="ruby-keyword kw">else</span>
|
||
|
90: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.errors"</span>] = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>
|
||
|
91: <span class="ruby-keyword kw">end</span>
|
||
|
92:
|
||
|
93: <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:input</span>] <span class="ruby-operator">||=</span> <span class="ruby-value str">""</span>
|
||
|
94: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:input</span>]
|
||
|
95: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.input"</span>] = <span class="ruby-constant">StringIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:input</span>])
|
||
|
96: <span class="ruby-keyword kw">else</span>
|
||
|
97: <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.input"</span>] = <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:input</span>]
|
||
|
98: <span class="ruby-keyword kw">end</span>
|
||
|
99:
|
||
|
100: <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">field</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
|
||
|
101: <span class="ruby-identifier">env</span>[<span class="ruby-identifier">field</span>] = <span class="ruby-identifier">value</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">String</span> <span class="ruby-operator">===</span> <span class="ruby-identifier">field</span>
|
||
|
102: }
|
||
|
103:
|
||
|
104: <span class="ruby-identifier">env</span>
|
||
|
105: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000114" class="method-detail">
|
||
|
<a name="M000114"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000114" class="method-signature">
|
||
|
<span class="method-name">new</span><span class="method-args">(app)</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000114-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000114-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 51</span>
|
||
|
51: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">app</span>)
|
||
|
52: <span class="ruby-ivar">@app</span> = <span class="ruby-identifier">app</span>
|
||
|
53: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<h3 class="section-bar">Public Instance methods</h3>
|
||
|
|
||
|
<div id="method-M000118" class="method-detail">
|
||
|
<a name="M000118"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000118" class="method-signature">
|
||
|
<span class="method-name">delete</span><span class="method-args">(uri, opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000118-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000118-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 58</span>
|
||
|
58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">delete</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>={}) <span class="ruby-identifier">request</span>(<span class="ruby-value str">"DELETE"</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000115" class="method-detail">
|
||
|
<a name="M000115"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000115" class="method-signature">
|
||
|
<span class="method-name">get</span><span class="method-args">(uri, opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000115-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000115-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 55</span>
|
||
|
55: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>={}) <span class="ruby-identifier">request</span>(<span class="ruby-value str">"GET"</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000116" class="method-detail">
|
||
|
<a name="M000116"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000116" class="method-signature">
|
||
|
<span class="method-name">post</span><span class="method-args">(uri, opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000116-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000116-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 56</span>
|
||
|
56: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">post</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>={}) <span class="ruby-identifier">request</span>(<span class="ruby-value str">"POST"</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000117" class="method-detail">
|
||
|
<a name="M000117"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000117" class="method-signature">
|
||
|
<span class="method-name">put</span><span class="method-args">(uri, opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000117-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000117-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 57</span>
|
||
|
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">put</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>={}) <span class="ruby-identifier">request</span>(<span class="ruby-value str">"PUT"</span>, <span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>) <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
<div id="method-M000119" class="method-detail">
|
||
|
<a name="M000119"></a>
|
||
|
|
||
|
<div class="method-heading">
|
||
|
<a href="#M000119" class="method-signature">
|
||
|
<span class="method-name">request</span><span class="method-args">(method="GET", uri="", opts={})</span>
|
||
|
</a>
|
||
|
</div>
|
||
|
|
||
|
<div class="method-description">
|
||
|
<p><a class="source-toggle" href="#"
|
||
|
onclick="toggleCode('M000119-source');return false;">[Source]</a></p>
|
||
|
<div class="method-source-code" id="M000119-source">
|
||
|
<pre>
|
||
|
<span class="ruby-comment cmt"># File lib/rack/mock.rb, line 60</span>
|
||
|
60: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">request</span>(<span class="ruby-identifier">method</span>=<span class="ruby-value str">"GET"</span>, <span class="ruby-identifier">uri</span>=<span class="ruby-value str">""</span>, <span class="ruby-identifier">opts</span>={})
|
||
|
61: <span class="ruby-identifier">env</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">env_for</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">opts</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">:method</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">method</span>))
|
||
|
62:
|
||
|
63: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:lint</span>]
|
||
|
64: <span class="ruby-identifier">app</span> = <span class="ruby-constant">Rack</span><span class="ruby-operator">::</span><span class="ruby-constant">Lint</span>.<span class="ruby-identifier">new</span>(<span class="ruby-ivar">@app</span>)
|
||
|
65: <span class="ruby-keyword kw">else</span>
|
||
|
66: <span class="ruby-identifier">app</span> = <span class="ruby-ivar">@app</span>
|
||
|
67: <span class="ruby-keyword kw">end</span>
|
||
|
68:
|
||
|
69: <span class="ruby-identifier">errors</span> = <span class="ruby-identifier">env</span>[<span class="ruby-value str">"rack.errors"</span>]
|
||
|
70: <span class="ruby-constant">MockResponse</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span>(<span class="ruby-identifier">app</span>.<span class="ruby-identifier">call</span>(<span class="ruby-identifier">env</span>) <span class="ruby-operator">+</span> [<span class="ruby-identifier">errors</span>]))
|
||
|
71: <span class="ruby-keyword kw">end</span>
|
||
|
</pre>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
</div>
|
||
|
|
||
|
|
||
|
<div id="validator-badges">
|
||
|
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
||
|
</div>
|
||
|
|
||
|
</body>
|
||
|
</html>
|