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

Mockito without mirrors? #27

Closed
Hixie opened this issue Aug 1, 2016 · 10 comments
Closed

Mockito without mirrors? #27

Hixie opened this issue Aug 1, 2016 · 10 comments

Comments

@Hixie
Copy link

Hixie commented Aug 1, 2016

Would it be possible to create a version of mockito that doesn't use dart:mirrors? That would enable mockito to be used in environments that disable the mirrors support.

@matanlurey
Copy link
Contributor

It looks like the only invocation of true mirrors is spy:

dynamic spy(dynamic mock, dynamic spiedObject) {
  var mirror = reflect(spiedObject);
  mock._defaultResponse = () => new CannedResponse(
      null, (Invocation realInvocation) => mirror.delegate(realInvocation));
  return mock;
}

I imagine this could be moved to mockito/spy.dart.

The rest of mirrors uses noSuchMethod, which is a sort of mirrors-light. Is that still supported in Flutter/AOT? We've had a few conversations about code-gen based mockito that had mixed reviews.

@matanlurey
Copy link
Contributor

It looks like noSuchMethod works for AOT. @TedSander is this a reasonable change?

@TedSander
Copy link
Contributor

Yep seems reasonable. Anyone want to send a pull request? I imagine we shouldn't have a breaking change for this. So have the original entrypoint export spy.dart, and mock.dart (or something like that,) and have AOT just import the second one.

@matanlurey
Copy link
Contributor

@Hixie does that sound OK?

We'd have:

lib/
  src/
    mock.dart
    spy.dart
  mockito.dart: Original library that also exports spy (won't work in AOT)
  mockito_no_mirrors.dart: Mockito without the spy function (or whatever else is added)

@Hixie
Copy link
Author

Hixie commented Aug 2, 2016

sgtm

@Hixie
Copy link
Author

Hixie commented Aug 2, 2016

and thanks for looking at this so quickly! much appreciated.

@matanlurey
Copy link
Contributor

@TedSander I'll shoot you a PR shortly 💋

@matanlurey
Copy link
Contributor

@Hixie of course!

@matanlurey
Copy link
Contributor

matanlurey commented Aug 2, 2016

Alright, take a look at PR https://github.com/fibulwinter/dart-mockito/pull/28

@Hixie
Copy link
Author

Hixie commented Aug 2, 2016

Thanks!

@TedSander TedSander mentioned this issue Feb 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants