4

I am using rspec expectations with cucumber. It seems that when using multiple expects in a cucumber steps, cucumber evaluates them until first of them fails. However I want to continue running also other expects to get a clear picture of what went wrong. Can I somehow achieve this?

Example: -let's suppose that response = "1", code = "2" and status = "3"

expect(response).to eq("0")
expect(code).to eq("2")
expect(status).to eq("1")

Cucumber will fail when evaluating response variable. But I want to check value of other two variables and get output for wrong status value too. Is this possible?

Dave Schweisguth
  • 36,475
  • 10
  • 98
  • 121
Tians
  • 443
  • 1
  • 5
  • 14

1 Answers1

3

The easiest would be:

expect({
  response: response,
  code: code,
  status: status}
).to eq({ response: "0", code: "2", status: "1" })

If the test fails, you would see two hashes comparead, with a diff clearly visible.

Yury Lebedev
  • 3,985
  • 19
  • 26
  • You actually answered my question. I am however interested if there exists any other solutions, because inside one of my step I call other steps. And if one of this called steps fails, execution immediately stops. But I don't want that. – Tians Nov 20 '15 at 11:36
  • @Tians i think a more cleaner way would be to make a custom rspec matcher, which takes the request as an argument, and then tests the status and the response. You can find some examples here: http://www.relishapp.com/rspec/rspec-expectations/v/3-4/docs/custom-matchers/define-a-custom-matcher – Yury Lebedev Nov 20 '15 at 13:06
  • I didn't know this was a problem, but I like it. – Dave McNulla Nov 20 '15 at 19:09
  • 1
    @tians, don't call steps inside other steps, its a really bad idea. Instead extract a helper method, and call that. – diabolist Nov 24 '15 at 09:11