fakettp 0.2.4.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +6 -0
  2. data/README.rdoc +201 -0
  3. data/Rakefile +113 -0
  4. data/VERSION +1 -0
  5. data/features/control.feature +12 -0
  6. data/features/dashboard.feature +38 -0
  7. data/features/expectations.feature +27 -0
  8. data/features/expectations/expect_get +3 -0
  9. data/features/expectations/get_foo +3 -0
  10. data/features/expectations/get_root +3 -0
  11. data/features/expectations/pass_and_fail +5 -0
  12. data/features/expectations/set_response +5 -0
  13. data/features/step_definitions/expectations.rb +5 -0
  14. data/features/step_definitions/http.rb +42 -0
  15. data/features/step_definitions/simulator.rb +25 -0
  16. data/features/step_definitions/webrat_steps.rb +99 -0
  17. data/features/support/env.rb +5 -0
  18. data/features/support/fakettp.rb +2 -0
  19. data/features/support/paths.rb +12 -0
  20. data/features/support/xpath.rb +10 -0
  21. data/features/verification.feature +49 -0
  22. data/lib/fakettp/commands/fakettp_command.rb +31 -19
  23. data/lib/fakettp/controller.rb +12 -0
  24. data/lib/fakettp/db.rb +7 -0
  25. data/lib/fakettp/error.rb +6 -18
  26. data/lib/fakettp/expectation.rb +28 -44
  27. data/lib/fakettp/fakettp.yml +3 -0
  28. data/lib/fakettp/public/fakettp.css +33 -0
  29. data/lib/fakettp/schema.rb +14 -0
  30. data/lib/fakettp/simulator.rb +16 -10
  31. data/lib/fakettp/views/index.erb +14 -0
  32. data/spec/fakettp/commands/fakettp_command_spec.rb +128 -0
  33. data/spec/fakettp/controller_spec.rb +250 -0
  34. data/spec/fakettp/error_spec.rb +40 -0
  35. data/spec/fakettp/expectation_helper_spec.rb +33 -0
  36. data/spec/fakettp/expectation_spec.rb +142 -0
  37. data/spec/fakettp/simulator_spec.rb +149 -0
  38. data/spec/spec.opts +1 -0
  39. data/spec/spec_helper.rb +18 -0
  40. metadata +73 -24
  41. data/README.html +0 -113
