rescue-dog 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/.travis.yml +22 -0
- data/Gemfile +6 -0
- data/README.md +45 -27
- data/Rakefile +3 -0
- data/deploy_gem.sh +5 -2
- data/lib/rescue/config.rb +32 -0
- data/lib/rescue/controller.rb +6 -4
- data/lib/rescue/{controller → controllers}/dynamic.rb +8 -4
- data/lib/rescue/{controller → controllers}/static.rb +1 -1
- data/lib/rescue/exceptions/application_error.rb +27 -0
- data/lib/rescue/exceptions/respond_error.rb +21 -0
- data/lib/rescue/version.rb +1 -1
- data/lib/rescue-dog.rb +6 -7
- data/spec/rails_spec_app.rb +34 -2
- data/spec/rescue/controller_spec.rb +9 -4
- data/spec/rescue/{controller → controllers}/dynamic_spec.rb +5 -7
- data/spec/rescue/{controller → controllers}/static_spec.rb +4 -6
- data/spec/rescue/exceptions/respond_error_spec.rb +36 -0
- data/spec/rescue_spec.rb +8 -12
- data/spec/spec_helper.rb +6 -0
- metadata +14 -8
data/.gitignore
CHANGED
data/.travis.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
language: ruby
|
2
|
+
bundler_args: --without development
|
3
|
+
rvm:
|
4
|
+
- 1.9.3
|
5
|
+
- 2.0.0
|
6
|
+
- ruby-head
|
7
|
+
- jruby-19mode
|
8
|
+
- jruby-head
|
9
|
+
- rbx-19mode
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: ruby-head
|
13
|
+
- rvm: jruby-head
|
14
|
+
branches:
|
15
|
+
only:
|
16
|
+
- master
|
17
|
+
after_success:
|
18
|
+
- cover -report coveralls
|
19
|
+
notifications:
|
20
|
+
recipients:
|
21
|
+
- yuliinfo@gmail.com
|
22
|
+
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
# Rescue Dog
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/rescue-dog.png)](http://badge.fury.io/rb/rescue-dog)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/yulii/rescue-dog/badge.png?branch=master)](https://coveralls.io/r/yulii/rescue-dog)
|
4
|
+
[![Build Status](https://travis-ci.org/yulii/rescue-dog.png)](https://travis-ci.org/yulii/rescue-dog)
|
2
5
|
|
3
6
|
The Rescue-Dog responds HTTP status (the code and message) when raise the exception.
|
4
7
|
|
@@ -6,15 +9,21 @@ The Rescue-Dog responds HTTP status (the code and message) when raise the except
|
|
6
9
|
|
7
10
|
Add this line to your application's Gemfile:
|
8
11
|
|
9
|
-
|
12
|
+
```ruby
|
13
|
+
gem 'rescue-dog'
|
14
|
+
```
|
10
15
|
|
11
16
|
And then execute:
|
12
17
|
|
13
|
-
|
18
|
+
```bash
|
19
|
+
$ bundle
|
20
|
+
```
|
14
21
|
|
15
22
|
Or install it yourself as:
|
16
23
|
|
17
|
-
|
24
|
+
```bash
|
25
|
+
$ gem install rescue-dog
|
26
|
+
```
|
18
27
|
|
19
28
|
## Usage
|
20
29
|
|
@@ -25,35 +34,51 @@ Or install it yourself as:
|
|
25
34
|
### Render Static Files
|
26
35
|
Render /public/400(.:format) if you raise BadRequest exception.
|
27
36
|
|
28
|
-
|
29
|
-
|
37
|
+
```bash
|
38
|
+
$ vim app/controllers/application_controller.rb
|
39
|
+
```
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class ApplicationController
|
30
43
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
44
|
+
include Rescue::Controller::Static
|
45
|
+
rescue_associate :BadRequest ,with: 400
|
46
|
+
rescue_associate :Unauthorized ,with: 401
|
47
|
+
rescue_associate :NotFound ,with: 404
|
48
|
+
rescue_associate :ServerError ,with: 500
|
49
|
+
```
|
36
50
|
|
37
51
|
### Render Template
|
38
52
|
Render app/views/errors/404(.:format) if you raise NotFound exception.
|
39
53
|
|
40
|
-
|
41
|
-
|
54
|
+
```bash
|
55
|
+
$ vim app/controllers/application_controller.rb
|
56
|
+
```
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
class ApplicationController
|
42
60
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
61
|
+
include Rescue::Controller::Dynamic
|
62
|
+
rescue_associate :BadRequest ,with: 400
|
63
|
+
rescue_associate :Unauthorized ,with: 401
|
64
|
+
rescue_associate :NotFound ,with: 404
|
65
|
+
rescue_associate :ServerError ,with: 500
|
66
|
+
```
|
48
67
|
|
49
68
|
### Associated with the exceptions
|
50
69
|
Call the response method when raise an exception.
|
51
70
|
|
52
71
|
#### for ActiveRecord
|
53
|
-
|
72
|
+
|
73
|
+
```ruby
|
74
|
+
rescue_associate ActiveRecord::RecordNotFound ,with: 404
|
75
|
+
```
|
76
|
+
|
54
77
|
#### for Mongoid
|
55
|
-
rescue_associate Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId, with: 404
|
56
78
|
|
79
|
+
```ruby
|
80
|
+
rescue_associate Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId, with: 404
|
81
|
+
```
|
57
82
|
|
58
83
|
## Contributing
|
59
84
|
|
@@ -67,11 +92,4 @@ Call the response method when raise an exception.
|
|
67
92
|
## LICENSE
|
68
93
|
(The MIT License)
|
69
94
|
|
70
|
-
Copyright © 2013 yulii
|
71
|
-
|
72
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
73
|
-
|
74
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
75
|
-
|
76
|
-
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
77
|
-
|
95
|
+
Copyright © 2013 yulii. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
data/deploy_gem.sh
CHANGED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module Rescue
|
4
|
+
|
5
|
+
def self.configure(&block)
|
6
|
+
yield @config ||= Rescue::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.config
|
10
|
+
@config
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration #:nodoc:
|
14
|
+
include ActiveSupport::Configurable
|
15
|
+
config_accessor :respond_name
|
16
|
+
config_accessor :suppress_response_codes
|
17
|
+
|
18
|
+
def param_name
|
19
|
+
config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
|
20
|
+
end
|
21
|
+
|
22
|
+
# define param_name writer (copied from AS::Configurable)
|
23
|
+
writer, line = 'def param_name=(value); config.param_name = value; end', __LINE__
|
24
|
+
singleton_class.class_eval writer, __FILE__, line
|
25
|
+
class_eval writer, __FILE__, line
|
26
|
+
end
|
27
|
+
|
28
|
+
configure do |config|
|
29
|
+
config.respond_name = :respond_status
|
30
|
+
config.suppress_response_codes = false
|
31
|
+
end
|
32
|
+
end
|
data/lib/rescue/controller.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
1
|
# coding: UTF-8
|
2
|
-
require File.join(File.dirname(__FILE__), "controller/static.rb")
|
3
|
-
require File.join(File.dirname(__FILE__), "controller/dynamic.rb")
|
4
2
|
|
5
3
|
module Rescue
|
6
4
|
module Controller
|
@@ -13,7 +11,7 @@ module Rescue
|
|
13
11
|
unless block_given?
|
14
12
|
if options.has_key?(:with)
|
15
13
|
if options[:with].is_a?(Integer)
|
16
|
-
block = lambda {|e| send(Rescue
|
14
|
+
block = lambda {|e| send(Rescue.config.respond_name, options[:with], e) }
|
17
15
|
elsif options[:with].is_a?(Proc)
|
18
16
|
block = options[:with]
|
19
17
|
end
|
@@ -26,7 +24,11 @@ module Rescue
|
|
26
24
|
key = if klass.is_a?(Class) && klass <= Exception
|
27
25
|
klass.name
|
28
26
|
elsif klass.is_a?(String) || klass.is_a?(Symbol)
|
29
|
-
|
27
|
+
if options.has_key?(:superclass)
|
28
|
+
Rescue::Bind.define_error_class klass, options[:superclass]
|
29
|
+
else
|
30
|
+
Rescue::Bind.define_error_class klass, StandardError
|
31
|
+
end
|
30
32
|
klass
|
31
33
|
else
|
32
34
|
raise ArgumentError, "#{klass} is neither an Exception nor a String"
|
@@ -6,11 +6,15 @@ module Rescue
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
|
-
define_method Rescue
|
9
|
+
define_method Rescue.config.respond_name do |code, exception = nil|
|
10
10
|
e = {}
|
11
|
-
e
|
12
|
-
|
13
|
-
|
11
|
+
if e.is_a? Rescue::ApplicationError
|
12
|
+
e = { code: e.code, status: e.status, message: e.message }
|
13
|
+
else
|
14
|
+
e[:code] = code
|
15
|
+
e[:status] = Rack::Utils::HTTP_STATUS_CODES[code]
|
16
|
+
e[:message] = exception.message if exception
|
17
|
+
end
|
14
18
|
|
15
19
|
respond_to do |format|
|
16
20
|
format.html { render status: code, template: "/errors/#{code}" }
|
@@ -6,7 +6,7 @@ module Rescue
|
|
6
6
|
|
7
7
|
def self.included(base)
|
8
8
|
base.class_eval do
|
9
|
-
define_method Rescue
|
9
|
+
define_method Rescue.config.respond_name do |code, exception = nil|
|
10
10
|
render status: code, file: "#{Rails.root}/public/#{code}", layout: false and return
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Rescue
|
2
|
+
class ApplicationError < StandardError
|
3
|
+
|
4
|
+
STATUS_CODES = {
|
5
|
+
40 => { http: 400, status: 'Invalid Request' },
|
6
|
+
49 => { http: 400, status: 'Unsupported' },
|
7
|
+
81 => { http: 401, status: 'Access Denied' },
|
8
|
+
83 => { http: 401, status: 'Expired Token' },
|
9
|
+
98 => { http: 403, status: 'Not Permitted' },
|
10
|
+
99 => { http: 403, status: 'Suspended Account' },
|
11
|
+
121 => { http: 410, status: 'Deleted Resources' },
|
12
|
+
140 => { http: 429, status: 'Rate Limit Exceeded' },
|
13
|
+
210 => { http: 500, status: 'Internal Error' },
|
14
|
+
230 => { http: 503, status: 'Over Capacity' },
|
15
|
+
}
|
16
|
+
|
17
|
+
attr_accessor :code
|
18
|
+
attr_accessor :stauts
|
19
|
+
|
20
|
+
def initialize code, status, message = nil
|
21
|
+
@code = code
|
22
|
+
@status = (message ? status : STATUS_CODES[code][:status])
|
23
|
+
@message = message
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Rescue
|
2
|
+
module RespondError
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
6
|
+
status_code = (Rescue.config.suppress_response_codes ? 200 : e[:http])
|
7
|
+
class_name = e[:status].gsub(' ', '')
|
8
|
+
next if Object.const_defined?(class_name)
|
9
|
+
|
10
|
+
exception_class = Class.new(Rescue::ApplicationError) do
|
11
|
+
define_method :initialize do |message = nil|
|
12
|
+
super code, e[:status], message
|
13
|
+
end
|
14
|
+
end
|
15
|
+
Object.const_set class_name, exception_class
|
16
|
+
base.rescue_associate class_name, with: status_code
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
data/lib/rescue/version.rb
CHANGED
data/lib/rescue-dog.rb
CHANGED
@@ -1,15 +1,14 @@
|
|
1
|
-
require
|
1
|
+
require 'rescue/config.rb'
|
2
|
+
require 'rescue/controller.rb'
|
3
|
+
require "rescue/controllers/static.rb"
|
4
|
+
require "rescue/controllers/dynamic.rb"
|
5
|
+
require 'rescue/exceptions/application_error.rb'
|
6
|
+
require 'rescue/exceptions/respond_error.rb'
|
2
7
|
|
3
|
-
require File.join(File.dirname(__FILE__),'rescue/controller.rb')
|
4
8
|
module Rescue
|
5
|
-
|
6
9
|
class Bind
|
7
10
|
class << self
|
8
11
|
|
9
|
-
def respond_name
|
10
|
-
:respond_status
|
11
|
-
end
|
12
|
-
|
13
12
|
def define_error_class class_name, superclass = nil
|
14
13
|
return if Object.const_defined?(class_name)
|
15
14
|
Object.const_set(class_name, Class.new(superclass||StandardError))
|
data/spec/rails_spec_app.rb
CHANGED
@@ -9,7 +9,24 @@ STATUSES = {
|
|
9
9
|
:server_error => 500,
|
10
10
|
}
|
11
11
|
|
12
|
+
# dummy module
|
13
|
+
module ActiveRecord
|
14
|
+
class RecordNotFound < StandardError ; end
|
15
|
+
end
|
16
|
+
module Mongoid
|
17
|
+
module Errors
|
18
|
+
class DocumentNotFound < StandardError ; end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
module BSON
|
22
|
+
class InvalidObjectId < RuntimeError ; end
|
23
|
+
end
|
24
|
+
|
12
25
|
# config
|
26
|
+
Rescue.configure do |config|
|
27
|
+
config.suppress_response_codes = true
|
28
|
+
end
|
29
|
+
|
13
30
|
app = Class.new Rails::Application
|
14
31
|
app.config.active_support.deprecation = :log
|
15
32
|
app.config.secret_token = 'ccedfce890492dd9fe2908a69a8732104ae133f1e2488bf6a1e96685b05a96d7e11aeaa3da5ade27604a50c3b2c7cc8323dd03ad11bb2e52e95256fb67ef9c8a'
|
@@ -24,6 +41,10 @@ app.routes.draw do
|
|
24
41
|
get "/static/#{name}" =>"static##{name}" ,as: name
|
25
42
|
get "/dynamic/#{name}" =>"dynamic##{name}" ,as: name
|
26
43
|
end
|
44
|
+
|
45
|
+
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
46
|
+
get "/status/#{code}" =>"status#error_#{code}" ,as: "status_#{code}"
|
47
|
+
end
|
27
48
|
end
|
28
49
|
|
29
50
|
# controllers
|
@@ -33,7 +54,7 @@ class StaticController < ApplicationController
|
|
33
54
|
include Rescue::Controller::Static
|
34
55
|
rescue_associate :BadRequest ,with: 400
|
35
56
|
rescue_associate :Unauthorized ,with: 401
|
36
|
-
rescue_associate :NotFound
|
57
|
+
rescue_associate :NotFound, Mongoid::Errors::DocumentNotFound, BSON::InvalidObjectId, with: 404
|
37
58
|
rescue_associate :ServerError ,with: 500
|
38
59
|
|
39
60
|
STATUSES.each do |name, code|
|
@@ -48,7 +69,7 @@ class DynamicController < ApplicationController
|
|
48
69
|
include Rescue::Controller::Dynamic
|
49
70
|
rescue_associate :BadRequest ,with: 400
|
50
71
|
rescue_associate :Unauthorized ,with: 401
|
51
|
-
rescue_associate :NotFound
|
72
|
+
rescue_associate :NotFound, ActiveRecord::RecordNotFound, with: 404
|
52
73
|
rescue_associate :ServerError ,with: 500
|
53
74
|
|
54
75
|
STATUSES.each do |name, code|
|
@@ -59,4 +80,15 @@ class DynamicController < ApplicationController
|
|
59
80
|
end
|
60
81
|
end
|
61
82
|
|
83
|
+
class StatusController < ApplicationController
|
84
|
+
include Rescue::Controller::Dynamic
|
85
|
+
include Rescue::RespondError
|
86
|
+
|
87
|
+
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
88
|
+
define_method "error_#{code}" do
|
89
|
+
raise e[:status].gsub(' ', '').constantize.new "This is an explanation of what caused the error."
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
62
94
|
Object.const_set(:ApplicationHelper,Module.new)
|
@@ -3,12 +3,17 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe Rescue::Controller do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
clazz = Class.new
|
8
|
-
include Rescue::Controller
|
9
|
-
define_errors :dynamic, BadRequest: 400, Unauthorized: 401, NotFound: 404, ServerError: 500
|
6
|
+
let(:object) do
|
7
|
+
clazz = Class.new ApplicationController do
|
8
|
+
include Rescue::Controller::ClassMethods
|
10
9
|
end
|
11
10
|
clazz.new
|
12
11
|
end
|
13
12
|
|
13
|
+
describe "include ClassMethods module" do
|
14
|
+
it "expects to be call `rescue_associate` method" do
|
15
|
+
expect(object.methods.include? :rescue_associate).to be_true
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
14
19
|
end
|
@@ -6,9 +6,8 @@ describe Rescue::Controller::Dynamic do
|
|
6
6
|
let(:object) { DynamicController.new }
|
7
7
|
|
8
8
|
describe "respond method" do
|
9
|
-
|
10
|
-
|
11
|
-
should be_true
|
9
|
+
it "expects to be called in a subclass of ApplicationController" do
|
10
|
+
expect(object.methods.include? Rescue.config.respond_name).to be_true
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
@@ -21,10 +20,9 @@ describe Rescue::Controller::Dynamic do
|
|
21
20
|
visit "/dynamic/#{name.to_s.underscore}.#{format.to_sym}"
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
it {
|
26
|
-
it {
|
27
|
-
it { response_headers["Content-Type"].should include(format.to_s) }
|
23
|
+
it { expect(page).to have_content name.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2') }
|
24
|
+
it { expect(page).to have_content "This is an explanation of what caused the error." } unless format.to_sym == :html
|
25
|
+
it { expect(response_headers["Content-Type"]).to include(format.to_s) }
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -6,9 +6,8 @@ describe Rescue::Controller::Static do
|
|
6
6
|
let(:object) { StaticController.new }
|
7
7
|
|
8
8
|
describe "respond method" do
|
9
|
-
|
10
|
-
|
11
|
-
should be_true
|
9
|
+
it "expects to be called in a subclass of ApplicationController" do
|
10
|
+
expect(object.methods.include? Rescue.config.respond_name).to be_true
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
@@ -21,9 +20,8 @@ describe Rescue::Controller::Static do
|
|
21
20
|
visit "/static/#{name.to_s.underscore}.#{format.to_sym}"
|
22
21
|
end
|
23
22
|
|
24
|
-
|
25
|
-
it {
|
26
|
-
it { response_headers["Content-Type"].should include(format.to_s) }
|
23
|
+
it { expect(page).to have_content name.to_s.gsub(/([A-Z]+)([A-Z][a-z])/,'\1 \2').gsub(/([a-z\d])([A-Z])/,'\1 \2') }
|
24
|
+
it { expect(response_headers["Content-Type"]).to include(format.to_s) }
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Rescue::RespondError do
|
5
|
+
|
6
|
+
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
7
|
+
describe "#{code} #{e[:status]}" do
|
8
|
+
let(:name) { e[:status].gsub(' ', '') }
|
9
|
+
|
10
|
+
it "expects to define an exception class of #{e[:status]}" do
|
11
|
+
expect(Object.const_defined? name).to be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "expects to define an exception class that is a kind of Rescue::ApplicationError" do
|
15
|
+
expect(Object.const_get(name).new).to be_a_kind_of Rescue::ApplicationError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "HTTP Status Code" do
|
21
|
+
context "Suppress Response code is #{Rescue.config.suppress_response_codes}" do
|
22
|
+
Rescue::ApplicationError::STATUS_CODES.each do |code, e|
|
23
|
+
describe "#{code} #{e[:status]}" do
|
24
|
+
before do
|
25
|
+
visit "/status//#{code}.json"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "expects to return #{Rescue.config.suppress_response_codes ? 200 : e[:http]}" do
|
29
|
+
expect(page.status_code).to eq (Rescue.config.suppress_response_codes ? 200 : e[:http])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
data/spec/rescue_spec.rb
CHANGED
@@ -7,14 +7,12 @@ describe Rescue do
|
|
7
7
|
let(:name) { :RescueStandardError }
|
8
8
|
before { Rescue::Bind.define_error_class name }
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
should be_true
|
10
|
+
it "expects to define an exception class" do
|
11
|
+
expect(Object.const_defined? name).to be_true
|
13
12
|
end
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
should be_a_kind_of StandardError
|
14
|
+
it "expects to define an exception class that is a kind of StandardError" do
|
15
|
+
expect(Object.const_get(name).new).to be_a_kind_of StandardError
|
18
16
|
end
|
19
17
|
end
|
20
18
|
|
@@ -22,14 +20,12 @@ describe Rescue do
|
|
22
20
|
let(:name) { :RescueScriptError }
|
23
21
|
before { Rescue::Bind.define_error_class name, ScriptError }
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
should be_true
|
23
|
+
it "expects to define an exception class" do
|
24
|
+
expect(Object.const_defined? name).to be_true
|
28
25
|
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
should be_a_kind_of ScriptError
|
27
|
+
it "expects to define an exception class that is a kind of StandardError" do
|
28
|
+
expect(Object.const_get(name).new).to be_a_kind_of ScriptError
|
33
29
|
end
|
34
30
|
end
|
35
31
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'rubygems'
|
3
3
|
require 'rescue-dog'
|
4
|
+
require 'coveralls'
|
4
5
|
|
5
6
|
require File.join(File.dirname(__FILE__), 'rails_spec_app')
|
6
7
|
require File.join(File.dirname(__FILE__), 'test_case')
|
7
8
|
require 'capybara/rails'
|
9
|
+
|
10
|
+
Coveralls.wear!('rails')
|
8
11
|
RSpec.configure do |config|
|
9
12
|
config.mock_with :rspec
|
13
|
+
config.expect_with :rspec do |c|
|
14
|
+
c.syntax = :expect # disables `should`
|
15
|
+
end
|
10
16
|
config.include Capybara::DSL
|
11
17
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rescue-dog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
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-
|
12
|
+
date: 2013-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -36,6 +36,7 @@ extra_rdoc_files: []
|
|
36
36
|
files:
|
37
37
|
- .gitignore
|
38
38
|
- .rspec
|
39
|
+
- .travis.yml
|
39
40
|
- Gemfile
|
40
41
|
- LICENSE.txt
|
41
42
|
- README.md
|
@@ -47,9 +48,12 @@ files:
|
|
47
48
|
- app/views/layouts/application.html.erb
|
48
49
|
- deploy_gem.sh
|
49
50
|
- lib/rescue-dog.rb
|
51
|
+
- lib/rescue/config.rb
|
50
52
|
- lib/rescue/controller.rb
|
51
|
-
- lib/rescue/
|
52
|
-
- lib/rescue/
|
53
|
+
- lib/rescue/controllers/dynamic.rb
|
54
|
+
- lib/rescue/controllers/static.rb
|
55
|
+
- lib/rescue/exceptions/application_error.rb
|
56
|
+
- lib/rescue/exceptions/respond_error.rb
|
53
57
|
- lib/rescue/version.rb
|
54
58
|
- public/400.html
|
55
59
|
- public/400.json
|
@@ -61,9 +65,10 @@ files:
|
|
61
65
|
- public/500.json
|
62
66
|
- rescue-dog.gemspec
|
63
67
|
- spec/rails_spec_app.rb
|
64
|
-
- spec/rescue/controller/dynamic_spec.rb
|
65
|
-
- spec/rescue/controller/static_spec.rb
|
66
68
|
- spec/rescue/controller_spec.rb
|
69
|
+
- spec/rescue/controllers/dynamic_spec.rb
|
70
|
+
- spec/rescue/controllers/static_spec.rb
|
71
|
+
- spec/rescue/exceptions/respond_error_spec.rb
|
67
72
|
- spec/rescue_spec.rb
|
68
73
|
- spec/spec_helper.rb
|
69
74
|
- spec/test_case.rb
|
@@ -93,9 +98,10 @@ specification_version: 3
|
|
93
98
|
summary: define respond methods
|
94
99
|
test_files:
|
95
100
|
- spec/rails_spec_app.rb
|
96
|
-
- spec/rescue/controller/dynamic_spec.rb
|
97
|
-
- spec/rescue/controller/static_spec.rb
|
98
101
|
- spec/rescue/controller_spec.rb
|
102
|
+
- spec/rescue/controllers/dynamic_spec.rb
|
103
|
+
- spec/rescue/controllers/static_spec.rb
|
104
|
+
- spec/rescue/exceptions/respond_error_spec.rb
|
99
105
|
- spec/rescue_spec.rb
|
100
106
|
- spec/spec_helper.rb
|
101
107
|
- spec/test_case.rb
|