Skip to content

Commit d9fb8ea

Browse files
committedJan 28, 2021
fix: raise Pact::Error not RuntimeError when invalid constructor arguments are supplied to a Pact::Term
1 parent 71cad78 commit d9fb8ea

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed
 

‎lib/pact/term.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require 'pact/shared/active_support_support'
22
require 'json/add/regexp'
3+
require 'pact/errors'
34

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

3334
def to_hash

‎spec/lib/pact/term_spec.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ module Pact
1717
context "when the matcher does not match the generated value" do
1818
let(:generate) { 'banana' }
1919
it 'raises an exception' do
20-
expect { subject }.to raise_error /does not match/
20+
expect { subject }.to raise_error Pact::Error, /does not match/
2121
end
2222
end
2323
end
2424
context 'when a matcher is not specified' do
2525
let(:matcher) { nil }
2626
it 'raises an exception' do
27-
expect { subject }.to raise_error /Please specify a matcher/
27+
expect { subject }.to raise_error Pact::Error, /Please specify a matcher/
2828
end
2929
end
3030
context 'when a generate is not specified' do
3131
let(:generate) { nil }
3232
it 'raises an exception' do
33-
expect { subject }.to raise_error /Please specify a value/
33+
expect { subject }.to raise_error Pact::Error, /Please specify a value/
3434
end
3535
end
3636
end

0 commit comments

Comments
 (0)
Please sign in to comment.