146 Commits

Author SHA1 Message Date
Tony Schneider
4f2b3dd18e Merge pull request #59 from juanhebert/patch-1
Fix typo in about_pattern_matching.rb
2026-03-21 09:23:20 -04:00
Juan Manuel Hébert
12c463c042 Fix typo in about_pattern_matching.rb
Fix typo in comment on line 172 of `about_pattern_matching.rb`.
2026-03-18 17:56:54 -04:00
Tony Schneider
e072392099 Merge pull request #55 from Hikelio/master
add tip about parentheses in regex in AboutMethods
2026-01-10 08:31:33 -05:00
Tony Schneider
fb05c506f0 Merge pull request #56 from werebus/integer-object-id
Fix assertion about the class of `Object#object_id`
2026-01-10 08:30:36 -05:00
Matt Moretti
411e86e5c3 Fix assertion about the class of #object_id
In Ruby 2.4, `Fixnum` and `Bignum` were unified into `Integer` and the
"bigness" of that integer became an internal implementation detail.
Because the koans support some pretty old rubies, we can't make a
universal assertion about the class of `Object.new.object_id`, but it
always `is_a? Integer`.
2025-12-23 10:26:27 -05:00
Ikelio
f2699f0ae7 add needed tip in AboutMethods 2025-02-23 21:41:04 +01:00
Tony Schneider
8e70162472 Merge pull request #54 from kaya3/patch-1
Enable 'about_pattern_matching' for Ruby 3
2025-02-01 13:23:04 -05:00
Andrew Kay
9082c4378a Enable 'about_pattern_matching' for Ruby 3
This set of koans seems to work perfectly fine in Ruby 3, so AFAICT there's no need to gate them to 2.7.
2024-11-21 17:40:07 +00:00
Tony Schneider
0bcbe408e7 Merge pull request #48 from edgecase/ts/ci
Add initial GHA workflows
2023-08-15 08:52:59 -04:00
Tony Schneider
9687825fe0 Add initial tests that run Jim's "checks" 2023-08-15 08:51:54 -04:00
Tony Schneider
ec0ae9dc99 Merge pull request #51 from bo-tato/bo-tato-observr-patch-1
fix path for observr
2023-08-12 07:40:58 -04:00
bo-tato
8a56b2bd16 Merge branch 'edgecase:master' into bo-tato-observr-patch-1 2023-08-09 12:40:48 -05:00
Tony Schneider
104b7f67b4 initial gha workflow 2023-08-09 07:34:49 -04:00
Tony Schneider
6f919cdb01 Update rubykoans.zip 2023-08-09 00:39:23 -04:00
Tony Schneider
59b29e7b86 Merge pull request #17 from Wolwer1nE/pattern_matching
Added pattern matching koans
2023-08-09 00:34:43 -04:00
Tony Schneider
c2538ad118 Merge pull request #35 from varun-iyer/master
Add a koan for mandatory keyword arguments
2023-08-09 00:33:31 -04:00
Tony Schneider
3334d7df48 Merge pull request #15 from Interdictor/master
Add test_default_value_attribute to about_hashes.rb
2023-08-09 00:32:38 -04:00
bo-tato
6fc6906274 fix path for observr 2023-08-04 22:16:55 -05:00
Mike Doel
3bb8d5da68 Upgrading to heroku-22 2023-04-03 10:18:06 -04:00
Tony Schneider
51f25cf68d Merge pull request #38 from wolfsblu/master
Replace deprecated exists call
2023-01-24 17:31:01 -05:00
wolfsblu
49a18944ed Replace deprecated exists call 2023-01-06 11:25:50 +01:00
Wolwer1ne
71196f474b Fix typo 2022-10-17 11:43:38 +03:00
Varun Iyer
c7a56e50fa Add a koan for mandatory keyword arguments
Previously, `about_keyword_arguments.rb` asked the reader
to reflect on the fact that keyword arguments must have default
values. However, this does not seem to be true anymore in Ruby.

