Skip to content

Commit

Permalink
Replace NotImplementedError with NoMethodError as it is more appr…
Browse files Browse the repository at this point in the history
…opriate for abstract class semantics.
  • Loading branch information
kmcphillips committed Apr 10, 2024
1 parent 79bf509 commit a86bb22
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# frozen_string_literal: true
class <%= class_name %>Responder < Twilio::Rails::SMS::DelegatedResponder
def handle?
raise NotImplementedError, "Implement #{ self.class }#handle?"
raise NoMethodError, "#{ self.class }#handle? must be implemented."
end

def reply
raise NotImplementedError, "Implement #{ self.class }#reply"
raise NoMethodError, "#{ self.class }#reply must be implemented."
end
end
2 changes: 1 addition & 1 deletion lib/twilio/rails/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ def all
private

def add_to_registry(value)
raise NotImplementedError
raise NoMethodError
end

def error_class
Expand Down
8 changes: 4 additions & 4 deletions lib/twilio/rails/sms/delegated_responder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@ def initialize(message)
@sms_conversation = message.sms_conversation
end

# Must be implemented by the subclass otherwise will raise a `NotImplementedError`. Returns true if this
# Must be implemented by the subclass otherwise will raise a `NoMethodError`. Returns true if this
# responder should handle the given message. If true then the {#reply} method will be called to generate the
# body of the response. It has access to the message and the conversation.
#
# @return [true, false] true if this responder should handle the given message.
def handle?
raise NotImplementedError
raise NoMethodError, "#{ self.class }#handle? must be implemented."
end

# Must be implemented by the subclass otherwise will raise a `NotImplementedError`. Returns the body of the
# Must be implemented by the subclass otherwise will raise a `NoMethodError`. Returns the body of the
# message to be sent in response. Will only be called if {#handle?} returns true. It has access to the message
# and the conversation.
#
# @return [String, nil] the body of the response to be sent as SMS, or `nil` if no message should be sent.
def reply
raise NotImplementedError
raise NoMethodError, "#{ self.class }#reply must be implemented."
end

protected
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/twilio/sms/delegated_responder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@

describe "#reply" do
it "raises" do
expect { subject.reply }.to raise_error(NotImplementedError)
expect { subject.reply }.to raise_error(NoMethodError)
end
end

describe "#handle?" do
it "raises" do
expect { subject.handle? }.to raise_error(NotImplementedError)
expect { subject.handle? }.to raise_error(NoMethodError)
end
end

Expand Down

0 comments on commit a86bb22

Please sign in to comment.