Code Monkey home page Code Monkey logo

Comments (4)

staticcat avatar staticcat commented on August 28, 2024

/tldr
Short answer, no.

Long answer, I wish it could be.

/explanation /rant
I really wanted to implement this feature. However as Delphi's parameter calling is undefined behaviour, I couldn't.

The goal syntax was the following, and can be seen in f-param-matches branch.

mock.Setup.WillReturn(TValue.From(true)).When.DoIt(Is.Any(), Is.Any());

As a result development has stalled a bit. I consider this to be a critical feature of a Mocking framework. The only other way I can see it implemented is via using text names of the functions, and procedures passing an array of parameter values.

mock.Setup.WillReturn(TValue.From(true)).When("DoIt", [Is.Any(), Is.Any()]);

The problem I have with this is that its not caught at compile time. Tests should break as early as possible. If the interface has changed, then the test should break in compile as it has not been updated. It will still break, but much later when the tests are actually run.

Another point to this is that maintenance is harder. The IDE knows nothing about the text passed to the When function being an actual function/procedure. So when IDE plugins look for usages of an interface, this test would not appear in that list.

So, when I or someone else gets some spare time we might implement the text version for starters until we think of something better. Better have a functional framework, rather than it being incomplete. I think the wind was taken out of our sails when we found the undefined behaviour (which we could see no real good reason for).

from delphi-mocks.

mmarquee avatar mmarquee commented on August 28, 2024

Thank you very much for this answer, whilst it doesn't enable me to do what I need to do (yet), it is very detailed and explains the situation properly.

from delphi-mocks.

staticcat avatar staticcat commented on August 28, 2024

This has been implemented in pr #64. The way I got around the undefined order of parameter execution was to simply define it when the matcher was called. This has lead to It being defined as a function now.

e.g.
It(0).IsAny()

The above example will match the first parameter. This means you could have the following;

e.g.
mock.Setup.WillReturn(8).When.TakesTwoParams(It(0).IsAny(), It(1).IsEqualTo(false));

Note that this means you can still get errors by incorrectly indexing the matches.

e.g.
mockCredit.Setup.WillReturn(8).When.TakesTwoParams(It(1).IsAny(), It(0).IsEqualTo(false));

If people could work on the param matcher branch and give me some feedback that would be great. If not, might just merge it.

from delphi-mocks.

staticcat avatar staticcat commented on August 28, 2024

So param matchers have been implemented and merged into master. I am marking this issue resolved.

from delphi-mocks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.