From aae0da5a005376beb3430687d56961c27e22085c Mon Sep 17 00:00:00 2001 From: Lindomar Reitz Date: Sat, 22 Jul 2017 15:37:31 +0100 Subject: [PATCH 1/2] Change generate to convert the values to string. --- lib/pact/term.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/pact/term.rb b/lib/pact/term.rb index 67e241e..a6b2d99 100644 --- a/lib/pact/term.rb +++ b/lib/pact/term.rb @@ -24,9 +24,11 @@ def self.unpack_regexps source def initialize(attributes = {}) @generate = attributes[:generate] + raise "Please specify a value to generate for the Term" unless @generate != nil + + @generate = @generate.to_s @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 end From 9be2736271aa2aa9f6b6994ef104c40c9d17cc92 Mon Sep 17 00:00:00 2001 From: Lindomar Reitz Date: Sat, 22 Jul 2017 15:38:09 +0100 Subject: [PATCH 2/2] Add tests to match integer/float values. --- spec/lib/pact/term_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/spec/lib/pact/term_spec.rb b/spec/lib/pact/term_spec.rb index 56e3a6a..15d73a0 100644 --- a/spec/lib/pact/term_spec.rb +++ b/spec/lib/pact/term_spec.rb @@ -14,6 +14,22 @@ module Pact end end + context "when the generate is a integer" do + let(:term) { Term.new(generate: 10, matcher: /[0-9]/)} + + it 'does not raise an exception' do + term + end + end + + context "when the generate is a float" do + let(:term) { Term.new(generate: 50.51, matcher: /\d(\.\d{1,2})/)} + + it 'does not raise an exception' do + term + end + end + context "when the matcher does not match the generated value" do let(:generate) { 'banana' } it 'raises an exception' do