collectiveidea / json_spec

Easily handle JSON in RSpec and Cucumber
rubygems.org/gems/json_spec
MIT License
919 stars 114 forks source link

Validate that the input to remember will not try to use the numeric % #91

Open fireyone29 opened 8 years ago

fireyone29 commented 8 years ago

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. This is especially problematic from the cucumber matchers, where your input is always run through remember.

I ran into the problem when trying to do a cucumber step like "And the JSON at "count" should be 10" but I am completely unable to reproduce it in this repo's cucumber tests (the 10 always comes in as a string some way I don't understand).

It appears possible to fix this either by doing .to_s on the income argument or changing the exclusion criteria to also include .is_a?(Numeric) (i.e. in addition to checking if the memory hash is empty). I think the is numeric check is more precise, so I'll submit a pull request with that change, but both solve my particular problem.