From d9fb8ea39d3072fe15efcecddffc4646a86794d1 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Thu, 28 Jan 2021 11:50:15 +1100 Subject: [PATCH] fix: raise Pact::Error not RuntimeError when invalid constructor arguments are supplied to a Pact::Term --- lib/pact/term.rb | 7 ++++--- spec/lib/pact/term_spec.rb | 6 +++--- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/pact/term.rb b/lib/pact/term.rb index b2b4d05..0e996e6 100644 --- a/lib/pact/term.rb +++ b/lib/pact/term.rb @@ -1,5 +1,6 @@ require 'pact/shared/active_support_support' require 'json/add/regexp' +require 'pact/errors' module Pact class Term @@ -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 diff --git a/spec/lib/pact/term_spec.rb b/spec/lib/pact/term_spec.rb index 28b697f..d2ced7d 100644 --- a/spec/lib/pact/term_spec.rb +++ b/spec/lib/pact/term_spec.rb @@ -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