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

Multiple expect_once #95

Open
ream88 opened this issue May 10, 2020 · 4 comments
Open

Multiple expect_once #95

ream88 opened this issue May 10, 2020 · 4 comments

Comments

@ream88
Copy link
Collaborator

ream88 commented May 10, 2020

@ream88 any possibility of making it so that within one test I can stack two expect_once's so that the first call to the given route gets my first expect_once and the second call gets the second expect_once?
Currently the second expect_once would just redefine the first expect_once and I would get an error because the route is called twice.

Originally posted by @agramichael in #88 (comment)

@ream88 ream88 mentioned this issue May 10, 2020
11 tasks
@ream88
Copy link
Collaborator Author

ream88 commented May 10, 2020

Any help/PR would be very appreciated @agramichael @mrdougwright 😊

@mrdougwright
Copy link

Hmm, looked at the code a bit. Does it make sense to rework expect_once? Or is it better to have a new function, like expect_this? It looks rather tricky to change expect_once, since Bypass simply counts requests, and fails when there are too many.

@thiamsantos
Copy link
Contributor

I was taking a look into this feature. I think we could change the data structure
of the expectations, to be a list of the expectations for the route.

When we have multiple expect_once we just append the new expectations, and after the call, we remove the called callback.
With that the main differences is that we wouldn't be able to count requests for request_once, as the callback would be removed from the list to be able to call the next one.
Also we wouldn't be able to redefine expect_onces as introduced by #80.

expect_once example:

Bypass.expect_once(bypass, "GET", "/foo", fun1)
Bypass.expect_once(bypass, "GET", "/foo", fun2)

Structure:

%{
  {"GET", "/foo"} => [
    %{
      expected: :once,
      fun: fun1,
      #...
    },
    %{
      expected: :once,
      fun: fun2,
      #...
    }
  ]
}

However for expect and stub the ideia is to remain the same,
each call to expect or stub will replace completely the list of expectations, and we only will have the last one.

expect example:

Bypass.expect_once(bypass, "GET", "/foo", fun1)
Bypass.expect(bypass, "GET", "/foo", fun2)

structure:

%{
  {"GET", "/foo"} => [
    %{
      expected: :once_or_more,
      fun: fun2,
      #...
    }
  ]
}

stub example:

Bypass.expect_once(bypass, "GET", "/foo", fun1)
Bypass.stub(bypass, "GET", "/foo", fun2)

Structure:

%{
  {"GET", "/foo"} => [
    %{
      expected: :none_or_more,
      fun: fun2,
      #...
    }
  ]
}

WDYT @ream88?

@cristopher-rodrigues
Copy link

any news here?

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

4 participants