Navigation Menu

Skip to content

Commit

Permalink
chore: correct spelling of 'rescuable'
Browse files Browse the repository at this point in the history
As pointed out by @R-obert in #247 (comment)
  • Loading branch information
bethesque committed Sep 7, 2017
1 parent 219f737 commit 72db4a8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion lib/webmachine/decision/fsm.rb
Expand Up @@ -49,7 +49,7 @@ def run

def handle_exceptions
yield
rescue Webmachine::RescueableException => e
rescue Webmachine::RescuableException => e
resource.handle_exception(e)
500
rescue MalformedRequest => e
Expand Down
30 changes: 15 additions & 15 deletions lib/webmachine/rescueable_exception.rb
@@ -1,30 +1,30 @@
module Webmachine::RescueableException
module Webmachine::RescuableException
require_relative 'errors'
require 'set'

UNRESCUEABLE_DEFAULTS = [
UNRESCUABLE_DEFAULTS = [
Webmachine::MalformedRequest,
NoMemoryError, SystemExit, SignalException
].freeze

UNRESCUEABLE = Set.new UNRESCUEABLE_DEFAULTS.dup
private_constant :UNRESCUEABLE
UNRESCUABLE = Set.new UNRESCUABLE_DEFAULTS.dup
private_constant :UNRESCUABLE

def self.===(e)
case e
when *UNRESCUEABLE then false
when *UNRESCUABLE then false
else true
end
end

#
# Remove modifications to Webmachine::RescueableException.
# Restores default list of unrescue-able exceptions,
# Remove modifications to Webmachine::RescuableException.
# Restores default list of unrescue-able exceptions.
#
# @return [nil]
#
def self.default!
UNRESCUEABLE.replace Set.new(UNRESCUEABLE_DEFAULTS.dup)
UNRESCUABLE.replace Set.new(UNRESCUABLE_DEFAULTS.dup)
nil
end

Expand All @@ -33,30 +33,30 @@ def self.default!
# Returns an Array of exceptions that will not be
# rescued by {Webmachine::Resource#handle_exception}.
#
def self.unrescueables
UNRESCUEABLE.to_a
def self.UNRESCUABLEs
UNRESCUABLE.to_a
end

#
# Add a variable number of exceptions that should be rescued by
# {Webmachine::Resource#handle_exception}. See {UNRESCUEABLE_DEFAULTS}
# {Webmachine::Resource#handle_exception}. See {UNRESCUABLE_DEFAULTS}
# for a list of exceptions that are not caught by default.
#
# @param (see #remove)
#
def self.add(*exceptions)
exceptions.each{|e| UNRESCUEABLE.delete(e)}
exceptions.each{|e| UNRESCUABLE.delete(e)}
end

#
# Remove a variable number ofexceptions from being rescued by
# {Webmachine::Resource#handle_exception}. See {UNRESCUEABLE_DEFAULTS}
# Remove a variable number of exceptions from being rescued by
# {Webmachine::Resource#handle_exception}. See {UNRESCUABLE_DEFAULTS}
# for a list of exceptions that are not caught by default.
#
# @param [Exception] *exceptions
# A subclass of Exception.
#
def self.remove(*exceptions)
exceptions.each{|e| UNRESCUEABLE.add(e)}
exceptions.each{|e| UNRESCUABLE.add(e)}
end
end
4 changes: 2 additions & 2 deletions spec/spec_helper.rb
Expand Up @@ -19,11 +19,11 @@ def add(severity, message=nil, progname=nil, &block)
end

config.before :each do
Webmachine::RescueableException.remove(RSpec::Mocks::MockExpectationError)
Webmachine::RescuableException.remove(RSpec::Mocks::MockExpectationError)
end

config.after :each do
Webmachine::RescueableException.default!
Webmachine::RescuableException.default!
end

config.before(:suite) do
Expand Down
14 changes: 7 additions & 7 deletions spec/webmachine/decision/fsm_spec.rb
Expand Up @@ -13,8 +13,8 @@
end

describe 'handling of exceptions from decision methods' do
let(:unrescueable_exceptions) do
Webmachine::RescueableException::UNRESCUEABLE
let(:UNRESCUABLE_exceptions) do
Webmachine::RescuableException::UNRESCUABLE
end

describe "rescueable exceptions" do
Expand All @@ -31,20 +31,20 @@
end
end

describe "unrescueable exceptions" do
shared_examples "unrescueable" do |e|
describe "UNRESCUABLE exceptions" do
shared_examples "UNRESCUABLE" do |e|
specify "#{e} is not rescued" do
allow(subject).to receive(Webmachine::Decision::Flow::START) {raise(e)}
expect(resource).to_not receive(:handle_exception).with instance_of(e)
expect { subject.run }.to raise_error(e)
end
end
eary = Webmachine::RescueableException::UNRESCUEABLE_DEFAULTS - [
eary = Webmachine::RescuableException::UNRESCUABLE_DEFAULTS - [
Webmachine::MalformedRequest, # Webmachine rescues by default, so it won't re-raise.
SignalException # Requires raise in form 'raise SignalException, "SIGSOMESIGNAL"'.
# Haven't found a good no-op signal to use here.
]
eary.each{|e| include_examples "unrescueable", e}
eary.each{|e| include_examples "UNRESCUABLE", e}
end
end

Expand Down Expand Up @@ -96,7 +96,7 @@
let(:exception) { Class.new(Exception).new }

before do
Webmachine::RescueableException.remove(exception)
Webmachine::RescuableException.remove(exception)
allow(resource).to receive(:finish_request) { raise exception }
end

Expand Down
12 changes: 6 additions & 6 deletions spec/webmachine/rescueable_exception_spec.rb
@@ -1,15 +1,15 @@
require 'spec_helper'
RSpec.describe Webmachine::RescueableException do
RSpec.describe Webmachine::RescuableException do
before { described_class.default! }

describe ".unrescueables" do
specify "returns an array of unrescueable exceptions" do
expect(described_class.unrescueables).to eq(described_class::UNRESCUEABLE_DEFAULTS)
describe ".UNRESCUABLEs" do
specify "returns an array of UNRESCUABLE exceptions" do
expect(described_class.UNRESCUABLEs).to eq(described_class::UNRESCUABLE_DEFAULTS)
end

specify "returns an array of unrescueable exceptions, with custom exceptions added" do
specify "returns an array of UNRESCUABLE exceptions, with custom exceptions added" do
described_class.remove(Exception)
expect(described_class.unrescueables).to eq(described_class::UNRESCUEABLE_DEFAULTS.dup.concat([Exception]))
expect(described_class.UNRESCUABLEs).to eq(described_class::UNRESCUABLE_DEFAULTS.dup.concat([Exception]))
end
end
end

0 comments on commit 72db4a8

Please sign in to comment.