Skip to content

Conversation

@vmalakhovskiy
Copy link
Contributor

No description provided.

import Foundation
import SwiftyMock
import Result
@testable import Betterme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome 👍

but please remove this dependency

btw is it possible to know in stencil what module we're in? like in xcode templates?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately I didn't found solution for that yet

@@ -0,0 +1,51 @@
import Foundation
@testable import Betterme
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately I didn't found solution for that yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can pass parameter to sourcery script

Copy link
Contributor

@a-voronov a-voronov May 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, just wanted to answer the same :)

there's args that you can pass and read inside

or better - setup yml file with all configs and pass path to it via --config flag

so that it'll contain

args:
  testable:
    - Betterme

and read as

<%_ if let testable = arguments["testable"] as? String { -%>
        <%_ %>@testable import <%= testable %>
<%_ } -%>

@@ -0,0 +1,54 @@
import Foundation
import SwiftyMock
import Result
Copy link
Contributor

@a-voronov a-voronov May 15, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and guess we don't need Result here as it's imported from ReactiveSwift

@PaulTaykalo
Copy link
Contributor

@vmalakhovskiy Can you please write down how are you using these stencils, may be add sourcery script right to the example itself?
Thanks

@vmalakhovskiy
Copy link
Contributor Author

Actually yeah, I'm using sourcery with config file running in watch mode, so it can detect changes in source code or templates and automatically regenerate code.

sourcery --config .sourcery.yml --watch

my config looks like this:

sources:
  - MyProject
  - MyProjectTests
templates:
  - MyProjectTests/Templates
output:
  path: MyProjectTests/Generated

@a-voronov
Copy link
Contributor

do we need random implementations?
I'd better not make it as a part of this tool, as it doesn't have anything to do with mocking

and there're many good tools that are specifically dedicated to randomization

a-voronov added a commit that referenced this pull request Jul 16, 2018
Polished sourcery templates given in #14
@adamkaplan
Copy link

adamkaplan commented Jul 27, 2018

I tend to agree Random is useful but orthogonal. However, one important note is that it is not a great idea to use pure random tests. Why? Because if a test fails, you cannot reliably reproduce the failure.

Tests should be predictable and reproducible. Proper randomized testing re-uses the same values in the same order each time after (re)generation. This way CI pipeline will always be consistent. You can do that by either saving the actual values used, or by seeding the RNG with the same value (however, not arc4random). Anyway this is a side note.

@a-voronov
Copy link
Contributor

@adamkaplan agree, I tend to use third-party libraries for randomization, i.e. RandomKit - it can be seeded

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

Successfully merging this pull request may close these issues.

5 participants