mirage 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.rvmrc +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +50 -0
- data/README.md +93 -0
- data/bin/mirage +54 -0
- data/features/checking_for_requests.feature +74 -0
- data/features/clearing_requests_and_responses.feature +81 -0
- data/features/client/checking_for_requests.feature +20 -0
- data/features/client/clearing_responses.feature +75 -0
- data/features/client/getting_responses.feature +30 -0
- data/features/client/mirage_client.feature +36 -0
- data/features/client/peeking.feature +32 -0
- data/features/client/setting_responses.feature +91 -0
- data/features/client/snapshotting.feature +34 -0
- data/features/command_line_iterface.feature +39 -0
- data/features/default_responses.feature +91 -0
- data/features/file_hosting.feature +8 -0
- data/features/logging.feature +7 -0
- data/features/peeking_at_response.feature +24 -0
- data/features/resources/test.zip +0 -0
- data/features/response_templates.feature +45 -0
- data/features/root_responses.feature +47 -0
- data/features/setting_responses.feature +40 -0
- data/features/setting_responses_with_a_delay.feature +10 -0
- data/features/setting_responses_with_pattern_matching.feature +72 -0
- data/features/snapshotting.feature +25 -0
- data/features/step_definitions/my_steps.rb +127 -0
- data/features/support/env.rb +89 -0
- data/features/web_user_interface.feature +39 -0
- data/full_build.sh +100 -0
- data/lib/config.ru +5 -0
- data/lib/mirage.rb +14 -0
- data/lib/mirage/client.rb +140 -0
- data/lib/mirage/core.rb +206 -0
- data/lib/mirage/util.rb +40 -0
- data/lib/mirage/web.rb +65 -0
- data/lib/start_mirage.rb +15 -0
- data/lib/view/mirage/index.xhtml +23 -0
- data/mirage.gemspec +40 -0
- data/rakefile +50 -0
- metadata +199 -0
data/lib/mirage/util.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
module Mirage
|
3
|
+
module Util
|
4
|
+
|
5
|
+
def wait_until time=30
|
6
|
+
start_time = Time.now
|
7
|
+
until Time.now >= start_time + time
|
8
|
+
sleep 0.1
|
9
|
+
return if yield
|
10
|
+
end
|
11
|
+
raise 'timeout waiting'
|
12
|
+
end
|
13
|
+
|
14
|
+
def parse_options args
|
15
|
+
options = {:port => 7001, :defaults_directory => 'defaults', :root_directory => '.'}
|
16
|
+
|
17
|
+
opt_parser = OptionParser.new do |opts|
|
18
|
+
opts.banner = "Usage: mirage start|stop [options]"
|
19
|
+
opts.on("-p", "--port PORT", "the port to start Mirage on") do |port|
|
20
|
+
options[:port] = port.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
opts.on("-d", "--defaults DIR", "location to load default responses from") do |directory|
|
24
|
+
options[:defaults_directory] = directory
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
opt_parser.parse args
|
30
|
+
rescue
|
31
|
+
puts "mirage start|stop [OPTIONS]"
|
32
|
+
puts opt_parser
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
options
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
data/lib/mirage/web.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module Mirage
|
2
|
+
module Web
|
3
|
+
class FileResponse
|
4
|
+
def initialize response
|
5
|
+
@response = response
|
6
|
+
end
|
7
|
+
|
8
|
+
def save_as path
|
9
|
+
@response.save_as(path)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def http_get url, params={}
|
14
|
+
uri = URI.parse(url)
|
15
|
+
if params[:body]
|
16
|
+
response = Net::HTTP.start(uri.host, uri.port) do |http|
|
17
|
+
request = Net::HTTP::Get.new(uri.path)
|
18
|
+
request.body=params[:body]
|
19
|
+
http.request(request)
|
20
|
+
end
|
21
|
+
|
22
|
+
def response.code
|
23
|
+
@code.to_i
|
24
|
+
end
|
25
|
+
|
26
|
+
else
|
27
|
+
response = using_mechanize do |browser|
|
28
|
+
browser.get(url, params)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
response
|
33
|
+
end
|
34
|
+
|
35
|
+
def http_post url, params={}
|
36
|
+
using_mechanize do |browser|
|
37
|
+
browser.post(url, params)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def using_mechanize
|
43
|
+
begin
|
44
|
+
browser = Mechanize.new
|
45
|
+
browser.keep_alive = false
|
46
|
+
response = yield browser
|
47
|
+
|
48
|
+
def response.code
|
49
|
+
@code.to_i
|
50
|
+
end
|
51
|
+
rescue Exception => e
|
52
|
+
response = e
|
53
|
+
|
54
|
+
def response.code
|
55
|
+
self.response_code.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
def response.body
|
59
|
+
""
|
60
|
+
end
|
61
|
+
end
|
62
|
+
response
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/start_mirage.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
$0='Mirage Server'
|
3
|
+
$LOAD_PATH.unshift("#{File.dirname(__FILE__)}/../lib")
|
4
|
+
require 'mirage'
|
5
|
+
include Mirage::Util
|
6
|
+
|
7
|
+
options = parse_options(ARGV)
|
8
|
+
|
9
|
+
DEFAULT_RESPONSES_DIR = "#{options[:defaults_directory]}"
|
10
|
+
Mirage.client = Mirage::Client.new
|
11
|
+
Ramaze::Log.loggers = [Logger.new('mirage.log')]
|
12
|
+
Ramaze::Log.level= Logger::WARN
|
13
|
+
Ramaze.start :port => options[:port]
|
14
|
+
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
6
|
+
<head>
|
7
|
+
<title>Mirage</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1>Welcome to Mirage</h1>
|
11
|
+
|
12
|
+
<p>Below are any responses you are currently hosting. Click the response itself to peek at it and click check to view the last request that triggered it. <br/>
|
13
|
+
Note: if requests or responses contain xml, you will need to view page source to see it properly.</p>
|
14
|
+
|
15
|
+
<?r unless @responses.empty? ?>
|
16
|
+
<table border="1" width='100%'>
|
17
|
+
<?r @responses.each do |key, response| ?>
|
18
|
+
<tr><td><a id='peek_response_#{response.response_id}' href="/mirage/peek/#{response.response_id}">#{key}</a></td><td><a id='check_response_#{response.response_id}' href="/mirage/check/#{response.response_id}">check</a></td></tr>
|
19
|
+
<?r end ?>
|
20
|
+
</table>
|
21
|
+
<?r end ?>
|
22
|
+
</body>
|
23
|
+
</html>
|
data/mirage.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'mirage'
|
3
|
+
s.version = '0.1.2'
|
4
|
+
s.authors = ["Leon Davis"]
|
5
|
+
s.homepage = 'https://github.com/lashd/Mirage'
|
6
|
+
s.description = 'Mirage is an application for hosting responses to fool your applications into thinking that they are talking to real endpoints whilst you are developing them. Its accessible via HTTP has a RESful interface so is easy to interact with.'
|
7
|
+
s.summary = "mirage-#{s.version}"
|
8
|
+
|
9
|
+
s.platform = Gem::Platform::RUBY
|
10
|
+
s.default_executable = "mirage"
|
11
|
+
s.post_install_message = %{
|
12
|
+
===============================================================================
|
13
|
+
Thanks you for installing mirage-#{s.version}.
|
14
|
+
|
15
|
+
Run Mirage with:
|
16
|
+
|
17
|
+
mirage start
|
18
|
+
===============================================================================
|
19
|
+
}
|
20
|
+
|
21
|
+
s.has_rdoc = 'true'
|
22
|
+
|
23
|
+
s.add_dependency 'rack', "~> 1.1.0"
|
24
|
+
s.add_dependency 'ramaze', ">= 2011.01.30"
|
25
|
+
s.add_dependency "mechanize", ">= 1.0.0"
|
26
|
+
|
27
|
+
s.add_development_dependency 'rake'
|
28
|
+
s.add_development_dependency 'cucumber'
|
29
|
+
s.add_development_dependency 'rspec'
|
30
|
+
s.add_development_dependency 'bundler'
|
31
|
+
|
32
|
+
s.rubygems_version = "1.3.7"
|
33
|
+
s.files = `git ls-files`.split("\n")
|
34
|
+
s.test_files = `git ls-files -- features/*`.split("\n")
|
35
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
36
|
+
s.require_path = "lib"
|
37
|
+
|
38
|
+
|
39
|
+
|
40
|
+
end
|
data/rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
$LOAD_PATH.unshift('lib')
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
|
5
|
+
require 'mirage/client'
|
6
|
+
require 'rake'
|
7
|
+
require 'open-uri'
|
8
|
+
require 'cucumber'
|
9
|
+
require 'cucumber/rake/task'
|
10
|
+
require 'mechanize'
|
11
|
+
|
12
|
+
def run_command command
|
13
|
+
system "export RUBYOPT='' && #{command}"
|
14
|
+
end
|
15
|
+
|
16
|
+
task :gem => :clean do
|
17
|
+
run_command 'gem build mirage.gemspec'
|
18
|
+
end
|
19
|
+
|
20
|
+
task :install => :gem do
|
21
|
+
run_command "gem install mirage"
|
22
|
+
end
|
23
|
+
|
24
|
+
Cucumber::Rake::Task.new(:features) do |t|
|
25
|
+
t.cucumber_opts = "mode=regression features --format pretty"
|
26
|
+
end
|
27
|
+
|
28
|
+
task :start_mirage => :stop_mirage do
|
29
|
+
run_command "mirage start"
|
30
|
+
task.reenable
|
31
|
+
end
|
32
|
+
|
33
|
+
task :stop_mirage do |task|
|
34
|
+
run_command "mirage stop"
|
35
|
+
task.reenable
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
task :clean do |task|
|
40
|
+
|
41
|
+
if run_command "gem list -i mirage"
|
42
|
+
puts "cleaning"
|
43
|
+
run_command "gem uninstall -x mirage"
|
44
|
+
end
|
45
|
+
Dir['*.gem'].each{|gem| FileUtils.rm_f(gem)}
|
46
|
+
task.reenable
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
task :default => [:install, :start_mirage, :features, :stop_mirage, :clean]
|
metadata
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mirage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.2
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leon Davis
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-03-22 00:00:00 +00:00
|
14
|
+
default_executable: mirage
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: rack
|
18
|
+
prerelease: false
|
19
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
|
+
none: false
|
21
|
+
requirements:
|
22
|
+
- - ~>
|
23
|
+
- !ruby/object:Gem::Version
|
24
|
+
version: 1.1.0
|
25
|
+
type: :runtime
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: ramaze
|
29
|
+
prerelease: false
|
30
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ">="
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 2011.01.30
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id002
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: mechanize
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 1.0.0
|
47
|
+
type: :runtime
|
48
|
+
version_requirements: *id003
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: rake
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
type: :development
|
59
|
+
version_requirements: *id004
|
60
|
+
- !ruby/object:Gem::Dependency
|
61
|
+
name: cucumber
|
62
|
+
prerelease: false
|
63
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: "0"
|
69
|
+
type: :development
|
70
|
+
version_requirements: *id005
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rspec
|
73
|
+
prerelease: false
|
74
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: "0"
|
80
|
+
type: :development
|
81
|
+
version_requirements: *id006
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: bundler
|
84
|
+
prerelease: false
|
85
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
86
|
+
none: false
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: "0"
|
91
|
+
type: :development
|
92
|
+
version_requirements: *id007
|
93
|
+
description: Mirage is an application for hosting responses to fool your applications into thinking that they are talking to real endpoints whilst you are developing them. Its accessible via HTTP has a RESful interface so is easy to interact with.
|
94
|
+
email:
|
95
|
+
executables:
|
96
|
+
- mirage
|
97
|
+
extensions: []
|
98
|
+
|
99
|
+
extra_rdoc_files: []
|
100
|
+
|
101
|
+
files:
|
102
|
+
- .rvmrc
|
103
|
+
- Gemfile
|
104
|
+
- Gemfile.lock
|
105
|
+
- README.md
|
106
|
+
- bin/mirage
|
107
|
+
- features/checking_for_requests.feature
|
108
|
+
- features/clearing_requests_and_responses.feature
|
109
|
+
- features/client/checking_for_requests.feature
|
110
|
+
- features/client/clearing_responses.feature
|
111
|
+
- features/client/getting_responses.feature
|
112
|
+
- features/client/mirage_client.feature
|
113
|
+
- features/client/peeking.feature
|
114
|
+
- features/client/setting_responses.feature
|
115
|
+
- features/client/snapshotting.feature
|
116
|
+
- features/command_line_iterface.feature
|
117
|
+
- features/default_responses.feature
|
118
|
+
- features/file_hosting.feature
|
119
|
+
- features/logging.feature
|
120
|
+
- features/peeking_at_response.feature
|
121
|
+
- features/resources/test.zip
|
122
|
+
- features/response_templates.feature
|
123
|
+
- features/root_responses.feature
|
124
|
+
- features/setting_responses.feature
|
125
|
+
- features/setting_responses_with_a_delay.feature
|
126
|
+
- features/setting_responses_with_pattern_matching.feature
|
127
|
+
- features/snapshotting.feature
|
128
|
+
- features/step_definitions/my_steps.rb
|
129
|
+
- features/support/env.rb
|
130
|
+
- features/web_user_interface.feature
|
131
|
+
- full_build.sh
|
132
|
+
- lib/config.ru
|
133
|
+
- lib/mirage.rb
|
134
|
+
- lib/mirage/client.rb
|
135
|
+
- lib/mirage/core.rb
|
136
|
+
- lib/mirage/util.rb
|
137
|
+
- lib/mirage/web.rb
|
138
|
+
- lib/start_mirage.rb
|
139
|
+
- lib/view/mirage/index.xhtml
|
140
|
+
- mirage.gemspec
|
141
|
+
- rakefile
|
142
|
+
has_rdoc: true
|
143
|
+
homepage: https://github.com/lashd/Mirage
|
144
|
+
licenses: []
|
145
|
+
|
146
|
+
post_install_message: "\n\
|
147
|
+
===============================================================================\n\
|
148
|
+
Thanks you for installing mirage-0.1.2. \n\n\
|
149
|
+
Run Mirage with:\n\n\
|
150
|
+
mirage start\n\
|
151
|
+
===============================================================================\n"
|
152
|
+
rdoc_options: []
|
153
|
+
|
154
|
+
require_paths:
|
155
|
+
- lib
|
156
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: "0"
|
162
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
|
+
none: false
|
164
|
+
requirements:
|
165
|
+
- - ">="
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: "0"
|
168
|
+
requirements: []
|
169
|
+
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 1.6.1
|
172
|
+
signing_key:
|
173
|
+
specification_version: 3
|
174
|
+
summary: mirage-0.1.2
|
175
|
+
test_files:
|
176
|
+
- features/checking_for_requests.feature
|
177
|
+
- features/clearing_requests_and_responses.feature
|
178
|
+
- features/client/checking_for_requests.feature
|
179
|
+
- features/client/clearing_responses.feature
|
180
|
+
- features/client/getting_responses.feature
|
181
|
+
- features/client/mirage_client.feature
|
182
|
+
- features/client/peeking.feature
|
183
|
+
- features/client/setting_responses.feature
|
184
|
+
- features/client/snapshotting.feature
|
185
|
+
- features/command_line_iterface.feature
|
186
|
+
- features/default_responses.feature
|
187
|
+
- features/file_hosting.feature
|
188
|
+
- features/logging.feature
|
189
|
+
- features/peeking_at_response.feature
|
190
|
+
- features/resources/test.zip
|
191
|
+
- features/response_templates.feature
|
192
|
+
- features/root_responses.feature
|
193
|
+
- features/setting_responses.feature
|
194
|
+
- features/setting_responses_with_a_delay.feature
|
195
|
+
- features/setting_responses_with_pattern_matching.feature
|
196
|
+
- features/snapshotting.feature
|
197
|
+
- features/step_definitions/my_steps.rb
|
198
|
+
- features/support/env.rb
|
199
|
+
- features/web_user_interface.feature
|