Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuring matcher default options #46

Merged
merged 1 commit into from
Oct 28, 2016
Merged

Conversation

seanpdoyle
Copy link
Collaborator

Closes #40.

To configure the default options passed to all matchers, call
JsonMatchers.configure:

JsonMatchers.configure do |config|
  config.options[:strict] = true
end

A list of available options can be found here.


expect(response_for({ "id" => 1, "title" => "bar" })).
to match_response_schema("foo_schema", strict: true)
expect(response_for({ "id" => 1 })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

},
})

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

"id" => { "type" => "number" },
"title" => {"type" => "string"},
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

context "when options are passed directly to the matcher" do
it "forwards options to the validator" do
create_schema("foo_schema", {
"type" => "object",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.

@@ -130,6 +113,52 @@
expect(invalid_response).not_to match_response_schema("collection")
end

context "when options are passed directly to the matcher" do
it "forwards options to the validator" do
create_schema("foo_schema", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

},
})

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

},
})

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

"id" => { "type" => "number" },
"title" => { "type" => "string" },
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

"id" => { "type" => "number" },
"title" => { "type" => "string" },
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

},
})

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

"id" => { "type" => "number" },
"title" => { "type" => "string" },
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

},
})

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

"id" => { "type" => "number" },
"title" => { "type" => "string" },
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

Closes [#40].

To configure the default options passed to *all* matchers, call
`JsonMatchers.configure`:

```rb

JsonMatchers.configure do |config|
  config.options[:strict] = true
end
```

A list of available options can be found [here][options].

[#40]: #40
[options]: https://github.com/ruby-json-schema/json-schema/blob/2.2.4/lib/json-schema/validator.rb#L160-L162

expect(response_for({ "id" => 1, "title" => "bar" })).
to match_response_schema("foo_schema")
expect(response_for({ "id" => 1 })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

config.options[:strict] = true
end

expect(response_for({ "id" => 1, "title" => "bar" })).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

"id" => { "type" => "number" },
"title" => { "type" => "string" },
},
})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indent the right brace the same as the first position after the preceding left parenthesis.

context "when options are configured globally" do
it "forwards them to the validator" do
create_schema("foo_schema", {
"type" => "object",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use 2 spaces for indentation in a hash, relative to the first position after the preceding left parenthesis.


context "when options are configured globally" do
it "forwards them to the validator" do
create_schema("foo_schema", {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant curly braces around a hash parameter.

@seanpdoyle seanpdoyle merged commit c9abdf9 into master Oct 28, 2016
@seanpdoyle seanpdoyle deleted the configure branch October 28, 2016 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants