airborne
airborne copied to clipboard
Apply Procs to doted paths
My API return {"result":"error","content":{"code":"LOGIN_DATA_INCORRECT","parameters":{"loginAttemptsLeft":4}}}
and I want to check that loginAttemptsLeft
was decremented after some actions.
For now when I want to use complex matcher (via Proc
) I need to use symbols as key i.e.:
expect_json(content: -> (n) { expect(n[:parameters][:loginAttemptsLeft]) < 5 })
But it would be awesome to have same complex matchers for dot paths like so:
expect_json('content.parameters.loginAttemptsLeft' -> (attemts_left) { expect(attemts_left) < 5 })
A bit late, but I was able to do so with expect_json_types
:
expect_json_types('visit.checkin_at', -> (actual) {
expect(iso8601?(actual)).to be_truthy
expect(Time.parse(actual)).to be_within(1.seconds).of(Time.current)
})