data/README.html DELETED
@@ -1,113 +0,0 @@
1
- <h1>FakeTTP</h1>
2
- <h2>Purpose</h2>
3
- <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>
4
- <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>
5
- <h2>Installation</h2>
6
- <h3>Install the gem</h3>
7
- <p>Add GitHub as a gem source (you only need to do this once):</p>
8
- <p><code>gem sources -a http://gems.github.com</code></p>
9
- <p>Then install FakeTTP:</p>
10
- <p><code>sudo gem install kerryb-fakettp</code></p>
11
- <p>Alternatively, you can specify the source when you install the gem:</p>
12
- <p><code>sudo gem install kerryb-fakettp --source http://gems.github.com</code></p>
13
- <h3>Create a FakeTTP directory</h3>
14
- <p>You can install FakeTTP anywhere that your web server user can see it:</p>
15
- <p><code>fakettp install &lt;directory&gt;</code></p>
16
- <h3>Point your web server at the directory</h3>
17
- <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>
18
- <pre><code>
19
- &lt;VirtualHost *:80&gt;
20
- ServerName fakettp.local
21
- DocumentRoot "/path/to/fakettp/public"
22
- &lt;directory "/path/to/fakettp/public"&gt;
23
- Order deny,allow
24
- Deny from all
25
- Allow from 127.0.0.1
26
- &lt;/directory&gt;
27
- &lt;/VirtualHost&gt;
28
- </code></pre>
29
- <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>
30
- <p><code>127.0.0.1 fakettp.local</code></p>
31
- <h3><span class="caps">IMPORTANT</span>: security note</h3>
32
- <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>
33
- <h2>Usage</h2>
34
- <h3>Resetting</h3>
35
- <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>
36
- <h4>Calling from curl</h4>
37
- <p><code>curl fakettp.local/reset -X POST</code></p>
38
- <h3>Setting expectations</h3>
39
- <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>
40
- <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>
41
- <pre><code>
42
- expect "GET of /foo" do
43
- request.host.should == 'fakettp.local'
44
- request.path_info.should == '/foo'
45
-
46
- content_type 'text/plain'
47
- "All is well\n"
48
- end
49
- </code></pre>
50
- <p>The label on the first line is used in error reporting.</p>
51
- <p>The expectation code has access to the underlying Sinatra request and response objects etc, as well as <a href="http://rspec.info">RSpec</a> matchers.</p>
52
- <h4>Calling from curl</h4>
53
- <p>Assuming the expectation is in <code>expectation_file</code>:</p>
54
- <p><code>curl -X POST fakettp.local/expect -X POST -H 'Content-Type:text/plain' --binary-data @expectation_file</code></p>
55
- <h3>Verifying</h3>
56
- <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>
57
- <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>
58
- <h4>Calling from curl</h4>
59
- <p><code>curl fakettp.local/verify</code></p>
60
- <h3>Multiple hosts</h3>
61
- <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>
62
- <p><code>ServerAlias foo.com bar.com</code></p>
63
- <h2>Change log</h2>
64
- <p>0.2.4.1 (5 May 2009)</p>
65
- <ul>
66
- <li>Temporarily depend on edge version of Sinatra, to gain Rack 1.0 compatibility.</li>
67
- </ul>
68
- <p>0.2.4 (25 Mar 2009)</p>
69
- <ul>
70
- <li>Fixed a bug which caused expectations to be run in the wrong order if there were more than nine of them.</li>
71
- </ul>
72
- <p>0.2.3 (19 Mar 2009)</p>
73
- <ul>
74
- <li>Fixed a bug where expectations were being overwritten on Linux due to Dir.entries not returning results in the expected order</li>
75
- </ul>
76
- <p>0.2.2 (18 Mar 2009)</p>
77
- <ul>
78
- <li>Only accept control requests (reset, expect, verify) on fakettp.local</li>
79
- </ul>
80
- <p>0.2.1 (17 Mar 2009)</p>
81
- <ul>
82
- <li>Fixed issue where rspec matchers weren&#8217;t available to expectations</li>
83
- </ul>
84
- <p>0.2 (14 Mar 2009)</p>
85
- <ul>
86
- <li>Complete rewrite, with tests and classes and stuff this time.</li>
87
- </ul>
88
- <p>If you get an &#8216;unexpected return&#8217; error, remove the return statement from your expectation, and just put the return value on the last line of the <em>expect</em> block.</p>
89
- <p>0.1.2 (13 Feb 2009)</p>
90
- <ul>
91
- <li>Make sure <span class="caps">README</span>.html appears in generated gem</li>
92
- </ul>
93
- <p>0.1.1 (13 Feb 2009)</p>
94
- <ul>
95
- <li>Fix permissions on installed tmp directory.</li>
96
- </ul>
97
- <p>0.1.0 (13 Feb 2009)</p>
98
- <ul>
99
- <li>First release as a gem.</li>
100
- </ul>
101
- <h2>To Do</h2>
102
- <ul>
103
- <li>Add examples</li>
104
- <li>Make control requests RESTful?</li>
105
- <li>Make main hostname configurable?</li>
106
- <li>Show label in verification error for expected requests that weren&#8217;t received</li>
107
- <li>Add facility to stub as well as mock requests</li>
108
- <li>Allow more flexibility in request ordering</li>
109
- <li>Allow user-specific helper files in installation dir</li>
110
- <li>Check install/run behaviour when development dependencies are not installed</li>
111
- <li>Provide Ruby <span class="caps">API</span> to set expectations etc</li>
112
- <li>Return the expected content type even if expectation fails</li>
113
- </ul>