anmo 0.0.15 → 0.0.16

Sign up to get free protection for your applications and to get access to all the features.
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p318
@@ -0,0 +1,4 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  Anmo
2
2
  ====
3
3
 
4
+ [![Build status](https://secure.travis-ci.org/AndrewVos/anmo.png)](https://secure.travis-ci.org/AndrewVos/anmo)
5
+
4
6
  What?
5
7
  -----
6
8
  Anmo acts as a mock api and can be used to store arbitrary pieces of data for integration testing flaky APIs.
data/Rakefile CHANGED
@@ -1,7 +1,15 @@
1
1
  require "bundler/gem_tasks"
2
+ require "cucumber"
3
+ require "cucumber/rake/task"
4
+
5
+ task :default => [:test, :features]
2
6
 
3
7
  task :test do
4
8
  Dir.glob("test/**/*_test.rb").each do |f|
5
9
  require File.expand_path(File.join(File.dirname(__FILE__), f))
6
10
  end
7
11
  end
12
+
13
+ Cucumber::Rake::Task.new(:features) do |t|
14
+ t.cucumber_opts = "features --format pretty"
15
+ end
@@ -195,22 +195,6 @@ Feature: API
195
195
  """
196
196
  Then I see that the anmo server is running
197
197
 
198
- Scenario: Anmo requests are different depending on the host
199
- Given an anmo server
200
- And I request the path "/hello1" on the host "http://example1.org"
201
- And I request the path "/hello2" on the host "http://example2.org"
202
- And I request the path "/hello3" on the host "http://example3.org"
203
- When I list requests on the host "http://example2.org"
204
- Then I should see the request with the path "/hello2"
205
-
206
- Scenario: Anmo objects are different depending on the host
207
- Given an anmo server
208
- And I save an object to the host "http://example.org"
209
- And I save an object to the host "http://another.org"
210
- And I save an object to the host "http://sample.org"
211
- When I request the object from the host "http://another.org"
212
- Then I see the object saved to the host "http://another.org"
213
-
214
198
  Scenario: Anmo knows what version the server is running
215
199
  Given an anmo server
216
200
  When I execute the code
@@ -82,36 +82,6 @@ Then /^I see that the anmo server is running$/ do
82
82
  @result.should == true
83
83
  end
84
84
 
85
- Given /^I save an object to the host "([^"]*)"$/ do |host|
86
- HTTParty.post("http://localhost:8787/__CREATE_OBJECT__", {
87
- :body => {:path => "/lulz", :body => host}.to_json,
88
- :headers => {"Host" => host}
89
- })
90
- end
91
-
92
- When /^I request the object from the host "([^"]*)"$/ do |host|
93
- @response = HTTParty.get("http://localhost:8787/lulz", :headers => {"Host" => host})
94
- end
95
-
96
- Then /^I see the object saved to the host "([^"]*)"$/ do |host|
97
- @response.body.should == host
98
- end
99
-
100
-
101
- Given /^I request the path "([^"]*)" on the host "([^"]*)"$/ do |path, host|
102
- @response = HTTParty.get("http://localhost:8787#{path}", :headers => {"Host" => host})
103
- end
104
-
105
- When /^I list requests on the host "([^"]*)"$/ do |host|
106
- json = HTTParty.get("http://localhost:8787/__REQUESTS__", :headers => {"Host" => host}).body
107
- @requests = JSON.parse(json)
108
- end
109
-
110
- Then /^I should see the request with the path "([^"]*)"$/ do |path|
111
- @requests.size.should == 1
112
- @requests.first["PATH_INFO"].should == path
113
- end
114
-
115
85
  Then /^I see the anmo version$/ do
116
86
  @result.should == Anmo::VERSION
117
87
  end
@@ -1,23 +1,16 @@
1
1
  module Anmo
2
2
  class ApplicationDataStore
3
3
  class << self
4
- [:requests, :objects].each do |t|
5
- define_method :"reset_#{t}!" do
6
- instance_variable_set(:"@stored_#{t}", {})
7
- end
8
-
9
- define_method :"stored_#{t}" do |host|
10
- name = :"@stored_#{t}"
11
- instance_variable_set(name, {}) unless instance_variable_get(name)
12
- values = instance_variable_get(name)
13
- values[host] ||= []
14
- values[host]
15
- end
16
- end
4
+ attr_accessor :stored_objects, :stored_requests
17
5
  end
18
6
  end
19
7
 
20
8
  class Application
9
+ def initialize
10
+ ApplicationDataStore.stored_objects ||= []
11
+ ApplicationDataStore.stored_requests ||= []
12
+ end
13
+
21
14
  def call env
22
15
  request = Rack::Request.new(env)
23
16
 
@@ -46,14 +39,6 @@ module Anmo
46
39
  [status, {"Content-Type" => "application/json"}, [json]]
47
40
  end
48
41
 
49
- def stored_requests request
50
- ApplicationDataStore.stored_requests(request.host)
51
- end
52
-
53
- def stored_objects request
54
- ApplicationDataStore.stored_objects(request.host)
55
- end
56
-
57
42
  def alive request
58
43
  text "<h1>anmo is alive</h1>"
59
44
  end
@@ -64,17 +49,17 @@ module Anmo
64
49
 
65
50
  def create_object request
66
51
  request_info = JSON.parse(read_request_body(request))
67
- stored_objects(request).unshift(request_info)
52
+ ApplicationDataStore.stored_objects.unshift(request_info)
68
53
  text "", 201
69
54
  end
70
55
 
71
56
  def delete_all_objects request
72
- ApplicationDataStore.reset_objects!
57
+ ApplicationDataStore.stored_objects = []
73
58
  text ""
74
59
  end
75
60
 
76
61
  def process_normal_request request
77
- stored_requests(request) << request.env
62
+ ApplicationDataStore.stored_requests << request.env
78
63
 
79
64
  if found_request = find_stored_request(request)
80
65
  text found_request["body"], Integer(found_request["status"]||200)
@@ -84,16 +69,16 @@ module Anmo
84
69
  end
85
70
 
86
71
  def requests request
87
- json stored_requests(request).to_json
72
+ json ApplicationDataStore.stored_requests.to_json
88
73
  end
89
74
 
90
75
  def delete_all_requests request
91
- ApplicationDataStore.reset_requests!
76
+ ApplicationDataStore.stored_requests = []
92
77
  text ""
93
78
  end
94
79
 
95
80
  def objects request
96
- json stored_objects(request).to_json
81
+ json ApplicationDataStore.stored_objects.to_json
97
82
  end
98
83
 
99
84
  def find_stored_request actual_request
@@ -102,7 +87,7 @@ module Anmo
102
87
  actual_request_url << "?" + actual_request.query_string
103
88
  end
104
89
 
105
- found_request = stored_objects(actual_request).find {|r| r["path"] == actual_request_url}
90
+ found_request = ApplicationDataStore.stored_objects.find {|r| r["path"] == actual_request_url}
106
91
  if found_request
107
92
  if found_request["method"]
108
93
  if actual_request.request_method != found_request["method"].upcase
@@ -1,3 +1,3 @@
1
1
  module Anmo
2
- VERSION = "0.0.15"
2
+ VERSION = "0.0.16"
3
3
  end
@@ -14,8 +14,8 @@ module Anmo
14
14
  end
15
15
 
16
16
  def setup
17
- ApplicationDataStore.reset_requests!
18
- ApplicationDataStore.reset_objects!
17
+ ApplicationDataStore.stored_objects = []
18
+ ApplicationDataStore.stored_requests = []
19
19
  end
20
20
 
21
21
  def save_object path, body, status, required_headers, method
@@ -177,48 +177,9 @@ module Anmo
177
177
  assert_equal "<h1>anmo is alive</h1>", last_response.body
178
178
  end
179
179
 
180
- def test_returns_different_requests_depending_on_http_host
181
- 1.upto(3) do |number|
182
- with_host "example#{number}.org" do
183
- get "/lulz#{number}"
184
- end
185
- end
186
-
187
- with_host "example2.org" do
188
- get "/__REQUESTS__"
189
- end
190
-
191
- json = JSON.parse(last_response.body)
192
- assert_equal 1, json.size
193
- assert_equal "/lulz2", json.first["PATH_INFO"]
194
- end
195
-
196
- def test_returns_different_objects_depending_on_http_host
197
- 1.upto(3) do |number|
198
- with_host "host#{number}.org" do
199
- save_object "/path", "body#{number}", nil, nil, nil
200
- end
201
- end
202
-
203
- with_host "host2.org" do
204
- get "/path"
205
- end
206
- assert_equal "body2", last_response.body
207
- end
208
-
209
180
  def test_exposes_server_version
210
181
  get "/__VERSION__"
211
182
  assert_equal Anmo::VERSION, last_response.body
212
183
  end
213
-
214
- private
215
-
216
- def with_host(host)
217
- previous_host = Rack::Test::DEFAULT_HOST.dup
218
- Rack::Test::DEFAULT_HOST.replace host
219
- yield
220
- ensure
221
- Rack::Test::DEFAULT_HOST.replace previous_host
222
- end
223
184
  end
224
185
  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.15
4
+ version: 0.0.16
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-23 00:00:00.000000000Z
12
+ date: 2012-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70248042461280 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70248042461280
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: thin
27
- requirement: &70248042460780 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70248042460780
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: httparty
38
- requirement: &70248042460100 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70248042460100
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rake
49
- requirement: &70248042453360 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70248042453360
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: minitest
60
- requirement: &70248042452900 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,10 +85,15 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70248042452900
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  - !ruby/object:Gem::Dependency
70
95
  name: rack-test
71
- requirement: &70248042452460 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
72
97
  none: false
73
98
  requirements:
74
99
  - - ! '>='
@@ -76,10 +101,15 @@ dependencies:
76
101
  version: '0'
77
102
  type: :development
78
103
  prerelease: false
79
- version_requirements: *70248042452460
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
80
110
  - !ruby/object:Gem::Dependency
81
111
  name: cucumber
82
- requirement: &70248042451940 !ruby/object:Gem::Requirement
112
+ requirement: !ruby/object:Gem::Requirement
83
113
  none: false
84
114
  requirements:
85
115
  - - ! '>='
@@ -87,10 +117,15 @@ dependencies:
87
117
  version: '0'
88
118
  type: :development
89
119
  prerelease: false
90
- version_requirements: *70248042451940
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
91
126
  - !ruby/object:Gem::Dependency
92
127
  name: rspec
93
- requirement: &70248042451460 !ruby/object:Gem::Requirement
128
+ requirement: !ruby/object:Gem::Requirement
94
129
  none: false
95
130
  requirements:
96
131
  - - ! '>='
@@ -98,10 +133,15 @@ dependencies:
98
133
  version: '0'
99
134
  type: :development
100
135
  prerelease: false
101
- version_requirements: *70248042451460
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
102
142
  - !ruby/object:Gem::Dependency
103
143
  name: guard
104
- requirement: &70248042450860 !ruby/object:Gem::Requirement
144
+ requirement: !ruby/object:Gem::Requirement
105
145
  none: false
106
146
  requirements:
107
147
  - - ! '>='
@@ -109,10 +149,15 @@ dependencies:
109
149
  version: '0'
110
150
  type: :development
111
151
  prerelease: false
112
- version_requirements: *70248042450860
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
113
158
  - !ruby/object:Gem::Dependency
114
159
  name: guard-shell
115
- requirement: &70248042449960 !ruby/object:Gem::Requirement
160
+ requirement: !ruby/object:Gem::Requirement
116
161
  none: false
117
162
  requirements:
118
163
  - - ! '>='
@@ -120,7 +165,12 @@ dependencies:
120
165
  version: '0'
121
166
  type: :development
122
167
  prerelease: false
123
- version_requirements: *70248042449960
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
124
174
  description: ''
125
175
  email:
126
176
  - andrew.vos@gmail.com
@@ -129,6 +179,8 @@ extensions: []
129
179
  extra_rdoc_files: []
130
180
  files:
131
181
  - .gitignore
182
+ - .rvmrc
183
+ - .travis.yml
132
184
  - Gemfile
133
185
  - Guardfile
134
186
  - README.md
@@ -161,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
213
  version: '0'
162
214
  requirements: []
163
215
  rubyforge_project: anmo
164
- rubygems_version: 1.8.10
216
+ rubygems_version: 1.8.21
165
217
  signing_key:
166
218
  specification_version: 3
167
219
  summary: ''