This commit replaces that comment with two koans that guide the
reader through validating and using a method with mandatory
keyword arguments.
2022-08-15 14:12:39 -07:00
Tony Schneider
0659d2a672 Release rubykoans zip 2022-03-03 00:17:21 +00:00
Tony Schneider
18c3504596 Merge pull request #32 from merryfaceTech/reorder_koans
re-order
2022-03-03 00:14:44 +00:00
Tarik Merrlees
aa614489b4 re-order first few tests to better match beginner's ability and progression 2022-02-25 15:39:10 +00:00
Mike Doel
93e33b001c deployment package updated 2022-02-13 22:13:58 -05:00
Tony Schneider
e79e874a18 Update ruby koans download 2022-02-13 15:01:04 +00:00
Tony Schneider
561965bb6a Use alt example in about_open_classes
Integer#even? ended up in a more modern version of ruby (yay progress!). This updates the koan to use a different, more outlandish example, that I don’t think will end up in Ruby — and that I know Jim would appreciate <3
2022-02-13 14:54:14 +00:00
Tony Schneider
250aaa44ab Update README.rdoc
Update issue tracker to GitHub issues
2022-02-13 11:22:56 +00:00
Tony Schneider
cd9bbe3df8 Merge pull request #30 from rnestler/patch-1
Fix name of parallel array assignement test
2022-02-13 11:02:53 +00:00
Tony Schneider
79fadeff4d Merge pull request #18 from tongkiat/doc
Update README.rdoc to show new progress indicator
2022-02-13 11:02:24 +00:00
Tony Schneider
453777ead0 Merge pull request #28 from mattschouten/master
Add support for Ruby 3
2022-02-13 10:58:31 +00:00
Raphael Nestler
353e281470 Fix name of parallel array assignement test
There are two variables and just one value, so I think
`test_parallel_assignments_with_too_few_values` is a better name.
2022-02-10 14:44:52 +01:00
Mike Doel
b77b8d90d8 Remove Neo from README 2021-10-02 17:39:06 -04:00
Matt Schouten
08945a10a1 Add support for Ruby 3 2021-09-09 16:30:31 -05:00
Tong-Kiat Tan
580c1fcf7d Update README.rdoc to show new progress indicator 2020-06-16 14:04:18 +08:00
wolwer1ne
7163953851 Added pattern matching koans 2020-06-10 18:46:03 +03:00
interdictor
e647408062 Add test_default_value_attribute to about_hashes.rb 2020-05-21 22:45:22 +02:00
Mike Doel
7d152b8afc new package with progress indicator 2020-05-21 08:29:52 -04:00
Mike Doel
45c0ff2a20 Merge pull request #14 from japf/user/japf/progress-percentage
Display progress as percentage
2020-05-20 10:54:39 -04:00
Jeremy Alles
dc5bbb58f8 display progress as percentage 2020-05-11 14:17:27 +02:00
Mike Doel
e3b4ac36b0 Regenerate download for ruby 2.7 fix 2020-02-28 09:16:29 -05:00
Mike Doel
33ed452081 Merge pull request #13 from edgecase/fix_27
Fix Ruby 2.7 behavior change
2020-02-28 09:09:58 -05:00
Mike Doel
3efe58ac1e Resolve #12 - behavior change in ruby 2.7 2020-02-24 10:03:00 -05:00
Mike Doel
4d2a32cbd1 remove inadvertent gzip files 2020-02-18 15:33:16 -05:00
Mike Doel
943f4dc543 new package file 2020-02-18 15:26:05 -05:00
Mike Doel
ff3795a815 Eliminate warning about method_missing being redefined 2020-02-18 15:06:35 -05:00
Mike Doel
c486b81dd4 Merge pull request #3 from derekgottlieb/replace-watchr-with-observr
Replace unmaintained watchr gem with observr fork
2020-02-18 14:30:22 -05:00
Derek Gottlieb
f9929c21d6 Replace abandoned watchr gem with maintained observr fork 2016-11-19 15:35:23 -06:00
Mike Doel
a1d3902b01 Merge pull request #2 from neo/master
Pull back from neo organization
2015-03-12 13:43:48 -04:00
Jim Weirich
8068f1f106 Latest zip file 2014-01-13 15:16:57 -05:00
Jim Weirich
0fb9b21a4e Fix require to include ./ 2014-01-13 15:16:46 -05:00
Jim Weirich
ad08a8de35 Handle version 2.1 2014-01-13 15:07:30 -05:00
Jim Weirich
c57b275de8 Fix 'accidental' solving of first 3 koans 2013-12-19 15:17:00 -05:00
Jim Weirich
174defbd1a Added clarification note about sending messages. 2013-11-13 23:13:26 -05:00
Jim Weirich
6622cf0d99 Fix typo in Rakefile 2013-11-13 23:11:26 -05:00
Jim Weirich
832e5e4ab5 Updated the zip file. 2013-10-01 22:54:48 -04:00
Jim Weirich
8d7dd30c0b Remove require_relative (#117)
Require relative is only available in modern rubies. Let's keep this
working on some of the older versions as well.

https://github.com/neo/ruby_koans/pull/117
2013-10-01 21:52:10 -04:00
Jim Weirich
e746cd33f4 Merge pull request #119 from harshadsabne/master
Code fix (Update README.rdoc)
2013-10-01 18:44:59 -07:00
Jim Weirich
9485ec734f Don't answer the first few questions (#120)
https://github.com/neo/ruby_koans/pull/120
2013-10-01 21:42:47 -04:00
Harshad Sabne
35e93072f6 Code fix (Update README.rdoc)
Applied correct tags to display "gem install rake" as code in rdoc.
2013-09-11 14:28:31 +05:30
Jim Weirich
fa699e6eeb Update zip file. 2013-07-10 17:41:21 -04:00
Jim Weirich
482ae6f86f Using the term 'modern ruby' 2013-07-10 17:40:36 -04:00
Jim Weirich
068c9357c9 Merge branch 'master' of https://github.com/mhenry07/ruby_koans into mhenry07
* 'master' of https://github.com/mhenry07/ruby_koans:
  Update about_strings.rb
2013-07-10 17:37:45 -04:00
Jim Weirich
d3b06902d8 Merge pull request #111 from smlance/changes-1
Minor changes to existing koan files
2013-07-10 14:36:28 -07:00
Jim Weirich
d85e9f09dc Update zip file. 2013-07-10 17:31:07 -04:00
Jim Weirich
3a8f125dd7 Shorter stack traces, even on exceptions. 2013-07-10 17:30:43 -04:00
Jim Weirich
0e6d826af4 Internalized assertions.
This makes us independent of test/unit and minitest.
2013-07-10 17:30:43 -04:00
Jim Weirich
2202e07785 Merge pull request #104 from michael-gebis/master
Cosmetic change for the benefit of Windows users.
2013-07-10 13:45:10 -07:00
smlance
cf61502734 Made a minor readability change to a comment in about_blocks.rb 2013-07-09 09:57:17 -04:00
smlance
4e5b9ca969 Fixed another small grammatical mistake (. to ? in dice file) 2013-07-09 09:44:01 -04:00
smlance
ea66a6d175 Initial minor changes (grammatical in methods; require -> require_relative in tri...). 2013-07-09 09:40:01 -04:00
Jim Weirich
a380b44165 Updated email addresses. 2013-07-02 15:55:31 -04:00
michael-gebis
8ce0fb6506 Trimmed artistic end message to 79 columns.
On Windows, the standard terminal will insert a blank line after
any 80-column line.  Yes, this is a silly way for a terminal to
work, but on Windows, this is likely to happen.  Trimming to 79
columns makes things much less ugly.
2013-06-11 23:11:48 -07:00
Mike Henry
98a72a5a4c Update about_strings.rb
Update single character representation test for Ruby 2.
2013-06-10 15:34:58 -06:00
Jim Weirich
7c2b5fe273 :zip task now depends on :package.
Rather than directly depending on ZIP_FILE.
2013-06-08 02:44:41 +08:00
Jim Weirich
8dd3acae41 Update the zip file with the latest changes. 2013-06-07 06:02:26 +08:00
Jim Weirich
d5b787cd2b Beefed up the greed scoring tests just a bit. 2013-06-07 06:01:01 +08:00
Jim Weirich
8122d347f0 Merge pull request #94 from jasonnoble/patch-1
Update .gitignore with .ruby-version
2013-06-06 14:43:54 -07:00
Jim Weirich
b8fa86ed1e Merge pull request #95 from ArturMoczulski/patch-1
Fixes a silly typo in the method name
2013-06-06 14:43:06 -07:00
Jim Weirich
3f49c8f000 Merge pull request #99 from StevenNdaye/about_keyword_arguments
Wrong class name from AboutMethods to AboutKeywordArguments
2013-06-06 14:39:47 -07:00
Jim Weirich
ad5f6f5fe8 Fixed missed sum => product change 2013-06-07 05:38:44 +08:00
Jim Weirich
4509e0c8fe Merge branch 'patch-1' of https://github.com/backspace/ruby_koans into product
* 'patch-1' of https://github.com/backspace/ruby_koans:
  test_inject_will_blow_your_mind uses an incorrect memo argument name
2013-06-07 05:36:33 +08:00
Jim Weirich
799f583ff3 Merge branch 'patch-1' of https://github.com/adlersantos/ruby_koans into curly
* 'patch-1' of https://github.com/adlersantos/ruby_koans:
  corrected example code in test_each_can_use_curly_brace_blocks_too
2013-06-07 05:32:53 +08:00
Jim Weirich
623e21fc18 Updated zip file to latest changes. 2013-06-06 23:04:18 +08:00
Jim Weirich
4ba9f3c142 Add zip task for building zip file. 2013-06-06 23:03:44 +08:00
Jim Weirich
718538b729 Add ~ files to ignore list. 2013-06-06 23:03:33 +08:00
Adler Santos
dfaeb570e5 corrected example code in test_each_can_use_curly_brace_blocks_too
test_each_can_use_curly_brace_blocks_too was using the do-end block instead of the curly brace syntax for the each method.
2013-06-03 02:18:29 +08:00
Buck Doyle
1ce6d52963 test_inject_will_blow_your_mind uses an incorrect memo argument name
No big NBD, but the second memo argument is better called 'product' than 'sum'.
2013-05-13 16:48:57 -03:00
Steven Ndaye
6b66d46156 Wrong class name from AboutMethods to AboutKeywordArguments 2013-05-13 11:22:02 +02:00
Artur Moczulski
f4d9dc0db7 Fixes a silly typo in the method name
in method_with_keyword_arguments_with_mandatory_argument
2013-04-24 00:24:09 -07:00
Jason Noble
24a0069c20 Update .gitignore with .ruby-version
.ruby-version is the new .rvmrc, although .rvmrc is used still.
2013-04-14 11:53:37 -06:00
Mike Mazur
610e219fa5 One more EdgeCase -> Neo change in the Rakefile
Fixes #92.
2013-04-12 09:23:21 -04:00
Jim Weirich
d7b5a6120d Added deploy instructions. 2013-04-09 16:04:07 -04:00
Jim Weirich
e947652bcf Zip file goes in download directory.
Moving the zip file to the source tree so it can be downloaded.
2013-04-09 15:19:32 -04:00
Jim Weirich
12639186cb Fix order of comparison in about symbols to follow standard. 2013-04-09 11:27:30 -04:00
Jim Weirich
197dd8eff8 Clarify the difference between here docs and multi-line strings. 2013-04-09 11:27:30 -04:00
Jim Weirich
63753656af Fix prematurely correct answer. 2013-04-09 11:27:30 -04:00
Jim Weirich
f3560581ce Removed RDoc 2013-04-09 11:27:30 -04:00
Jim Weirich
5119038f9c Merge pull request #83 from TheTeaNerd/dk-explain-watchr-in-README
Explain Watchr use in README
2013-04-09 07:52:32 -07:00
Jim Weirich
86cb9c5a27 Fixed times example. 2013-04-09 10:46:13 -04:00
Jim Weirich
a079acbacd Merge pull request #89 from lucasrcosta/master
Added Times Statement in Control Statements
2013-04-09 07:45:19 -07:00
Jim Weirich
dc8f73f107 Remove test_helper.rb 2013-04-09 10:40:49 -04:00
Jim Weirich
09b03e9b1c Change EdgeCase to Neo 2013-04-09 10:40:27 -04:00
Jim Weirich
67750bf9bf Fix missing blanks in about hashes. 2013-04-09 10:33:43 -04:00
Jim Weirich
7eb51a9a30 Remove unused files. 2013-04-09 10:33:43 -04:00
Jim Weirich
f2e4a1f357 Make each do/end usage more consistent. 2013-04-09 10:33:43 -04:00
Jim Weirich
ceca9875cf Merge pull request #87 from weilu/remove_unused_variables
Remove assigned but unused variables
2013-04-09 07:13:04 -07:00
Jim Weirich
957b672d7a Merge pull request #86 from weilu/fix_indentation
Fix indentation
2013-04-09 07:12:05 -07:00
Jim Weirich
e150dd6d9e Fix private message error for JRuby. 2013-04-09 10:10:24 -04:00
Jim Weirich
f03e0d21ee Add keyword arguments (with correct answers). 2013-04-09 09:45:23 -04:00
Jim Weirich
58238ef54a Removed fixed object_id koan
This koan is not as important now that Ruby 2 has changed all the
object ids.
2013-04-09 09:30:33 -04:00
mfeckie
9c5ecb509a Add support for Ruby 2.0 2013-04-06 13:23:56 +08:00
mfeckie
cb14e48f1d Add tests for keyword arguments in Ruby 2.0 2013-04-06 12:18:41 +08:00
mfeckie
405c42eb81 Updated Sensei for 2.0.0
Add support for Ruby 2.0.0
2013-04-06 11:31:32 +08:00
Jim Weirich
2df8e5554d Added todo for EdgeCase to Neo conversion. 2013-04-01 19:10:47 -04:00
Adam McCrea
213aece7e9 Move to Neo 2013-04-01 17:11:02 -03:00
Adam McCrea
5c5ffc645d Move to Neo 2013-04-01 17:09:01 -03:00
lucasrcosta
4d41bab6e6 Added Times Statement 2013-03-10 14:31:05 -03:00
Wei Lu
aa3c83f044 Remove assigned but unused variables 2013-02-28 18:59:58 +08:00
Wei Lu
676d9ce8ac Fix indentation 2013-02-28 15:44:28 +08:00
David Kennedy
f36a964fdd Explain how to use Watchr in the README
The koans have support for Watchr now, and this is very helpful
as you can focus on editing and not on re-running rake over and
over. However, a user new to Ruby will not even know what Watchr
is (I'd not used it before! I was using Guard) so they might miss
this choice.

There are some other minor edits for style and consistency. I explain
that Koans are tests. We/You tidy up. Removed some excess wordage.
Made some "your should do this" statements more imperative. Made
mark up more consistent.
2013-02-14 14:22:11 +00:00
David Kennedy
eedfeb1022 Explain how to use watchr in the README
Support has been added for watchr, and this is very helpful while
walking the path to enlightenment as it keeps the users focus on
the koans and not on the repeated need to run rake after each edit.

However, only an experienced Rubyist would know how to install and
use watchr (or worse, they might just not notice the watchr config
file). So let's add an optional section to the README explaining
how to use watchr.
2013-02-14 13:21:06 +00:00
TheTeaNerd
4ca68510b0 Merge pull request #1 from TheTeaNerd/dk-ignore-rvm
Ignore RVM config if the user wants to use it
2013-02-14 04:57:48 -08:00
David Kennedy
5f3a6a19f2 Ignore RVM config if the user wants to use it
RVM allows the user to select a specific Ruby for a specific
project. It is common to put a .rvmrc config file in the root
of a project to select the Ruby automatically when the user
switches into that project.

The Ruby Koans should ignore this file if present and not mistake
it for a change to the Koans themselves. There are other ways
of choosing a Ruby to use, and use of RVM is not mandated by the
Koans so ignoring seems like the right solution.
2013-02-14 12:51:00 +00:00
Adam McCrea
1a073e5db5 Merge pull request #66 from oflannabhra/patch-1
Test that constants are symbols by comparing strings
2012-11-26 06:17:39 -08:00
Marc Peabody
9cb57ef35f Merge pull request #77 from thebinarypenguin/about-hashes-bonus-question
Modify test to better illustrate point
2012-06-05 12:19:07 -07:00
Ethan Zimmerman
7f29082e95 Modify test to better illustrate point 2012-06-05 14:22:14 -04:00
Marc Peabody
75ba956176 Merge pull request #72 from Erkan-Yilmaz/master
missing: ) + first example output adapted
2012-03-08 06:35:36 -08:00
Erkan Yilmaz
f3d20b8e14 seems screen output of the 1st example changed 2012-03-08 14:03:45 +01:00
Erkan Yilmaz
03caa9b349 add missing: ) 2012-03-08 13:57:01 +01:00
Matthew Boston
7bef32522e Merge branch 'master' of github.com:edgecase/ruby_koans 2012-02-23 11:19:54 -05:00
Matthew Boston
48fd6fdb1e Merge branch 'master' of github.com:edgecase/ruby_koans 2012-02-10 16:32:45 -05:00
Matthew Boston
7d0550259b Merge branch 'master' of github.com:edgecase/ruby_koans 2012-02-10 16:32:34 -05:00
Matthew Boston
bd94b445de Merge pull request #70 from saterus/master
Switch from Autotest to Watchr
2012-02-10 13:32:14 -08:00
Alex Burkhart
6af4597b80 Use rake instead of directly invoking path_to_enlightenment. 2012-02-10 19:36:50 +00:00
Alex Burkhart
a565ac232d Removed autotest. Added Watchr script. 2012-02-09 18:57:31 +00:00
Matthew Boston
711564c452 remove line-ending whitespace 2012-02-07 22:16:52 -05:00
Matthew Boston
34d1127f98 whitespace cleanup 2012-02-06 23:17:48 -05:00
Matthew Boston
8926a0d96b Merge pull request #68 from liuhenry/master
Fixed color support in OS X
2012-01-27 10:51:25 -08:00
Matthew Boston
c014f6db04 update Rakefile to use pre-defined directories 2012-01-27 10:39:22 -05:00
Matthew Boston
2625f10997 not sure why the extra line was thrown in... 2012-01-27 10:34:00 -05:00
Matthew Boston
d1ab51e7cd updating README with directions for generating the koans 2012-01-27 10:26:46 -05:00
Henry Liu
907c1fc0be Fixed color support in OS X 2012-01-22 00:20:40 -08:00
oflannabhra
b44b5f8bb2 Compare strings instead of symbols for constants, similar to method names. 2012-01-02 22:33:46 -05:00
51 changed files with 679 additions and 332 deletions

16
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,16 @@
name: CI
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Ruby!
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.2.2"
- name: run tests
run: rake test

3
.gitignore vendored
View File

@@ -1,5 +1,8 @@
dist
.project_env.rc
.path_progress
.rvmrc
.ruby-version
*.rbc
koans/*
*~

12
DEPLOYING Normal file
View File

@@ -0,0 +1,12 @@
= Deploying a new Ruby Koans ZIP file
The "Download" button on the rubykoans.com web-site points to the
download/rubykoans.zip file in the github repository. So to update the
download target on the web-site, just rebuild the .zip file, commit
and push the changes.
rake package
git add download
git push
That's it.

View File

@@ -1,18 +1,18 @@
= EdgeCase Ruby Koans
= Ruby Koans
The Ruby Koans walk you along the path to enlightenment in order to learn Ruby.
The goal is to learn the Ruby language, syntax, structure, and some common
functions and libraries. We also teach you culture. Testing is not just something we
pay lip service to, but something we live. It is essential in your quest to learn
and do great things in the language.
functions and libraries. We also teach you culture by basing the koans on tests.
Testing is not just something we pay lip service to, but something we
live. Testing is essential in your quest to learn and do great things in Ruby.
== The Structure
The koans are broken out into areas by file, hashes are covered in about_hashes.rb,
modules are introduced in about_modules.rb, etc. They are presented in order in the
path_to_enlightenment.rb file.
The koans are broken out into areas by file, hashes are covered in +about_hashes.rb+,
modules are introduced in +about_modules.rb+, <em>etc</em>. They are presented in
order in the +path_to_enlightenment.rb+ file.
Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at
Each koan builds up your knowledge of Ruby and builds upon itself. It will stop at
the first place you need to correct.
Some koans simply need to have the correct answer substituted for an incorrect one.
@@ -23,30 +23,41 @@ make it work correctly.
== Installing Ruby
If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for
operating specific instructions. In order to run this you need ruby and rake
installed. To check the installations simply type:
operating specific instructions. In order to run the koans you need +ruby+ and
+rake+ installed. To check your installations simply type:
*nix platforms from any terminal window:
[~] $ ruby --version
[~] $ rake --version
Windows from the command prompt (cmd.exe)
Windows from the command prompt (+cmd.exe+)
c:\ruby --version
c:\rake --version
If you don't have rake installed, just run `gem install rake`
If you don't have +rake+ installed, just run <code>gem install rake</code>
Any response for Ruby with a version number greater than 1.8 is fine (should be
around 1.8.6 or more). Any version of rake will do.
around 1.8.6 or more). Any version of +rake+ will do.
== Generating the Koans
A fresh checkout will not include the koans, you will need to generate
them.
[ruby_koans] $ rake gen # generates the koans directory
If you need to regenerate the koans, thus wiping your current `koans`,
[ruby_koans] $ rake regen # regenerates the koans directory, wiping the original
== The Path To Enlightenment
You can run the tests through rake or by calling the file itself (rake is the
You can run the tests through +rake+ or by calling the file itself (+rake+ is the
recommended way to run them as we might build more functionality into this task).
*nix platforms, from the koans directory
*nix platforms, from the +ruby_koans+ directory
[ruby_koans] $ rake # runs the default target :walk_the_path
[ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
@@ -58,54 +69,88 @@ Windows is the same thing
=== Red, Green, Refactor
In test-driven development the mantra has always been, red, green, refactor. Write a
failing test and run it (red), make the test pass (green), then refactor it (that is
look at the code and see if you can make it any better. In this case you will need
to run the koan 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).
In test-driven development the mantra has always been <em>red, green, refactor</em>.
Write a failing test and run it (<em>red</em>), make the test pass (<em>green</em>),
then look at the code and consider if you can make it any better (<em>refactor</em>).
The very first time you run it you will see the following output:
While walking the path to Ruby enlightenment you will need to run the koan and
see it fail (<em>red</em>), make the test pass (<em>green</em>), 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 (<em>refactor</em>).
The very first time you run the koans you will see the following output:
[ ruby_koans ] $ rake
(in /Users/person/dev/ruby_koans)
cd koans
/usr/bin/ruby1.8 path_to_enlightenment.rb
Thinking AboutAsserts
test_assert_truth has damaged your karma.
AboutAsserts#test_assert_truth has damaged your karma.
You have not yet reached enlightenment ...
The Master says:
You have not yet reached enlightenment.
The answers you seek...
<false> is not true.
Please meditate on the following code:
./about_asserts.rb:10:in `test_assert_truth'
path_to_enlightenment.rb:27
path_to_enlightenment.rb:38:in `each_with_index'
path_to_enlightenment.rb:38
mountains are merely mountains
your path thus far [X_________________________________________________] 0/280 (0%)
You have come to your first stage. If you notice it is telling you where to look for
You have come to your first stage. Notice it is telling you where to look for
the first solution:
Please meditate on the following code:
./about_asserts.rb:10:in `test_assert_truth'
path_to_enlightenment.rb:27
path_to_enlightenment.rb:38:in `each_with_index'
path_to_enlightenment.rb:38
We then open up the about_asserts.rb file and look at the first test:
Open the +about_asserts.rb+ file and look at the first test:
# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth
assert false # This should be true
end
We then change the +false+ to +true+ and run the test again. After you are
Change the +false+ to +true+ and re-run the test. After you are
done, think about what you are learning. In this case, ignore everything except
the method name (+test_assert_truth+) and the parts inside the method (everything
before the +end+).
In this case 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
method, it will either ensure it is +true+ and continue on, or fail if
the statement is +false+.
=== Running the Koans automatically
<em>This section is optional.</em>
Normally the path to enlightenment looks like this:
cd ruby_koans
rake
# edit
rake
# edit
rake
# etc
If you prefer, you can keep the koans running in the background so that after you
make a change in your editor, the koans will immediately run again. This will
hopefully keep your focus on learning Ruby instead of on the command line.
Install the Ruby gem (library) called +observr+ and then ask it to
"watch" the koans for changes:
cd ruby_koans
rake
# decide to run rake automatically from now on as you edit
gem install observr
observr ./koans.watchr
== Inspiration
A special thanks to Mike Clark and Ara Howard for inspiring this
@@ -132,9 +177,9 @@ Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby ::
= Other stuff
Author :: Jim Weirich <jim@weirichhouse.org>
Author :: Joe O'Brien <joe@edgecase.com>
Issue Tracker :: http://www.pivotaltracker.com/projects/48111
Author :: Jim Weirich <jim@neo.org>
Author :: Joe O'Brien <joe@objo.com>
Issue Tracker :: https://github.com/edgecase/ruby_koans/issues
Requires :: Ruby 1.8.x or later and Rake (any recent version)
= License

47
Rakefile Normal file → Executable file
View File

@@ -2,25 +2,17 @@
# -*- ruby -*-
require 'rake/clean'
begin
require 'rdoc/task'
rescue LoadError => ex
# No rdoc task availble.
end
SRC_DIR = 'src'
PROB_DIR = 'koans'
DIST_DIR = 'dist'
DOWNLOAD_DIR = 'download'
SRC_FILES = FileList["#{SRC_DIR}/*"]
KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
today = Time.now.strftime("%Y-%m-%d")
TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
ZIP_FILE = "#{DOWNLOAD_DIR}/rubykoans.zip"
CLEAN.include("**/*.rbc")
CLOBBER.include(DIST_DIR)
module Koans
extend Rake::DSL if defined?(Rake::DSL)
@@ -40,10 +32,8 @@ module Koans
end
def Koans.make_koan_file(infile, outfile)
if infile =~ /edgecase/
if infile =~ /neo/
cp infile, outfile
elsif infile =~ /autotest/
cp_r infile, outfile
else
open(infile) do |ins|
open(outfile, "w") do |outs|
@@ -88,34 +78,29 @@ end
task :default => :walk_the_path
task :walk_the_path do
cd 'koans'
cd PROB_DIR
ruby 'path_to_enlightenment.rb'
end
if defined?(Rake::RDocTask)
Rake::RDocTask.new do |rd|
rd.main = "README.rdoc"
rd.rdoc_files.include("README.rdoc", "koans/*.rb")
end
end
directory DIST_DIR
directory DOWNLOAD_DIR
directory PROB_DIR
file ZIP_FILE => KOAN_FILES + [DIST_DIR] do
desc "(re)Build zip file"
task :zip => [:clobber_zip, :package]
task :clobber_zip do
rm ZIP_FILE
end
file ZIP_FILE => KOAN_FILES + [DOWNLOAD_DIR] do
sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
end
file TAR_FILE => KOAN_FILES + [DIST_DIR] do
sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
end
desc "Create packaged files for distribution"
task :package => [TAR_FILE, ZIP_FILE]
task :package => [ZIP_FILE]
desc "Upload the package files to the web server"
task :upload => [TAR_FILE, ZIP_FILE] do
sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
task :upload => [ZIP_FILE] do
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
end
@@ -140,7 +125,7 @@ end
task :run do
puts 'koans'
Dir.chdir("src") do
Dir.chdir("#{SRC_DIR}") do
puts "in #{Dir.pwd}"
sh "ruby path_to_enlightenment.rb"
end

