Add test to show failure case for string factories.
This adds a test case to show that using the response factory for non-map types causes a failure when attempting to build them. This makes it difficult to use this library for testing non-JSON like responses.
Coverage remained the same at 95.789% when pulling d744f8e32218e7e8c86d8244e8b361b53ce15c80 on jalcine:broken-support-for-non-string into ffbfb3ed106003bc1c8a1e6ec089d3270693472c on bernardolins:master.
Coverage remained the same at 95.789% when pulling d744f8e32218e7e8c86d8244e8b361b53ce15c80 on jalcine:broken-support-for-non-string into ffbfb3ed106003bc1c8a1e6ec089d3270693472c on bernardolins:master.
Hi @jalcine, thanks for your contribution!
I think you want to make it clear that response factories only work with maps or strings that are in JSON format, right? This test you added will never pass, unless factories start to support plain text strings. Would you mind to change it to check if an error is raised so the test passes? I think something like this will do the work:
test_with_server "basic factory usage with text" do
assert_raise FakeServer.Error, fn ->
route("/plain", MyResponseFactory.build(:plain_text))
end
end
Btw you can test plain text responses by using a Response structure like this:
test_with_server "basic factory usage with text" do
route "/plain", FakeServer.Response.ok!("Hello World", %{"Content-Type" => "text/plain"})
response = HTTPoison.get!(FakeServer.address() <> "/plain")
assert response.body == "Hello World"
end
Please let me know if you have any problem using FakeServer!