anmo 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -177,3 +177,20 @@ Feature: API
177
177
  {"path" => "/some/object", "body" => "some data"}
178
178
  ]
179
179
  """
180
+
181
+ Scenario: Anmo knows if a server is not running
182
+ When I execute the code
183
+ """
184
+ Anmo.server = "http://localhost:8459"
185
+ @result = Anmo.running?
186
+ """
187
+ Then I see that the anmo server is not running
188
+
189
+ Scenario: Anmo knows if a server is running
190
+ Given an anmo server
191
+ When I execute the code
192
+ """
193
+ Anmo.server = "http://localhost:8787"
194
+ @result = Anmo.running?
195
+ """
196
+ Then I see that the anmo server is running
@@ -73,3 +73,11 @@ end
73
73
  Then /^I should see the value$/ do |code|
74
74
  @result.should == eval(code)
75
75
  end
76
+
77
+ Then /^I see that the anmo server is not running$/ do
78
+ @result.should == false
79
+ end
80
+
81
+ Then /^I see that the anmo server is running$/ do
82
+ @result.should == true
83
+ end
@@ -5,20 +5,25 @@ require "httparty"
5
5
  require "json"
6
6
 
7
7
  module Anmo
8
- class << self
9
- attr_accessor :server
8
+ def self.server
9
+ @server ||= "http://localhost:#{@port}"
10
+ end
11
+
12
+ def self.server= server
13
+ @server = server
10
14
  end
11
15
 
12
16
  def self.launch_server port = 8787
17
+ @port = port
13
18
  Thin::Server.start("0.0.0.0", port, Anmo::Application.new)
14
19
  end
15
20
 
16
21
  def self.create_request options
17
- HTTParty.post("#{server}/__CREATE__", {:body => options.to_json, :headers => {"Content-Type" => "application/json"}})
22
+ HTTParty.post("#{server}/__CREATE_OBJECT__", {:body => options.to_json, :headers => {"Content-Type" => "application/json"}})
18
23
  end
19
24
 
20
25
  def self.delete_all
21
- HTTParty.put("#{server}/__DELETE_ALL__")
26
+ HTTParty.put("#{server}/__DELETE_ALL_OBJECTS__")
22
27
  end
23
28
 
24
29
  def self.requests
@@ -31,7 +36,11 @@ module Anmo
31
36
  end
32
37
 
33
38
  def self.stored_objects
34
- json = HTTParty.get("#{server}/__STORED_OBJECTS__")
39
+ json = HTTParty.get("#{server}/__OBJECTS__")
35
40
  JSON.parse(json.body)
36
41
  end
42
+
43
+ def self.running?
44
+ HTTParty.get("#{server}/__ALIVE__").code == 200 rescue false
45
+ end
37
46
  end
@@ -14,30 +14,33 @@ module Anmo
14
14
  def call env
15
15
  request = Rack::Request.new(env)
16
16
 
17
- if request.path_info == "/__CREATE__"
18
- create_object request
19
- elsif request.path_info == "/__DELETE_ALL__"
20
- delete_all_objects
21
- elsif request.path_info == "/__REQUESTS__"
22
- requests
23
- elsif request.path_info == "/__DELETE_ALL_REQUESTS__"
24
- delete_all_requests
25
- elsif request.path_info == "/__STORED_OBJECTS__"
26
- stored_objects
27
- else
28
- process_normal_request request
29
- end
17
+ controller_methods = [
18
+ :alive,
19
+ :create_object,
20
+ :delete_all_objects,
21
+ :requests,
22
+ :delete_all_requests,
23
+ :objects
24
+ ]
25
+
26
+ method = controller_methods.find {|m| request.path_info =~ /\/?__#{m.upcase}__\/?/}
27
+ method ||= :process_normal_request
28
+ send(method, request)
30
29
  end
31
30
 
32
31
  private
33
32
 
33
+ def alive request
34
+ [200, {"Content-Type" => "text/html"}, ["<h1>anmo is alive</h1>"]]
35
+ end
36
+
34
37
  def create_object request
35
38
  request_info = JSON.parse(read_request_body(request))
36
39
  ApplicationDataStore.stored_objects.unshift(request_info)
37
40
  [201, {"Content-Type" => "text/html"}, [""]]
38
41
  end
39
42
 
40
- def delete_all_objects
43
+ def delete_all_objects request
41
44
  ApplicationDataStore.stored_objects = []
42
45
  [200, {"Content-Type" => "text/html"}, [""]]
43
46
  end
@@ -52,16 +55,16 @@ module Anmo
52
55
  end
53
56
  end
54
57
 
55
- def requests
58
+ def requests request
56
59
  [200, {"Content-Type" => "application/json"}, [(ApplicationDataStore.stored_requests || []).to_json]]
57
60
  end
58
61
 
59
- def delete_all_requests
62
+ def delete_all_requests request
60
63
  ApplicationDataStore.stored_requests = []
61
64
  [200, {"Content-Type" => "text/html"}, ""]
62
65
  end
63
66
 
64
- def stored_objects
67
+ def objects request
65
68
  [200, {"Content-Type" => "application/json"}, [ApplicationDataStore.stored_objects.to_json]]
66
69
  end
67
70
 
@@ -1,3 +1,3 @@
1
1
  module Anmo
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
@@ -14,8 +14,8 @@ module Anmo
14
14
  end
15
15
 
16
16
  def setup
17
- get "/__DELETE_ALL"
18
- get "/__DELETE_ALL_REQUESTS__"
17
+ ApplicationDataStore.stored_objects = []
18
+ ApplicationDataStore.stored_requests = []
19
19
  end
20
20
 
21
21
  def save_object path, body, status, required_headers, method
@@ -27,7 +27,7 @@ module Anmo
27
27
  }
28
28
  options[:method] = method if method
29
29
 
30
- put "__CREATE__", options.to_json
30
+ put "__CREATE_OBJECT__", options.to_json
31
31
  end
32
32
 
33
33
  def test_404s_if_object_does_not_exist
@@ -71,7 +71,7 @@ module Anmo
71
71
  get "/this/is/the/path.object"
72
72
  first_response = last_response
73
73
 
74
- put "__DELETE_ALL__"
74
+ put "__DELETE_ALL_OBJECTS__"
75
75
  assert_equal 200, last_response.status
76
76
 
77
77
  get "/this/is/the/path.object"
@@ -129,7 +129,7 @@ module Anmo
129
129
 
130
130
  def test_does_not_store_create_or_delete_requests
131
131
  save_object "/oh/hai", "the first content", nil, nil, nil
132
- put "__DELETE_ALL__"
132
+ put "__DELETE_ALL_OBJECTS__"
133
133
  get "/__REQUESTS__"
134
134
  json = JSON.parse(last_response.body)
135
135
  assert_equal 0, json.size
@@ -155,18 +155,26 @@ module Anmo
155
155
  end
156
156
 
157
157
  def test_returns_empty_list_of_stored_objects
158
- get "/__STORED_OBJECTS__"
159
- assert_equal "application/json", last_response.content_type
158
+ get "/__OBJECTS__"
160
159
  json = JSON.parse(last_response.body)
160
+ assert_equal "application/json", last_response.content_type
161
161
  assert_equal 0, json.size
162
162
  end
163
163
 
164
164
  def test_lists_stored_objects
165
165
  save_object "/some/path", nil, nil, nil, nil
166
- get "/__STORED_OBJECTS__"
166
+
167
+ get "/__OBJECTS__"
168
+
167
169
  json = JSON.parse(last_response.body)
168
170
  assert_equal 1, json.size
169
171
  assert_equal "/some/path", json.first["path"]
170
172
  end
173
+
174
+ def test_shows_that_its_alive
175
+ get "/__ALIVE__"
176
+ assert last_response.ok?
177
+ assert_equal "<h1>anmo is alive</h1>", last_response.body
178
+ end
171
179
  end
172
180
  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.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-21 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
16
- requirement: &70241129996800 !ruby/object:Gem::Requirement
16
+ requirement: &70349591122580 !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: *70241129996800
24
+ version_requirements: *70349591122580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thin
27
- requirement: &70241129996340 !ruby/object:Gem::Requirement
27
+ requirement: &70349591122140 !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: *70241129996340
35
+ version_requirements: *70349591122140
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: httparty
38
- requirement: &70241129995800 !ruby/object:Gem::Requirement
38
+ requirement: &70349591121640 !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: *70241129995800
46
+ version_requirements: *70349591121640
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70241129995320 !ruby/object:Gem::Requirement
49
+ requirement: &70349591121180 !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: *70241129995320
57
+ version_requirements: *70349591121180
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: minitest
60
- requirement: &70241129994860 !ruby/object:Gem::Requirement
60
+ requirement: &70349591120700 !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: *70241129994860
68
+ version_requirements: *70349591120700
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &70241129994320 !ruby/object:Gem::Requirement
71
+ requirement: &70349591120220 !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: *70241129994320
79
+ version_requirements: *70349591120220
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: cucumber
82
- requirement: &70241129993840 !ruby/object:Gem::Requirement
82
+ requirement: &70349591119800 !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: *70241129993840
90
+ version_requirements: *70349591119800
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &70241129993400 !ruby/object:Gem::Requirement
93
+ requirement: &70349591119360 !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: *70241129993400
101
+ version_requirements: *70349591119360
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: guard
104
- requirement: &70241129992940 !ruby/object:Gem::Requirement
104
+ requirement: &70349591118940 !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: *70241129992940
112
+ version_requirements: *70349591118940
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: guard-shell
115
- requirement: &70241129989760 !ruby/object:Gem::Requirement
115
+ requirement: &70349591118480 !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: *70241129989760
123
+ version_requirements: *70349591118480
124
124
  description: ''
125
125
  email:
126
126
  - andrew.vos@gmail.com