lunarmodules / luassert

Assertion library for Lua
MIT License
202 stars 77 forks source link

Can I pass state between modifiers/assertions? #139

Closed Tieske closed 7 years ago

Tieske commented 8 years ago

I'd like to store a value, and then have other elements in the chain act on that value.

Example;

local r = http:get( ... some request ...)
assert.response(r).has.status(200)
local value = assert.response(r).has.header("Content-Length")
assert.are.equal(123, value)

So basically status and header assertions (which I can write myself and add to luassert) would operate on the value provided by the response modifier.

It's related to/prerequisite for #135 I think

I tried to add a value to the state parameter that is passed along the chain, but is was unreliable due to all the meta-table magic the state object has. So I ended up with an ugly wrapper on assert that would reset a custom state table (upvalue) on each call, and the modifiers storing data in that upvalue.

What would be the right approach to implement this?

Tieske commented 8 years ago

apologies, I meant it's related to #131, not 135

Tieske commented 7 years ago

closing this since I created #145