From 3b49daf2c5cd6ad66f36faaabecd5731c0a43abf Mon Sep 17 00:00:00 2001 From: Keegan Roth Date: Thu, 8 Oct 2015 16:43:22 -0400 Subject: [PATCH] Validate that the input to remember will not try to use the numeric % The code in JsonSpec.remember assumes that the incoming argument will be a string and uses the % operator to interpolate from the memory hash into the string. However, it is perfectly possible to pass in a Numeric type (e.g. Fixnum) for which the % operator means something totally different which causes the code to try to convert the hash to fixnum, which it can't. Fixes #90 --- lib/json_spec/memory.rb | 2 +- spec/json_spec/memory_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/json_spec/memory.rb b/lib/json_spec/memory.rb index df589c1..113146e 100644 --- a/lib/json_spec/memory.rb +++ b/lib/json_spec/memory.rb @@ -9,7 +9,7 @@ def memorize(key, value) end def remember(json) - memory.empty? ? json : json % memory + (memory.empty? or json.is_a?(Numeric)) ? json : json % memory end def forget diff --git a/spec/json_spec/memory_spec.rb b/spec/json_spec/memory_spec.rb index b644812..e248ae0 100644 --- a/spec/json_spec/memory_spec.rb +++ b/spec/json_spec/memory_spec.rb @@ -24,6 +24,11 @@ JsonSpec.remember("foo%{bar}").should == "foobaz" end + it "ignores numeric types" do + JsonSpec.memorize(:bar, "baz") + JsonSpec.remember(10).should == 10 + end + it "forgets" do JsonSpec.memorize(:key, "value") JsonSpec.forget