shamrock 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -0
- data/lib/shamrock/monitor.rb +1 -9
- data/lib/shamrock/service.rb +6 -0
- data/lib/shamrock/version.rb +1 -1
- data/spec/shamrock/monitor_spec.rb +11 -0
- data/spec/shamrock/service_spec.rb +16 -5
- metadata +3 -1
data/README.md
CHANGED
@@ -39,6 +39,7 @@ Thanks to Mike Barinek for writing up an example of this code that used Threads
|
|
39
39
|
the rack application - this gem draws from code in his blog post at
|
40
40
|
http://pivotallabs.com/users/mbarinek/blog/articles/2043-testing-ruby-services-without-mocks
|
41
41
|
|
42
|
+
Thanks to Kurt Eldridge (http://github.com/truk) for pair programming on a test problem with Threads.
|
42
43
|
|
43
44
|
## Contributing
|
44
45
|
|
data/lib/shamrock/monitor.rb
CHANGED
@@ -13,13 +13,11 @@ module Shamrock
|
|
13
13
|
|
14
14
|
def wait_until_ready
|
15
15
|
Timeout::timeout(DEFAULT_TIMEOUT) do
|
16
|
-
until
|
16
|
+
until ready? do
|
17
17
|
sleep RE_CHECK_WAIT
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
-
puts "Started server #{server_name} on #{port.number}."
|
22
|
-
|
23
21
|
rescue Timeout::Error => error
|
24
22
|
abort "Server never started!"
|
25
23
|
end
|
@@ -33,11 +31,5 @@ module Shamrock
|
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
36
|
-
private
|
37
|
-
|
38
|
-
def server_name
|
39
|
-
@rack_app.class.name
|
40
|
-
end
|
41
|
-
|
42
34
|
end
|
43
35
|
end
|
data/lib/shamrock/service.rb
CHANGED
data/lib/shamrock/version.rb
CHANGED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Shamrock::Monitor do
|
4
|
+
describe "#wait_until_ready" do
|
5
|
+
it "should check to see if the given url is available" do
|
6
|
+
monitor = Shamrock::Monitor.new('http://example.com')
|
7
|
+
monitor.should_receive(:ready?).and_return(true)
|
8
|
+
monitor.wait_until_ready
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -3,22 +3,33 @@ require 'spec_helper'
|
|
3
3
|
describe Shamrock::Service do
|
4
4
|
before do
|
5
5
|
@rack_app = proc {|env| [200, {"Content-Type" => "text/html"}, "Hello Rack!"]}
|
6
|
-
|
7
|
-
|
6
|
+
end
|
7
|
+
|
8
|
+
class Shamrock::Service::Thread
|
9
|
+
def initialize(&block)
|
10
|
+
yield
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
describe "#start" do
|
11
15
|
it "should start the server" do
|
16
|
+
monitor = mock('monitor', wait_until_ready: true)
|
17
|
+
monitor_class = mock('monitor class', new: monitor)
|
18
|
+
|
12
19
|
handler = mock('handler')
|
13
|
-
service = Shamrock::Service.new(@rack_app, handler,
|
20
|
+
service = Shamrock::Service.new(@rack_app, handler, monitor_class)
|
14
21
|
handler.should_receive(:run).with(@rack_app, Port: service.port.number)
|
15
22
|
service.start
|
16
23
|
end
|
17
24
|
|
18
25
|
it "should wait for the server to become available" do
|
19
|
-
|
26
|
+
monitor = mock('monitor')
|
27
|
+
monitor_class = mock('monitor class', new: monitor)
|
28
|
+
|
29
|
+
monitor.should_receive(:wait_until_ready).once
|
30
|
+
|
20
31
|
handler = mock('handler', run: true)
|
21
|
-
Shamrock::Service.new(@rack_app, handler,
|
32
|
+
Shamrock::Service.new(@rack_app, handler, monitor_class).start
|
22
33
|
end
|
23
34
|
end
|
24
35
|
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/shamrock/service.rb
|
95
95
|
- lib/shamrock/version.rb
|
96
96
|
- shamrock.gemspec
|
97
|
+
- spec/shamrock/monitor_spec.rb
|
97
98
|
- spec/shamrock/port_spec.rb
|
98
99
|
- spec/shamrock/service_spec.rb
|
99
100
|
- spec/spec_helper.rb
|
@@ -122,6 +123,7 @@ signing_key:
|
|
122
123
|
specification_version: 3
|
123
124
|
summary: Facilitates setting up stub services in your application
|
124
125
|
test_files:
|
126
|
+
- spec/shamrock/monitor_spec.rb
|
125
127
|
- spec/shamrock/port_spec.rb
|
126
128
|
- spec/shamrock/service_spec.rb
|
127
129
|
- spec/spec_helper.rb
|