shamrock 0.0.2 → 0.0.3
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.
- data/.rspec +3 -0
- data/lib/shamrock/http.rb +20 -0
- data/lib/shamrock/monitor.rb +5 -14
- data/lib/shamrock/service.rb +2 -1
- data/lib/shamrock/version.rb +1 -1
- data/lib/shamrock.rb +1 -0
- data/spec/shamrock/http_spec.rb +25 -0
- data/spec/shamrock/monitor_spec.rb +12 -2
- metadata +6 -2
data/.rspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module Shamrock
|
4
|
+
class Http
|
5
|
+
|
6
|
+
attr_reader :uri
|
7
|
+
|
8
|
+
def initialize(url)
|
9
|
+
@uri = URI.parse(url)
|
10
|
+
end
|
11
|
+
|
12
|
+
def ready?
|
13
|
+
Net::HTTP.get_response(uri)
|
14
|
+
true
|
15
|
+
|
16
|
+
rescue SystemCallError, SocketError
|
17
|
+
false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/shamrock/monitor.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'net/http'
|
2
1
|
require 'timeout'
|
3
2
|
|
4
3
|
module Shamrock
|
@@ -7,13 +6,15 @@ module Shamrock
|
|
7
6
|
DEFAULT_TIMEOUT = 10
|
8
7
|
RE_CHECK_WAIT = 0.1
|
9
8
|
|
10
|
-
|
11
|
-
|
9
|
+
attr_reader :http
|
10
|
+
|
11
|
+
def initialize(http)
|
12
|
+
@http = http
|
12
13
|
end
|
13
14
|
|
14
15
|
def wait_until_ready
|
15
16
|
Timeout::timeout(DEFAULT_TIMEOUT) do
|
16
|
-
until ready? do
|
17
|
+
until http.ready? do
|
17
18
|
sleep RE_CHECK_WAIT
|
18
19
|
end
|
19
20
|
end
|
@@ -21,15 +22,5 @@ module Shamrock
|
|
21
22
|
rescue Timeout::Error => error
|
22
23
|
abort "Server never started!"
|
23
24
|
end
|
24
|
-
|
25
|
-
def ready?
|
26
|
-
begin
|
27
|
-
response = Net::HTTP.get_response(@uri)
|
28
|
-
response.is_a?(Net::HTTPSuccess)
|
29
|
-
rescue SystemCallError => error
|
30
|
-
false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
25
|
end
|
35
26
|
end
|
data/lib/shamrock/service.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
module Shamrock
|
2
2
|
class Service
|
3
|
+
|
3
4
|
attr_reader :port, :url
|
4
5
|
|
5
6
|
def initialize(rack_app,
|
@@ -10,7 +11,7 @@ module Shamrock
|
|
10
11
|
@handler = handler
|
11
12
|
@port = Port.new
|
12
13
|
@url = "http://localhost:#{port.number}"
|
13
|
-
@monitor = monitor.new(url)
|
14
|
+
@monitor = monitor.new(Shamrock::Http.new(url))
|
14
15
|
end
|
15
16
|
|
16
17
|
def start
|
data/lib/shamrock/version.rb
CHANGED
data/lib/shamrock.rb
CHANGED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shamrock::Http do
|
4
|
+
describe "#ready?" do
|
5
|
+
it "should be ready if the HTTP response is successful" do
|
6
|
+
Net::HTTP.stub!(:get_response).and_return(Net::HTTPSuccess.new(nil, nil, nil))
|
7
|
+
Shamrock::Http.new('http://example.com').should be_ready
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be ready if the HTTP response if the resource has been moved" do
|
11
|
+
Net::HTTP.stub!(:get_response).and_return(Net::HTTPMovedPermanently.new(nil, nil, nil))
|
12
|
+
Shamrock::Http.new('http://example.com').should be_ready
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should not be ready if the HTTP request raises a SocketError" do
|
16
|
+
Net::HTTP.stub!(:get_response).and_raise(SocketError)
|
17
|
+
Shamrock::Http.new('http://example.com').should_not be_ready
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should not be ready if the HTTP request raises a Errno::ECONNREFUSED" do
|
21
|
+
Net::HTTP.stub!(:get_response).and_raise(Errno::ECONNREFUSED)
|
22
|
+
Shamrock::Http.new('http://example.com').should_not be_ready
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -3,8 +3,18 @@ require 'spec_helper'
|
|
3
3
|
describe Shamrock::Monitor do
|
4
4
|
describe "#wait_until_ready" do
|
5
5
|
it "should check to see if the given url is available" do
|
6
|
-
|
7
|
-
|
6
|
+
http = mock('http')
|
7
|
+
http.should_receive(:ready?).and_return(true)
|
8
|
+
|
9
|
+
monitor = Shamrock::Monitor.new(http)
|
10
|
+
monitor.wait_until_ready
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should check the http connection a second time if it is not ready at first" do
|
14
|
+
http = mock('http')
|
15
|
+
http.should_receive(:ready?).and_return(false, true)
|
16
|
+
|
17
|
+
monitor = Shamrock::Monitor.new(http)
|
8
18
|
monitor.wait_until_ready
|
9
19
|
end
|
10
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shamrock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-06-
|
12
|
+
date: 2012-06-10 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rack
|
@@ -84,16 +84,19 @@ extensions: []
|
|
84
84
|
extra_rdoc_files: []
|
85
85
|
files:
|
86
86
|
- .gitignore
|
87
|
+
- .rspec
|
87
88
|
- Gemfile
|
88
89
|
- LICENSE
|
89
90
|
- README.md
|
90
91
|
- Rakefile
|
91
92
|
- lib/shamrock.rb
|
93
|
+
- lib/shamrock/http.rb
|
92
94
|
- lib/shamrock/monitor.rb
|
93
95
|
- lib/shamrock/port.rb
|
94
96
|
- lib/shamrock/service.rb
|
95
97
|
- lib/shamrock/version.rb
|
96
98
|
- shamrock.gemspec
|
99
|
+
- spec/shamrock/http_spec.rb
|
97
100
|
- spec/shamrock/monitor_spec.rb
|
98
101
|
- spec/shamrock/port_spec.rb
|
99
102
|
- spec/shamrock/service_spec.rb
|
@@ -123,6 +126,7 @@ signing_key:
|
|
123
126
|
specification_version: 3
|
124
127
|
summary: Facilitates setting up stub services in your application
|
125
128
|
test_files:
|
129
|
+
- spec/shamrock/http_spec.rb
|
126
130
|
- spec/shamrock/monitor_spec.rb
|
127
131
|
- spec/shamrock/port_spec.rb
|
128
132
|
- spec/shamrock/service_spec.rb
|