BIN
download/rubykoans.zip Normal file

Binary file not shown.

9
rakelib/test.rake Normal file
View File

@@ -0,0 +1,9 @@
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "tests"
t.test_files = FileList["tests/**/*_test.rb"]
t.verbose = true
end
desc 'Run tests'

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutArrayAssignment < EdgeCase::Koan
class AboutArrayAssignment < Neo::Koan
def test_non_parallel_assignment
names = ["John", "Smith"]
assert_equal __(["John", "Smith"]), names
@@ -24,7 +24,7 @@ class AboutArrayAssignment < EdgeCase::Koan
assert_equal __(["Smith","III"]), last_name
end
def test_parallel_assignments_with_too_few_variables
def test_parallel_assignments_with_too_few_values
first_name, last_name = ["Cher"]
assert_equal __("Cher"), first_name
assert_equal __(nil), last_name

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutArrays < EdgeCase::Koan
class AboutArrays < Neo::Koan
def test_creating_arrays
empty_array = Array.new
assert_equal __(Array), empty_array.class

View File

@@ -1,9 +1,9 @@
#!/usr/bin/env ruby
# -*- ruby -*-
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutAsserts < EdgeCase::Koan
class AboutAsserts < Neo::Koan
# We shall contemplate truth by testing reality, via asserts.
def test_assert_truth

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutBlocks < EdgeCase::Koan
class AboutBlocks < Neo::Koan
def method_with_block
result = yield
result
@@ -23,7 +23,7 @@ class AboutBlocks < EdgeCase::Koan
end
def test_blocks_can_take_arguments
result = method_with_block_arguments do |argument|
method_with_block_arguments do |argument|
assert_equal __("Jim"), argument
end
end
@@ -70,7 +70,7 @@ class AboutBlocks < EdgeCase::Koan
add_one = lambda { |n| n + 1 }
assert_equal __(11), add_one.call(10)
# Alternative calling sequence
# Alternative calling syntax
assert_equal __(11), add_one[10]
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutClassMethods < EdgeCase::Koan
class AboutClassMethods < Neo::Koan
class Dog
end
@@ -47,7 +47,7 @@ class AboutClassMethods < EdgeCase::Koan
end
# ------------------------------------------------------------------
class Dog2
def wag
:instance_level_wag
@@ -96,14 +96,13 @@ class AboutClassMethods < EdgeCase::Koan
def test_you_can_define_class_methods_inside_the_class
assert_equal __(:dogs_class_method), Dog.a_class_method
end
# ------------------------------------------------------------------
LastExpressionInClassStatement = class Dog
21
end
def test_class_statements_return_the_value_of_their_last_expression
assert_equal __(21), LastExpressionInClassStatement
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutClasses < EdgeCase::Koan
class AboutClasses < Neo::Koan
class Dog
end
@@ -147,7 +147,7 @@ class AboutClasses < EdgeCase::Koan
end
def to_s
__(@name)
@name
end
def inspect

