You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is a use-case which isn't currently tested well:
We have boot-time checking of the dependency tree (so we check that ExtractBearerTokenprovides :bearer_token)
We have unit tests of each sub-middleware behaving in the correct way in isolation.
We have request specs testing the overall route (including interactions of all the other middleware).
But there doesn't seem to be a simple way of saying, in a test, "run this smaller middleware chain" (i.e. invoke each sub-middleware and then run Middleware::Authenticate#call). The behaviours of this unit might vary depending on inputs/outputs of each sub-middleware in a way which isn't best expressed in isolated unit tests nor in the high-level request specs (which can be slow).
I think that endorsing this kind of testing to uncover interaction edge-cases would be incredibly valuable.
Proposal
Add a high-level API, either to coach/rspec or in the README, for running a full middleware chain like this.
The usage would look something like:
describeMiddleware::Authenticatedosubject(:instance){Coach::Chain.new(described_class)}# this is the interesting bitit{is_expected.tocall_next_middleware}it{is_expected.toprovide(user: ...)}context"when a bearer token isn't in the request"doit"bails out before calling the main function"endend
The text was updated successfully, but these errors were encountered:
nickcampbell18
changed the title
No easy way to test composition of middleware
No defined way to test composition of middleware
Apr 17, 2018
Problem
Let's say I have a large application, with many middleware. Some middleware are simply composition units of others, for example:
I think this is a use-case which isn't currently tested well:
ExtractBearerToken
provides :bearer_token
)But there doesn't seem to be a simple way of saying, in a test, "run this smaller middleware chain" (i.e. invoke each sub-middleware and then run
Middleware::Authenticate#call
). The behaviours of this unit might vary depending on inputs/outputs of each sub-middleware in a way which isn't best expressed in isolated unit tests nor in the high-level request specs (which can be slow).I think that endorsing this kind of testing to uncover interaction edge-cases would be incredibly valuable.
Proposal
Add a high-level API, either to
coach/rspec
or in the README, for running a full middleware chain like this.The usage would look something like:
The text was updated successfully, but these errors were encountered: