mock_server 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -24
- data/lib/mock_server/record.rb +2 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -1,14 +1,13 @@
|
|
1
|
-
|
1
|
+
MockServer
|
2
|
+
----------
|
2
3
|
|
3
|
-
|
4
|
+
MockServer let you record interactions with Rack-apps and provide playback with advanced request matching for your tests.
|
4
5
|
|
5
|
-
[
|
6
|
+
Its a solution to a real world problem that came up at [Teambox](http://teambox.com) where we use it extensively for our acceptance test suite.
|
6
7
|
|
7
|
-
|
8
|
+
When building javascript application that communicate with the backend over an API, you will find yourself testing the entire stack again and again, waiting after the database while you only want ensure that your javascript applicatin is correctly communicating with the server.
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
Our solution was to considere our own backend as it was an external API and completely mock the interaction with the API.
|
10
|
+
Our solution was to considere our own backend as it was an external service and completely mock the API interaction.
|
12
11
|
|
13
12
|
### Speed. Its fast.
|
14
13
|
|
@@ -18,27 +17,30 @@ Run test against a completely fake server, don't hit you application stack.
|
|
18
17
|
|
19
18
|
Avoid duplicated testing. Test your API in its own test suite and let the frontend perform request against fixtures to avoid testing the entire stack (again).
|
20
19
|
|
21
|
-
|
20
|
+
## How it work
|
21
|
+
|
22
|
+
MockServer is a very light solution with three parts.
|
22
23
|
|
23
24
|
* a recording Rack middleware
|
24
25
|
* a playback Rack middleware
|
25
26
|
* an helper module to use inside your tests
|
26
27
|
|
27
|
-
|
28
|
+
Getting started
|
29
|
+
---------------
|
28
30
|
|
29
|
-
|
31
|
+
### Installation
|
30
32
|
|
31
33
|
```bash
|
32
34
|
gem install mock_server
|
33
35
|
```
|
34
36
|
|
35
|
-
|
37
|
+
### Recording mode
|
36
38
|
|
37
39
|
Mounting the rack middleware, in rails
|
38
40
|
|
39
41
|
```ruby
|
40
42
|
require 'mock_server/record'
|
41
|
-
config.middleware.use MockServer::Record,
|
43
|
+
config.middleware.use MockServer::Record,
|
42
44
|
{ :path => 'fixtures/records', :filename => 'api'
|
43
45
|
:routes => [ '/api/*/**', '/api_v2/**' ] }
|
44
46
|
```
|
@@ -47,21 +49,21 @@ At this point, the `MockServer::Record` middleware will record all the intractio
|
|
47
49
|
|
48
50
|
You can record from your test or just boot the app and click around, be creative.
|
49
51
|
|
50
|
-
|
52
|
+
### Playback mode
|
51
53
|
|
52
|
-
Once you are done recording, disable the `MockServer::Record
|
54
|
+
Once you are done recording, disable the `MockServer::Record`. You are ready to use the `MockServer::Playback` middleware.
|
53
55
|
|
54
56
|
```ruby
|
55
57
|
require 'mock_server/playback'
|
56
|
-
config.middleware.use MockServer::Playback,
|
58
|
+
config.middleware.use MockServer::Playback,
|
57
59
|
{ :path => 'fixtures/records' }
|
58
60
|
```
|
59
61
|
|
60
62
|
You are now ready to test.
|
61
63
|
|
62
|
-
|
64
|
+
### Rspec
|
63
65
|
|
64
|
-
MockServer
|
66
|
+
MockServer come with an helper module to load fixture, listen to paths and register matchers.
|
65
67
|
|
66
68
|
You just need to include the module in your test.
|
67
69
|
|
@@ -78,16 +80,14 @@ Inside your test, basic usage exemple:
|
|
78
80
|
|
79
81
|
```ruby
|
80
82
|
before :each do
|
81
|
-
|
82
83
|
# Set the filename where you store the records
|
83
84
|
# in this exemple, it will load `fixtures/records/bootsrap.yml`
|
84
85
|
# and `fixtures/records/uploads.yml`
|
85
86
|
mock_server_use_record 'bootsrap', 'uploads'
|
86
87
|
|
87
|
-
# From now on, those
|
88
|
-
# if we can't
|
89
|
-
mock_server_enable_routes '
|
90
|
-
|
88
|
+
# From now on, those paths belong to MockServer.
|
89
|
+
# if we can't find a record with the matchers, the server return a 404 and populate the errors stack.
|
90
|
+
mock_server_enable_routes '/api/2/**'
|
91
91
|
end
|
92
92
|
|
93
93
|
after :each do
|
@@ -126,6 +126,6 @@ Yes.
|
|
126
126
|
|
127
127
|
## Credits
|
128
128
|
|
129
|
-
MockServer borrow
|
129
|
+
MockServer borrow awesome ideas of [VCR](https://github.com/myronmarston/vcr) from [Myron Marston](https://github.com/myronmarston) that does similar work with HTTP interactions to external services.
|
130
130
|
|
131
|
-
MockServer
|
131
|
+
MockServer actively developped for our internal use at [Teambox](http://teambox.com/). Thanks to my colleges for their insightful feedback and pull requests.
|
data/lib/mock_server/record.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mock_server
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2012-
|
14
|
+
date: 2012-09-17 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rack
|