kerryb-fakettp 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/README.html +83 -0
  2. metadata +1 -1
data/README.html ADDED
@@ -0,0 +1,83 @@
1
+ <p><!-- README.html is generated from README.textile --></p>
2
+ <h1>FakeTTP</h1>
3
+ <h2>Purpose</h2>
4
+ <p>When you are writing acceptance/integration tests for an application which makes <span class="caps">HTTP</span> requests to a remote application, sometimes you need to be able to test the interactions in different scenarios without talking to a real instance of the remote application.</p>
5
+ <p>FakeTTP is a standalone web application that allows you to mock requests (ie set and verify expectations on the requests your application makes, and return suitable responses to those requests).</p>
6
+ <h2>Installation</h2>
7
+ <h3>Install the gem</h3>
8
+ <p>Add GitHub as a gem source (you only need to do this once):</p>
9
+ <p><code>gem sources -a http://gems.github.com</code></p>
10
+ <p>Then install FakeTTP:</p>
11
+ <p><code>sudo gem install kerryb-fakettp</code></p>
12
+ <p>Alternatively, you can specify the source when you install the gem:</p>
13
+ <p><code>sudo gem install kerryb-fakettp --source http://gems.github.com</code></p>
14
+ <h3>Create a FakeTTP directory</h3>
15
+ <p>You can install FakeTTP anywhere that your web server user can see it:</p>
16
+ <p><code>fakettp install &lt;directory&gt;</code></p>
17
+ <h3>Point your web server at the directory</h3>
18
+ <p>FakeTTP should work with any Rack-compatible server: just point the server to the correct directory. For example, using <a href="http://www.modrails.com/">Passenger</a> (mod_rails) with Apache, create a virtual host along these lines:</p>
19
+ <pre><code>
20
+ &lt;VirtualHost *:80&gt;
21
+ ServerName fakettp.local
22
+ DocumentRoot "/path/to/fakettp/public"
23
+ &lt;directory "/path/to/fakettp/public"&gt;
24
+ Order deny,allow
25
+ Deny from all
26
+ Allow from 127.0.0.1
27
+ &lt;/directory&gt;
28
+ &lt;/VirtualHost&gt;
29
+ </code></pre>
30
+ <p>Then make sure <code>fakettp.local</code> resolves to 127.0.0.1 (assuming you&#8217;re running the simulator on the same machine as the application under test), eg by adding the following line to <code>/etc/hosts</code>:</p>
31
+ <p><code>127.0.0.1 fakettp.local</code></p>
32
+ <h3><span class="caps">IMPORTANT</span>: security note</h3>
33
+ <p>Because expectations are set by posting Ruby code to be executed on the server, you probably don&#8217;t want any old Tom, Dick or Harry to be able to connect. The security settings in the virtual host config example above restrict access to clients running on the local machine.</p>
34
+ <h2>Usage</h2>
35
+ <h3>Resetting</h3>
36
+ <p>To reset FakeTTP (ie remove all expectations and errors), make an <span class="caps">HTTP</span> <span class="caps">POST</span> request to <code>http://fakettp.local/reset</code>.</p>
37
+ <h3>Setting expectations</h3>
38
+ <p>To create a new expectation, make an <span class="caps">HTTP</span> <span class="caps">POST</span> request to <code>http://fakettp.local/expect</code>, with a <em>Content-Type</em> header of &#8216;text/plain&#8217; and the request data containing a Ruby block to execute.</p>
39
+ <p>The supplied code should be in the following format, and will generally consist of a number of assertions on the request, followed by creation of the response to return to the application under test.</p>
40
+ <pre><code>
41
+ expect "GET of /foo" do
42
+ request.host.should == 'fakettp.local'
43
+ request.path_info.should == '/foo'
44
+
45
+ content_type 'text/plain'
46
+ "All is well\n"
47
+ end
48
+ </code></pre>
49
+ <p>The label on the first line is used in error reporting.</p>
50
+ <p>The expectation code has access to the underlying Sinatra/Rack stuff (this will be tidied up at some point), as well as <a href="http://rspec.info">RSpec</a> matchers.</p>
51
+ <h3>Verifying</h3>
52
+ <p>To verify that all expectations have been met, make an <span class="caps">HTTP</span> <span class="caps">GET</span> request to <code>http://fakettp.local/verify</code>.</p>
53
+ <p>If all is well, the response will be a <em>200 OK</em> with a body of &#8216;OK&#8217;. Otherwise the status will be <em>400 Bad Request</em>, with a list of failures in the body. The failure messages include the complete details of the unexpected request that was received, to assist debugging.</p>
54
+ <h3>Multiple hosts</h3>
55
+ <p>To have FakeTTP respond to multiple hostnames, create the appropriate hosts entries. If you&#8217;re using name-based virtual hosts in Apache, add a <em>ServerAlias</em> entry to the virtual host config, under the <em>ServerName</em> line, eg:</p>
56
+ <p><code>ServerAlias foo.com bar.com</code></p>
57
+ <h2>Change log</h2>
58
+ <p>0.1.2 (13 Feb 2009)</p>
59
+ <ul>
60
+ <li>Make sure <span class="caps">README</span>.html appears in generated gem</li>
61
+ </ul>
62
+ <p>0.1.1 (13 Feb 2009)</p>
63
+ <ul>
64
+ <li>Fix permissions on installed tmp directory.</li>
65
+ </ul>
66
+ <p>0.1.0 (13 Feb 2009)</p>
67
+ <ul>
68
+ <li>First release as a gem.</li>
69
+ </ul>
70
+ <h2>To Do</h2>
71
+ <ul>
72
+ <li>Increase test coverage</li>
73
+ <li>Refactor to be OO rather than dumping everything in Kernel</li>
74
+ <li>Add examples</li>
75
+ <li>Only respond to control requests (reset/expect/verify) on main hostname only</li>
76
+ <li>Make control requests RESTful?</li>
77
+ <li>Make main hostname configurable?</li>
78
+ <li>Show label in verification error for expected requests that weren&#8217;t received</li>
79
+ <li>Add facility to stub as well as mock requests</li>
80
+ <li>Allow more flexibility in request ordering</li>
81
+ <li>Allow user-specific helper files in installation dir</li>
82
+ <li>Check install/run behaviour when development dependencies are not installed</li>
83
+ </ul>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kerryb-fakettp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kerry Buckley