mirage 3.0.0.alpha.2 → 3.0.0.alpha.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +23 -1
- data/VERSION +1 -1
- data/lib/mirage/client/client.rb +2 -2
- data/lib/mirage/client/template.rb +7 -4
- data/lib/mirage/client/templates.rb +9 -2
- data/mirage.gemspec +2 -2
- data/server/mock_response.rb +4 -0
- data/server/server.rb +6 -5
- data/spec/client/cli_bridge_spec.rb +52 -57
- data/spec/client/client_spec.rb +2 -10
- data/spec/client/request_spec.rb +14 -30
- data/spec/client/requests_spec.rb +3 -4
- data/spec/client/runner_spec.rb +0 -1
- data/spec/client/template_configuration_spec.rb +2 -2
- data/spec/client/template_spec.rb +10 -2
- data/spec/client/templates_spec.rb +46 -18
- data/spec/server/mock_response_spec.rb +8 -0
- data/spec/server/server_spec.rb +10 -1
- data/spec/spec_helper.rb +2 -1
- data/test.rb +18 -17
- metadata +3 -3
data/README.md
CHANGED
@@ -17,7 +17,29 @@ Installation
|
|
17
17
|
gem install mirage
|
18
18
|
|
19
19
|
What's New?
|
20
|
-
-----------
|
20
|
+
-----------
|
21
|
+
### 3.0.0 (Currently in alpha)
|
22
|
+
------------------------------
|
23
|
+
3.0.0 is not out yet but I am going to spend the next few days filling in the what's new section in preparation for its release.
|
24
|
+
#### What's new in the Server:
|
25
|
+
##### 1: Mirage uses JSON as its communucations medium
|
26
|
+
Mirage is now configured using JSON. JSON is also used as the output format for Mirage's other operations.
|
27
|
+
##### 2: Full Request Data now tracked
|
28
|
+
You can now retrieve all data associated with a request that triggers a response. Previously only the the request body/query string was tracked.
|
29
|
+
Now the full request, including HTTP headers are returned when querying '/requests/template_id'
|
30
|
+
##### 3. Parameters and body content matchers are now specified seperately
|
31
|
+
Now you can specify as many parameter and body matchers as you want. These can be both litteral strings or Regex's
|
32
|
+
|
33
|
+
Previously, it was only possible to specify a single matcher and this would be applied against both the querystring and the request body.
|
34
|
+
##### 4. HTTP Header matchers
|
35
|
+
You can now also specify matchers against HTTP headers.
|
36
|
+
##### 5. More advanced template resolution.
|
37
|
+
Templates are now scored to find the most appropriate template when finding a match for a particular request. Previously the first potential match was returned even
|
38
|
+
if there was a more appropriate template.
|
39
|
+
|
40
|
+
Litteral matchers are worth more in the scoring process than regex based ones for example.
|
41
|
+
#### What's new in the Client:
|
42
|
+
|
21
43
|
### 2.4.0
|
22
44
|
---------
|
23
45
|
#### What do I get?
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.0.alpha.
|
1
|
+
3.0.0.alpha.3
|
data/lib/mirage/client/client.rb
CHANGED
@@ -2,6 +2,7 @@ require 'ostruct'
|
|
2
2
|
require 'json'
|
3
3
|
require 'httparty'
|
4
4
|
require 'hashie/mash'
|
5
|
+
|
5
6
|
module Mirage
|
6
7
|
|
7
8
|
class Template
|
@@ -23,6 +24,7 @@ module Mirage
|
|
23
24
|
template.delay = response_config.delay
|
24
25
|
template.content_type = response_config.content_type
|
25
26
|
template.status = response_config.status
|
27
|
+
template.headers = response_config.headers
|
26
28
|
|
27
29
|
template.required_parameters = request_config.parameters
|
28
30
|
template.required_body_content = request_config.body_content
|
@@ -37,7 +39,7 @@ module Mirage
|
|
37
39
|
|
38
40
|
format :json
|
39
41
|
|
40
|
-
attr_accessor :content_type, :http_method, :default, :status, :delay, :required_parameters, :required_body_content, :required_headers, :endpoint, :id, :url, :requests_url
|
42
|
+
attr_accessor :content_type, :http_method, :default, :status, :delay, :required_parameters, :required_body_content, :required_headers, :endpoint, :id, :url, :requests_url, :headers
|
41
43
|
attr_reader :value
|
42
44
|
|
43
45
|
|
@@ -52,6 +54,7 @@ module Mirage
|
|
52
54
|
@required_parameters = {}
|
53
55
|
@required_headers = {}
|
54
56
|
@required_body_content = []
|
57
|
+
@headers = {}
|
55
58
|
@default = default_config.default
|
56
59
|
end
|
57
60
|
|
@@ -72,15 +75,15 @@ module Mirage
|
|
72
75
|
:body => Base64.encode64(@value),
|
73
76
|
:status => status,
|
74
77
|
:default => default,
|
75
|
-
:content_type => content_type
|
78
|
+
:content_type => content_type,
|
79
|
+
:headers => headers
|
76
80
|
|
77
81
|
},
|
78
82
|
:request => {
|
79
83
|
:parameters => encode_regexs(required_parameters),
|
80
84
|
:headers => encode_regexs(required_headers),
|
81
85
|
:body_content => encode_regexs(required_body_content),
|
82
|
-
:http_method => http_method
|
83
|
-
|
86
|
+
:http_method => http_method,
|
84
87
|
},
|
85
88
|
:delay => delay
|
86
89
|
}.to_json
|
@@ -17,8 +17,15 @@ module Mirage
|
|
17
17
|
@requests.delete_all
|
18
18
|
end
|
19
19
|
|
20
|
-
def put
|
21
|
-
|
20
|
+
def put *args
|
21
|
+
if args.first.is_a?(Template)
|
22
|
+
template = args.first
|
23
|
+
template.endpoint = "#{@url}/#{template.endpoint}"
|
24
|
+
else
|
25
|
+
endpoint, response = args
|
26
|
+
template = Mirage::Template.new "#{@url}/#{endpoint}", response, @default_config
|
27
|
+
yield template if block_given?
|
28
|
+
end
|
22
29
|
yield template if block_given?
|
23
30
|
template.create
|
24
31
|
end
|
data/mirage.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "mirage"
|
8
|
-
s.version = "3.0.0.alpha.
|
8
|
+
s.version = "3.0.0.alpha.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leon Davis"]
|
12
|
-
s.date = "2013-04-
|
12
|
+
s.date = "2013-04-21"
|
13
13
|
s.description = "Mirage aids testing of your applications by hosting mock responses so that your applications do not have to talk to real endpoints. Its accessible via HTTP and has a RESTful interface."
|
14
14
|
s.executables = ["mirage"]
|
15
15
|
s.extra_rdoc_files = [
|
data/server/mock_response.rb
CHANGED
data/server/server.rb
CHANGED
@@ -136,11 +136,12 @@ module Mirage
|
|
136
136
|
block.call Mirage::Client.new "http://localhost:#{settings.port}/mirage"
|
137
137
|
end
|
138
138
|
|
139
|
-
def send_response(
|
140
|
-
sleep
|
141
|
-
content_type(
|
142
|
-
status
|
143
|
-
|
139
|
+
def send_response(mock_response, body='', request={}, query_string='')
|
140
|
+
sleep mock_response.response_spec['delay']
|
141
|
+
content_type(mock_response.response_spec['content_type'])
|
142
|
+
status mock_response.response_spec['status']
|
143
|
+
headers mock_response.headers
|
144
|
+
mock_response.value(body, request, query_string)
|
144
145
|
end
|
145
146
|
|
146
147
|
def extract_http_headers(env)
|
@@ -1,68 +1,63 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'mirage/client'
|
3
3
|
|
4
|
-
describe
|
5
|
-
|
6
|
-
|
7
|
-
before :each do
|
8
|
-
@bridge = Object.new
|
9
|
-
@bridge.extend(Mirage::CLIBridge)
|
4
|
+
describe CLIBridge do
|
5
|
+
def mapping port
|
6
|
+
{port.to_s => port_pid_mappings[port.to_s]}
|
10
7
|
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
include_context :windows
|
15
|
-
|
16
|
-
it 'should find the pids of mirage instances for given ports' do
|
17
|
-
|
18
|
-
tasklist_output = "#{process_string_for_mirage(7001, 18903)}
|
19
|
-
#{process_string_for_mirage(7002, 18904)}
|
20
|
-
#{process_string_for_mirage(7003, 18905)}"
|
21
|
-
|
22
|
-
@bridge.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(tasklist_output)
|
23
|
-
@bridge.mirage_process_ids([7001, 7002]).should == {"7001" => "18903", "7002" => "18904"}
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should find the pids of mirage instances for all ports' do
|
27
|
-
tasklist_output = "#{process_string_for_mirage(7001, 18903)}
|
28
|
-
#{process_string_for_mirage(7002, 18904)}
|
29
|
-
#{process_string_for_mirage(7003, 18905)}"
|
30
|
-
|
31
|
-
@bridge.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(tasklist_output)
|
32
|
-
@bridge.mirage_process_ids([:all]).should == {"7001" => "18903", "7002" => "18904", "7003" => "18905"}
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'should kill the given process id' do
|
36
|
-
@bridge.should_receive(:`).with(/taskkill \/F \/T \/PID 18903/)
|
37
|
-
@bridge.kill(18903)
|
38
|
-
end
|
9
|
+
let(:port_pid_mappings) do
|
10
|
+
{"7001" => "18903", "7002" => "18904", "7003" => "18905"}
|
39
11
|
end
|
40
12
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
it 'should find the pids of mirage instances for all ports' do
|
55
|
-
ps_aux_output = "#{process_string_for_mirage(7001, 18903)}
|
56
|
-
#{process_string_for_mirage(7002, 18904)}
|
57
|
-
#{process_string_for_mirage(7003, 18905)}"
|
58
|
-
|
59
|
-
IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(ps_aux_output)
|
60
|
-
@bridge.mirage_process_ids([:all]).should == {"7001" => "18903", "7002" => "18904", "7003" => "18905"}
|
61
|
-
end
|
13
|
+
let(:operating_system) do
|
14
|
+
Hashie::Mash.new({
|
15
|
+
:windows => {
|
16
|
+
:kill_string => "taskkill /F /T /PID %d",
|
17
|
+
:set_ps_cmd_expectation => proc{bridge.should_receive(:`).with(/tasklist.*/).any_number_of_times.and_return(tasklist_output)}
|
18
|
+
},
|
19
|
+
:linux => {
|
20
|
+
:kill_string => "kill -9 %d",
|
21
|
+
:set_ps_cmd_expectation => proc{IO.should_receive(:popen).with(/ps aux.*/).any_number_of_times.and_return(tasklist_output)}
|
22
|
+
}
|
23
|
+
})
|
24
|
+
end
|
62
25
|
|
63
|
-
|
64
|
-
|
65
|
-
|
26
|
+
[:linux,:windows].each do |os_name|
|
27
|
+
|
28
|
+
describe os_name do
|
29
|
+
let(:os){operating_system[os_name]}
|
30
|
+
let!(:bridge) do
|
31
|
+
bridge = Object.new
|
32
|
+
bridge.extend(CLIBridge)
|
33
|
+
end
|
34
|
+
|
35
|
+
include_context os_name do
|
36
|
+
|
37
|
+
let(:tasklist_output) do
|
38
|
+
output = []
|
39
|
+
port_pid_mappings.each do |port, pid|
|
40
|
+
output << process_string_for_mirage(port, pid)
|
41
|
+
end
|
42
|
+
output.join("\n")
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should find the pids of mirage instances for given ports' do
|
46
|
+
os.set_ps_cmd_expectation.call
|
47
|
+
bridge.mirage_process_ids([7001, 7002]).should == mapping(7001).merge(mapping(7002))
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should find the pids of mirage instances for all ports' do
|
51
|
+
os.set_ps_cmd_expectation.call
|
52
|
+
bridge.mirage_process_ids([:all]).should == port_pid_mappings
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should kill the given process id' do
|
56
|
+
bridge.should_receive(:`).with(os.kill_string % 18903)
|
57
|
+
bridge.kill(18903)
|
58
|
+
end
|
59
|
+
end
|
66
60
|
end
|
67
61
|
end
|
62
|
+
|
68
63
|
end
|
data/spec/client/client_spec.rb
CHANGED
@@ -2,11 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'mirage/client'
|
3
3
|
|
4
4
|
describe Mirage::Client do
|
5
|
-
|
6
|
-
Templates = Mirage::Templates
|
7
|
-
Template = Mirage::Template
|
8
|
-
Requests = Mirage::Requests
|
9
|
-
Request = Mirage::Request
|
5
|
+
|
10
6
|
|
11
7
|
before :each do
|
12
8
|
@response = mock('response').as_null_object
|
@@ -66,7 +62,7 @@ describe Mirage::Client do
|
|
66
62
|
mirage.templates(1).should == mock_template
|
67
63
|
end
|
68
64
|
|
69
|
-
it
|
65
|
+
it "should put a response on mirage by passing args on to template's put method " do
|
70
66
|
endpoint, value, block = 'greeting', 'hello', Proc.new{}
|
71
67
|
|
72
68
|
templates_mock = mock('templates')
|
@@ -93,10 +89,6 @@ describe Mirage::Client do
|
|
93
89
|
end
|
94
90
|
end
|
95
91
|
|
96
|
-
#describe 'stop' do
|
97
|
-
#
|
98
|
-
#end
|
99
|
-
|
100
92
|
describe 'save' do
|
101
93
|
it 'should save the current template setup of mirage' do
|
102
94
|
mirage = Client.new
|
data/spec/client/request_spec.rb
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'mirage/client'
|
3
2
|
|
3
|
+
describe Request do
|
4
|
+
let(:request_url) { "url" }
|
5
|
+
let(:trigger_url) { "trigger url" }
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
+
let(:body) { "body" }
|
8
|
+
let(:parameters) { {"name" => "joe"} }
|
9
|
+
let(:headers) { {"header" => "value"} }
|
10
|
+
|
11
|
+
let(:request_json) do
|
12
|
+
{body: body,
|
13
|
+
headers: headers,
|
14
|
+
parameters: parameters,
|
15
|
+
request_url: trigger_url}
|
16
|
+
end
|
7
17
|
|
8
18
|
it 'delete a request' do
|
9
19
|
request_url = "url"
|
@@ -14,21 +24,7 @@ describe Mirage::Request do
|
|
14
24
|
end
|
15
25
|
|
16
26
|
it 'should load request data' do
|
17
|
-
request_url
|
18
|
-
trigger_url = "trigger url"
|
19
|
-
|
20
|
-
body = "body"
|
21
|
-
parameters = {"name" => "joe"}
|
22
|
-
headers = {"header" => "value"}
|
23
|
-
|
24
|
-
request_json = {
|
25
|
-
body: body,
|
26
|
-
headers: headers,
|
27
|
-
parameters: parameters,
|
28
|
-
request_url: trigger_url
|
29
|
-
}
|
30
|
-
|
31
|
-
Request.should_receive(:backedup_get).with(request_url,format: :json).and_return(request_json)
|
27
|
+
Request.should_receive(:backedup_get).with(request_url, format: :json).and_return(request_json)
|
32
28
|
|
33
29
|
request = Request.get(request_url)
|
34
30
|
request.headers.should == headers
|
@@ -37,16 +33,4 @@ describe Mirage::Request do
|
|
37
33
|
request.parameters.should == parameters
|
38
34
|
end
|
39
35
|
|
40
|
-
it 'should contain parameters' do
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should contain the request body' do
|
45
|
-
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'should contain the triggering url' do
|
49
|
-
|
50
|
-
end
|
51
|
-
|
52
36
|
end
|
@@ -1,10 +1,9 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
require 'mirage/client'
|
3
2
|
|
4
|
-
describe
|
3
|
+
describe Requests do
|
5
4
|
it 'should delete all request data' do
|
6
5
|
base_url = "base_url"
|
7
|
-
|
8
|
-
|
6
|
+
Requests.should_receive(:delete).with("#{base_url}/requests")
|
7
|
+
Requests.new(base_url).delete_all
|
9
8
|
end
|
10
9
|
end
|
data/spec/client/runner_spec.rb
CHANGED
@@ -3,8 +3,8 @@ require 'mirage/client'
|
|
3
3
|
|
4
4
|
|
5
5
|
|
6
|
-
describe
|
7
|
-
|
6
|
+
describe TemplateConfiguration do
|
7
|
+
|
8
8
|
it 'should have defaults' do
|
9
9
|
configuration = TemplateConfiguration.new
|
10
10
|
assert_defaults configuration
|
@@ -3,8 +3,6 @@ require 'mirage/client'
|
|
3
3
|
|
4
4
|
|
5
5
|
describe Mirage::Template do
|
6
|
-
Template = Mirage::Template
|
7
|
-
Request = Mirage::Request
|
8
6
|
|
9
7
|
describe 'get' do
|
10
8
|
it 'should load a template given its id' do
|
@@ -16,6 +14,7 @@ describe Mirage::Template do
|
|
16
14
|
delay = 1.2
|
17
15
|
content_type = "application/json"
|
18
16
|
status = 201
|
17
|
+
headers = {'header' => 'value'}
|
19
18
|
|
20
19
|
|
21
20
|
required_parameters = {"name" => 'joe'}
|
@@ -33,6 +32,7 @@ describe Mirage::Template do
|
|
33
32
|
delay: delay,
|
34
33
|
content_type: content_type,
|
35
34
|
status: status,
|
35
|
+
headers: headers
|
36
36
|
},
|
37
37
|
request: {
|
38
38
|
parameters: required_parameters,
|
@@ -55,6 +55,7 @@ describe Mirage::Template do
|
|
55
55
|
template.delay.should == delay
|
56
56
|
template.content_type.should == content_type
|
57
57
|
template.status.should == status
|
58
|
+
template.headers.should == headers
|
58
59
|
|
59
60
|
template.required_parameters.should == required_parameters
|
60
61
|
template.required_body_content.should == required_body_content
|
@@ -237,5 +238,12 @@ describe Mirage::Template do
|
|
237
238
|
end
|
238
239
|
end
|
239
240
|
|
241
|
+
it 'should set headers' do
|
242
|
+
header, value = 'header', 'value'
|
243
|
+
template = Template.new 'endpoint', value
|
244
|
+
template.headers[header] = value
|
245
|
+
JSON.parse(template.to_json)["response"]["headers"].should == {header => value}
|
246
|
+
end
|
247
|
+
|
240
248
|
end
|
241
249
|
end
|
@@ -2,9 +2,7 @@ require 'spec_helper'
|
|
2
2
|
require 'mirage/client'
|
3
3
|
|
4
4
|
describe 'templates' do
|
5
|
-
|
6
|
-
Requests = Mirage::Requests
|
7
|
-
Template = Mirage::Template
|
5
|
+
|
8
6
|
|
9
7
|
describe 'deleting' do
|
10
8
|
it 'should delete all templates and associated request data' do
|
@@ -50,30 +48,60 @@ describe 'templates' do
|
|
50
48
|
|
51
49
|
describe 'putting templates' do
|
52
50
|
|
51
|
+
|
53
52
|
endpoint = "greeting"
|
54
53
|
value = "hello"
|
55
54
|
|
56
|
-
before :each do
|
57
|
-
@base_url = "base_url"
|
58
|
-
@templates = Templates.new(@base_url)
|
59
55
|
|
60
|
-
@template_mock = mock('template')
|
61
|
-
Template.should_receive(:new).with("#{@base_url}/templates/#{endpoint}", value, @templates.default_config).and_return(@template_mock)
|
62
|
-
@template_mock.should_receive(:create)
|
63
|
-
end
|
64
56
|
|
57
|
+
context 'template as parameter' do
|
58
|
+
before :each do
|
59
|
+
@base_url = "base_url"
|
60
|
+
@templates = Templates.new(@base_url)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should take a preconfigured template as a parameter' do
|
64
|
+
|
65
|
+
template = Template.new 'endpoint', 'value'
|
66
|
+
template.should_receive(:create)
|
67
|
+
@templates.put template
|
68
|
+
template.endpoint.should == "#{@base_url}/templates/endpoint"
|
69
|
+
end
|
65
70
|
|
66
|
-
|
67
|
-
|
71
|
+
it 'should accept a block to allow the template to be customised' do
|
72
|
+
block_called = false
|
73
|
+
template = Template.new 'endpoint', 'value'
|
74
|
+
template.should_receive(:create)
|
75
|
+
@templates.put(template) do |the_same_template|
|
76
|
+
block_called = true
|
77
|
+
the_same_template.should == template
|
78
|
+
end
|
79
|
+
block_called.should == true
|
80
|
+
end
|
68
81
|
end
|
69
82
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
83
|
+
context 'endpoint and value as parameters' do
|
84
|
+
before :each do
|
85
|
+
@base_url = "base_url"
|
86
|
+
@templates = Templates.new(@base_url)
|
87
|
+
|
88
|
+
@template_mock = mock('template')
|
89
|
+
Template.should_receive(:new).with("#{@base_url}/templates/#{endpoint}", value, @templates.default_config).and_return(@template_mock)
|
90
|
+
@template_mock.should_receive(:create)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should create a template' do
|
94
|
+
@templates.put(endpoint, value)
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should accept a block to allow the template to be customised' do
|
98
|
+
block_called = false
|
99
|
+
@templates.put(endpoint, value) do |template|
|
100
|
+
block_called = true
|
101
|
+
template.should == @template_mock
|
102
|
+
end
|
103
|
+
block_called.should == true
|
75
104
|
end
|
76
|
-
block_called.should == true
|
77
105
|
end
|
78
106
|
end
|
79
107
|
end
|
@@ -67,6 +67,14 @@ describe Mirage::MockResponse do
|
|
67
67
|
|
68
68
|
describe "response values" do
|
69
69
|
|
70
|
+
it 'should return any headers set' do
|
71
|
+
headers = {
|
72
|
+
'header' => 'value'
|
73
|
+
}
|
74
|
+
response_spec = convert_keys_to_strings({:response => {:headers => headers}})
|
75
|
+
MockResponse.new("greeting", response_spec).headers.should == headers
|
76
|
+
end
|
77
|
+
|
70
78
|
it 'should return the response value' do
|
71
79
|
response_spec = convert_keys_to_strings({:response => {:body => Base64.encode64("hello")}})
|
72
80
|
MockResponse.new("greeting", response_spec).value.should == "hello"
|
data/spec/server/server_spec.rb
CHANGED
@@ -4,10 +4,13 @@ require 'base64'
|
|
4
4
|
|
5
5
|
describe "Mirage Server" do
|
6
6
|
include_context :rack_test, :disable_sinatra_error_handling => true
|
7
|
+
before :each do
|
8
|
+
Mirage::MockResponse.delete_all
|
9
|
+
end
|
10
|
+
|
7
11
|
|
8
12
|
describe "when adding responses" do
|
9
13
|
before :each do
|
10
|
-
Mirage::MockResponse.delete_all
|
11
14
|
@mock_response = Mirage::MockResponse.new('endpoint','value')
|
12
15
|
end
|
13
16
|
|
@@ -87,6 +90,12 @@ describe "Mirage Server" do
|
|
87
90
|
put('/mirage/templates/level1/level2', {:response => {:body => Base64.encode64("level2"), :default => true}}.to_json)
|
88
91
|
get('/mirage/responses/level1/level2/level3').body.should == "level2"
|
89
92
|
end
|
93
|
+
|
94
|
+
it 'should set any headers specified' do
|
95
|
+
headers = {header: 'value'}
|
96
|
+
put('/mirage/templates/greeting', {:response => {headers: headers, :body => ''}}.to_json)
|
97
|
+
get('/mirage/responses/greeting').headers['header'].should == 'value'
|
98
|
+
end
|
90
99
|
end
|
91
100
|
|
92
101
|
describe 'checking templates' do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
ROOT_DIR = "#{File.dirname(__FILE__)}/.."
|
2
2
|
$LOAD_PATH.unshift "#{ROOT_DIR}/lib"
|
3
3
|
$LOAD_PATH.unshift "#{ROOT_DIR}/server"
|
4
|
-
|
5
4
|
require 'simplecov' if ENV['coverage']
|
5
|
+
require 'mirage/client'
|
6
6
|
require 'rspec'
|
7
7
|
require 'json'
|
8
8
|
require 'base64'
|
@@ -14,6 +14,7 @@ module JsonHelpers
|
|
14
14
|
end
|
15
15
|
|
16
16
|
RSpec.configure do |config|
|
17
|
+
include Mirage
|
17
18
|
config.include JsonHelpers
|
18
19
|
end
|
19
20
|
|
data/test.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
1
|
require './lib/mirage/client'
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
|
4
|
+
mirage = Mirage.start
|
5
|
+
|
6
|
+
#mirage.clear
|
7
|
+
#mirage.put('some/path/greeting', 'hello') do |response|
|
8
|
+
# response.http_method = :post
|
9
|
+
#end
|
10
|
+
#
|
11
|
+
#template = mirage.put('some/path/greeting', 'hello Michele') do |response|
|
12
|
+
# response.http_method = :post
|
13
|
+
# response.required_parameters['name']='Michele'
|
14
|
+
# response.required_body_content << 'stara'
|
15
|
+
# response.required_headers['Custom-Header']='special'
|
16
|
+
#end
|
17
|
+
#
|
18
|
+
|
19
|
+
|
20
|
+
|
5
21
|
|
6
22
|
|
7
|
-
client.put "greeting", 'hello' do |response|
|
8
|
-
response.http_method = :post
|
9
|
-
response.delay = 1.2
|
10
|
-
response.required_parameters = {:name => 'leon'}
|
11
|
-
response.required_body_content = %w(profile)
|
12
|
-
response.required_headers = {:header => 'value'}
|
13
|
-
end
|
14
23
|
|
15
24
|
|
16
|
-
client.put "greeting/something/hello", 'hello' do |response|
|
17
|
-
response.http_method = :post
|
18
|
-
response.delay = 1.2
|
19
|
-
response.required_parameters = {:name => 'leon'}
|
20
|
-
response.required_body_content = %w(profile)
|
21
|
-
response.required_headers = {:header => 'value'}
|
22
|
-
end
|
23
25
|
|
24
|
-
Mirage.stop
|
25
26
|
|
26
27
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mirage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.0.alpha.
|
4
|
+
version: 3.0.0.alpha.3
|
5
5
|
prerelease: 6
|
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-04-
|
12
|
+
date: 2013-04-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -340,7 +340,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
340
340
|
version: '0'
|
341
341
|
segments:
|
342
342
|
- 0
|
343
|
-
hash: -
|
343
|
+
hash: -894267295153814806
|
344
344
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
345
345
|
none: false
|
346
346
|
requirements:
|