View File

@@ -1,8 +1,8 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
C = "top level"
class AboutConstants < EdgeCase::Koan
class AboutConstants < Neo::Koan
C = "nested"

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutControlStatements < EdgeCase::Koan
class AboutControlStatements < Neo::Koan
def test_if_then_else_statements
if true
@@ -131,4 +131,12 @@ class AboutControlStatements < EdgeCase::Koan
assert_equal [__("FISH"), __("AND"), __("CHIPS")], result
end
def test_times_statement
sum = 0
10.times do
sum += 1
end
assert_equal __(10), sum
end
end

View File

@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
# Implement a DiceSet Class here:
#
@@ -15,7 +15,7 @@ class DiceSet
end
#++
class AboutDiceProject < EdgeCase::Koan
class AboutDiceProject < Neo::Koan
def test_can_create_a_dice_set
dice = DiceSet.new
assert_not_nil dice
@@ -56,7 +56,7 @@ class AboutDiceProject < EdgeCase::Koan
#
# If the rolls are random, then it is possible (although not
# likely) that two consecutive rolls are equal. What would be a
# better way to test this.
# better way to test this?
end
def test_you_can_roll_different_numbers_of_dice

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutExceptions < EdgeCase::Koan
class AboutExceptions < Neo::Koan
class MySpecialError < RuntimeError
end
@@ -48,7 +48,7 @@ class AboutExceptions < EdgeCase::Koan
result = nil
begin
fail "Oops"
rescue StandardError => ex
rescue StandardError
# no code here
ensure
result = :always_run

View File

@@ -1,10 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutHashes < EdgeCase::Koan
class AboutHashes < Neo::Koan
def test_creating_hashes
empty_hash = Hash.new
assert_equal __(Hash), empty_hash.class
assert_equal({}, empty_hash) # __
assert_equal(__({}), empty_hash)
assert_equal __(0), empty_hash.size
end
@@ -37,7 +37,7 @@ class AboutHashes < EdgeCase::Koan
hash[:one] = "eins"
expected = { :one => __("eins"), :two => "dos" }
assert_equal __(true), expected == hash
assert_equal __(expected), hash
# Bonus Question: Why was "expected" broken out into a variable
# rather than used as a literal?
@@ -113,4 +113,14 @@ class AboutHashes < EdgeCase::Koan
assert_equal __(["dos"]), hash[:two]
assert_equal __([]), hash[:three]
end
def test_default_value_attribute
hash = Hash.new
assert_equal __(nil), hash[:some_key]
hash.default = 'peanut'
assert_equal __('peanut'), hash[:some_key]
end
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutInheritance < EdgeCase::Koan
class AboutInheritance < Neo::Koan
class Dog
attr_reader :name

View File

@@ -1,12 +1,12 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutIteration < EdgeCase::Koan
class AboutIteration < Neo::Koan
# -- An Aside ------------------------------------------------------
# Ruby 1.8 stores names as strings. Ruby 1.9 stores names as
# symbols. So we use a version dependent method "as_name" to convert
# to the right format in the koans. We will use "as_name" whenever
# comparing to lists of methods.
# Ruby 1.8 stores names as strings. Ruby 1.9 and later stores names
# as symbols. So we use a version dependent method "as_name" to
# convert to the right format in the koans. We will use "as_name"
# whenever comparing to lists of methods.
in_ruby_version("1.8") do
def as_name(name)
@@ -14,7 +14,7 @@ class AboutIteration < EdgeCase::Koan
end
end
in_ruby_version("1.9") do
in_ruby_version("1.9", "2", "3") do
def as_name(name)
name.to_sym
end
@@ -39,19 +39,17 @@ class AboutIteration < EdgeCase::Koan
def test_each_can_use_curly_brace_blocks_too
array = [1, 2, 3]
sum = 0
array.each { |item|
sum += item
}
array.each { |item| sum += item }
assert_equal __(6), sum
end
def test_break_works_with_each_style_iterations
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sum = 0
array.each { |item|
array.each do |item|
break if item > 3
sum += item
}
end
assert_equal __(6), sum
end
@@ -86,7 +84,7 @@ class AboutIteration < EdgeCase::Koan
result = [2, 3, 4].inject(0) { |sum, item| sum + item }
assert_equal __(9), result
result2 = [2, 3, 4].inject(1) { |sum, item| sum * item }
result2 = [2, 3, 4].inject(1) { |product, item| product * item }
assert_equal __(24), result2
# Extra Credit:

View File

@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
include Java
@@ -11,7 +11,7 @@ include Java
# * Calling custom java class
# * Calling Ruby from java???
class AboutJavaInterop < EdgeCase::Koan
class AboutJavaInterop < Neo::Koan
def test_using_a_java_library_class
java_array = java.util.ArrayList.new
assert_equal __(Java::JavaUtil::ArrayList), java_array.class

View File

