Skip to content

"Fuzzy" call matching #14

Closed
Closed
@christopher-dG

Description

@christopher-dG

Sometimes you don't know or want to paste the exact arguments to some mocked function, but you still want to assert that it was called in a certain manner, and you do know some things about the call arguments.

For example:

using Random: randstring
using SimpleMock: called_with, mock, SomethingThatIDontKnowWhatToName

f(x) = x * randstring()

mock(*) do star
    f("foo")
    @test called_with(star, "foo", SomethingThatIDontKnowWhatToName(x -> match(r"\s{8}", x) !== nothing)
end

Instead of comparing the observed argument, which in this case is the output of randstring(), to the expected argument by value, the function x -> match(r"\s{8}", x) !== nothing would run on the observed argument, and be considered a match if that outputted true.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions