mirage 3.0.13 → 3.0.14
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- metadata +1 -75
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.simplecov +0 -6
- data/.travis.yml +0 -4
- data/Gemfile +0 -27
- data/Gemfile.lock +0 -142
- data/HISTORY +0 -24
- data/Rakefile +0 -10
- data/VERSION +0 -1
- data/features/.nav +0 -29
- data/features/client/clear.feature +0 -78
- data/features/client/configure.feature +0 -72
- data/features/client/model.feature +0 -95
- data/features/client/preview_responses.feature +0 -33
- data/features/client/prime.feature +0 -32
- data/features/client/put.feature +0 -111
- data/features/client/readme.md +0 -3
- data/features/client/requests.feature +0 -20
- data/features/client/running.feature +0 -51
- data/features/client/save_and_revert.feature +0 -39
- data/features/client/start.feature +0 -46
- data/features/client/stop.feature +0 -53
- data/features/commandline_interface/help.feature +0 -17
- data/features/commandline_interface/readme.md +0 -1
- data/features/commandline_interface/start.feature +0 -18
- data/features/commandline_interface/stop.feature +0 -42
- data/features/logging.feature +0 -6
- data/features/prime.feature +0 -35
- data/features/readme.md +0 -7
- data/features/requests/delete.feature +0 -48
- data/features/requests/get.feature +0 -36
- data/features/save_and_revert.feature +0 -35
- data/features/step_definitions/my_steps.rb +0 -97
- data/features/step_definitions/observation_steps.rb +0 -102
- data/features/support/command_line.rb +0 -37
- data/features/support/env.rb +0 -22
- data/features/support/hooks.rb +0 -26
- data/features/support/mirage.rb +0 -12
- data/features/support/web.rb +0 -19
- data/features/templates/delete.feature +0 -45
- data/features/templates/get.feature +0 -54
- data/features/templates/path_wildcards.feature +0 -10
- data/features/templates/preview.feature +0 -18
- data/features/templates/put.feature +0 -77
- data/features/templates/put_with_substitutions.feature +0 -22
- data/features/templates/readme.md +0 -4
- data/features/templates/required_content.feature +0 -113
- data/features/web_user_interface.feature +0 -44
- data/full_build.sh +0 -100
- data/mirage.gemspec +0 -174
- data/spec/mirage/client/cli_bridge_spec.rb +0 -63
- data/spec/mirage/client/client_spec.rb +0 -179
- data/spec/mirage/client/helpers/method_builder_spec.rb +0 -48
- data/spec/mirage/client/request_spec.rb +0 -44
- data/spec/mirage/client/requests_spec.rb +0 -9
- data/spec/mirage/client/runner_spec.rb +0 -138
- data/spec/mirage/client/template/configuration_spec.rb +0 -32
- data/spec/mirage/client/template/model/common_methods_spec.rb +0 -25
- data/spec/mirage/client/template/model/instance_methods_spec.rb +0 -169
- data/spec/mirage/client/template/model_spec.rb +0 -119
- data/spec/mirage/client/template_spec.rb +0 -146
- data/spec/mirage/client/templates_spec.rb +0 -197
- data/spec/mirage/wait_methods_spec.rb +0 -42
- data/spec/resources/binary.file +0 -0
- data/spec/server/binary_data_checker_spec.rb +0 -21
- data/spec/server/helpers/http_headers_spec.rb +0 -20
- data/spec/server/helpers/template_requirements_spec.rb +0 -34
- data/spec/server/mock_response_set_spec.rb +0 -57
- data/spec/server/mock_response_spec.rb +0 -577
- data/spec/server/server_spec.rb +0 -156
- data/spec/spec_helper.rb +0 -85
- data/tasks/application.rake +0 -7
- data/tasks/packaging.rake +0 -28
- data/tasks/tests.rake +0 -25
@@ -1,102 +0,0 @@
|
|
1
|
-
Then /^'([^']*)' should be returned$/ do |expected_response|
|
2
|
-
response_text = @response.body
|
3
|
-
if response_text != expected_response
|
4
|
-
expected_response.split('&').each { |param_value_pair| response_text.should =~ /#{param_value_pair}/ }
|
5
|
-
expected_response.length.should == response_text.length
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
Then /^a (\d+) should be returned$/ do |error_code|
|
10
|
-
@response.code.to_i.should == error_code.to_i
|
11
|
-
end
|
12
|
-
|
13
|
-
Then /^it should take at least '(.*)' seconds$/ do |time|
|
14
|
-
(@response_time).should >= time.to_f
|
15
|
-
end
|
16
|
-
|
17
|
-
Then /^mirage (should|should not) be running on '(.*)'$/ do |should, url|
|
18
|
-
running = begin
|
19
|
-
get(url).code.to_i.should == 200
|
20
|
-
rescue
|
21
|
-
false
|
22
|
-
end
|
23
|
-
|
24
|
-
should == "should" ? running.should == true : running.should == false
|
25
|
-
end
|
26
|
-
|
27
|
-
Given /^Mirage (is|is not) running$/ do |running|
|
28
|
-
if running == 'is'
|
29
|
-
start_mirage_in_scratch_dir unless Mirage.running?
|
30
|
-
else
|
31
|
-
Mirage.stop :all
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
Then /^the usage information should be displayed$/ do
|
36
|
-
@usage.each_line { |line| @commandline_output.should include(line) }
|
37
|
-
end
|
38
|
-
|
39
|
-
Then /^I should see '(.*?)' on the command line$/ do |content|
|
40
|
-
@commandline_output.should include(content)
|
41
|
-
end
|
42
|
-
|
43
|
-
Then /^'(.*)' should exist$/ do |path|
|
44
|
-
File.exists?("#{SCRATCH}/#{path}").should == true
|
45
|
-
end
|
46
|
-
|
47
|
-
Then /^mirage.log should contain '(.*)'$/ do |content|
|
48
|
-
log_file_content = @mirage_log_file.readlines.to_s
|
49
|
-
fail("#{content} not found in mirage.log: #{log_file_content}") unless log_file_content.index(content)
|
50
|
-
end
|
51
|
-
|
52
|
-
Given /^I goto '(.*)'$/ do |url|
|
53
|
-
@page = Mechanize.new.get url
|
54
|
-
end
|
55
|
-
|
56
|
-
Then /^I should see '(.*)'$/ do |text|
|
57
|
-
@page.body.index(text).should_not == nil
|
58
|
-
end
|
59
|
-
|
60
|
-
When /^the response '([^']*)' should be '([^']*)'$/ do |header, value|
|
61
|
-
@response.response[header].should include(value)
|
62
|
-
end
|
63
|
-
|
64
|
-
Then /^request data should have been retrieved$/ do
|
65
|
-
request_data = JSON.parse(@response.body)
|
66
|
-
request_data.include?('parameters').should == true
|
67
|
-
request_data.include?('headers').should == true
|
68
|
-
request_data.include?('body').should == true
|
69
|
-
request_data.include?('request_url').should == true
|
70
|
-
request_data.include?('id').should == true
|
71
|
-
end
|
72
|
-
|
73
|
-
Then(/^the template (request|response) specification should have the following set:$/) do |spec, table|
|
74
|
-
template_json = JSON.parse(get("http://localhost:7001/templates/#{JSON.parse(@response.body)['id']}").body)
|
75
|
-
request_specification = template_json[spec]
|
76
|
-
request_specification.size.should==table.hashes.size
|
77
|
-
table.hashes.each do |hash|
|
78
|
-
default = request_specification[hash['Setting'].downcase.gsub(' ', '_')]
|
79
|
-
case required_default = hash['Default']
|
80
|
-
when 'none'
|
81
|
-
case default
|
82
|
-
when Array
|
83
|
-
default.should == []
|
84
|
-
when Hash
|
85
|
-
default.should == {}
|
86
|
-
else
|
87
|
-
default.should == ""
|
88
|
-
|
89
|
-
end
|
90
|
-
else
|
91
|
-
default.to_s.downcase.should == required_default.downcase
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
Then(/^the following json should be returned:$/) do |text|
|
97
|
-
JSON.parse(text).should == JSON.parse(@response.body)
|
98
|
-
end
|
99
|
-
|
100
|
-
When(/^the content-type should be '(.*)'$/) do |content_type|
|
101
|
-
@response.content_type.should == content_type
|
102
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require 'tempfile'
|
2
|
-
require 'wait_methods'
|
3
|
-
|
4
|
-
module CommandLine
|
5
|
-
include Mirage::WaitMethods
|
6
|
-
|
7
|
-
def run command
|
8
|
-
output = Tempfile.new("child")
|
9
|
-
Dir.chdir SCRATCH do
|
10
|
-
process = ChildProcess.build(*("#{command}".split(' ')))
|
11
|
-
process.detach
|
12
|
-
process.io.stdout = output
|
13
|
-
process.io.stderr = output
|
14
|
-
process.start
|
15
|
-
wait_until(:timeout_after => 30) { process.exited? }
|
16
|
-
end
|
17
|
-
File.read(output.path)
|
18
|
-
end
|
19
|
-
|
20
|
-
def normalise text
|
21
|
-
text.gsub(/[\n]/, ' ').gsub(/\s+/, ' ').strip
|
22
|
-
end
|
23
|
-
|
24
|
-
def write_to_file file_path, content
|
25
|
-
file_path = "#{SCRATCH}/#{file_path}" unless file_path =~ /^\//
|
26
|
-
|
27
|
-
FileUtils.rm_rf(file_path) if File.exists?(file_path)
|
28
|
-
FileUtils.mkdir_p(File.dirname(file_path))
|
29
|
-
|
30
|
-
File.open("#{file_path}", 'w') do |file|
|
31
|
-
file.write(content)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
World CommandLine
|
37
|
-
include CommandLine
|
data/features/support/env.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
ROOT_DIR = File.expand_path("#{File.dirname(__FILE__)}/../..")
|
2
|
-
SOURCE_PATH = "#{ROOT_DIR}/lib"
|
3
|
-
Bundler.require
|
4
|
-
|
5
|
-
$LOAD_PATH.unshift(SOURCE_PATH)
|
6
|
-
require 'base64'
|
7
|
-
require 'mirage/client'
|
8
|
-
|
9
|
-
SCRATCH = "#{ROOT_DIR}/scratch"
|
10
|
-
RUBY_CMD = ChildProcess.jruby? ? 'jruby' : 'ruby'
|
11
|
-
BLANK_RUBYOPT_CMD = ChildProcess.windows? ? 'set RUBYOPT=' : "export RUBYOPT=''"
|
12
|
-
ENV['RUBYOPT'] = ''
|
13
|
-
|
14
|
-
|
15
|
-
if 'regression' == ENV['mode']
|
16
|
-
MIRAGE_CMD = ChildProcess.windows? ? `where mirage.bat`.chomp : 'mirage'
|
17
|
-
else
|
18
|
-
MIRAGE_CMD = "#{RUBY_CMD} ../bin/mirage"
|
19
|
-
end
|
20
|
-
|
21
|
-
|
22
|
-
|
data/features/support/hooks.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
Before do
|
2
|
-
FileUtils.mkdir_p(SCRATCH)
|
3
|
-
|
4
|
-
mirage.templates.delete_all
|
5
|
-
|
6
|
-
Dir["#{SCRATCH}/*"].each do |file|
|
7
|
-
FileUtils.rm_rf(file) unless file == "#{SCRATCH}/mirage.log"
|
8
|
-
end
|
9
|
-
|
10
|
-
if File.exists? "#{SCRATCH}/mirage.log"
|
11
|
-
@mirage_log_file = File.open("#{SCRATCH}/mirage.log")
|
12
|
-
@mirage_log_file.seek(0, IO::SEEK_END)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
Before ('@command_line') do
|
17
|
-
Mirage.stop :all
|
18
|
-
end
|
19
|
-
|
20
|
-
After('@command_line') do
|
21
|
-
Mirage.stop :all
|
22
|
-
end
|
23
|
-
|
24
|
-
at_exit do
|
25
|
-
Mirage.stop :all
|
26
|
-
end
|
data/features/support/mirage.rb
DELETED
data/features/support/web.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
module Mirage
|
3
|
-
module Web
|
4
|
-
def get *args
|
5
|
-
HTTParty.get(*args)
|
6
|
-
end
|
7
|
-
def put *args
|
8
|
-
HTTParty.put(*args)
|
9
|
-
end
|
10
|
-
def post *args
|
11
|
-
HTTParty.post(*args)
|
12
|
-
end
|
13
|
-
def delete *args
|
14
|
-
HTTParty.delete(*args)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
World(Mirage::Web)
|
@@ -1,45 +0,0 @@
|
|
1
|
-
Feature: Deleting
|
2
|
-
When a template is deleted, any tracked request data is also removed.
|
3
|
-
|
4
|
-
Background: The MockServer has already got a response for greeting and leaving on it.
|
5
|
-
Given the following template template:
|
6
|
-
"""
|
7
|
-
{
|
8
|
-
"response":{
|
9
|
-
"body":"Hello"
|
10
|
-
}
|
11
|
-
}
|
12
|
-
"""
|
13
|
-
And 'response.body' is base64 encoded
|
14
|
-
And the template is sent using PUT to '/templates/greeting'
|
15
|
-
|
16
|
-
Given the following template template:
|
17
|
-
"""
|
18
|
-
{
|
19
|
-
"response":{
|
20
|
-
"body":"Goodbye"
|
21
|
-
}
|
22
|
-
}
|
23
|
-
"""
|
24
|
-
And 'response.body' is base64 encoded
|
25
|
-
And the template is sent using PUT to '/templates/leaving'
|
26
|
-
|
27
|
-
|
28
|
-
Scenario: Deleting all templates
|
29
|
-
Given DELETE is sent to '/templates'
|
30
|
-
When GET is sent to '/responses/greeting'
|
31
|
-
Then a 404 should be returned
|
32
|
-
When GET is sent to '/responses/leaving'
|
33
|
-
Then a 404 should be returned
|
34
|
-
|
35
|
-
|
36
|
-
Scenario: Deleting a particular template
|
37
|
-
Given DELETE is sent to '/templates/1'
|
38
|
-
|
39
|
-
When GET is sent to '/responses/greeting'
|
40
|
-
Then a 404 should be returned
|
41
|
-
|
42
|
-
When GET is sent to '/responses/leaving'
|
43
|
-
Then a 200 should be returned
|
44
|
-
|
45
|
-
|
@@ -1,54 +0,0 @@
|
|
1
|
-
Feature: Retrieving
|
2
|
-
Templates can be retrieved by using the ID that was returned when they were created
|
3
|
-
|
4
|
-
|
5
|
-
Scenario: Retrieving a template
|
6
|
-
Given the following template template:
|
7
|
-
"""
|
8
|
-
{
|
9
|
-
"response":{
|
10
|
-
"default":false,
|
11
|
-
"body":"Hello",
|
12
|
-
"delay":0,
|
13
|
-
"content_type":"text/plain",
|
14
|
-
"status":200
|
15
|
-
},
|
16
|
-
"request":{
|
17
|
-
"parameters":{
|
18
|
-
|
19
|
-
},
|
20
|
-
"body_content":[
|
21
|
-
|
22
|
-
],
|
23
|
-
"http_method":"get"
|
24
|
-
}
|
25
|
-
}
|
26
|
-
"""
|
27
|
-
And the template is sent using PUT to '/templates/greeting'
|
28
|
-
When GET is sent to '/templates/1'
|
29
|
-
Then the following json should be returned:
|
30
|
-
"""
|
31
|
-
{
|
32
|
-
"id": 1,
|
33
|
-
"endpoint": "greeting",
|
34
|
-
"requests_url": "http://localhost:7001/requests/1",
|
35
|
-
"response":{
|
36
|
-
"default":false,
|
37
|
-
"body":"Hello",
|
38
|
-
"delay":0,
|
39
|
-
"content_type":"text/plain",
|
40
|
-
"status":200
|
41
|
-
},
|
42
|
-
"request":{
|
43
|
-
"parameters":{
|
44
|
-
|
45
|
-
},
|
46
|
-
"headers":{},
|
47
|
-
"body_content":[
|
48
|
-
],
|
49
|
-
"http_method":"get"
|
50
|
-
}
|
51
|
-
}
|
52
|
-
"""
|
53
|
-
|
54
|
-
|
@@ -1,10 +0,0 @@
|
|
1
|
-
Feature: URI wildcards
|
2
|
-
|
3
|
-
Scenario: Setting a template with wildcards
|
4
|
-
Given the following Template JSON:
|
5
|
-
"""
|
6
|
-
{"response":{"body":"SGVsbG8="}}
|
7
|
-
"""
|
8
|
-
And the template is sent using PUT to '/templates/greeting/*/davis'
|
9
|
-
When GET is sent to '/responses/greeting/leon/davis'
|
10
|
-
Then 'Hello' should be returned
|
@@ -1,18 +0,0 @@
|
|
1
|
-
Feature: Previewing
|
2
|
-
A Template's body can be previewed
|
3
|
-
|
4
|
-
|
5
|
-
Scenario: Preview template body
|
6
|
-
Given the following template template:
|
7
|
-
"""
|
8
|
-
{
|
9
|
-
"response":{
|
10
|
-
"body":"SGVsbG8="
|
11
|
-
},
|
12
|
-
"request":{
|
13
|
-
}
|
14
|
-
}
|
15
|
-
"""
|
16
|
-
And the template is sent using PUT to '/templates/greeting'
|
17
|
-
When GET is sent to '/templates/1/preview'
|
18
|
-
Then 'Hello' should be returned
|
@@ -1,77 +0,0 @@
|
|
1
|
-
Feature: Creating a Template
|
2
|
-
Mirage can be configured with Templates. Templates describe the characteristics of responses that should be returned to a client. In addition to this a templates also describe the conditions under which a template may be used to generate a response.
|
3
|
-
|
4
|
-
On setting a template, a unique id is returned. This is a key that can be used to manage the Template.
|
5
|
-
|
6
|
-
Templates can be configured to respond to either, GET, POST, PUT, or DELETE.
|
7
|
-
|
8
|
-
More than one Template can be placed at the same resource address as long as they have different request contraints. In this case they are given different IDs. For example if two templates are configured to respond to request using different HTTP methods then they will not overwrite each other but both be stored.
|
9
|
-
|
10
|
-
Requirements can be specified as required when configuring a Template:
|
11
|
-
* request parameters
|
12
|
-
* body content
|
13
|
-
* HTTP Headers
|
14
|
-
* HTTP Method
|
15
|
-
|
16
|
-
The following attributes of a response can be configured
|
17
|
-
* HTTP status code
|
18
|
-
* Whether this template is to be treated as the default response if a match is not found for a sub URI
|
19
|
-
* A delay before the response is returned to the client. This is in seconds and floats are accepted
|
20
|
-
* Content-Type
|
21
|
-
|
22
|
-
Things to note:
|
23
|
-
---------------
|
24
|
-
The body attribute of the response should be Base64 encoded. This is so that you may specify binary data if that is what you would like to send back to clients.
|
25
|
-
|
26
|
-
|
27
|
-
Scenario: Setting a Template on Mirage
|
28
|
-
Given the following Template JSON:
|
29
|
-
"""
|
30
|
-
{
|
31
|
-
"request":{
|
32
|
-
"parameters":{},
|
33
|
-
"http_method":"get",
|
34
|
-
"headers": {},
|
35
|
-
"body_content":[]
|
36
|
-
},
|
37
|
-
"response":{
|
38
|
-
"default":false,
|
39
|
-
"body":"SGVsbG8=",
|
40
|
-
"delay":0,
|
41
|
-
"content_type":"text/plain",
|
42
|
-
"status":200
|
43
|
-
}
|
44
|
-
}
|
45
|
-
"""
|
46
|
-
When the template is sent using PUT to '/templates/greeting'
|
47
|
-
Then '{"id":1}' should be returned
|
48
|
-
|
49
|
-
When GET is sent to '/responses/greeting'
|
50
|
-
Then 'Hello' should be returned
|
51
|
-
And a 200 should be returned
|
52
|
-
|
53
|
-
|
54
|
-
Scenario: Template defaults
|
55
|
-
Given the following Template JSON:
|
56
|
-
"""
|
57
|
-
{}
|
58
|
-
"""
|
59
|
-
When the template is sent using PUT to '/templates/greeting'
|
60
|
-
Then the template request specification should have the following set:
|
61
|
-
| Setting | Default |
|
62
|
-
| parameters | none |
|
63
|
-
| body content | none |
|
64
|
-
| headers | none |
|
65
|
-
| HTTP method | GET |
|
66
|
-
And the template response specification should have the following set:
|
67
|
-
| Setting | Default |
|
68
|
-
| default | false |
|
69
|
-
| body | none |
|
70
|
-
| content_type | text/plain |
|
71
|
-
| delay | 0 |
|
72
|
-
| status | 200 |
|
73
|
-
|
74
|
-
Scenario: Making a request that is unmatched
|
75
|
-
When GET is sent to '/responses/unmatched'
|
76
|
-
Then a 404 should be returned
|
77
|
-
|
@@ -1,22 +0,0 @@
|
|
1
|
-
Feature: Substituting values from requests in to a template
|
2
|
-
Parts of a response can be substituted for values found in the request body or query string.
|
3
|
-
This allows dynamic content to be sent back to a client.
|
4
|
-
|
5
|
-
To do this, substitution, matchers must be put in the the response value.
|
6
|
-
|
7
|
-
Either a string literal or a regex can be used in between ${} to find a match
|
8
|
-
|
9
|
-
Scenario: A response template populated from matches found in the request body using a regex
|
10
|
-
Given the following template template:
|
11
|
-
"""
|
12
|
-
{
|
13
|
-
"response":{
|
14
|
-
"body":"Hello ${name}"
|
15
|
-
}
|
16
|
-
}
|
17
|
-
"""
|
18
|
-
And 'response.body' is base64 encoded
|
19
|
-
And the template is sent using PUT to '/templates/greeting'
|
20
|
-
When I send GET to '/responses/greeting' with parameters:
|
21
|
-
|name|Joe |
|
22
|
-
Then 'Hello Joe' should be returned
|