I was working with the lotrepls Ruby interpreter, and I want like to write tests in the interpreter that I can then write Ruby code to pass. In Python, I can write doctests and then write code to pass the doctests. For example:
>>> b
1
This tests that b=1, and entering b=1 will get this doctest to pass.
Is there a similar way to write tests in a Ruby interpreter, execute them, write code to pass the tests, and then execute the test again? Is there a Ruby doctest equivalent? For my application, I will execute tests and code in a hosted interpreter like lotrepls rather than install something on my local machine.
There’s
RubyDocTest, but I’d encourage you to look at something like RSpec or another modern BDD/TDD framework.It’s pretty easy to write tests there too, and you get access to complex and/or custom assertions that you can’t really get in a doctest. For instance, here’s a simple set of tests for a baseball scoring app: