Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor tests #22

Closed
andreineculau opened this issue Nov 23, 2015 · 2 comments
Closed

refactor tests #22

andreineculau opened this issue Nov 23, 2015 · 2 comments
Assignees

Comments

@andreineculau
Copy link
Member

to get around these annoyances:

  • put together constructs related to one test, so that you can read assertion, mocked request, mocked apib (not jump through the file, or have 3 buffers opened just to have the full view of 1 test). Possibly go as far as 1 test module per test (more copy-paste boilerplate, but who cares)
  • if a test fails today, the output is truncated (ellipsis)
  • TBC
@sstrigler
Copy link

Don't beat me but would it be so bad to do the "meck:expect" in each test itself respectively?

katt_run_basic(lhttpc_request) ->
  fun( "http://127.0.0.1/step1" = _Url
                   , "POST" = _Method
                   , _Headers
                   , _Body
                   , _Timeout
                   , _Options
                   ) ->
      {ok, { {201, []}
           , [ {"Location", "http://127.0.0.1/step2"}
             , {"Cache-Control", "no-cache"}
             , {"Cache-Control", "no-store"}
             , {"Cache-Control", "must-revalidate"}
             , {"X-Another-Duplicate-Header", "foo"}
             , {"X-Another-Duplicate-Header", "bar"}
             ]
           , <<>>}}
  end;
katt_run_basic(katt_blueprint_parse_file) ->
  fun("/mock/basic.apib") ->
      katt_blueprint_parse:string(
    <<"--- Test 1 ---

---
Some description
---

# Step 1

The merchant creates a new example object on our server, and we respond with
the location of the created example.

POST /step1
> Accept: application/json
> Content-Type: application/json
{
    \"cart\": {
        \"items\": [
            {
                \"name\": \"Horse\",
                \"quantity\": 1,
                \"unit_price\": 4495000
            },
[...]

HEAD /step5
< 404
< Content-Type: text/html
<<<
>>>
"/utf8>>)
  end;
katt_run_basic(test) ->
  fun() ->
  meck:expect(lhttpc, request, katt_run_basic(lhttpc_request)),
  meck:expect(katt_blueprint_parse, file, katt_run_basic(katt_blueprint_parse_file)),

  Scenario = "/mock/basic.apib",
  ?_assertMatch( { pass
                 , Scenario
                 , _
                 , _
                 , [ {_, _, _, _, pass}
                   , {_, _, _, _, pass}
                   , {_, _, _, _, pass}
                   , {_, _, _, _, pass}
                   , {_, _, _, _, pass}
                   ]
                 }
               , katt:run(Scenario)
               )
  end.

@sstrigler
Copy link

ah, uh, oh - just forget about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants