anmo 0.0.14 → 0.0.15

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
1
+ Anmo
2
+ ====
3
+
4
+ What?
5
+ -----
6
+ Anmo acts as a mock api and can be used to store arbitrary pieces of data for integration testing flaky APIs.
7
+ This is generally *not a good idea*, but where you can't use [VCR](https://github.com/myronmarston/vcr) anmo is now an option.
8
+
9
+ How?
10
+ ----
11
+
12
+ ```
13
+ require "anmo"
14
+
15
+ Thread.new { Anmo.launch_server }
16
+
17
+ Anmo.create_request({
18
+ :path => "/lookatmyhorse",
19
+ :body => "my horse is amazing"
20
+ })
21
+ ```
22
+
23
+ ```
24
+ curl http://localhost:8787/lookatmyhorse
25
+ my horse is amazing
26
+ ```
27
+
28
+ Multiple Hosts?
29
+ ---------------
30
+
31
+ Yep. If you have one running anmo server then each domain that points to that server will have it's own data in anmo.
32
+ For example the hosts anmo2.example.org and anmo2.example.org can point at the same anmo instance, and each will have their own data.
@@ -210,3 +210,11 @@ Feature: API
210
210
  And I save an object to the host "http://sample.org"
211
211
  When I request the object from the host "http://another.org"
212
212
  Then I see the object saved to the host "http://another.org"
213
+
214
+ Scenario: Anmo knows what version the server is running
215
+ Given an anmo server
216
+ When I execute the code
217
+ """
218
+ Anmo.server_version
219
+ """
220
+ Then I see the anmo version
@@ -7,7 +7,7 @@ When /^I execute the following code in a new thread$/ do |code|
7
7
  end
8
8
 
9
9
  When /^I execute the code$/ do |code|
10
- eval code
10
+ @result = eval code
11
11
  end
12
12
 
13
13
  Then /^I see an anmo server on port (\d+)$/ do |port|
@@ -111,3 +111,7 @@ Then /^I should see the request with the path "([^"]*)"$/ do |path|
111
111
  @requests.size.should == 1
112
112
  @requests.first["PATH_INFO"].should == path
113
113
  end
114
+
115
+ Then /^I see the anmo version$/ do
116
+ @result.should == Anmo::VERSION
117
+ end
@@ -13,6 +13,10 @@ module Anmo
13
13
  @server = server
14
14
  end
15
15
 
16
+ def self.server_version
17
+ HTTParty.get("#{server}/__VERSION__").body
18
+ end
19
+
16
20
  def self.launch_server port = 8787
17
21
  @port = port
18
22
  Thin::Server.start("0.0.0.0", port, Anmo::Application.new)
@@ -1,24 +1,18 @@
1
1
  module Anmo
2
2
  class ApplicationDataStore
3
3
  class << self
4
- def reset_requests!
5
- @stored_requests = {}
6
- end
7
-
8
- def reset_stored_objects!
9
- @stored_objects = {}
10
- end
11
-
12
- def stored_requests host
13
- @stored_requests ||= {}
14
- @stored_requests[host] ||= []
15
- @stored_requests[host]
16
- end
4
+ [:requests, :objects].each do |t|
5
+ define_method :"reset_#{t}!" do
6
+ instance_variable_set(:"@stored_#{t}", {})
7
+ end
17
8
 
18
- def stored_objects host
19
- @stored_objects ||= {}
20
- @stored_objects[host] ||= []
21
- @stored_objects[host]
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
22
16
  end
23
17
  end
24
18
  end
@@ -29,11 +23,12 @@ module Anmo
29
23
 
30
24
  controller_methods = [
31
25
  :alive,
26
+ :version,
32
27
  :create_object,
33
- :delete_all_objects,
28
+ :objects,
34
29
  :requests,
35
- :delete_all_requests,
36
- :objects
30
+ :delete_all_objects,
31
+ :delete_all_requests
37
32
  ]
38
33
 
39
34
  method = controller_methods.find {|m| request.path_info =~ /\/?__#{m.to_s.upcase}__\/?/}
@@ -43,6 +38,14 @@ module Anmo
43
38
 
44
39
  private
45
40
 
41
+ def text text, status = 200
42
+ [status, {"Content-Type" => "text/html"}, [text]]
43
+ end
44
+
45
+ def json json, status = 200
46
+ [status, {"Content-Type" => "application/json"}, [json]]
47
+ end
48
+
46
49
  def stored_requests request
47
50
  ApplicationDataStore.stored_requests(request.host)
48
51
  end
@@ -52,41 +55,45 @@ module Anmo
52
55
  end
53
56
 
54
57
  def alive request
55
- [200, {"Content-Type" => "text/html"}, ["<h1>anmo is alive</h1>"]]
58
+ text "<h1>anmo is alive</h1>"
59
+ end
60
+
61
+ def version request
62
+ text Anmo::VERSION
56
63
  end
57
64
 
58
65
  def create_object request
59
66
  request_info = JSON.parse(read_request_body(request))
60
67
  stored_objects(request).unshift(request_info)
61
- [201, {"Content-Type" => "text/html"}, [""]]
68
+ text "", 201
62
69
  end
63
70
 
64
71
  def delete_all_objects request
65
- ApplicationDataStore.reset_stored_objects!
66
- [200, {"Content-Type" => "text/html"}, [""]]
72
+ ApplicationDataStore.reset_objects!
73
+ text ""
67
74
  end
68
75
 
69
76
  def process_normal_request request
70
77
  stored_requests(request) << request.env
71
78
 
72
79
  if found_request = find_stored_request(request)
73
- [Integer(found_request["status"]||200), {"Content-Type" => "text/html"}, [found_request["body"]]]
80
+ text found_request["body"], Integer(found_request["status"]||200)
74
81
  else
75
- [404, {"Content-Type" => "text/html"}, ["Not Found"]]
82
+ text "Not Found", 404
76
83
  end
77
84
  end
78
85
 
79
86
  def requests request
80
- [200, {"Content-Type" => "application/json"}, [stored_requests(request).to_json]]
87
+ json stored_requests(request).to_json
81
88
  end
82
89
 
83
90
  def delete_all_requests request
84
91
  ApplicationDataStore.reset_requests!
85
- [200, {"Content-Type" => "text/html"}, ""]
92
+ text ""
86
93
  end
87
94
 
88
95
  def objects request
89
- [200, {"Content-Type" => "application/json"}, [stored_objects(request).to_json]]
96
+ json stored_objects(request).to_json
90
97
  end
91
98
 
92
99
  def find_stored_request actual_request
@@ -1,3 +1,3 @@
1
1
  module Anmo
2
- VERSION = "0.0.14"
2
+ VERSION = "0.0.15"
3
3
  end
@@ -15,7 +15,7 @@ module Anmo
15
15
 
16
16
  def setup
17
17
  ApplicationDataStore.reset_requests!
18
- ApplicationDataStore.reset_stored_objects!
18
+ ApplicationDataStore.reset_objects!
19
19
  end
20
20
 
21
21
  def save_object path, body, status, required_headers, method
@@ -206,6 +206,11 @@ module Anmo
206
206
  assert_equal "body2", last_response.body
207
207
  end
208
208
 
209
+ def test_exposes_server_version
210
+ get "/__VERSION__"
211
+ assert_equal Anmo::VERSION, last_response.body
212
+ end
213
+
209
214
  private
210
215
 
211
216
  def with_host(host)
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.14
4
+ version: 0.0.15
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-22 00:00:00.000000000Z
12
+ date: 2012-03-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70126373762960 !ruby/object:Gem::Requirement
16
+ requirement: &70248042461280 !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: *70126373762960
24
+ version_requirements: *70248042461280
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thin
27
- requirement: &70126373762520 !ruby/object:Gem::Requirement
27
+ requirement: &70248042460780 !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: *70126373762520
35
+ version_requirements: *70248042460780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: httparty
38
- requirement: &70126373762100 !ruby/object:Gem::Requirement
38
+ requirement: &70248042460100 !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: *70126373762100
46
+ version_requirements: *70248042460100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70126373761680 !ruby/object:Gem::Requirement
49
+ requirement: &70248042453360 !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: *70126373761680
57
+ version_requirements: *70248042453360
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitest
60
- requirement: &70126373761240 !ruby/object:Gem::Requirement
60
+ requirement: &70248042452900 !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: *70126373761240
68
+ version_requirements: *70248042452900
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &70126373760820 !ruby/object:Gem::Requirement
71
+ requirement: &70248042452460 !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: *70126373760820
79
+ version_requirements: *70248042452460
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cucumber
82
- requirement: &70126373760400 !ruby/object:Gem::Requirement
82
+ requirement: &70248042451940 !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: *70126373760400
90
+ version_requirements: *70248042451940
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &70126373759960 !ruby/object:Gem::Requirement
93
+ requirement: &70248042451460 !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: *70126373759960
101
+ version_requirements: *70248042451460
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard
104
- requirement: &70126373759480 !ruby/object:Gem::Requirement
104
+ requirement: &70248042450860 !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: *70126373759480
112
+ version_requirements: *70248042450860
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-shell
115
- requirement: &70126373759040 !ruby/object:Gem::Requirement
115
+ requirement: &70248042449960 !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: *70126373759040
123
+ version_requirements: *70248042449960
124
124
  description: ''
125
125
  email:
126
126
  - andrew.vos@gmail.com
@@ -131,6 +131,7 @@ files:
131
131
  - .gitignore
132
132
  - Gemfile
133
133
  - Guardfile
134
+ - README.md
134
135
  - Rakefile
135
136
  - anmo.gemspec
136
137
  - features/api.feature