layout | os | editors | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
default |
windows |
|
These instructions are for Windows. We also have *nix instructions.
You must have a version of Ruby installed in order to run the Koans. Please take the time to download a version of Ruby that best suits your needs. The koans use features that are built into the ruby language so many ports of the Ruby Interpreter will run the koans without additional configuration or hacking. If you're unsure which version of ruby to install, the one click installer at ( https://rubyinstaller.org/ ) is probably the best place to start. There are times when the latest version of the Ruby Interpreter (traditionally released on Christmas) is not yet fully supported on Windows. If you use the version suggested on that site, you should be fine.
Download it and double click the installer. This will place all the ruby libraries and executables into a directory on your local machine. If you happen to forget to tick the box that asks if you wish to alter your PATH variable (where the command line looks for programs to run when you're typing commands) then you can do that manually by:
- Find where you installed Ruby (usually something like C:\Ruby26-x64 though it will depend on the version you install)
- Right click on My Computer (or the recent windows equal) and click "Properties"
- On the advanced tab click the button "Environmental Variables"
- Add "PATH-TO-RUBY\bin;" to the beginning (or end, or whereever)
Note - another option, if you are adventurous is to install, the ( Windows Subsystem for Linux (WSL) ) and follow along with ( the *nix instructions ) in your bash shell. The details of this is beyond the scope of this tutorial, but there is an impressive amount of info now available online.
Now open a command prompt and type "ruby -v" if you get a response and no error, then you've done it! Now that you have ruby installed you'll need to pull down the koans.
- Unzip to C:\oss\ruby_koans
- Open command prompt (start > run > type "cmd" hit enter)
- run (based on step 1) "cd C:\oss\ruby_koans"
- run "rake"
At your command prompt, you can also optionally run "gem install win32console". This will color the output to make it easier to see what is happening.
These instructions are for Windows. We also have *nix instructions.
You can really use any editor you'd like, but here are some suggestions:
-
{% for editor in page.editors %}
- {{ editor.name }} {% endfor %}
These instructions are for Windows platforms. We also have *nix instructions.
You can run the tests by calling the path_to_enlightenment.rb file.
In your terminal, while in the ruby_koans directory, type:
C:\oss\ruby_koans > ruby path_to_enlightenment.rb
In test-driven development (TDD) the mantra has always been red: write a failing test and run it, green: make the test pass, and refactor: look at the code and see if you can make it any better.
With the koans, you will need to run the tests and see it fail (red), make the test pass (green), then take a moment and reflect upon the test to see what it is teaching you and improve the code to better communicate its intent (refactor).
The very first time you run it you will see the following output:
C:\oss\ruby_koans > ruby path_to_enlightenment.rb
(in /Users/person/dev/ruby_koans)
cd koans
Thinking AboutAsserts
test_assert_truth has damaged your karma.
You have not yet reached enlightenment ...
<false> is not true.
Please meditate on the following code:
\./about_asserts.rb:10:in `test_assert_truth'
path_to_enlightenment.rb:27
mountains are merely mountains
You have come to the first error. Notice you are told where to look for the error:
Please meditate on the following code:
\./about_asserts.rb:10:in `test_assert_truth'
path_to_enlightenment.rb:27
You then open up the about_asserts.rb file in your text editor and look at line 10:
\# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth
assert false # This should be true
end
You then change false to true and run the tests again. You should get a new error.
Before moving on, think about what you are learning.
In this specific case, ignore everything except the method name (test_assert_truth) and the parts inside the method (everything before the end). The goal is for you to see that if you pass a value to the assert method, it will either ensure it is true and continue on, or fail if in fact the statement is false.