lyre 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile.lock +34 -0
- data/README.md +8 -0
- data/Rakefile +1 -1
- data/lib/lyre/app.rb +55 -0
- data/lib/lyre/constants.rb +3 -0
- data/lib/lyre/registry.rb +27 -0
- data/lib/lyre/version.rb +1 -1
- data/lib/lyre.rb +2 -0
- data/lyre.gemspec +2 -0
- data/spec/end_to_end_spec.rb +17 -0
- data/spec/fake_service_spec.rb +7 -0
- data/spec/lifecycle_spec.rb +47 -0
- data/spec/registration_spec.rb +20 -0
- data/spec/spec_helper.rb +5 -1
- data/spec/support/fake_service.rb +4 -2
- data/spec/support/fake_service_lyre.rb +16 -0
- data/spec/support/life_cycle_lyre.rb +27 -0
- data/spec/support/no_life_cycle_lyre.rb +2 -0
- metadata +52 -2
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,15 +2,39 @@ PATH
|
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
4
|
lyre (0.0.0)
|
5
|
+
capybara
|
5
6
|
sinatra
|
6
7
|
|
7
8
|
GEM
|
8
9
|
remote: http://rubygems.org/
|
9
10
|
specs:
|
11
|
+
capybara (2.0.2)
|
12
|
+
mime-types (>= 1.16)
|
13
|
+
nokogiri (>= 1.3.3)
|
14
|
+
rack (>= 1.0.0)
|
15
|
+
rack-test (>= 0.5.4)
|
16
|
+
selenium-webdriver (~> 2.0)
|
17
|
+
xpath (~> 1.0.0)
|
18
|
+
childprocess (0.3.8)
|
19
|
+
ffi (~> 1.0, >= 1.0.11)
|
20
|
+
columnize (0.3.6)
|
21
|
+
debugger (1.3.1)
|
22
|
+
columnize (>= 0.3.1)
|
23
|
+
debugger-linecache (~> 1.1.1)
|
24
|
+
debugger-ruby_core_source (~> 1.1.8)
|
25
|
+
debugger-linecache (1.1.2)
|
26
|
+
debugger-ruby_core_source (>= 1.1.1)
|
27
|
+
debugger-ruby_core_source (1.1.8)
|
10
28
|
diff-lcs (1.1.3)
|
29
|
+
ffi (1.3.1)
|
30
|
+
mime-types (1.21)
|
31
|
+
multi_json (1.6.0)
|
32
|
+
nokogiri (1.5.6)
|
11
33
|
rack (1.5.2)
|
12
34
|
rack-protection (1.3.2)
|
13
35
|
rack
|
36
|
+
rack-test (0.6.2)
|
37
|
+
rack (>= 1.0)
|
14
38
|
rake (10.0.3)
|
15
39
|
rspec (2.12.0)
|
16
40
|
rspec-core (~> 2.12.0)
|
@@ -20,16 +44,26 @@ GEM
|
|
20
44
|
rspec-expectations (2.12.1)
|
21
45
|
diff-lcs (~> 1.1.3)
|
22
46
|
rspec-mocks (2.12.2)
|
47
|
+
rubyzip (0.9.9)
|
48
|
+
selenium-webdriver (2.29.0)
|
49
|
+
childprocess (>= 0.2.5)
|
50
|
+
multi_json (~> 1.0)
|
51
|
+
rubyzip
|
52
|
+
websocket (~> 1.0.4)
|
23
53
|
sinatra (1.3.4)
|
24
54
|
rack (~> 1.4)
|
25
55
|
rack-protection (~> 1.3)
|
26
56
|
tilt (~> 1.3, >= 1.3.3)
|
27
57
|
tilt (1.3.3)
|
58
|
+
websocket (1.0.7)
|
59
|
+
xpath (1.0.0)
|
60
|
+
nokogiri (~> 1.3)
|
28
61
|
|
29
62
|
PLATFORMS
|
30
63
|
ruby
|
31
64
|
|
32
65
|
DEPENDENCIES
|
66
|
+
debugger
|
33
67
|
lyre!
|
34
68
|
rake
|
35
69
|
rspec
|
data/README.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# Notes
|
2
|
+
|
3
|
+
http://robots.thoughtbot.com/post/34761570235/using-capybara-to-test-javascript-that-makes-http
|
4
|
+
|
5
|
+
Check out the set_configuration call below:
|
6
|
+
https://github.com/thoughtbot/fake_braintree/blob/master/lib/fake_braintree.rb
|
7
|
+
|
8
|
+
http://www.sinatrarb.com/intro#Rack%20Middleware
|
data/Rakefile
CHANGED
data/lib/lyre/app.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'lyre/registry'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
module Lyre
|
5
|
+
|
6
|
+
#NOTE: Not sure this is the right name for this class
|
7
|
+
class App < Sinatra::Base
|
8
|
+
|
9
|
+
attr_accessor :host, :port
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :setup_block, :teardown_block
|
13
|
+
|
14
|
+
def setup(&block)
|
15
|
+
self.setup_block = block
|
16
|
+
end
|
17
|
+
|
18
|
+
def teardown(&block)
|
19
|
+
self.teardown_block = block
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :create, :new! #Sinatra redefines new as new!, so make it easy to access
|
23
|
+
end
|
24
|
+
|
25
|
+
def start
|
26
|
+
return if started?
|
27
|
+
Lyre::Registry.register_and_run self
|
28
|
+
self.instance_eval(&self.class.setup_block) if self.class.setup_block
|
29
|
+
self.started = true
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def stop
|
34
|
+
return unless started?
|
35
|
+
Lyre::Registry.stop_and_deregister self
|
36
|
+
self.instance_eval(&self.class.teardown_block) if self.class.teardown_block
|
37
|
+
self.started = false
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
def endpoint
|
42
|
+
"http://#{host}:#{port}" #may want to make http/https configurable
|
43
|
+
end
|
44
|
+
|
45
|
+
def started?
|
46
|
+
started
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
attr_accessor :started
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
@@ -0,0 +1,27 @@
|
|
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
|
data/lib/lyre/version.rb
CHANGED
data/lib/lyre.rb
CHANGED
data/lyre.gemspec
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'End to end test - Refactor later' do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@lyre = FakeServiceLyre.create.start
|
7
|
+
end
|
8
|
+
|
9
|
+
after(:all) do
|
10
|
+
@lyre.stop
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should mock the endpoint that FakeService tries to access" do
|
14
|
+
FakeService.call_service.should == 'Hello World'
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Lifecycle Tests" do
|
4
|
+
|
5
|
+
describe "setup and teardown are called" do
|
6
|
+
before(:each) { @lyre = LifeCycleLyre.create.start }
|
7
|
+
after(:each) { @lyre.stop }
|
8
|
+
|
9
|
+
it "should call setup block when the lyre is started" do
|
10
|
+
LifeCycleLyre.setup_called.should be_true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should call teardown block when the lyre is stopped" do
|
14
|
+
@lyre.stop
|
15
|
+
|
16
|
+
LifeCycleLyre.setup_called.should be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "setup and teardown are optional" do
|
21
|
+
before(:each) { @lyre = NoLifeCycleLyre.create }
|
22
|
+
after(:each) { @lyre.stop }
|
23
|
+
|
24
|
+
it "should not fail if the lyre has no setup" do
|
25
|
+
@lyre.start
|
26
|
+
end
|
27
|
+
|
28
|
+
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
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
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
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
require '
|
1
|
+
require 'lyre'
|
2
2
|
|
3
3
|
PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')).freeze
|
4
4
|
|
5
5
|
Dir[File.join(PROJECT_ROOT, 'spec', 'support', '**', '*.rb')].each { |file| require(file) }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.order = :random
|
9
|
+
end
|
@@ -4,7 +4,7 @@ class FakeService
|
|
4
4
|
|
5
5
|
class << self
|
6
6
|
def endpoint
|
7
|
-
@endpoint || 'example.com'
|
7
|
+
@endpoint || 'http://nowhere.example.com'
|
8
8
|
end
|
9
9
|
|
10
10
|
def endpoint=(value)
|
@@ -12,7 +12,9 @@ class FakeService
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def call_service
|
15
|
-
|
15
|
+
url = URI.parse(endpoint)
|
16
|
+
|
17
|
+
http = Net::HTTP.new(url.host, url.port)
|
16
18
|
request = Net::HTTP::Get.new("/")
|
17
19
|
response = http.request(request)
|
18
20
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class LifeCycleLyre < Lyre::App
|
2
|
+
|
3
|
+
setup do
|
4
|
+
LifeCycleLyre.setup_called = true
|
5
|
+
end
|
6
|
+
|
7
|
+
teardown do
|
8
|
+
LifeCycleLyre.teardown_called = true
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.setup_called
|
12
|
+
@@setup_called
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.setup_called=(value)
|
16
|
+
@@setup_called = value
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.teardown_called
|
20
|
+
@@teardown_called
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.teardown_called=(value)
|
24
|
+
@@teardown_called = value
|
25
|
+
end
|
26
|
+
|
27
|
+
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.0.
|
4
|
+
version: 0.0.1
|
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-
|
12
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: capybara
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
- !ruby/object:Gem::Dependency
|
31
47
|
name: rake
|
32
48
|
requirement: !ruby/object:Gem::Requirement
|
@@ -59,6 +75,22 @@ dependencies:
|
|
59
75
|
- - ! '>='
|
60
76
|
- !ruby/object:Gem::Version
|
61
77
|
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: debugger
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
62
94
|
description: Awesome mocks of external REST API dependencies
|
63
95
|
email:
|
64
96
|
- dev@sortfolio.com
|
@@ -70,12 +102,23 @@ files:
|
|
70
102
|
- .rvmrc
|
71
103
|
- Gemfile
|
72
104
|
- Gemfile.lock
|
105
|
+
- README.md
|
73
106
|
- Rakefile
|
74
107
|
- lib/lyre.rb
|
108
|
+
- lib/lyre/app.rb
|
109
|
+
- lib/lyre/constants.rb
|
110
|
+
- lib/lyre/registry.rb
|
75
111
|
- lib/lyre/version.rb
|
76
112
|
- lyre.gemspec
|
113
|
+
- spec/end_to_end_spec.rb
|
114
|
+
- spec/fake_service_spec.rb
|
115
|
+
- spec/lifecycle_spec.rb
|
116
|
+
- spec/registration_spec.rb
|
77
117
|
- spec/spec_helper.rb
|
78
118
|
- spec/support/fake_service.rb
|
119
|
+
- spec/support/fake_service_lyre.rb
|
120
|
+
- spec/support/life_cycle_lyre.rb
|
121
|
+
- spec/support/no_life_cycle_lyre.rb
|
79
122
|
homepage: ''
|
80
123
|
licenses: []
|
81
124
|
post_install_message:
|
@@ -101,5 +144,12 @@ signing_key:
|
|
101
144
|
specification_version: 3
|
102
145
|
summary: Awesome mocks of external REST API dependencies
|
103
146
|
test_files:
|
147
|
+
- spec/end_to_end_spec.rb
|
148
|
+
- spec/fake_service_spec.rb
|
149
|
+
- spec/lifecycle_spec.rb
|
150
|
+
- spec/registration_spec.rb
|
104
151
|
- spec/spec_helper.rb
|
105
152
|
- spec/support/fake_service.rb
|
153
|
+
- spec/support/fake_service_lyre.rb
|
154
|
+
- spec/support/life_cycle_lyre.rb
|
155
|
+
- spec/support/no_life_cycle_lyre.rb
|