collectiveidea / json_spec

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

Shortcut syntax idea #74

Closed alexbel closed 10 years ago

alexbel commented 10 years ago

Just an idea and working code. Added have matcher. It accepts path and type. Type is not required. Symbol will be interpreted as Integer and a string as String Examples:

json = normalize_json(last_response.body)

# json.should have_json_type(Integer).at_path('id')
# can be written as
json.should have :id
# or
json.should have :id, Integer

# json.should have_json_type(String).at_path('first_name')
json.should have 'first_name'

# any defined class
json.should have :my_float, Float
json.should have 'my/flag', TrueClass