mimic 0.2.0 → 0.3.0
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 +4 -0
- data/Rakefile +8 -2
- data/lib/mimic.rb +26 -1
- data/lib/mimic/fake_host.rb +10 -10
- metadata +4 -4
data/README.md
CHANGED
@@ -46,6 +46,10 @@ Finally, because Mimic is built on top of Sinatra for the core request handling,
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
|
49
|
+
## Contributors
|
50
|
+
|
51
|
+
* [James Fairbairn](http://github.com/jfairbairn)
|
52
|
+
|
49
53
|
## License
|
50
54
|
|
51
55
|
As usual, the code is released under the MIT license which is included in the repository.
|
data/Rakefile
CHANGED
@@ -14,6 +14,7 @@ Spec::Rake::SpecTask.new('specs') do |t|
|
|
14
14
|
end
|
15
15
|
|
16
16
|
task :default => :specs
|
17
|
+
task :all => [:specs, :features]
|
17
18
|
|
18
19
|
require "rake/gempackagetask"
|
19
20
|
require "rake/rdoctask"
|
@@ -27,9 +28,9 @@ spec = Gem::Specification.new do |s|
|
|
27
28
|
|
28
29
|
# Change these as appropriate
|
29
30
|
s.name = "mimic"
|
30
|
-
s.version = "0.
|
31
|
+
s.version = "0.3.0"
|
31
32
|
s.summary = "A Ruby gem for faking external web services for testing"
|
32
|
-
s.
|
33
|
+
s.authors = "Luke Redpath"
|
33
34
|
s.email = "luke@lukeredpath.co.uk"
|
34
35
|
s.homepage = "http://lukeredpath.co.uk"
|
35
36
|
|
@@ -82,3 +83,8 @@ desc 'Clear out RDoc and generated packages'
|
|
82
83
|
task :clean => [:clobber_rdoc, :clobber_package] do
|
83
84
|
rm "#{spec.name}.gemspec"
|
84
85
|
end
|
86
|
+
|
87
|
+
task 'Release if all specs pass'
|
88
|
+
task :release => [:specs, :features, :package] do
|
89
|
+
system("gem push pkg/#{spec.name}-#{spec.version}.gem")
|
90
|
+
end
|
data/lib/mimic.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
require 'mimic/fake_host'
|
2
2
|
require 'singleton'
|
3
3
|
require 'rack'
|
4
|
-
require 'ghost'
|
5
4
|
require 'logger'
|
6
5
|
|
7
6
|
module Mimic
|
@@ -36,6 +35,8 @@ module Mimic
|
|
36
35
|
|
37
36
|
) { |server| @server = server }
|
38
37
|
end
|
38
|
+
|
39
|
+
wait_for_service(host_app.hostname, port)
|
39
40
|
end
|
40
41
|
|
41
42
|
def shutdown
|
@@ -44,5 +45,29 @@ module Mimic
|
|
44
45
|
@server.shutdown
|
45
46
|
end
|
46
47
|
end
|
48
|
+
|
49
|
+
# courtesy of http://is.gd/eoYho
|
50
|
+
|
51
|
+
def listening?(host, port)
|
52
|
+
begin
|
53
|
+
socket = TCPSocket.new(host, port)
|
54
|
+
socket.close unless socket.nil?
|
55
|
+
true
|
56
|
+
rescue Errno::ECONNREFUSED, SocketError,
|
57
|
+
Errno::EBADF, # Windows
|
58
|
+
Errno::EADDRNOTAVAIL # Windows
|
59
|
+
false
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def wait_for_service(host, port, timeout = 5)
|
64
|
+
start_time = Time.now
|
65
|
+
|
66
|
+
until listening?(host, port)
|
67
|
+
if timeout && (Time.now > (start_time + timeout))
|
68
|
+
raise SocketError.new("Socket did not open within #{timeout} seconds")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
47
72
|
end
|
48
73
|
end
|
data/lib/mimic/fake_host.rb
CHANGED
@@ -14,24 +14,24 @@ module Mimic
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
def get(path)
|
18
|
-
request("GET", path)
|
17
|
+
def get(path, &block)
|
18
|
+
request("GET", path, &block)
|
19
19
|
end
|
20
20
|
|
21
|
-
def post(path)
|
22
|
-
request("POST", path)
|
21
|
+
def post(path, &block)
|
22
|
+
request("POST", path, &block)
|
23
23
|
end
|
24
24
|
|
25
|
-
def put(path)
|
26
|
-
request("PUT", path)
|
25
|
+
def put(path, &block)
|
26
|
+
request("PUT", path, &block)
|
27
27
|
end
|
28
28
|
|
29
|
-
def delete(path)
|
30
|
-
request("DELETE", path)
|
29
|
+
def delete(path, &block)
|
30
|
+
request("DELETE", path, &block)
|
31
31
|
end
|
32
32
|
|
33
|
-
def head(path)
|
34
|
-
request("HEAD", path)
|
33
|
+
def head(path, &block)
|
34
|
+
request("HEAD", path, &block)
|
35
35
|
end
|
36
36
|
|
37
37
|
def call(env)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mimic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Luke Redpath
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-08-
|
18
|
+
date: 2010-08-20 00:00:00 +01:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|