anmo 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/features/api.feature +19 -0
- data/features/step_definitions/api_steps.rb +6 -0
- data/lib/anmo.rb +5 -0
- data/lib/anmo/application.rb +23 -25
- data/lib/anmo/version.rb +1 -1
- data/test/anmo/application_test.rb +31 -7
- metadata +22 -22
data/features/api.feature
CHANGED
@@ -158,3 +158,22 @@ Feature: API
|
|
158
158
|
Anmo.delete_all_requests
|
159
159
|
"""
|
160
160
|
Then there should be no stored requests
|
161
|
+
|
162
|
+
Scenario: List all saved objects
|
163
|
+
Given an anmo server
|
164
|
+
When I execute the code
|
165
|
+
"""
|
166
|
+
Anmo.server = "http://localhost:8787"
|
167
|
+
Anmo.create_request({
|
168
|
+
:path => "/some/object",
|
169
|
+
:body => "some data"
|
170
|
+
})
|
171
|
+
|
172
|
+
@result = Anmo.stored_objects
|
173
|
+
"""
|
174
|
+
Then I should see the value
|
175
|
+
"""
|
176
|
+
[
|
177
|
+
{"path" => "/some/object", "body" => "some data"}
|
178
|
+
]
|
179
|
+
"""
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require "stringio"
|
2
|
+
|
1
3
|
When /^I execute the following code in a new thread$/ do |code|
|
2
4
|
Thread.new do
|
3
5
|
eval code
|
@@ -67,3 +69,7 @@ end
|
|
67
69
|
Then /^there should be no stored requests$/ do
|
68
70
|
Anmo.requests.size.should == 0
|
69
71
|
end
|
72
|
+
|
73
|
+
Then /^I should see the value$/ do |code|
|
74
|
+
@result.should == eval(code)
|
75
|
+
end
|
data/lib/anmo.rb
CHANGED
data/lib/anmo/application.rb
CHANGED
@@ -1,43 +1,37 @@
|
|
1
|
-
require "ostruct"
|
2
|
-
|
3
1
|
module Anmo
|
4
2
|
class Application
|
5
3
|
def call env
|
6
|
-
@
|
4
|
+
@stored_objects ||= []
|
5
|
+
@@stored_requests ||= []
|
6
|
+
|
7
7
|
request = Rack::Request.new(env)
|
8
8
|
|
9
9
|
if request.path_info == "/__CREATE__"
|
10
|
-
|
10
|
+
create request
|
11
11
|
elsif request.path_info == "/__DELETE_ALL__"
|
12
|
-
|
12
|
+
delete_all_objects
|
13
13
|
elsif request.path_info == "/__REQUESTS__"
|
14
|
-
|
14
|
+
requests
|
15
15
|
elsif request.path_info == "/__DELETE_ALL_REQUESTS__"
|
16
|
-
|
16
|
+
delete_all_requests
|
17
|
+
elsif request.path_info == "/__STORED_OBJECTS__"
|
18
|
+
stored_objects
|
17
19
|
else
|
18
|
-
|
20
|
+
@@stored_requests << request.env
|
19
21
|
process_normal_request request
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def self.requests
|
24
|
-
@@requests ||= []
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.delete_all_requests
|
28
|
-
@@requests = nil
|
29
|
-
end
|
30
|
-
|
31
25
|
private
|
32
26
|
|
33
|
-
def
|
27
|
+
def create request
|
34
28
|
request_info = JSON.parse(read_request_body(request))
|
35
|
-
@
|
29
|
+
@stored_objects.unshift(request_info)
|
36
30
|
[201, {}, ""]
|
37
31
|
end
|
38
32
|
|
39
|
-
def
|
40
|
-
@
|
33
|
+
def delete_all_objects
|
34
|
+
@stored_objects = []
|
41
35
|
[200, {}, ""]
|
42
36
|
end
|
43
37
|
|
@@ -49,22 +43,26 @@ module Anmo
|
|
49
43
|
end
|
50
44
|
end
|
51
45
|
|
52
|
-
def
|
53
|
-
[200, {"Content-Type" => "application/json"},
|
46
|
+
def requests
|
47
|
+
[200, {"Content-Type" => "application/json"}, (@@stored_requests || []).to_json]
|
54
48
|
end
|
55
49
|
|
56
|
-
def
|
57
|
-
|
50
|
+
def delete_all_requests
|
51
|
+
@@stored_requests = []
|
58
52
|
[200, {}, ""]
|
59
53
|
end
|
60
54
|
|
55
|
+
def stored_objects
|
56
|
+
[200, {"Content-Type" => "application/json"}, [@stored_objects.to_json]]
|
57
|
+
end
|
58
|
+
|
61
59
|
def find_stored_request actual_request
|
62
60
|
actual_request_url = actual_request.path_info
|
63
61
|
if actual_request.query_string != ""
|
64
62
|
actual_request_url << "?" + actual_request.query_string
|
65
63
|
end
|
66
64
|
|
67
|
-
found_request = @
|
65
|
+
found_request = @stored_objects.find {|r| r["path"] == actual_request_url}
|
68
66
|
if found_request
|
69
67
|
if found_request["method"]
|
70
68
|
if actual_request.request_method != found_request["method"].upcase
|
data/lib/anmo/version.rb
CHANGED
@@ -14,7 +14,7 @@ module Anmo
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def setup
|
17
|
-
|
17
|
+
get "__DELETE_ALL_REQUESTS__"
|
18
18
|
end
|
19
19
|
|
20
20
|
def save_object path, body, status, required_headers, method
|
@@ -118,15 +118,20 @@ module Anmo
|
|
118
118
|
def test_stores_all_requests
|
119
119
|
get "/hello"
|
120
120
|
get "/hai"
|
121
|
-
|
122
|
-
|
123
|
-
|
121
|
+
get "/__REQUESTS__"
|
122
|
+
json = JSON.parse(last_response.body)
|
123
|
+
|
124
|
+
assert_equal 2, json.size
|
125
|
+
assert_equal "/hello", json.first["PATH_INFO"]
|
126
|
+
assert_equal "/hai", json.last["PATH_INFO"]
|
124
127
|
end
|
125
128
|
|
126
129
|
def test_does_not_store_create_or_delete_requests
|
127
130
|
save_object "/oh/hai", "the first content", nil, nil, nil
|
128
131
|
put "__DELETE_ALL__"
|
129
|
-
|
132
|
+
get "/__REQUESTS__"
|
133
|
+
json = JSON.parse(last_response.body)
|
134
|
+
assert_equal 0, json.size
|
130
135
|
end
|
131
136
|
|
132
137
|
def test_returns_requests_as_json
|
@@ -139,9 +144,28 @@ module Anmo
|
|
139
144
|
|
140
145
|
def test_deletes_all_requests
|
141
146
|
get "/hello"
|
142
|
-
|
147
|
+
get "/__REQUESTS__"
|
148
|
+
json = JSON.parse(last_response.body)
|
149
|
+
assert_equal 1, json.size
|
143
150
|
get "/__DELETE_ALL_REQUESTS__"
|
144
|
-
|
151
|
+
get "/__REQUESTS__"
|
152
|
+
json = JSON.parse(last_response.body)
|
153
|
+
assert_equal 0, json.size
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_returns_empty_list_of_stored_objects
|
157
|
+
get "/__STORED_OBJECTS__"
|
158
|
+
assert_equal "application/json", last_response.content_type
|
159
|
+
json = JSON.parse(last_response.body)
|
160
|
+
assert_equal 0, json.size
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_lists_stored_objects
|
164
|
+
save_object "/some/path", nil, nil, nil, nil
|
165
|
+
get "/__STORED_OBJECTS__"
|
166
|
+
json = JSON.parse(last_response.body)
|
167
|
+
assert_equal 1, json.size
|
168
|
+
assert_equal "/some/path", json.first["path"]
|
145
169
|
end
|
146
170
|
end
|
147
171
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
16
|
-
requirement: &
|
16
|
+
requirement: &70125158390620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70125158390620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: thin
|
27
|
-
requirement: &
|
27
|
+
requirement: &70125158390200 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70125158390200
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: httparty
|
38
|
-
requirement: &
|
38
|
+
requirement: &70125158389780 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70125158389780
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: rake
|
49
|
-
requirement: &
|
49
|
+
requirement: &70125158389360 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70125158389360
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: minitest
|
60
|
-
requirement: &
|
60
|
+
requirement: &70125158388940 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,10 +65,10 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *70125158388940
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rack-test
|
71
|
-
requirement: &
|
71
|
+
requirement: &70125158388520 !ruby/object:Gem::Requirement
|
72
72
|
none: false
|
73
73
|
requirements:
|
74
74
|
- - ! '>='
|
@@ -76,10 +76,10 @@ dependencies:
|
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
|
-
version_requirements: *
|
79
|
+
version_requirements: *70125158388520
|
80
80
|
- !ruby/object:Gem::Dependency
|
81
81
|
name: cucumber
|
82
|
-
requirement: &
|
82
|
+
requirement: &70125158388100 !ruby/object:Gem::Requirement
|
83
83
|
none: false
|
84
84
|
requirements:
|
85
85
|
- - ! '>='
|
@@ -87,10 +87,10 @@ dependencies:
|
|
87
87
|
version: '0'
|
88
88
|
type: :development
|
89
89
|
prerelease: false
|
90
|
-
version_requirements: *
|
90
|
+
version_requirements: *70125158388100
|
91
91
|
- !ruby/object:Gem::Dependency
|
92
92
|
name: rspec
|
93
|
-
requirement: &
|
93
|
+
requirement: &70125158418380 !ruby/object:Gem::Requirement
|
94
94
|
none: false
|
95
95
|
requirements:
|
96
96
|
- - ! '>='
|
@@ -98,10 +98,10 @@ dependencies:
|
|
98
98
|
version: '0'
|
99
99
|
type: :development
|
100
100
|
prerelease: false
|
101
|
-
version_requirements: *
|
101
|
+
version_requirements: *70125158418380
|
102
102
|
- !ruby/object:Gem::Dependency
|
103
103
|
name: guard
|
104
|
-
requirement: &
|
104
|
+
requirement: &70125158417960 !ruby/object:Gem::Requirement
|
105
105
|
none: false
|
106
106
|
requirements:
|
107
107
|
- - ! '>='
|
@@ -109,10 +109,10 @@ dependencies:
|
|
109
109
|
version: '0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
|
-
version_requirements: *
|
112
|
+
version_requirements: *70125158417960
|
113
113
|
- !ruby/object:Gem::Dependency
|
114
114
|
name: guard-shell
|
115
|
-
requirement: &
|
115
|
+
requirement: &70125158417540 !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|
118
118
|
- - ! '>='
|
@@ -120,7 +120,7 @@ dependencies:
|
|
120
120
|
version: '0'
|
121
121
|
type: :development
|
122
122
|
prerelease: false
|
123
|
-
version_requirements: *
|
123
|
+
version_requirements: *70125158417540
|
124
124
|
description: ''
|
125
125
|
email:
|
126
126
|
- andrew.vos@gmail.com
|