mirage 3.0.0.alpha.16 → 3.0.0.alpha.17
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 +8 -5
- data/VERSION +1 -1
- data/lib/mirage/client/templates.rb +12 -4
- data/mirage.gemspec +1 -1
- data/spec/client/templates_spec.rb +25 -11
- metadata +2 -2
data/README.md
CHANGED
@@ -24,21 +24,24 @@ What's New?
|
|
24
24
|
#### What's new in the Server:
|
25
25
|
##### 1: Mirage uses JSON as its communucations medium
|
26
26
|
Mirage is now configured using JSON. JSON is also used as the output format for Mirage's other operations.
|
27
|
-
##### 2:
|
27
|
+
##### 2: Wildcards are now supported in the URI.
|
28
|
+
You can now specify wild cards in the URI matcher. This means that a url such as '/*/world' would match '/hello/world' :)
|
29
|
+
##### 3: Full Request Data now tracked
|
28
30
|
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
31
|
Now the full request, including HTTP headers are returned when querying '/requests/template_id'
|
30
|
-
|
32
|
+
|
33
|
+
##### 4. Parameters and body content matchers are now specified seperately
|
31
34
|
Now you can specify as many parameter and body matchers as you want. These can be both litteral strings or Regex's
|
32
35
|
|
33
36
|
Previously, it was only possible to specify a single matcher and this would be applied against both the querystring and the request body.
|
34
|
-
#####
|
37
|
+
##### 5. HTTP Header matchers
|
35
38
|
You can now also specify matchers against HTTP headers.
|
36
|
-
#####
|
39
|
+
##### 6. More advanced template resolution.
|
37
40
|
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
41
|
if there was a more appropriate template.
|
39
42
|
|
40
43
|
Litteral matchers are worth more in the scoring process than regex based ones for example.
|
41
|
-
#####
|
44
|
+
##### 7. The url has changed
|
42
45
|
Mirage is now accessible via: http://localhost:7001. I.e. 'mirage' has been removed from all resources
|
43
46
|
|
44
47
|
e.g. responses are now under http://localhost:7001/responses
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.0.alpha.
|
1
|
+
3.0.0.alpha.17
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module Mirage
|
2
2
|
class Templates
|
3
3
|
include HTTParty
|
4
|
+
|
4
5
|
def initialize base_url
|
5
6
|
@url = "#{base_url}/templates"
|
6
7
|
@requests = Requests.new(base_url)
|
@@ -23,19 +24,26 @@ module Mirage
|
|
23
24
|
def put *args, &block
|
24
25
|
if args.first.class.is_a?(Template::Model)
|
25
26
|
template = args.first
|
27
|
+
template = template.clone
|
26
28
|
template.endpoint "#{@url}/#{template.endpoint}" unless template.endpoint.to_s.start_with?(@url)
|
27
29
|
else
|
28
|
-
|
29
|
-
template =
|
30
|
+
|
31
|
+
endpoint, template = args
|
32
|
+
if template.class.is_a?(Template::Model)
|
33
|
+
template = template.clone
|
34
|
+
template.endpoint "#{@url}/#{endpoint}"
|
35
|
+
else
|
36
|
+
template = Mirage::Template.new("#{@url}/#{endpoint}", template, @default_config)
|
37
|
+
end
|
38
|
+
|
30
39
|
end
|
31
40
|
|
32
41
|
if block
|
33
42
|
calling_instance = eval "self", block.binding
|
34
43
|
template.caller_binding = calling_instance
|
35
|
-
template.instance_exec(template
|
44
|
+
template.instance_exec(template, &block)
|
36
45
|
template.caller_binding = nil
|
37
46
|
end
|
38
|
-
|
39
47
|
template.create
|
40
48
|
end
|
41
49
|
end
|
data/mirage.gemspec
CHANGED
@@ -85,33 +85,36 @@ describe 'templates' do
|
|
85
85
|
value = "hello"
|
86
86
|
let(:base_url) { "base_url" }
|
87
87
|
let!(:templates) { Templates.new(base_url) }
|
88
|
+
let!(:model_class) do
|
89
|
+
Class.new do
|
90
|
+
extend Template::Model
|
91
|
+
endpoint endpoint
|
92
|
+
|
93
|
+
def create
|
94
|
+
self
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
88
98
|
|
89
99
|
|
90
100
|
context 'model as parameter' do
|
91
101
|
let!(:endpoint) { 'endpoint' }
|
92
|
-
|
93
|
-
Class.new do
|
94
|
-
extend Template::Model
|
95
|
-
endpoint endpoint
|
96
|
-
def create
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
102
|
+
|
100
103
|
before :each do
|
101
104
|
@base_url = "base_url"
|
102
105
|
@templates = Templates.new(@base_url)
|
103
106
|
end
|
104
107
|
it 'should take a model as a parameter' do
|
105
108
|
template = model_class.new
|
106
|
-
@templates.put template
|
109
|
+
template = @templates.put template
|
107
110
|
template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
|
108
111
|
end
|
109
112
|
|
110
113
|
it 'should prepend base url to the endpoint unless it is set already' do
|
111
114
|
template = model_class.new
|
112
|
-
@templates.put template
|
115
|
+
template = @templates.put template
|
113
116
|
template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
|
114
|
-
@templates.put template
|
117
|
+
template = @templates.put template
|
115
118
|
template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
|
116
119
|
end
|
117
120
|
|
@@ -166,6 +169,17 @@ describe 'templates' do
|
|
166
169
|
end
|
167
170
|
end
|
168
171
|
|
172
|
+
context 'endpoint and model as parameters' do
|
173
|
+
it 'should put the given template on the given endpoint' do
|
174
|
+
@base_url = "base_url"
|
175
|
+
@templates = Templates.new(@base_url)
|
176
|
+
|
177
|
+
template = model_class.new
|
178
|
+
template = @templates.put 'greeting', template
|
179
|
+
template.endpoint.should == "#{@base_url}/templates/greeting"
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
169
183
|
describe 'block parameter that can be used for template customisation' do
|
170
184
|
it 'it is called in the context of the template' do
|
171
185
|
template = Template.new('', '')
|
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.17
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -355,7 +355,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
355
355
|
version: '0'
|
356
356
|
segments:
|
357
357
|
- 0
|
358
|
-
hash:
|
358
|
+
hash: -286461807850956295
|
359
359
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
360
360
|
none: false
|
361
361
|
requirements:
|