Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

To have or not to have a 'setup' code sample? #75

Open
madziaf opened this issue Sep 25, 2014 · 12 comments
Open

To have or not to have a 'setup' code sample? #75

madziaf opened this issue Sep 25, 2014 · 12 comments

Comments

@madziaf
Copy link
Contributor

madziaf commented Sep 25, 2014

A couple of days before ataru reminded us, that it is checking code samples in a file in a random order, which means, that checking the same file, it can show one or more errors in the output, depending if there was any dependency between code samples.
For example, in test/resources/test_markdown.md ais defined in upper code sample and a is used in the last code sample of the file, without defining it again. Therefore ataru exits with one error (always there) or two errors (NameError).
Possible solutions:

  1. have all the tests run in a descendimng order (critic - you loose the independency of tests, and sharing the same environment by all the code snippets can lead to unexpected behaviour)
  2. having a setup code:
    a. having it on the top of the markdown file flagged in a way, e.g.
#setup
def bla 
end

or

def bla 
end

b. in the ataru_setup.rb file, that has to be written by the user.

Another question is - do I want the setup code sample to be visible for ALL other or only chosen code samples? (and how would that be possible).

@emig
Copy link

emig commented Sep 25, 2014

IMHO pretending to mimic all the unit test posibilities in terms of
setting up of a test can increase the complexity of the documentation itself.

Without further changes in usage, can we allow the user choose between:

  • have the tests run sequencially?
  • have tests randomized, and the user has to take care of having
    correct code, knowing that a new test is created for every #=>?

To answer the written points:

  1. yes
    • (a) no extra setup code in the documentation itself
    • (b) any setup needed can be written in the ataru_setup.rb

@emig
Copy link

emig commented Sep 25, 2014

The user would choose between randomized/sequencially setting the choice in
the ataru configuration file, that will pass those settings to the UnitTest
Runner

@moonglum
Copy link

I agree with @emig.

Run in sequence or random:
Make it configurable and default to random.

setup:
I would allow people to define a method called setup (and also teardown) in the ataru_setup. This method can then be called by Ataru before every code example run.

@madziaf
Copy link
Contributor Author

madziaf commented Sep 29, 2014

hi all,
I'll try to sum up the ideas:

  • in ataru_setup.rb the user can write the code, that she wants to run before code samples in the markdown file. That code would be wrapped in setup method. For now, it will be possible to have only one setup code and that code will be run before all given markdown files
  • in ataru_setup.rb the user should write teardown method (or I'm writing this one?)
  • running examples in sequence or random order - that could be configured in .config.rc User creates that file, if she needs one. If there is no .config.rc than by default test run in random order.

Am I understanding things right?
Do you agree with this solution?

@moonglum
Copy link

Yes, I agree with this solution 😄 I would imagine those things working as follows:

require 'my_fancy_lib'

def setup
  # Do some nice setup that is run before every snippet
end

def teardown
  # Do some cleanup that is run after every snippet
end

Ataru.configure do |c|
  c.run_examples_in_sequence
end

@schultyy
Copy link

@moonglum good idea :)

@madziaf
Copy link
Contributor Author

madziaf commented Sep 29, 2014

great, as MiniTest doesn't take config file, configure block in ataru_setup.rb will be written

@emig
Copy link

emig commented Sep 29, 2014

yes, a configure block will do 👍

@moonglum
Copy link

Great!

@madziaf If you need help with implementing the configure block, ping me 😉

@code-later
Copy link

I like this approach too. One question for my understanding: This will make another .config.rc obsolete right? Because everything can be handled in ataru_setup.rb.

@madziaf
Copy link
Contributor Author

madziaf commented Sep 29, 2014

yes, correct. Fine with that?

@code-later
Copy link

Yes, super fine. Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants