Closed dblock closed 8 years ago
Obviously, get("/")
is better.
But I don't know how to design DSL for requests with custom header or body.
So I built it like this, it's the same with plug and everyone knows plug can use it easily.
I'll optimize it step by step.
I can't tell you how excited I am for your attention.
I copied DSL of grape exactly before maru v0.8.x, but I can't going to do it by reason of difference between ruby
and elixir
, they're quite different language. And then I almost totally rewrite it.
Leave me a message at any time if there's any question or suggestion about maru
!
Thank you for your awesome grape
, again!
We'll figure it out!
I think you could wrap this by adding a get/2
into Maru.Test
?
def get(path, version \\ nil) do
Plug.Test.conn(:get, path) |> make_response(version)
end
Maybe it would be useful for Maru.Test
to actually build on this and include some basic functions that wrap around Plug.Conn
like Phoenix does? For example:
test "returning json" do
conn = get("/users")
assert json_response(conn) == [%{"name" => "lee"}]
end
test "returning text" do
conn = get("/other")
assert text_response(conn) == "hello, world"
end
@leejarvis This looks closer to what I'd want. PR!
@leejarvis @dblock
What should I do if I need a custom header or post body as format of form_data
?
In that case it might be worth considering again doing something similar what Phoenix does. They build a %Plug.Conn
and then use that to form the request, e.g.:
test "returning text" do
conn = build_conn()
conn = conn.put_req_header(conn, "Authorization", "something")
conn = get(conn, "/other")
assert text_response(conn) == "hello, world"
end
Which would allow you to use the setup tags quite nicely too:
setup(tags) do
tags = Map.put(tags, :conn, build_conn())
{:ok, tags}
end
test "returning text", %{conn: conn} do
response = conn
|> put_req_header("Authorisation", "something")
|> get("/")
|> text_response
assert response == "hello, world"
end
Just a couple of ideas, anyway.
@leejarvis Thank you! It looks good, I'll try to do something like this.
I think this can be closed?
Yeah.
Nice work!
This is a little cumbersome to spell:
Maybe it can be more Ruby-like? We'd want to write
Now this is my first day writing Elixir, but I'd be happy to give it a shot if anyone thinks it's a good idea.