Cuckoo icon indicating copy to clipboard operation
Cuckoo copied to clipboard

Trying to exclude protocols that are ObservableObject

Open brandtdaniels opened this issue 5 years ago • 3 comments

Now that I'm starting to use SwiftUI, my view models are conforming to protocols which conform/inherit to ObservableObject.

Of course now I'm getting errors in GeneratedMocks like:

Protocol 'EmailViewModelProtocol' can only be used as a generic constraint because it has Self or associated type requirements

Since, I only need to manually mock my view models for the sake of SwiftUI Previews, I am thinking that for now I can just exclude them in the run script.

The issue I'm having now is that I can't seem to get the exclude to work.

"${PROJECT_DIR}/run" --download generate --glob --no-class-mocking \
--testable "${PROJECT_NAME}" \
--output "${OUTPUT_FILE}" \
--exclude "AttachmentViewModelProtocol, EmailViewModelProtocol" \
"${INPUT_DIR}/Application/Protocols/**/*.swift" \

The syntax described in the readme is not really clear, maybe show some examples.

brandtdaniels avatar Aug 09 '20 02:08 brandtdaniels

Hey, @brandtdaniels. I'm trying to reproduce your issue, but I can't get exclude to NOT work. If you delete all the mocks inside the file, does the regenerated file contain the excluded types?

Otherwise I'm all out of ideas and might need some concrete project to see what's going wrong.

MatyasKriz avatar Aug 22 '20 16:08 MatyasKriz

Maybe i'm getting the syntax wrong, Do I need to include the path to the file and/or just the file name? is it a comma separated string? or a swift style array of strings? ["string1", "string2"]

brandtdaniels avatar Aug 24 '20 21:08 brandtdaniels

You can check out the way the tests are run for Cuckoo itself which includes using this flag. Though I tried multiple ways of excluding and it worked without the quotes (removing the space of course) as well as with quotes and without the space after the comma. Swift syntax wouldn't work here, I didn't try it, but I'm pretty confident the boundary identifiers would contain the starting and ending brackets which would lead to them matching nothing.

You should probably take a look at the GenerateMocksCommand.swift file which takes care of the generator CLI, perhaps you can find a bug we are not aware of.

MatyasKriz avatar Aug 25 '20 05:08 MatyasKriz