Skip to content

Commit

Permalink
fix: raise Pact::Error not RuntimeError when invalid constructor argu…
Browse files Browse the repository at this point in the history
…ments are supplied to a Pact::Term
  • Loading branch information
bethesque committed Jan 28, 2021
1 parent 71cad78 commit d9fb8ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 4 additions & 3 deletions lib/pact/term.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'pact/shared/active_support_support'
require 'json/add/regexp'
require 'pact/errors'

module Pact
class Term
Expand All @@ -25,9 +26,9 @@ def self.unpack_regexps source
def initialize(attributes = {})
@generate = attributes[:generate]
@matcher = attributes[:matcher]
raise "Please specify a matcher for the Term" unless @matcher != nil
raise "Please specify a value to generate for the Term" unless @generate != nil
raise "Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}" unless @generate =~ @matcher
raise Pact::Error.new("Please specify a matcher for the Term") unless @matcher != nil
raise Pact::Error.new("Please specify a value to generate for the Term") unless @generate != nil
raise Pact::Error.new("Value to generate \"#{@generate}\" does not match regular expression #{@matcher.inspect}") unless @generate =~ @matcher
end

def to_hash
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/pact/term_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ module Pact
context "when the matcher does not match the generated value" do
let(:generate) { 'banana' }
it 'raises an exception' do
expect { subject }.to raise_error /does not match/
expect { subject }.to raise_error Pact::Error, /does not match/
end
end
end
context 'when a matcher is not specified' do
let(:matcher) { nil }
it 'raises an exception' do
expect { subject }.to raise_error /Please specify a matcher/
expect { subject }.to raise_error Pact::Error, /Please specify a matcher/
end
end
context 'when a generate is not specified' do
let(:generate) { nil }
it 'raises an exception' do
expect { subject }.to raise_error /Please specify a value/
expect { subject }.to raise_error Pact::Error, /Please specify a value/
end
end
end
Expand Down

0 comments on commit d9fb8ea

Please sign in to comment.