|
142 | 142 |
|
143 | 143 | context "when options are configured globally" do |
144 | 144 | it "forwards them to the validator" do |
145 | | - create_schema("foo_schema", { |
146 | | - "type" => "object", |
147 | | - "properties" => { |
148 | | - "id" => { "type" => "number" }, |
149 | | - "title" => { "type" => "string" }, |
150 | | - }, |
151 | | - }) |
152 | | - |
153 | | - JsonMatchers.configure do |config| |
154 | | - config.options[:strict] = true |
155 | | - end |
156 | | - |
157 | | - expect(response_for({ "id" => 1, "title" => "bar" })). |
158 | | - to match_response_schema("foo_schema") |
159 | | - expect(response_for({ "id" => 1 })). |
160 | | - not_to match_response_schema("foo_schema") |
161 | | - end |
162 | | - |
163 | | - after do |
164 | | - JsonMatchers.configure do |config| |
165 | | - config.options.delete(:strict) |
| 145 | + with_options(strict: true) do |
| 146 | + create_schema("foo_schema", { |
| 147 | + "type" => "object", |
| 148 | + "properties" => { |
| 149 | + "id" => { "type" => "number" }, |
| 150 | + "title" => { "type" => "string" }, |
| 151 | + }, |
| 152 | + }) |
| 153 | + |
| 154 | + expect(response_for({ "id" => 1, "title" => "bar" })). |
| 155 | + to match_response_schema("foo_schema") |
| 156 | + expect(response_for({ "id" => 1 })). |
| 157 | + not_to match_response_schema("foo_schema") |
166 | 158 | end |
167 | 159 | end |
168 | 160 |
|
169 | | - context "when options specify to record errors" do |
170 | | - around do |example| |
171 | | - JsonMatchers.configure do |config| |
172 | | - config.options[:record_errors] = true |
173 | | - end |
174 | | - |
175 | | - example.run |
176 | | - |
177 | | - JsonMatchers.configure do |config| |
178 | | - config.options.delete(:record_errors) |
179 | | - end |
180 | | - end |
181 | | - |
| 161 | + context "when configured to record errors" do |
182 | 162 | it "fails when the body is missing a required property" do |
183 | | - create_schema("foo_schema", |
184 | | - "type" => "object", |
185 | | - "required" => ["foo"]) |
| 163 | + with_options(record_errors: true) do |
| 164 | + create_schema("foo_schema", |
| 165 | + "type" => "object", |
| 166 | + "required" => ["foo"]) |
186 | 167 |
|
187 | | - expect(response_for({})).not_to match_response_schema("foo_schema") |
| 168 | + expect(response_for({})).not_to match_response_schema("foo_schema") |
| 169 | + end |
188 | 170 | end |
189 | 171 | end |
190 | 172 | end |
|
0 commit comments