poisol 0.1.7 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +94 -23
- data/lib/poisol/server.rb +17 -7
- data/spec/data/main/delete.yml +5 -0
- data/spec/functional/delete_spec.rb +7 -0
- data/spec/spec_helper.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d298d18998b092b79bc87bbdc5b2287fb7c3862
|
4
|
+
data.tar.gz: 83177b3ad21fb80e97100611bac316019a649278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5c593114f02e24cbd288566840f8d4baed2b58c12a89351c72589c91eedefbdf9c127688ff9203e3c9ec54eaf8cd3450e2ba6eb54e18a683f9d88e28b51c54f4
|
7
|
+
data.tar.gz: 36bb858a3f9df8547c6fe3a972db6d09076af64d977990efcff6b364305bab5c9b8b29bb75cafb434d8cb61e39d3752ef78fc588635f8e9a02b272145bba3d62
|
data/README.md
CHANGED
@@ -3,49 +3,50 @@
|
|
3
3
|
|
4
4
|
#Poisol
|
5
5
|
|
6
|
-
|
6
|
+
Poisol provides DSL, with default builders, to stub http endpoints.Similar to Active records and fixtures (factorygirl) used to set test data in database.
|
7
7
|
|
8
|
-
Hence, avoiding clumsy manual
|
8
|
+
Hence, avoiding clumsy manual manipulations and duplications of url's & json, and keeping test stub data setup as part of test's code.
|
9
9
|
|
10
10
|
###Example
|
11
11
|
|
12
12
|
Stubbing a http service that provides user identification, gets as simple as
|
13
13
|
|
14
14
|
```ruby
|
15
|
-
User.new.
|
16
|
-
# =>
|
15
|
+
User.new.for_name('Joe').has_role('buyer').build
|
16
|
+
# => stub that would return with role as 'buyer' for http call for user 'Joe'
|
17
17
|
|
18
|
-
User.new.
|
19
|
-
# =>
|
18
|
+
User.new.for_name('Mani').has_role('Manager').build
|
19
|
+
# => stub that would return with role as 'Manager' for http call for user 'Mani'
|
20
20
|
|
21
21
|
User.new.build
|
22
|
-
# =>
|
22
|
+
# => stub that would return with role as 'Singer' for http call for user 'Raji'
|
23
23
|
```
|
24
24
|
given a minimal configuration
|
25
25
|
|
26
26
|
```yaml
|
27
27
|
#user.yml
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
request:
|
29
|
+
url: http://authentication.service:80/user
|
30
|
+
query:
|
31
|
+
name: "Raji"
|
32
|
+
response:
|
33
|
+
body:'{
|
34
|
+
role : "singer"
|
35
|
+
}'
|
35
36
|
```
|
36
|
-
Poisol, dynamically generates class called 'User', with methods '
|
37
|
+
Poisol, dynamically generates class called 'User', with methods 'of_name' and 'has_role', which can be used to build as many User's as we need for the tests.
|
37
38
|
|
38
39
|
It handles complex request and responses, like array, nested array, array having nested array etc..
|
39
40
|
|
40
|
-
The following can be dynamically configured
|
41
|
+
The following can be dynamically configured, through the builders available
|
41
42
|
- Request
|
42
43
|
- url
|
43
|
-
-
|
44
|
+
- method*
|
44
45
|
- query params
|
45
46
|
- request body
|
46
47
|
- Response
|
47
48
|
- status code
|
48
|
-
- header
|
49
|
+
- header*
|
49
50
|
- response body
|
50
51
|
|
51
52
|
## Prepositions
|
@@ -59,9 +60,79 @@ The following can be dynamically configured
|
|
59
60
|
| has | response body field/array item |
|
60
61
|
| with | response body array item field |
|
61
62
|
|
63
|
+
##Usage
|
64
|
+
|
65
|
+
In your project Gemfile add
|
66
|
+
|
67
|
+
```
|
68
|
+
gem 'poisol'
|
69
|
+
```
|
70
|
+
|
71
|
+
###Cucumber
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
#features/support/env.rb
|
75
|
+
require 'poisol'
|
76
|
+
```
|
77
|
+
```ruby
|
78
|
+
#suppoert/hooks.rb
|
79
|
+
Before do
|
80
|
+
if $poisol_loaded.blank?
|
81
|
+
Poisol.start #starts the stub server
|
82
|
+
Poisol.load "<--location of the stub configs folder-->" #loads the configs as stub builders
|
83
|
+
#Poisol.load "features/stub_data/payment_gateway"
|
84
|
+
#Poisol.load "features/stub_data/exchange_service"
|
85
|
+
$poisol_loaded = true
|
86
|
+
end
|
87
|
+
Poisol.reset_data #clears the stubs configured prior, hence every test is independent
|
88
|
+
end
|
89
|
+
|
90
|
+
at_exit do
|
91
|
+
Poisol.stop
|
92
|
+
end
|
93
|
+
```
|
94
|
+
###Rspec
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
#spec/spec_helper.rb
|
98
|
+
require 'poisol'
|
99
|
+
|
100
|
+
RSpec.configure do |config|
|
101
|
+
|
102
|
+
config.before(:each) do
|
103
|
+
Poisol.reset_data #clears the stubs configured prior, hence every test is independent
|
104
|
+
end
|
105
|
+
|
106
|
+
config.before(:suite) do
|
107
|
+
Poisol.start #starts the stub server
|
108
|
+
Poisol.load "<--location of the stub configs folder-->" #loads the configs as stub builders
|
109
|
+
#Poisol.load "spec/stub_data/payment_gateway"
|
110
|
+
#Poisol.load "spec/stub_data/exchange_service"
|
111
|
+
end
|
112
|
+
|
113
|
+
config.after(:suite) do
|
114
|
+
Poisol.stop
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
```
|
119
|
+
### Port
|
120
|
+
By default, on Poisol.start will start the stub server in port localhost:3030, we can change the default port on server start by Poisol.start(:port=>3333)
|
121
|
+
|
122
|
+
#### Sub Domain
|
123
|
+
Given all the external services stubbed will be handled
|
124
|
+
|
125
|
+
## Builders
|
126
|
+
####URL
|
127
|
+
```yml
|
128
|
+
#user.yml
|
129
|
+
request:
|
130
|
+
url: user/{id|2}
|
131
|
+
...
|
132
|
+
```
|
133
|
+
|
134
|
+
|
135
|
+
|
62
136
|
##ToDo
|
63
|
-
*
|
64
|
-
*
|
65
|
-
* Documentation for 'getting started' and details
|
66
|
-
* Test coverage
|
67
|
-
* Throw error when configured and input field values are different
|
137
|
+
* Make header configurable
|
138
|
+
* Ensure contract mentioned to not changed
|
data/lib/poisol/server.rb
CHANGED
@@ -1,10 +1,25 @@
|
|
1
|
+
require 'webrick'
|
2
|
+
|
3
|
+
|
1
4
|
module Poisol
|
5
|
+
|
6
|
+
class ExtendedServer < WEBrick::HTTPServlet::AbstractServlet
|
7
|
+
def do_GET req,res
|
8
|
+
stub_response = Poisol::ResponseMapper.map(req)
|
9
|
+
res.status = stub_response.status
|
10
|
+
res.body = stub_response.body.to_json
|
11
|
+
res.content_type = 'application/json'
|
12
|
+
end
|
13
|
+
alias do_DELETE do_GET
|
14
|
+
alias do_POST do_GET
|
15
|
+
alias do_PUT do_GET
|
16
|
+
end
|
17
|
+
|
2
18
|
module Server
|
3
19
|
extend self
|
4
20
|
|
5
21
|
def start port
|
6
22
|
PoisolLog.info "Starting server... as http://localhost:#{port}"
|
7
|
-
require 'webrick'
|
8
23
|
@server = WEBrick::HTTPServer.new :Port => port, :Logger => log, :AccessLog => access_log
|
9
24
|
@port = port
|
10
25
|
attach_shutdown
|
@@ -18,12 +33,7 @@ module Poisol
|
|
18
33
|
end
|
19
34
|
|
20
35
|
def attach_request_handling
|
21
|
-
@server.
|
22
|
-
stub_response = ResponseMapper.map(req)
|
23
|
-
res.status = stub_response.status
|
24
|
-
res.body = stub_response.body.to_json
|
25
|
-
res.content_type = 'application/json'
|
26
|
-
end
|
36
|
+
@server.mount '/', ExtendedServer
|
27
37
|
end
|
28
38
|
|
29
39
|
def attach_shutdown
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: poisol
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Deepak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -158,6 +158,7 @@ files:
|
|
158
158
|
- spec/data/domain/first/first.yml
|
159
159
|
- spec/data/domain/second/domain.yml
|
160
160
|
- spec/data/domain/second/second.yml
|
161
|
+
- spec/data/main/delete.yml
|
161
162
|
- spec/data/main/domain.yml
|
162
163
|
- spec/data/main/key_value/explicit.yml
|
163
164
|
- spec/data/main/key_value/key_value.yml
|
@@ -171,6 +172,7 @@ files:
|
|
171
172
|
- spec/data/main/user/config.yml
|
172
173
|
- spec/data/main/user/request.json
|
173
174
|
- spec/data/main/user/response.json
|
175
|
+
- spec/functional/delete_spec.rb
|
174
176
|
- spec/functional/key_value/explicit_inclusion_spec.rb
|
175
177
|
- spec/functional/key_value/implicit_inclusion_spec.rb
|
176
178
|
- spec/functional/multi_domain_spec.rb
|
@@ -228,6 +230,7 @@ test_files:
|
|
228
230
|
- spec/data/main/response/array/columns.yml
|
229
231
|
- spec/data/main/response/array/rows.yml
|
230
232
|
- spec/data/main/response/nested_array.yml
|
233
|
+
- spec/data/main/delete.yml
|
231
234
|
- spec/data/main/query/book_explicit.yml
|
232
235
|
- spec/data/main/query/book.yml
|
233
236
|
- spec/unit/extension/hash_spec.rb
|
@@ -237,6 +240,7 @@ test_files:
|
|
237
240
|
- spec/spec_helper.rb
|
238
241
|
- spec/functional/wasted_spec.rb
|
239
242
|
- spec/functional/multi_domain_spec.rb
|
243
|
+
- spec/functional/delete_spec.rb
|
240
244
|
- spec/functional/key_value/explicit_inclusion_spec.rb
|
241
245
|
- spec/functional/key_value/implicit_inclusion_spec.rb
|
242
246
|
- spec/functional/post_request_spec.rb
|