@@ -0,0 +1,43 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutKeywordArguments < Neo::Koan
def method_with_keyword_arguments(one: 1, two: 'two')
[one, two]
end
def test_keyword_arguments
assert_equal __(Array), method_with_keyword_arguments.class
assert_equal __([1, 'two']), method_with_keyword_arguments
assert_equal __(['one', 'two']), method_with_keyword_arguments(one: 'one')
assert_equal __([1, 2]), method_with_keyword_arguments(two: 2)
end
def method_with_keyword_arguments_with_mandatory_argument(one, two: 2, three: 3)
[one, two, three]
end
def test_keyword_arguments_with_wrong_number_of_arguments
exception = assert_raise (___(ArgumentError)) do
method_with_keyword_arguments_with_mandatory_argument
end
assert_match(/#{__("wrong number of arguments")}/, exception.message)
end
def method_with_mandatory_keyword_arguments(one:, two: 'two')
[one, two]
end
def test_mandatory_keyword_arguments
assert_equal __(['one', 'two']), method_with_mandatory_keyword_arguments(one: 'one')
assert_equal __([1, 2]), method_with_mandatory_keyword_arguments(two: 2, one: 1)
end
def test_mandatory_keyword_arguments_without_mandatory_argument
exception = assert_raise(___(ArgumentError)) do
method_with_mandatory_keyword_arguments
end
assert_match(/#{__("missing keyword: :one")}/, exception.message)
end
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutMessagePassing < EdgeCase::Koan
class AboutMessagePassing < Neo::Koan
class MessageCatcher
def caught?
@@ -63,6 +63,13 @@ class AboutMessagePassing < EdgeCase::Koan
assert_equal __([3, 4, nil, 6]), mc.send(:add_a_payload, 3, 4, nil, 6)
end
# NOTE:
#
# Both obj.msg and obj.send(:msg) sends the message named :msg to
# the object. We use "send" when the name of the message can vary
# dynamically (e.g. calculated at run time), but by far the most
# common way of sending a message is just to say: obj.msg.
# ------------------------------------------------------------------
class TypicalObject
@@ -93,11 +100,11 @@ class AboutMessagePassing < EdgeCase::Koan
# NOTE:
#
# In Ruby 1.8 the method_missing method is public and can be
# called as shown above. However, in Ruby 1.9 the method_missing
# method is private. We explicitly made it public in the testing
# framework so this example works in both versions of Ruby. Just
# keep in mind you can't call method_missing like that in Ruby
# 1.9. normally.
# called as shown above. However, in Ruby 1.9 (and later versions)
# the method_missing method is private. We explicitly made it
# public in the testing framework so this example works in both
# versions of Ruby. Just keep in mind you can't call
# method_missing like that after Ruby 1.9 normally.
#
# Thanks. We now return you to your regularly scheduled Ruby
# Koans.
@@ -122,7 +129,7 @@ class AboutMessagePassing < EdgeCase::Koan
def test_catching_messages_makes_respond_to_lie
catcher = AllMessageCatcher.new
assert_nothing_raised(NoMethodError) do # __
assert_nothing_raised do # __
catcher.any_method
end
assert_equal __(false), catcher.respond_to?(:any_method)

View File

@@ -1,10 +1,10 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
def my_global_method(a,b)
a + b
end
class AboutMethods < EdgeCase::Koan
class AboutMethods < Neo::Koan
def test_calling_global_methods
assert_equal __(5), my_global_method(2,3)
@@ -37,8 +37,9 @@ class AboutMethods < EdgeCase::Koan
#
end
# NOTE: wrong number of argument is not a SYNTAX error, but a
# NOTE: wrong number of arguments is not a SYNTAX error, but a
# runtime error.
# tip: When regex contains parentheses, you must escape them with backslash.
def test_calling_global_methods_with_wrong_number_of_arguments
exception = assert_raise(___(ArgumentError)) do
my_global_method
@@ -126,11 +127,13 @@ class AboutMethods < EdgeCase::Koan
assert_equal __("a secret"), my_private_method
end
def test_calling_private_methods_with_an_explicit_receiver
exception = assert_raise(___(NoMethodError)) do
self.my_private_method
if before_ruby_version("2.7") # https://github.com/edgecase/ruby_koans/issues/12
def test_calling_private_methods_with_an_explicit_receiver
exception = assert_raise(___(NoMethodError)) do
self.my_private_method
end
assert_match /#{__("method `my_private_method'")}/, exception.message
end
assert_match /#{__("private method `my_private_method' called ")}/, exception.message
end
# ------------------------------------------------------------------

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutModules < EdgeCase::Koan
class AboutModules < Neo::Koan
module Nameable
def set_name(new_name)
@name = new_name
@@ -44,7 +44,7 @@ class AboutModules < EdgeCase::Koan
def test_module_methods_are_also_available_in_the_object
fido = Dog.new
assert_nothing_raised(Exception) do # __
assert_nothing_raised do # __
fido.set_name("Rover")
end
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutNil < EdgeCase::Koan
class AboutNil < Neo::Koan
def test_nil_is_an_object
assert_equal __(true), nil.is_a?(Object), "Unlike NULL in other languages"
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutObjects < EdgeCase::Koan
class AboutObjects < Neo::Koan
def test_everything_is_an_object
assert_equal __(true), 1.is_a?(Object)
assert_equal __(true), 1.5.is_a?(Object)
@@ -21,7 +21,7 @@ class AboutObjects < EdgeCase::Koan
def test_every_object_has_an_id
obj = Object.new
assert_equal __(Fixnum), obj.object_id.class
assert obj.object_id.is_a?(__(Integer))
end
def test_every_object_has_different_id
@@ -30,12 +30,6 @@ class AboutObjects < EdgeCase::Koan
assert_equal __(true), obj.object_id != another_obj.object_id
end
def test_some_system_objects_always_have_the_same_id
assert_equal __(0), false.object_id
assert_equal __(2), true.object_id
assert_equal __(4), nil.object_id
end
def test_small_integers_have_fixed_ids
assert_equal __(1), 0.object_id
assert_equal __(3), 1.object_id

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutOpenClasses < EdgeCase::Koan
class AboutOpenClasses < Neo::Koan
class Dog
def bark
"WOOF"
@@ -30,16 +30,16 @@ class AboutOpenClasses < EdgeCase::Koan
# ------------------------------------------------------------------
class ::Integer
def even?
(self % 2) == 0
def answer_to_life_universe_and_everything?
self == 42
end
end
def test_even_existing_built_in_classes_can_be_reopened
assert_equal __(false), 1.even?
assert_equal __(true), 2.even?
assert_equal __(false), 1.answer_to_life_universe_and_everything?
assert_equal __(true), 42.answer_to_life_universe_and_everything?
end
# NOTE: To understand why we need the :: before Integer, you need to
# become enlightened about scope.
# become enlightened about scope.
end

View File

@@ -0,0 +1,215 @@
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutPatternMatching < Neo::Koan
def test_pattern_may_not_match
begin
case [true, false]
in [a, b] if a == b # The condition after pattern is called guard.
:match
end
rescue Exception => ex
# What exception has been caught?
assert_equal __, ex.class
end
end
def test_we_can_use_else
result = case [true, false]
in [a, b] if a == b
:match
else
:no_match
end
assert_equal __, result
end
# ------------------------------------------------------------------
def value_pattern(variable)
case variable
in 0
:match_exact_value
in 1..10
:match_in_range
in Integer
:match_with_class
else
:no_match
end
end
def test_value_pattern
assert_equal __, value_pattern(0)
assert_equal __, value_pattern(5)
assert_equal __, value_pattern(100)
assert_equal __, value_pattern('Not a Number!')
end
# ------------------------------------------------------------------
# This pattern will bind variable to the value
def variable_pattern_with_binding(variable)
case 0
in variable
variable
else
:no_match
end
end
def test_variable_pattern_with_binding
assert_equal __, variable_pattern_with_binding(1)
end
# ------------------------------------------------------------------
# We can pin the value of the variable with ^
def variable_pattern_with_pin(variable)
case 0
in ^variable
variable
else
:no_match
end
end
def test_variable_pattern_with_pin
assert_equal __, variable_pattern_with_pin(1)
end
# ------------------------------------------------------------------
# We can drop values from pattern
def pattern_with_dropping(variable)
case variable
in [_, 2]
:match
else
:no_match
end
end
def test_pattern_with_dropping
assert_equal __, pattern_with_dropping(['I will not be checked', 2])
assert_equal __, pattern_with_dropping(['I will not be checked', 'But I will!'])
end
# ------------------------------------------------------------------
# We can use logical *or* in patterns
def alternative_pattern(variable)
case variable
in 0 | false | nil
:match
else
:no_match
end
end
def test_alternative_pattern
assert_equal __, alternative_pattern(0)
assert_equal __, alternative_pattern(false)
assert_equal __, alternative_pattern(nil)
assert_equal __, alternative_pattern(4)
end
# ------------------------------------------------------------------
# As pattern binds the variable to the value if pattern matches
# pat: pat => var
def as_pattern
a = 'First I was afraid'
case 'I was petrified'
in String => a
a
else
:no_match
end
end
def test_as_pattern
assert_equal __, as_pattern
end
# ------------------------------------------------------------------
# Array pattern works with all objects that have #deconstruct method that returns Array
# It is useful to cut needed parts from Array-ish objects
class Deconstructible
def initialize(str)
@data = str
end
def deconstruct
@data&.split('')
end
end
def array_pattern(deconstructible)
case deconstructible
in 'a', *res, 'd'
res
else
:no_match
end
end
def test_array_pattern
assert_equal __, array_pattern(Deconstructible.new('abcd'))
assert_equal __, array_pattern(Deconstructible.new('123'))
end
# ------------------------------------------------------------------
# Hash pattern is quite the same as Array pattern, but it expects #deconstruct_keys(keys) method
# It works with symbol keys for now
class LetterAccountant
def initialize(str)
@data = str
end
def deconstruct_keys(keys)
# we will count number of occurrences of each key in our data
keys.map { |key| [key, @data.count(key.to_s)] }.to_h
end
end
def hash_pattern(deconstructible_as_hash)
case deconstructible_as_hash
in {a: a, b: b}
[a, b]
else
:no_match
end
end
def test_hash_pattern
assert_equal __, hash_pattern(LetterAccountant.new('aaabbc'))
assert_equal __, hash_pattern(LetterAccountant.new('xyz'))
end
# we can write it even shorter
def hash_pattern_with_sugar(deconstructible_as_hash)
case deconstructible_as_hash
in a:, b:
[a, b]
else
:no_match
end
end
def test_hash_pattern_with_sugar
assert_equal __, hash_pattern_with_sugar(LetterAccountant.new('aaabbc'))
assert_equal __, hash_pattern_with_sugar(LetterAccountant.new('xyz'))
end
end

View File

@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
# Project: Create a Proxy Class
#
@@ -42,7 +42,7 @@ end
# The proxy object should pass the following Koan:
#
class AboutProxyObjectProject < EdgeCase::Koan
class AboutProxyObjectProject < Neo::Koan
def test_proxy_method_returns_wrapped_object
# NOTE: The Television class is defined below
tv = Proxy.new(Television.new)
@@ -135,7 +135,7 @@ class Television
end
# Tests for the Television class. All of theses tests should pass.
class TelevisionTest < EdgeCase::Koan
class TelevisionTest < Neo::Koan
def test_it_turns_on
tv = Television.new

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutRegularExpressions < EdgeCase::Koan
class AboutRegularExpressions < Neo::Koan
def test_a_pattern_is_a_regular_expression
assert_equal __(Regexp), /pattern/.class
end

View File

@@ -1,11 +1,11 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutSandwichCode < EdgeCase::Koan
class AboutSandwichCode < Neo::Koan
def count_lines(file_name)
file = open(file_name)
count = 0
while line = file.gets
while file.gets
count += 1
end
count
@@ -66,7 +66,7 @@ class AboutSandwichCode < EdgeCase::Koan
def count_lines2(file_name)
file_sandwich(file_name) do |file|
count = 0
while line = file.gets
while file.gets
count += 1
end
count
@@ -99,7 +99,7 @@ class AboutSandwichCode < EdgeCase::Koan
def count_lines3(file_name)
open(file_name) do |file|
count = 0
while line = file.gets
while file.gets
count += 1
end
count

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutScope < EdgeCase::Koan
class AboutScope < Neo::Koan
module Jims
class Dog
def identify
@@ -19,7 +19,7 @@ class AboutScope < EdgeCase::Koan
def test_dog_is_not_available_in_the_current_scope
assert_raise(___(NameError)) do
fido = Dog.new
Dog.new
end
end

View File

@@ -1,4 +1,4 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
# Greed is a dice game where you roll up to five dice to accumulate
# points. The following "score" function will be used to calculate the
@@ -54,7 +54,7 @@ def score(dice)
#++
end
class AboutScoringProject < EdgeCase::Koan
class AboutScoringProject < Neo::Koan
def test_score_of_an_empty_list_is_zero
assert_equal 0, score([])
end
@@ -90,6 +90,9 @@ class AboutScoringProject < EdgeCase::Koan
def test_score_of_mixed_is_sum
assert_equal 250, score([2,5,2,2,3])
assert_equal 550, score([5,5,5,5])
assert_equal 1100, score([1,1,1,1])
assert_equal 1200, score([1,1,1,1,1])
assert_equal 1150, score([1,1,1,5,1])
end
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutStrings < EdgeCase::Koan
class AboutStrings < Neo::Koan
def test_double_quoted_strings_are_strings
string = "Hello, World"
assert_equal __(true), string.is_a?(String)
@@ -42,6 +42,7 @@ It was the worst of times.
}
assert_equal __(54), long_string.length
assert_equal __(3), long_string.lines.count
assert_equal __("\n"), long_string[0,1]
end
def test_here_documents_can_also_handle_multiple_lines
@@ -51,6 +52,7 @@ It was the worst of times.
EOS
assert_equal __(53), long_string.length
assert_equal __(2), long_string.lines.count
assert_equal __("I"), long_string[0,1]
end
def test_plus_will_concatenate_two_strings
@@ -149,7 +151,7 @@ EOS
end
in_ruby_version("1.8") do
def test_in_ruby_1_8_single_characters_are_represented_by_integers
def test_in_older_ruby_single_characters_are_represented_by_integers
assert_equal __(97, 'a'), ?a
assert_equal __(true, false), ?a == 97
@@ -157,8 +159,8 @@ EOS
end
end
in_ruby_version("1.9") do
def test_in_ruby_1_9_single_characters_are_represented_by_strings
in_ruby_version("1.9", "2", "3") do
def test_in_modern_ruby_single_characters_are_represented_by_strings
assert_equal __('a'), ?a
assert_equal __(false), ?a == 97
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutSymbols < EdgeCase::Koan
class AboutSymbols < Neo::Koan
def test_symbols_are_symbols
symbol = :ruby
assert_equal __(true), symbol.is_a?(Symbol)
@@ -36,9 +36,9 @@ class AboutSymbols < EdgeCase::Koan
in_ruby_version("mri") do
RubyConstant = "What is the sound of one hand clapping?"
def test_constants_become_symbols
all_symbols = Symbol.all_symbols
all_symbols_as_strings = Symbol.all_symbols.map { |x| x.to_s }
assert_equal __(true), all_symbols.include?(__(:RubyConstant))
assert_equal __(true), all_symbols_as_strings.include?(__("RubyConstant"))
end
end
@@ -50,14 +50,14 @@ class AboutSymbols < EdgeCase::Koan
def test_symbols_with_spaces_can_be_built
symbol = :"cats and dogs"
assert_equal symbol, __("cats and dogs").to_sym
assert_equal __("cats and dogs").to_sym, symbol
end
def test_symbols_with_interpolation_can_be_built
value = "and"
symbol = :"cats #{value} dogs"
assert_equal symbol, __("cats and dogs").to_sym
assert_equal __("cats and dogs").to_sym, symbol
end
def test_to_s_is_called_on_interpolated_symbols

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutToStr < EdgeCase::Koan
class AboutToStr < Neo::Koan
class CanNotBeTreatedAsString
def to_s

View File

@@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'
require './triangle'
class AboutTriangleProject < EdgeCase::Koan
class AboutTriangleProject < Neo::Koan
def test_equilateral_triangles_have_equal_sides
assert_equal :equilateral, triangle(2, 2, 2)
assert_equal :equilateral, triangle(10, 10, 10)
@@ -22,4 +22,3 @@ class AboutTriangleProject < EdgeCase::Koan
assert_equal :scalene, triangle(5, 4, 2)
end
end

View File

@@ -1,9 +1,9 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
# You need to write the triangle method in the file 'triangle.rb'
require 'triangle.rb'
require './triangle.rb'
class AboutTriangleProject2 < EdgeCase::Koan
class AboutTriangleProject2 < Neo::Koan
# The first assignment did not talk about how to handle errors.
# Let's handle that part now.
def test_illegal_triangles_throw_exceptions
@@ -12,6 +12,5 @@ class AboutTriangleProject2 < EdgeCase::Koan
assert_raise(TriangleError) do triangle(1, 1, 3) end
assert_raise(TriangleError) do triangle(2, 4, 2) end
# HINT: for tips, see http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
end
end
end

View File

@@ -1,6 +1,6 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
require File.expand_path(File.dirname(__FILE__) + '/neo')
class AboutTrueAndFalse < EdgeCase::Koan
class AboutTrueAndFalse < Neo::Koan
def truth_value(condition)
if condition
:true_stuff

View File

@@ -1,47 +0,0 @@
require 'test_helper'
class ArrayTest < EdgeCase::TestCase
def test_basic_arrays
food = [:peanut, :button, :and, :jelly]
assert_equal __, food[0]
assert_equal __, food.size
end
def test_array_access
food = [:peanut, :button, :and, :jelly]
assert_equal __, food.first
assert_equal __, food.last
assert_equal __, food[0]
assert_equal __, food[2]
assert_equal __, food[(food.size() - 1)]
end
def test_arrays_with_other_objects
food = [:peanut, :button, :and, :jelly, 1, nil]
assert_equal __, food.size
assert_equal __, food.last
assert_equal __, food[5]
end
def test_adding_to_an_array_with_shovel_shovel
food = [:peanut, :button, :and, :jelly]
food << 'sandwich'
assert_equal __, food.size
assert_equal __, food.first
end
def test_adding_to_an_array_with_push
food = [:peanut, :button, :and, :jelly]
food.push('sandwich')
assert_equal __, food.last
end
def test_adding_to_an_array_with_unshift
food = [:peanut, :button, :and, :jelly]
food.unshift('a')
assert_equal __, food.first
end
end

View File

@@ -1,3 +0,0 @@
Autotest.add_discovery do
"rubykoan" if File.exist? 'path_to_enlightenment.rb'
end

View File

@@ -1,24 +0,0 @@
require 'autotest'
class Autotest::Rubykoan < Autotest
def initialize
super
@exceptions = /\.txt|Rakefile|\.rdoc/
self.order = :alpha
self.add_mapping(/^about_.*rb$/) do |filename, _|
filename
end
end
def make_test_cmd files_to_test
"#{ruby} 'path_to_enlightenment.rb'"
end
# quiet test/unit chatter
def handle_results(results)
end
end

View File

@@ -1 +0,0 @@
require File.expand_path(File.dirname(__FILE__) + '/edgecase')

View File

@@ -1,11 +0,0 @@
require 'test/unit'
class TestSomething < Test::Unit::TestCase
def test_assert
assert true
assert_equal 1, 1
assert_equal 1, 1.0
end
end

3
src/koans.watchr Normal file
View File

@@ -0,0 +1,3 @@
watch( '.*\.rb' ) do
system 'rake'
end

View File

@@ -1,7 +1,8 @@
#!/usr/bin/env ruby
# -*- ruby -*-
require 'test/unit/assertions'
$VERBOSE = nil
begin
require 'win32console'
rescue LoadError
@@ -24,6 +25,10 @@ def in_ruby_version(*versions)
yield if versions.any? { |v| ruby_version?(v) }
end
def before_ruby_version(version)
Gem::Version.new(RUBY_VERSION) < Gem::Version.new(version)
end
in_ruby_version("1.8") do
class KeyError < StandardError
end
@@ -65,7 +70,7 @@ class Object
end
end
in_ruby_version("1.9") do
in_ruby_version("1.9", "2", "3") do
public :method_missing
end
end
@@ -83,7 +88,7 @@ class String
end
end
module EdgeCase
module Neo
class << self
def simple_output
ENV['SIMPLE_KOAN_OUTPUT'] == 'true'
@@ -122,6 +127,8 @@ module EdgeCase
if ENV['ANSI_COLOR'].nil?
if using_windows?
using_win32console
else
return true
end
else
ENV['ANSI_COLOR'] =~ /^(t|y)/i
@@ -137,20 +144,68 @@ module EdgeCase
end
end
module Assertions
FailedAssertionError = Class.new(StandardError)
def flunk(msg)
raise FailedAssertionError, msg
end
def assert(condition, msg=nil)
msg ||= "Failed assertion."
flunk(msg) unless condition
true
end
def assert_equal(expected, actual, msg=nil)
msg ||= "Expected #{expected.inspect} to equal #{actual.inspect}"
assert(expected == actual, msg)
end
def assert_not_equal(expected, actual, msg=nil)
msg ||= "Expected #{expected.inspect} to not equal #{actual.inspect}"
assert(expected != actual, msg)
end
def assert_nil(actual, msg=nil)
msg ||= "Expected #{actual.inspect} to be nil"
assert(nil == actual, msg)
end
def assert_not_nil(actual, msg=nil)
msg ||= "Expected #{actual.inspect} to not be nil"
assert(nil != actual, msg)
end
def assert_match(pattern, actual, msg=nil)
msg ||= "Expected #{actual.inspect} to match #{pattern.inspect}"
assert pattern =~ actual, msg
end
def assert_raise(exception)
begin
yield
rescue Exception => ex
expected = ex.is_a?(exception)
assert(expected, "Exception #{exception.inspect} expected, but #{ex.inspect} was raised")
return ex
end
flunk "Exception #{exception.inspect} expected, but nothing raised"
end
def assert_nothing_raised
begin
yield
rescue Exception => ex
flunk "Expected nothing to be raised, but exception #{exception.inspect} was raised"
end
end
end
class Sensei
attr_reader :failure, :failed_test, :pass_count
in_ruby_version("1.8") do
AssertionError = Test::Unit::AssertionFailedError
end
in_ruby_version("1.9") do
if defined?(MiniTest)
AssertionError = MiniTest::Assertion
else
AssertionError = Test::Unit::AssertionFailedError
end
end
FailedAssertionError = Assertions::FailedAssertionError
def initialize
@pass_count = 0
@@ -163,7 +218,7 @@ module EdgeCase
def add_progress(prog)
@_contents = nil
exists = File.exists?(PROGRESS_FILE_NAME)
exists = File.exist?(PROGRESS_FILE_NAME)
File.open(PROGRESS_FILE_NAME,'a+') do |f|
f.print "#{',' if exists}#{prog}"
end
@@ -171,7 +226,7 @@ module EdgeCase
def progress
if @_contents.nil?
if File.exists?(PROGRESS_FILE_NAME)
if File.exist?(PROGRESS_FILE_NAME)
File.open(PROGRESS_FILE_NAME,'r') do |f|
@_contents = f.read.to_s.gsub(/\s/,'').split(',')
end
@@ -193,7 +248,7 @@ module EdgeCase
@failure = step.failure
add_progress(@pass_count)
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
throw :edgecase_exit
throw :neo_exit
end
end
@@ -202,7 +257,7 @@ module EdgeCase
end
def assert_failed?
failure.is_a?(AssertionError)
failure.is_a?(FailedAssertionError)
end
def instruct
@@ -219,7 +274,7 @@ module EdgeCase
def show_progress
bar_width = 50
total_tests = EdgeCase::Koan.total_tests
total_tests = Neo::Koan.total_tests
scale = bar_width.to_f/total_tests
print Color.green("your path thus far [")
happy_steps = (pass_count*scale).to_i
@@ -230,12 +285,12 @@ module EdgeCase
print Color.cyan('_'*(bar_width-1-happy_steps))
end
print Color.green(']')
print " #{pass_count}/#{total_tests}"
print " #{pass_count}/#{total_tests} (#{pass_count*100/total_tests}%)"
puts
end
def end_screen
if EdgeCase.simple_output
if Neo.simple_output
boring_end_screen
else
artistic_end_screen
@@ -266,13 +321,13 @@ module EdgeCase
,:::::::::::, ::::::::::::,
:::::::::::, ,::::::::::::
::::::::::::: ,::::::::::::
:::::::::::: Ruby Koans ::::::::::::,
::::::::::::#{ ruby_version },::::::::::::,
:::::::::::, , ::::::::::::
,:::::::::::::, brought to you by ,,::::::::::::,
:::::::::::: Ruby Koans ::::::::::::
::::::::::::#{ ruby_version },::::::::::::
:::::::::::, , :::::::::::
,:::::::::::::, brought to you by ,,::::::::::::
:::::::::::::: ,::::::::::::
::::::::::::::, ,:::::::::::::
::::::::::::, EdgeCase Software Artisans , ::::::::::::
::::::::::::, Neo Software Artisans , ::::::::::::
:,::::::::: :::: :::::::::::::
,::::::::::: ,: ,,:::::::::::::,
:::::::::::: ,::::::::::::::,
@@ -307,11 +362,7 @@ ENDTEXT
puts Color.red(indent(failure.message).join)
puts
puts "Please meditate on the following code:"
if assert_failed?
puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
else
puts embolden_first_line_only(indent(failure.backtrace))
end
puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
puts
end
@@ -334,7 +385,7 @@ ENDTEXT
def find_interesting_lines(backtrace)
backtrace.reject { |line|
line =~ /test\/unit\/|edgecase\.rb|minitest/
line =~ /neo\.rb/
}
end
@@ -364,7 +415,7 @@ ENDTEXT
end
class Koan
include Test::Unit::Assertions
include Assertions
attr_reader :name, :failure, :koan_count, :step_count, :koan_file
@@ -394,19 +445,19 @@ ENDTEXT
setup
begin
send(name)
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
failed(ex)
ensure
begin
teardown
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
failed(ex) if passed?
end
end
self
end
# Class methods for the EdgeCase test suite.
# Class methods for the Neo test suite.
class << self
def inherited(subclass)
subclasses << subclass
@@ -463,7 +514,7 @@ ENDTEXT
class ThePath
def walk
sensei = EdgeCase::Sensei.new
sensei = Neo::Sensei.new
each_step do |step|
sensei.observe(step.meditate)
end
@@ -471,9 +522,9 @@ ENDTEXT
end
def each_step
catch(:edgecase_exit) {
catch(:neo_exit) {
step_count = 0
EdgeCase::Koan.subclasses.each_with_index do |koan,koan_index|
Neo::Koan.subclasses.each_with_index do |koan,koan_index|
koan.testmethods.each do |method_name|
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
yield step
@@ -485,6 +536,6 @@ ENDTEXT
end
END {
EdgeCase::Koan.command_line(ARGV)
EdgeCase::ThePath.new.walk
Neo::Koan.command_line(ARGV)
Neo::ThePath.new.walk
}

View File

@@ -3,18 +3,21 @@
$LOAD_PATH << File.dirname(__FILE__)
require 'about_asserts'
require 'about_nil'
require 'about_objects'
require 'about_arrays'
require 'about_array_assignment'
require 'about_hashes'
require 'about_true_and_false'
require 'about_strings'
require 'about_symbols'
require 'about_regular_expressions'
require 'about_arrays'
require 'about_array_assignment'
require 'about_objects'
require 'about_nil'
require 'about_hashes'
require 'about_methods'
in_ruby_version("2", "3") do
require 'about_keyword_arguments'
end
require 'about_constants'
require 'about_regular_expressions'
require 'about_control_statements'
require 'about_true_and_false'
require 'about_triangle_project'
require 'about_exceptions'
require 'about_triangle_project_2'
@@ -35,4 +38,7 @@ require 'about_to_str'
in_ruby_version("jruby") do
require 'about_java_interop'
end
in_ruby_version("2.7", "3") do
require 'about_pattern_matching'
end
require 'about_extra_credit'

View File

@@ -1,7 +0,0 @@
require 'test/unit'
def __
"FILL ME IN"
end
EdgeCase = Test::Unit

26
tests/check_test.rb Normal file
View File

@@ -0,0 +1,26 @@
require_relative "test_helper"
class CheckTest < Minitest::Test
def with_captured_stdout
original_stdout = $stdout
$stdout = StringIO.new
yield
$stdout.string
ensure
$stdout = original_stdout
end
def test_check_asserts
output = with_captured_stdout do
Rake::Task['check:asserts'].invoke
end
assert_match(/OK/, output)
end
def test_check_abouts
output = with_captured_stdout do
Rake::Task['check:abouts'].invoke
end
assert_match(/OK/, output)
end
end

4
tests/test_helper.rb Normal file
View File

@@ -0,0 +1,4 @@
require "minitest/autorun"
require "rake"
Rake.application.load_rakefile