shamrock 0.0.4 → 0.0.5
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/README.md +1 -1
- data/Rakefile +11 -2
- data/integration_spec/service_spec.rb +12 -0
- data/lib/shamrock/service.rb +1 -8
- data/lib/shamrock/version.rb +1 -1
- data/spec/shamrock/service_spec.rb +1 -8
- data/spec/spec_helper.rb +7 -0
- metadata +3 -2
data/README.md
CHANGED
@@ -22,7 +22,7 @@ You can then easily start the stub service either for the spec examples that nee
|
|
22
22
|
globally in your spec_helper file. You can replace the Proc below with any Rack application.
|
23
23
|
In some cases, we use Sinatra for stub services.
|
24
24
|
|
25
|
-
my_rack_app = proc {|env| [200, {"Content-Type" => "text/html"}, "Hello Rack!"]}
|
25
|
+
my_rack_app = proc {|env| [200, {"Content-Type" => "text/html"}, ["Hello Rack!"]]}
|
26
26
|
@service = Shamrock::Service.new(my_rack_app)
|
27
27
|
@service.start
|
28
28
|
|
data/Rakefile
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
require "bundler/gem_tasks"
|
3
3
|
|
4
4
|
require "rspec/core/rake_task"
|
5
|
-
RSpec::Core::RakeTask.new(:spec)
|
6
5
|
|
7
|
-
|
6
|
+
namespace :spec do
|
7
|
+
RSpec::Core::RakeTask.new(:unit) do |t|
|
8
|
+
t.pattern = Dir['spec/*/**/*_spec.rb']
|
9
|
+
end
|
10
|
+
|
11
|
+
RSpec::Core::RakeTask.new(:integration) do |t|
|
12
|
+
t.pattern = "integration_spec/**/*_spec.rb"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task :default => ["spec:unit", "spec:integration"]
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'shamrock'
|
3
|
+
|
4
|
+
describe "starting a service and making a request" do
|
5
|
+
it "should respond successfully" do
|
6
|
+
rack_app = proc {|env| [200, {"Content-Type" => "text/html"}, ["Hello Rack!"]]}
|
7
|
+
service = Shamrock::Service.new(rack_app)
|
8
|
+
service.start
|
9
|
+
Net::HTTP.get(URI.parse("http://localhost:#{service.port}")).to_s.should == "Hello Rack!"
|
10
|
+
service.stop
|
11
|
+
end
|
12
|
+
end
|
data/lib/shamrock/service.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
1
|
module Shamrock
|
4
2
|
class Service
|
5
3
|
|
@@ -18,7 +16,6 @@ module Shamrock
|
|
18
16
|
options = DEFAULT_OPTIONS.merge(options)
|
19
17
|
|
20
18
|
@handler = options[:handler]
|
21
|
-
@logger = logger
|
22
19
|
|
23
20
|
@port = options[:port] || random_port
|
24
21
|
@url = "http://localhost:#{port}"
|
@@ -27,7 +24,7 @@ module Shamrock
|
|
27
24
|
|
28
25
|
def start
|
29
26
|
@thread = Thread.new do
|
30
|
-
@handler.run(@rack_app, Port: port
|
27
|
+
@handler.run(@rack_app, Port: port)
|
31
28
|
end
|
32
29
|
|
33
30
|
@monitor.wait_until_ready
|
@@ -39,10 +36,6 @@ module Shamrock
|
|
39
36
|
|
40
37
|
private
|
41
38
|
|
42
|
-
def logger
|
43
|
-
defined? Rails ? Rails.logger : Logger.new(STDOUT)
|
44
|
-
end
|
45
|
-
|
46
39
|
def random_port
|
47
40
|
Random.rand(PORT_RANGE)
|
48
41
|
end
|
data/lib/shamrock/version.rb
CHANGED
@@ -18,20 +18,13 @@ describe Shamrock::Service do
|
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#start" do
|
21
|
-
# In-line the service startup for this test
|
22
|
-
class Shamrock::Service::Thread
|
23
|
-
def initialize(&block)
|
24
|
-
yield
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
21
|
it "should start the server" do
|
29
22
|
monitor = mock('monitor', wait_until_ready: true)
|
30
23
|
monitor_class = mock('monitor class', new: monitor)
|
31
24
|
|
32
25
|
handler = mock('handler')
|
33
26
|
service = Shamrock::Service.new(@rack_app, handler: handler, monitor: monitor_class)
|
34
|
-
handler.should_receive(:run).with(@rack_app, Port: service.port
|
27
|
+
handler.should_receive(:run).with(@rack_app, Port: service.port)
|
35
28
|
service.start
|
36
29
|
end
|
37
30
|
|
data/spec/spec_helper.rb
CHANGED
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.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -90,6 +90,7 @@ files:
|
|
90
90
|
- LICENSE
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
|
+
- integration_spec/service_spec.rb
|
93
94
|
- lib/shamrock.rb
|
94
95
|
- lib/shamrock/http.rb
|
95
96
|
- lib/shamrock/monitor.rb
|
@@ -120,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
121
|
version: '0'
|
121
122
|
requirements: []
|
122
123
|
rubyforge_project:
|
123
|
-
rubygems_version: 1.8.
|
124
|
+
rubygems_version: 1.8.21
|
124
125
|
signing_key:
|
125
126
|
specification_version: 3
|
126
127
|
summary: Facilitates setting up stub services in your application
|