-
-
Save moonglum/85c935810341a47eca85 to your computer and use it in GitHub Desktop.
Ataru Idea
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem 'minitest' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'minitest/autorun' | |
# This is the setup file that the user provided to you, you just require it. | |
# The user has to create a module called `Setup` in there. | |
require_relative 'setup' | |
# This is a test class that you generate in Ataru. It should work as it does right now, | |
# with one tiny difference | |
class MyTest < Minitest::Test | |
# And this is the difference: | |
include Setup | |
# By using this line, all methods defined in the module `Setup` that your user has | |
# defined will be available in the snippets \o/ | |
# This would be one of the test methods you generate | |
def test_that_was_created | |
# And here you can see that we are using one of the methods that the user defined | |
# in the setup.rb :) | |
assert_equal let_us_test_this_method, 'hello' | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Setup | |
def let_us_test_this_method | |
return 'hello' | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the
setup.rb
file, the user can require the gem that they want to use or other dependencies that they need for testing. Then they can define helper methods that will be available in all the snippets! This could for example be used to make an instance availalbe that you need throughout your test cases! Imagine you have an Addition class that you want to test, and your code examples look like this:Then Ruby would be sad, because
addition
is not defined. Not any more when you have the following setup.rb:Now addition will return a fresh instance for you, so it can be used in your tests 👍 And it could also take all kinds of arguments in its constructor if necessary, because it is pure Ruby!