mirage 3.0.0.alpha.4 → 3.0.0.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/mirage/client/template/model.rb +4 -2
- data/lib/mirage/client/templates.rb +2 -3
- data/mirage.gemspec +2 -2
- data/spec/client/template/model_spec.rb +24 -0
- data/spec/client/templates_spec.rb +16 -16
- data/test.rb +40 -8
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.0.0.alpha.
|
1
|
+
3.0.0.alpha.5
|
@@ -13,13 +13,15 @@ module Mirage
|
|
13
13
|
clazz.send(:include, HTTParty)
|
14
14
|
clazz.send(:include, InstanceMethods)
|
15
15
|
|
16
|
-
|
17
|
-
def initialize
|
16
|
+
mod = Module.new do
|
17
|
+
def initialize *args
|
18
18
|
super self.class.endpoint, ''
|
19
19
|
status self.class.status if self.class.status
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
+
clazz.send(:include, mod)
|
24
|
+
|
23
25
|
clazz.format :json
|
24
26
|
clazz
|
25
27
|
end
|
@@ -17,16 +17,15 @@ module Mirage
|
|
17
17
|
@requests.delete_all
|
18
18
|
end
|
19
19
|
|
20
|
-
def put *args
|
20
|
+
def put *args, &block
|
21
21
|
if args.first.class.is_a?(Template::Model)
|
22
22
|
template = args.first
|
23
23
|
template.endpoint "#{@url}/#{template.endpoint}"
|
24
24
|
else
|
25
25
|
endpoint, response = args
|
26
26
|
template = Mirage::Template.new "#{@url}/#{endpoint}", response, @default_config
|
27
|
-
yield template if block_given?
|
28
27
|
end
|
29
|
-
|
28
|
+
template.instance_eval &block if block
|
30
29
|
template.create
|
31
30
|
end
|
32
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.5"
|
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-26"
|
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 = [
|
@@ -1,9 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Template::Model do
|
4
|
+
let(:endpoint){'endpoint'}
|
4
5
|
let!(:test_class) do
|
5
6
|
Class.new do
|
6
7
|
extend Template::Model
|
8
|
+
|
9
|
+
endpoint 'endpoint'
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
super
|
13
|
+
end
|
7
14
|
end
|
8
15
|
end
|
9
16
|
context 'class' do
|
@@ -11,6 +18,23 @@ describe Template::Model do
|
|
11
18
|
test_class.is_a?(Template::Model::ClassMethods).should == true
|
12
19
|
test_class.is_a?(Helpers::MethodBuilder).should == true
|
13
20
|
end
|
21
|
+
|
22
|
+
context 'inherited constructor' do
|
23
|
+
it 'should set the endpoint of the class' do
|
24
|
+
test_class.new.endpoint.should == 'endpoint'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'calls to super should not fail if a constructor has been defined that takes args' do
|
28
|
+
test_class.class_eval do
|
29
|
+
def initialize arg
|
30
|
+
super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
test_class.new('arg').endpoint.should == endpoint
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
14
38
|
end
|
15
39
|
|
16
40
|
context 'instances' do
|
@@ -51,6 +51,8 @@ describe 'templates' do
|
|
51
51
|
|
52
52
|
endpoint = "greeting"
|
53
53
|
value = "hello"
|
54
|
+
let(:base_url){ "base_url"}
|
55
|
+
let!(:templates){Templates.new(base_url)}
|
54
56
|
|
55
57
|
|
56
58
|
|
@@ -74,16 +76,7 @@ describe 'templates' do
|
|
74
76
|
template.endpoint.should == "#{@base_url}/templates/#{endpoint}"
|
75
77
|
end
|
76
78
|
|
77
|
-
|
78
|
-
block_called = false
|
79
|
-
template = model_class.new
|
80
|
-
template.should_receive(:create)
|
81
|
-
@templates.put(template) do |the_same_template|
|
82
|
-
block_called = true
|
83
|
-
the_same_template.should == template
|
84
|
-
end
|
85
|
-
block_called.should == true
|
86
|
-
end
|
79
|
+
|
87
80
|
end
|
88
81
|
|
89
82
|
context 'endpoint and value as parameters' do
|
@@ -100,14 +93,21 @@ describe 'templates' do
|
|
100
93
|
@templates.put(endpoint, value)
|
101
94
|
end
|
102
95
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
describe 'block parameter that can be used for template customisation' do
|
100
|
+
it 'it is called in the context of the template' do
|
101
|
+
template = Template.new('','')
|
102
|
+
template.stub(:create)
|
103
|
+
Template.should_receive(:new).and_return(template)
|
104
|
+
templates.put(endpoint, value) do
|
105
|
+
status 404
|
108
106
|
end
|
109
|
-
|
107
|
+
template.status.should == 404
|
110
108
|
end
|
109
|
+
|
111
110
|
end
|
111
|
+
|
112
112
|
end
|
113
113
|
end
|
data/test.rb
CHANGED
@@ -1,18 +1,50 @@
|
|
1
1
|
require './lib/mirage/client'
|
2
|
+
#
|
3
|
+
#class ServiceNowResponse
|
4
|
+
# extend Mirage::Template::Model
|
5
|
+
#
|
6
|
+
# endpoint 'service_now'
|
7
|
+
#
|
8
|
+
# builder_methods :this,:that
|
9
|
+
#
|
10
|
+
# def value
|
11
|
+
# "my value : #{this}, #{that}"
|
12
|
+
# end
|
13
|
+
#end
|
14
|
+
#
|
15
|
+
Mirage.stop
|
16
|
+
mirage = Mirage.start
|
17
|
+
#mirage.put ServiceNowResponse.new.this('foo').that('bar')
|
18
|
+
#mirage.put ServiceNowResponse.new.this('foo').that('bar').required_body_content(%w(hello world))
|
19
|
+
#mirage.put ServiceNowResponse.new.this('foo').that('bar').required_parameters({:name => 'leon'})
|
2
20
|
|
3
|
-
|
21
|
+
require 'ostruct'
|
22
|
+
class UserServiceProfile
|
4
23
|
extend Mirage::Template::Model
|
5
24
|
|
6
|
-
endpoint '
|
25
|
+
endpoint 'Users'
|
7
26
|
|
8
|
-
|
27
|
+
def initialize persona
|
28
|
+
super
|
29
|
+
required_parameters[:token] = persona.token
|
30
|
+
@persona = persona
|
31
|
+
end
|
9
32
|
|
10
33
|
def value
|
11
|
-
|
34
|
+
{name: @persona.name}.to_json
|
12
35
|
end
|
13
36
|
end
|
14
37
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
38
|
+
leon = OpenStruct.new(
|
39
|
+
:name => 'leon',
|
40
|
+
:token => '1234'
|
41
|
+
)
|
42
|
+
|
43
|
+
mirage.clear
|
44
|
+
|
45
|
+
|
46
|
+
leons_user_profile = UserServiceProfile.new leon
|
47
|
+
mirage.put leons_user_profile do
|
48
|
+
status 404
|
49
|
+
method :get
|
50
|
+
end
|
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.5
|
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-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
@@ -349,7 +349,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
349
349
|
version: '0'
|
350
350
|
segments:
|
351
351
|
- 0
|
352
|
-
hash:
|
352
|
+
hash: 4242158940323490709
|
353
353
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
354
354
|
none: false
|
355
355
|
requirements:
|