spec/client/template_spec.rb in mirage-3.0.0.alpha.11 vs spec/client/template_spec.rb in mirage-3.0.0.alpha.12
- old
+ new
@@ -8,11 +8,11 @@
it 'should load a template given its id' do
endpoint = "endpoint"
id = 1
requests_url = 'request_url'
body = "Hello"
- default = false
+ default = true
delay = 1.2
content_type = "application/json"
status = 201
headers = {'header' => 'value'}
@@ -26,11 +26,11 @@
endpoint: endpoint,
id: id,
requests_url: requests_url,
response:{
default: default,
- body: body,
+ body: Base64.encode64(body),
delay: delay,
content_type: content_type,
status: status,
headers: headers
},
@@ -39,21 +39,21 @@
body_content: required_body_content,
headers: required_headers,
http_method: http_method
}
}
+ template_json.should_receive(:code).and_return 200
template_url = "url"
Template.should_receive(:backedup_get).with(template_url, :format => :json).and_return(template_json)
template = Template.get(template_url)
template.body.should == body
template.endpoint.should == endpoint
template.id.should == id
template.default.should == default
- template.default.should == default
template.delay.should == delay
template.content_type.should == content_type
template.status.should == status
template.headers.should == headers
@@ -62,10 +62,17 @@
template.required_headers.should == required_headers
template.http_method.should == http_method
template.url.should == template_url
template.requests_url.should == requests_url
end
+
+ it 'should raise an error if the template is not found' do
+ template_url = 'url'
+ response = mock(code: 404)
+ Template.should_receive(:backedup_get).with(template_url, :format => :json).and_return response
+ expect{Template.get(template_url)}.to raise_error Mirage::ResponseNotFound
+ end
end
describe 'initialize' do
it 'throws and exception if an endpoint is not supplied as the first parameter' do
expect{Template.new}.to raise_error(ArgumentError)
@@ -131,9 +138,9 @@
template.caller_binding = caller
template.some_method
end
it 'should throw a standard method missing error if a caller binding is not set' do
- expect{Template.new('endpoint').some_method}.should raise_error(NameError)
+ expect{Template.new('endpoint').some_method}.to raise_error(NameError)
end
end
end