cjstehno / ersatz

🤖 A simulated HTTP server for testing client code with configurable responses.
https://cjstehno.github.io/ersatz
Apache License 2.0
47 stars 5 forks source link

header points to request in response block / wrong resolve strategy for @DelegatesTo #102

Closed KrzysztofKowalczyk closed 5 years ago

KrzysztofKowalczyk commented 5 years ago

Ersatz is using default delegation strategy for closures, which delegates first to owner of the closure, not to the delegate which in my opinion would be working better.

To add header to response one have to use delegate:

server.expectations {
  get("/foo") {
    header('Accept', 'application/json')

    responder {
      delegate.header("Bad", "code") // without delegate that would resolve to Request.header
      content('{"hello":"world"}', 'application/json')
    }
  }
}

If ersatz would be marked to do delegate first, one could write:

server.expectations {
  get("/foo") {
    header('Accept', 'application/json')

    responder {
      header("Bad", "code") // delegate first resolves to Response.header
      content('{"hello":"world"}', 'application/json')
    }
  }
}
cjstehno commented 5 years ago

Odd that hasn't popped up earlier. I'll take a look. Thanks.

cjstehno commented 5 years ago

Definitely an issue. I'll fix this in the upcoming 1.8 release. Good catch. I tend to forget about the delegate strategy.

KrzysztofKowalczyk commented 5 years ago

Thanks for fast reaction

cjstehno commented 5 years ago

The fix for this is in release 1.8.1, which was published today.