chancancode/json_expressions — pull request #7 by tdumitrescu (2012-09-27 02:05:03+00:00)
Title: Custom matcher which allows nil values

We just started playing with json_expressions for testing API controllers at Lumos Labs, and it's awesome for using specs to document response formats concisely. One pattern we've needed repeatedly is a value which can be either nil or a specific type/set of values; for instance, a foreign key which can either be a Fixnum or nil. So I added a #nil_or matcher which always matches on nil, and otherwise delegates matching to the given pattern/value. So nil_or(Fixnum) will succeed with both 5 and nil, but not 'meow'. Thought it would be helpful for other people too.