Didn't realize you were trying to do so much in one statement.
The idea of a matcher, custom or built-in, is that the match block has
one expectation expressed as a boolean - it should return true or
false to indicate pass or fail. This one matcher is wrapping 10
different expectations in logical pairs. I'd probably start with 5
examples with two expectations in each:
it "is valid with the minimum params" do
get "/api/v1/originator/hello", @minimum_params
expect(response.status).to eq(200)
expect(response.body).not_to include("missing parameter:")
end
it "requires api_key in params" do
get "/api/v1/originator/hello", @minimum_params.except("api_key")
expect(response.status).to eq(400)
expect(response.body).to include("missing parameter: api_key")
end
# 3 more failure cases
Each example has two expectations, but they work together to specify
different parts of the same outcome, so I'm comfortable bypassing the
one-expectation-per-example guideline.
You could, conceivably, reduce some of the duplication with a custom
matcher that just deals with one parameter - something like:
it { should require_param("api_key") }
Either that or wrap the failure examples in an an iterator:
describe "minimum params" do
MIN_PARAMS = {
api_key: "",
nonce: "",
timestamp: "",
hmac_digest: "
}
MIN_PARAMS.each_pair do |k, v|
it "requires api_key in params" do
get "/api/v1/originator/hello", MIN_PARAMS.except(k)
expect(response.status).to eq(400)
expect(response.body).to include("missing parameter: #{k}")
end
end
end
WDYT?
> --
> You received this message because you are subscribed to the Google Groups
> "rspec" group.
> To post to this group, send email to
rs...@googlegroups.com.
> To unsubscribe from this group, send email to
>
rspec+un...@googlegroups.com.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/rspec/-/R3BPlOkxEZIJ.
> For more options, visit
https://groups.google.com/groups/opt_out.
>
>