airborne icon indicating copy to clipboard operation
airborne copied to clipboard

Apply Procs to doted paths

Open brbrr opened this issue 9 years ago • 1 comments

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 })

brbrr avatar Nov 05 '15 15:11 brbrr

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)
      })

Ajaxy avatar Oct 03 '17 23:10 Ajaxy