-
Notifications
You must be signed in to change notification settings - Fork 136
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
Make documentation code samples subject to regular automated tests #99
Comments
I've created a new branch which contains a custom jekyll plugin that can load code samples from GitHub. This is just a proposal, but if we use this plugin we can add code samples to markdown pages as follows:
The plugin loads the samples during the build of the website, so in production the samples are static (as opposed to my previous implementation). To test this, you should locally checkout the |
@GeorgiKhomeriki that's very nice, IMHO that's the way to go. @Test def exampleWithoutReplay() {
// {BEGIN exampleNoReplay}
val numbers = Observable.interval(1000 millis).take(6)
val sharedNumbers = numbers.publish
sharedNumbers.subscribe(n => println(s"subscriber 1 gets $n"))
sharedNumbers.connect
// subscriber 2 misses 0, 1, 2!
doLater(3500 millis, () => { sharedNumbers.subscribe(n => println(s"subscriber 2 gets $n")) })
// {END exampleNoReplay}
waitFor(sharedNumbers)
}
@Test def exampleWithReplay() {
// {BEGIN exampleReplay}
val numbers = Observable.interval(1000 millis).take(6)
val sharedNumbers = numbers.replay
sharedNumbers.subscribe(n => println(s"subscriber 1 gets $n"))
sharedNumbers.connect
// subscriber 2 subscribes later but still gets all numbers
doLater(3500 millis, () => { sharedNumbers.subscribe(n => println(s"subscriber 2 gets $n")) })
// {END exampleReplay}
waitFor(sharedNumbers)
} And to include it, one would also have to give the identifier of the snippet within the source file. Something like
|
(This was discussed in Issue #20 by @headinthebox, @GeorgiKhomeriki, @samuelgruetter, @benjchristensen, @staltz & @DavidMGross but deserves a stand-alone issue.)
The documentation is full of code samples. To ensure that these are (and remain) accurate, they should be tested and these tests should be re-run whenever changes are made to the samples, the ReactiveX implementation they are written against, or relevant parts of the language/OS they run within.
How to do this well is a bit of a puzzle. Some of the issues/ideas:
Thoughts?
The text was updated successfully, but these errors were encountered: