mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 15:48:43 -05:00
Add TESTING.md with instructions about FakeWeb and curl
This commit is contained in:
parent
e4c1b9702b
commit
dd724b2d42
1 changed files with 39 additions and 0 deletions
39
TESTING.md
Normal file
39
TESTING.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
# Discourse Developer Testing Guide
|
||||
|
||||
Some notes about testing Discourse:
|
||||
|
||||
## FakeWeb
|
||||
|
||||
We use the [FakeWeb](https://github.com/chrisk/fakeweb) gem to fake external web
|
||||
requests.
|
||||
For example, check out the specs on `specs/components/oneboxer`.
|
||||
|
||||
This has several advantages to making real requests:
|
||||
|
||||
* We freeze the expected response from the remote server.
|
||||
* We don't need a network connection to run the specs.
|
||||
* It's faster.
|
||||
|
||||
So, if you need to define a spec that makes a web request, you'll have to record
|
||||
the real response to a fixture file, and tell FakeWeb to respond with it for the
|
||||
URI of your request.
|
||||
|
||||
Check out `spec/components/oneboxer/amazon_onebox_spec.rb` for an example on
|
||||
this.
|
||||
|
||||
### Recording responses
|
||||
|
||||
To record the actual response from the remote server, you can use curl and save the response to a file. We use the `-i` option to include headers in the output
|
||||
|
||||
curl -i http://en.m.wikipedia.org/wiki/Ruby > wikipedia.response
|
||||
|
||||
If you need to specify the User-Agent to send to the server, you can use `-A`:
|
||||
|
||||
curl -i -A 'Mozilla/5.0 (iPhone; CPU iPhone OS 5_0_1 like Mac OS X) AppleWebKit/534.46 (KHTML, like Gecko) Version/5.1 Mobile/9A405 Safari/7534.48.3' http://en.m.wikipedia.org/wiki/Ruby > wikipedia.response
|
||||
|
||||
If the remote server is responding with a redirect, you'll need to fake both the
|
||||
original request and the one for the destination. Check out the
|
||||
`wikipedia.response` and `wikipedia_redirected.response` files in
|
||||
`spec/fixtures/oneboxer` for an example. You can also consider working directly
|
||||
with the final URL for simplicity.
|
||||
|
Loading…
Reference in a new issue