lyre 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/lyre/app.rb CHANGED
@@ -1,12 +1,12 @@
1
- require 'lyre/registry'
2
- require 'sinatra'
1
+ require 'sinatra/base'
2
+ require 'capybara'
3
3
 
4
4
  module Lyre
5
5
 
6
6
  #NOTE: Not sure this is the right name for this class
7
7
  class App < Sinatra::Base
8
8
 
9
- attr_accessor :host, :port
9
+ attr_accessor :endpoint
10
10
 
11
11
  class << self
12
12
  attr_accessor :setup_block, :teardown_block
@@ -19,37 +19,25 @@ module Lyre
19
19
  self.teardown_block = block
20
20
  end
21
21
 
22
- alias_method :create, :new! #Sinatra redefines new as new!, so make it easy to access
23
- end
22
+ def boot
23
+ instance = self.new! #maybe just new
24
24
 
25
- def start
26
- return if started?
27
- Lyre::Registry.register_and_run self
28
- self.class.setup_block.call(self) if self.class.setup_block
29
- self.started = true
30
- self
31
- end
25
+ Capybara::Server.new(instance).tap do |server|
26
+ server.boot
32
27
 
33
- def stop
34
- return unless started?
35
- Lyre::Registry.stop_and_deregister self
36
- self.class.teardown_block.call(self) if self.class.teardown_block
37
- self.started = false
38
- self
39
- end
28
+ instance.endpoint = "http://#{server.host}:#{server.port}"
29
+
30
+ setup_block.call(instance) if setup_block
31
+ end
40
32
 
41
- def endpoint
42
- "http://#{host}:#{port}" #may want to make http/https configurable
33
+ instance
34
+ end
43
35
  end
44
36
 
45
- def started?
46
- started
37
+ def shutdown
38
+ self.class.teardown_block.call(self) if self.class.teardown_block
47
39
  end
48
40
 
49
- private
50
-
51
- attr_accessor :started
52
-
53
41
  end
54
42
 
55
43
  end
data/lib/lyre/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Lyre
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -3,11 +3,11 @@ require 'spec_helper'
3
3
  describe 'End to end test - Refactor later' do
4
4
 
5
5
  before(:all) do
6
- @lyre = FakeServiceLyre.create.start
6
+ @lyre = FakeServiceLyre.boot
7
7
  end
8
8
 
9
9
  after(:all) do
10
- @lyre.stop
10
+ @lyre.shutdown
11
11
  end
12
12
 
13
13
  it "should mock the endpoint that FakeService tries to access" do
@@ -3,45 +3,28 @@ require 'spec_helper'
3
3
  describe "Lifecycle Tests" do
4
4
 
5
5
  describe "setup and teardown are called" do
6
- before(:each) { @lyre = LifeCycleLyre.create.start }
7
- after(:each) { @lyre.stop }
6
+ before(:each) { @lyre = LifeCycleLyre.boot }
7
+ after(:each) { @lyre.shutdown }
8
8
 
9
9
  it "should call setup block when the lyre is started" do
10
10
  LifeCycleLyre.setup_called.should be_true
11
11
  end
12
12
 
13
13
  it "should call teardown block when the lyre is stopped" do
14
- @lyre.stop
14
+ @lyre.shutdown
15
15
 
16
16
  LifeCycleLyre.setup_called.should be_true
17
17
  end
18
18
  end
19
19
 
20
20
  describe "setup and teardown are optional" do
21
- before(:each) { @lyre = NoLifeCycleLyre.create }
22
- after(:each) { @lyre.stop }
23
-
24
21
  it "should not fail if the lyre has no setup" do
25
- @lyre.start
22
+ NoLifeCycleLyre.boot
26
23
  end
27
24
 
28
25
  it "should not fail of the lyre has no teardown" do
29
- @lyre.stop
30
- end
31
- end
32
-
33
- describe "start and stop are idempotent" do
34
- before(:each) { @lyre = NoLifeCycleLyre.create }
35
- after(:each) { @lyre.stop }
36
-
37
- it "should allow start to be called twice" do
38
- @lyre.start.start
39
- end
40
-
41
- it "should allow stop to be called twice" do
42
- @lyre.start.stop.stop
26
+ NoLifeCycleLyre.boot.shutdown
43
27
  end
44
-
45
28
  end
46
29
 
47
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lyre
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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: 2013-02-17 00:00:00.000000000 Z
12
+ date: 2013-02-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
@@ -123,13 +123,11 @@ files:
123
123
  - lib/lyre.rb
124
124
  - lib/lyre/app.rb
125
125
  - lib/lyre/constants.rb
126
- - lib/lyre/registry.rb
127
126
  - lib/lyre/version.rb
128
127
  - lyre.gemspec
129
128
  - spec/end_to_end_spec.rb
130
129
  - spec/fake_service_spec.rb
131
130
  - spec/lifecycle_spec.rb
132
- - spec/registration_spec.rb
133
131
  - spec/spec_helper.rb
134
132
  - spec/support/fake_service.rb
135
133
  - spec/support/fake_service_lyre.rb
@@ -163,7 +161,6 @@ test_files:
163
161
  - spec/end_to_end_spec.rb
164
162
  - spec/fake_service_spec.rb
165
163
  - spec/lifecycle_spec.rb
166
- - spec/registration_spec.rb
167
164
  - spec/spec_helper.rb
168
165
  - spec/support/fake_service.rb
169
166
  - spec/support/fake_service_lyre.rb
data/lib/lyre/registry.rb DELETED
@@ -1,27 +0,0 @@
1
- require 'capybara'
2
-
3
- module Lyre
4
- module Registry
5
-
6
- @@registry = {}
7
-
8
- def self.register_and_run(lyre)
9
- raise "Lyre already registered" if @@registry.has_key? lyre.class
10
-
11
- @@registry[lyre.class] = Capybara::Server.new(lyre).tap do |server|
12
- server.boot
13
-
14
- lyre.host = server.host
15
- lyre.port = server.port
16
- end
17
- end
18
-
19
- def self.stop_and_deregister(lyre)
20
- raise "Lyre not registered" unless @@registry.has_key? lyre.class
21
-
22
- #server cannot be stopped
23
-
24
- @@registry.delete(lyre.class)
25
- end
26
- end
27
- end
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Lyre registration" do
4
-
5
- before(:each) do
6
- @lyre_one = FakeServiceLyre.create
7
- @lyre_two = FakeServiceLyre.create
8
- end
9
-
10
- after(:each) do
11
- @lyre_one.stop
12
- @lyre_two.stop
13
- end
14
-
15
- it "should not allow two instances of the same lyre to run simultaneously" do
16
- @lyre_one.start
17
- expect { @lyre_two.start }.to raise_error('Lyre already registered')
18
- end
19
-
20
- end