chancancode / json_expressions

JSON matchmaking for all your API testing needs.
MIT License
415 stars 38 forks source link

Define JSON pattern outside of tests? #19

Closed sricc closed 11 years ago

sricc commented 11 years ago

Is it currently possible to define the JSON patterns outside of a test?

I've tried to define my patterns in a module in spec/support/json_patterns.rb, but have not been able to do so successfully. It would be nice to be able to have them all together so the patterns don't take up space in the tests.

Also, you'd be able to do something like.

module JsonPatterns
  class Person
    self.pattern = {
      id:         :person_id,
      first_name: String,
      last_name:  String,
      created_at: wildcard_matcher,
      updated_at: wildcard_matcher
    }
  end

  class Family
    self.pattern = {
      id:     :family_id,
      father: Person.pattern,
      mother: Person.pattern,
      ....
    }
  end
end
chancancode commented 11 years ago

Yep. Just do JsonExpressions::Matcher.new(...)

sricc commented 11 years ago

Ok, great. Thanks.