mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Compare commits
146 Commits
LA_Ruby_Co
...
4f2b3dd18e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f2b3dd18e | ||
|
|
12c463c042 | ||
|
|
e072392099 | ||
|
|
fb05c506f0 | ||
|
|
411e86e5c3 | ||
|
|
f2699f0ae7 | ||
|
|
8e70162472 | ||
|
|
9082c4378a | ||
|
|
0bcbe408e7 | ||
|
|
9687825fe0 | ||
|
|
ec0ae9dc99 | ||
|
|
8a56b2bd16 | ||
|
|
104b7f67b4 | ||
|
|
6f919cdb01 | ||
|
|
59b29e7b86 | ||
|
|
c2538ad118 | ||
|
|
3334d7df48 | ||
|
|
6fc6906274 | ||
|
|
3bb8d5da68 | ||
|
|
51f25cf68d | ||
|
|
49a18944ed | ||
|
|
71196f474b | ||
|
|
c7a56e50fa | ||
|
|
0659d2a672 | ||
|
|
18c3504596 | ||
|
|
aa614489b4 | ||
|
|
93e33b001c | ||
|
|
e79e874a18 | ||
|
|
561965bb6a | ||
|
|
250aaa44ab | ||
|
|
cd9bbe3df8 | ||
|
|
79fadeff4d | ||
|
|
453777ead0 | ||
|
|
353e281470 | ||
|
|
b77b8d90d8 | ||
|
|
08945a10a1 | ||
|
|
580c1fcf7d | ||
|
|
7163953851 | ||
|
|
e647408062 | ||
|
|
7d152b8afc | ||
|
|
45c0ff2a20 | ||
|
|
dc5bbb58f8 | ||
|
|
e3b4ac36b0 | ||
|
|
33ed452081 | ||
|
|
3efe58ac1e | ||
|
|
4d2a32cbd1 | ||
|
|
943f4dc543 | ||
|
|
ff3795a815 | ||
|
|
c486b81dd4 | ||
|
|
f9929c21d6 | ||
|
|
a1d3902b01 | ||
|
|
8068f1f106 | ||
|
|
0fb9b21a4e | ||
|
|
ad08a8de35 | ||
|
|
c57b275de8 | ||
|
|
174defbd1a | ||
|
|
6622cf0d99 | ||
|
|
832e5e4ab5 | ||
|
|
8d7dd30c0b | ||
|
|
e746cd33f4 | ||
|
|
9485ec734f | ||
|
|
35e93072f6 | ||
|
|
fa699e6eeb | ||
|
|
482ae6f86f | ||
|
|
068c9357c9 | ||
|
|
d3b06902d8 | ||
|
|
d85e9f09dc | ||
|
|
3a8f125dd7 | ||
|
|
0e6d826af4 | ||
|
|
2202e07785 | ||
|
|
cf61502734 | ||
|
|
4e5b9ca969 | ||
|
|
ea66a6d175 | ||
|
|
a380b44165 | ||
|
|
8ce0fb6506 | ||
|
|
98a72a5a4c | ||
|
|
7c2b5fe273 | ||
|
|
8dd3acae41 | ||
|
|
d5b787cd2b | ||
|
|
8122d347f0 | ||
|
|
b8fa86ed1e | ||
|
|
3f49c8f000 | ||
|
|
ad5f6f5fe8 | ||
|
|
4509e0c8fe | ||
|
|
799f583ff3 | ||
|
|
623e21fc18 | ||
|
|
4ba9f3c142 | ||
|
|
718538b729 | ||
|
|
dfaeb570e5 | ||
|
|
1ce6d52963 | ||
|
|
6b66d46156 | ||
|
|
f4d9dc0db7 | ||
|
|
24a0069c20 | ||
|
|
610e219fa5 | ||
|
|
d7b5a6120d | ||
|
|
e947652bcf | ||
|
|
12639186cb | ||
|
|
197dd8eff8 | ||
|
|
63753656af | ||
|
|
f3560581ce | ||
|
|
5119038f9c | ||
|
|
86cb9c5a27 | ||
|
|
a079acbacd | ||
|
|
dc8f73f107 | ||
|
|
09b03e9b1c | ||
|
|
67750bf9bf | ||
|
|
7eb51a9a30 | ||
|
|
f2e4a1f357 | ||
|
|
ceca9875cf | ||
|
|
957b672d7a | ||
|
|
e150dd6d9e | ||
|
|
f03e0d21ee | ||
|
|
58238ef54a | ||
|
|
9c5ecb509a | ||
|
|
cb14e48f1d | ||
|
|
405c42eb81 | ||
|
|
2df8e5554d | ||
|
|
213aece7e9 | ||
|
|
5c5ffc645d | ||
|
|
4d41bab6e6 | ||
|
|
aa3c83f044 | ||
|
|
676d9ce8ac | ||
|
|
f36a964fdd | ||
|
|
eedfeb1022 | ||
|
|
4ca68510b0 | ||
|
|
5f3a6a19f2 | ||
|
|
1a073e5db5 | ||
|
|
9cb57ef35f | ||
|
|
7f29082e95 | ||
|
|
75ba956176 | ||
|
|
f3d20b8e14 | ||
|
|
03caa9b349 | ||
|
|
7bef32522e | ||
|
|
48fd6fdb1e | ||
|
|
7d0550259b | ||
|
|
bd94b445de | ||
|
|
6af4597b80 | ||
|
|
a565ac232d | ||
|
|
711564c452 | ||
|
|
34d1127f98 | ||
|
|
8926a0d96b | ||
|
|
c014f6db04 | ||
|
|
2625f10997 | ||
|
|
d1ab51e7cd | ||
|
|
907c1fc0be | ||
|
|
b44b5f8bb2 |
16
.github/workflows/ci.yml
vendored
Normal file
16
.github/workflows/ci.yml
vendored
Normal 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
3
.gitignore
vendored
@@ -1,5 +1,8 @@
|
|||||||
dist
|
dist
|
||||||
.project_env.rc
|
.project_env.rc
|
||||||
.path_progress
|
.path_progress
|
||||||
|
.rvmrc
|
||||||
|
.ruby-version
|
||||||
*.rbc
|
*.rbc
|
||||||
koans/*
|
koans/*
|
||||||
|
*~
|
||||||
|
|||||||
12
DEPLOYING
Normal file
12
DEPLOYING
Normal 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.
|
||||||
115
README.rdoc
115
README.rdoc
@@ -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 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
|
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
|
functions and libraries. We also teach you culture by basing the koans on tests.
|
||||||
pay lip service to, but something we live. It is essential in your quest to learn
|
Testing is not just something we pay lip service to, but something we
|
||||||
and do great things in the language.
|
live. Testing is essential in your quest to learn and do great things in Ruby.
|
||||||
|
|
||||||
== The Structure
|
== The Structure
|
||||||
|
|
||||||
The koans are broken out into areas by file, hashes are covered in about_hashes.rb,
|
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
|
modules are introduced in +about_modules.rb+, <em>etc</em>. They are presented in
|
||||||
path_to_enlightenment.rb file.
|
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.
|
the first place you need to correct.
|
||||||
|
|
||||||
Some koans simply need to have the correct answer substituted for an incorrect one.
|
Some koans simply need to have the correct answer substituted for an incorrect one.
|
||||||
@@ -23,30 +23,41 @@ make it work correctly.
|
|||||||
== Installing Ruby
|
== Installing Ruby
|
||||||
|
|
||||||
If you do not have Ruby setup, please visit http://ruby-lang.org/en/downloads/ for
|
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
|
operating specific instructions. In order to run the koans you need +ruby+ and
|
||||||
installed. To check the installations simply type:
|
+rake+ installed. To check your installations simply type:
|
||||||
|
|
||||||
*nix platforms from any terminal window:
|
*nix platforms from any terminal window:
|
||||||
|
|
||||||
[~] $ ruby --version
|
[~] $ ruby --version
|
||||||
[~] $ rake --version
|
[~] $ rake --version
|
||||||
|
|
||||||
Windows from the command prompt (cmd.exe)
|
Windows from the command prompt (+cmd.exe+)
|
||||||
|
|
||||||
c:\ruby --version
|
c:\ruby --version
|
||||||
c:\rake --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
|
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
|
== 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).
|
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] $ rake # runs the default target :walk_the_path
|
||||||
[ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
|
[ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
|
||||||
@@ -58,54 +69,88 @@ Windows is the same thing
|
|||||||
|
|
||||||
=== Red, Green, Refactor
|
=== Red, Green, Refactor
|
||||||
|
|
||||||
In test-driven development the mantra has always been, red, green, refactor. Write a
|
In test-driven development the mantra has always been <em>red, green, refactor</em>.
|
||||||
failing test and run it (red), make the test pass (green), then refactor it (that is
|
Write a failing test and run it (<em>red</em>), make the test pass (<em>green</em>),
|
||||||
look at the code and see if you can make it any better. In this case you will need
|
then look at the code and consider if you can make it any better (<em>refactor</em>).
|
||||||
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).
|
|
||||||
|
|
||||||
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
|
[ ruby_koans ] $ rake
|
||||||
(in /Users/person/dev/ruby_koans)
|
(in /Users/person/dev/ruby_koans)
|
||||||
cd koans
|
/usr/bin/ruby1.8 path_to_enlightenment.rb
|
||||||
|
|
||||||
Thinking AboutAsserts
|
AboutAsserts#test_assert_truth has damaged your karma.
|
||||||
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.
|
<false> is not true.
|
||||||
|
|
||||||
Please meditate on the following code:
|
Please meditate on the following code:
|
||||||
./about_asserts.rb:10:in `test_assert_truth'
|
./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
|
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:
|
the first solution:
|
||||||
|
|
||||||
Please meditate on the following code:
|
Please meditate on the following code:
|
||||||
./about_asserts.rb:10:in `test_assert_truth'
|
./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.
|
# We shall contemplate truth by testing reality, via asserts.
|
||||||
def test_assert_truth
|
def test_assert_truth
|
||||||
assert false # This should be true
|
assert false # This should be true
|
||||||
end
|
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
|
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
|
the method name (+test_assert_truth+) and the parts inside the method (everything
|
||||||
before the +end+).
|
before the +end+).
|
||||||
|
|
||||||
In this case the goal is for you to see that if you pass a value to the +assert+
|
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+.
|
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
|
== Inspiration
|
||||||
|
|
||||||
A special thanks to Mike Clark and Ara Howard for inspiring this
|
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
|
= Other stuff
|
||||||
|
|
||||||
Author :: Jim Weirich <jim@weirichhouse.org>
|
Author :: Jim Weirich <jim@neo.org>
|
||||||
Author :: Joe O'Brien <joe@edgecase.com>
|
Author :: Joe O'Brien <joe@objo.com>
|
||||||
Issue Tracker :: http://www.pivotaltracker.com/projects/48111
|
Issue Tracker :: https://github.com/edgecase/ruby_koans/issues
|
||||||
Requires :: Ruby 1.8.x or later and Rake (any recent version)
|
Requires :: Ruby 1.8.x or later and Rake (any recent version)
|
||||||
|
|
||||||
= License
|
= License
|
||||||
|
|||||||
47
Rakefile
Normal file → Executable file
47
Rakefile
Normal file → Executable file
@@ -2,25 +2,17 @@
|
|||||||
# -*- ruby -*-
|
# -*- ruby -*-
|
||||||
|
|
||||||
require 'rake/clean'
|
require 'rake/clean'
|
||||||
begin
|
|
||||||
require 'rdoc/task'
|
|
||||||
rescue LoadError => ex
|
|
||||||
# No rdoc task availble.
|
|
||||||
end
|
|
||||||
|
|
||||||
SRC_DIR = 'src'
|
SRC_DIR = 'src'
|
||||||
PROB_DIR = 'koans'
|
PROB_DIR = 'koans'
|
||||||
DIST_DIR = 'dist'
|
DOWNLOAD_DIR = 'download'
|
||||||
|
|
||||||
SRC_FILES = FileList["#{SRC_DIR}/*"]
|
SRC_FILES = FileList["#{SRC_DIR}/*"]
|
||||||
KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
|
KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
|
||||||
|
|
||||||
today = Time.now.strftime("%Y-%m-%d")
|
ZIP_FILE = "#{DOWNLOAD_DIR}/rubykoans.zip"
|
||||||
TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
|
|
||||||
ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
|
|
||||||
|
|
||||||
CLEAN.include("**/*.rbc")
|
CLEAN.include("**/*.rbc")
|
||||||
CLOBBER.include(DIST_DIR)
|
|
||||||
|
|
||||||
module Koans
|
module Koans
|
||||||
extend Rake::DSL if defined?(Rake::DSL)
|
extend Rake::DSL if defined?(Rake::DSL)
|
||||||
@@ -40,10 +32,8 @@ module Koans
|
|||||||
end
|
end
|
||||||
|
|
||||||
def Koans.make_koan_file(infile, outfile)
|
def Koans.make_koan_file(infile, outfile)
|
||||||
if infile =~ /edgecase/
|
if infile =~ /neo/
|
||||||
cp infile, outfile
|
cp infile, outfile
|
||||||
elsif infile =~ /autotest/
|
|
||||||
cp_r infile, outfile
|
|
||||||
else
|
else
|
||||||
open(infile) do |ins|
|
open(infile) do |ins|
|
||||||
open(outfile, "w") do |outs|
|
open(outfile, "w") do |outs|
|
||||||
@@ -88,34 +78,29 @@ end
|
|||||||
task :default => :walk_the_path
|
task :default => :walk_the_path
|
||||||
|
|
||||||
task :walk_the_path do
|
task :walk_the_path do
|
||||||
cd 'koans'
|
cd PROB_DIR
|
||||||
ruby 'path_to_enlightenment.rb'
|
ruby 'path_to_enlightenment.rb'
|
||||||
end
|
end
|
||||||
|
|
||||||
if defined?(Rake::RDocTask)
|
directory DOWNLOAD_DIR
|
||||||
Rake::RDocTask.new do |rd|
|
|
||||||
rd.main = "README.rdoc"
|
|
||||||
rd.rdoc_files.include("README.rdoc", "koans/*.rb")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
directory DIST_DIR
|
|
||||||
directory PROB_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}/*"
|
sh "zip #{ZIP_FILE} #{PROB_DIR}/*"
|
||||||
end
|
end
|
||||||
|
|
||||||
file TAR_FILE => KOAN_FILES + [DIST_DIR] do
|
|
||||||
sh "tar zcvf #{TAR_FILE} #{PROB_DIR}"
|
|
||||||
end
|
|
||||||
|
|
||||||
desc "Create packaged files for distribution"
|
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"
|
desc "Upload the package files to the web server"
|
||||||
task :upload => [TAR_FILE, ZIP_FILE] do
|
task :upload => [ZIP_FILE] do
|
||||||
sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
|
|
||||||
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -140,7 +125,7 @@ end
|
|||||||
|
|
||||||
task :run do
|
task :run do
|
||||||
puts 'koans'
|
puts 'koans'
|
||||||
Dir.chdir("src") do
|
Dir.chdir("#{SRC_DIR}") do
|
||||||
puts "in #{Dir.pwd}"
|
puts "in #{Dir.pwd}"
|
||||||
sh "ruby path_to_enlightenment.rb"
|
sh "ruby path_to_enlightenment.rb"
|
||||||
end
|
end
|
||||||
|
|||||||
BIN
download/rubykoans.zip
Normal file
BIN
download/rubykoans.zip
Normal file
Binary file not shown.
9
rakelib/test.rake
Normal file
9
rakelib/test.rake
Normal 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'
|
||||||
|
|
||||||
@@ -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
|
def test_non_parallel_assignment
|
||||||
names = ["John", "Smith"]
|
names = ["John", "Smith"]
|
||||||
assert_equal __(["John", "Smith"]), names
|
assert_equal __(["John", "Smith"]), names
|
||||||
@@ -24,7 +24,7 @@ class AboutArrayAssignment < EdgeCase::Koan
|
|||||||
assert_equal __(["Smith","III"]), last_name
|
assert_equal __(["Smith","III"]), last_name
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_parallel_assignments_with_too_few_variables
|
def test_parallel_assignments_with_too_few_values
|
||||||
first_name, last_name = ["Cher"]
|
first_name, last_name = ["Cher"]
|
||||||
assert_equal __("Cher"), first_name
|
assert_equal __("Cher"), first_name
|
||||||
assert_equal __(nil), last_name
|
assert_equal __(nil), last_name
|
||||||
|
|||||||
@@ -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
|
def test_creating_arrays
|
||||||
empty_array = Array.new
|
empty_array = Array.new
|
||||||
assert_equal __(Array), empty_array.class
|
assert_equal __(Array), empty_array.class
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# -*- 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.
|
# We shall contemplate truth by testing reality, via asserts.
|
||||||
def test_assert_truth
|
def test_assert_truth
|
||||||
|
|||||||
@@ -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
|
def method_with_block
|
||||||
result = yield
|
result = yield
|
||||||
result
|
result
|
||||||
@@ -23,7 +23,7 @@ class AboutBlocks < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_blocks_can_take_arguments
|
def test_blocks_can_take_arguments
|
||||||
result = method_with_block_arguments do |argument|
|
method_with_block_arguments do |argument|
|
||||||
assert_equal __("Jim"), argument
|
assert_equal __("Jim"), argument
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -70,7 +70,7 @@ class AboutBlocks < EdgeCase::Koan
|
|||||||
add_one = lambda { |n| n + 1 }
|
add_one = lambda { |n| n + 1 }
|
||||||
assert_equal __(11), add_one.call(10)
|
assert_equal __(11), add_one.call(10)
|
||||||
|
|
||||||
# Alternative calling sequence
|
# Alternative calling syntax
|
||||||
assert_equal __(11), add_one[10]
|
assert_equal __(11), add_one[10]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
class Dog
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ class AboutClassMethods < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class Dog2
|
class Dog2
|
||||||
def wag
|
def wag
|
||||||
:instance_level_wag
|
:instance_level_wag
|
||||||
@@ -96,14 +96,13 @@ class AboutClassMethods < EdgeCase::Koan
|
|||||||
def test_you_can_define_class_methods_inside_the_class
|
def test_you_can_define_class_methods_inside_the_class
|
||||||
assert_equal __(:dogs_class_method), Dog.a_class_method
|
assert_equal __(:dogs_class_method), Dog.a_class_method
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
LastExpressionInClassStatement = class Dog
|
LastExpressionInClassStatement = class Dog
|
||||||
21
|
21
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_statements_return_the_value_of_their_last_expression
|
def test_class_statements_return_the_value_of_their_last_expression
|
||||||
assert_equal __(21), LastExpressionInClassStatement
|
assert_equal __(21), LastExpressionInClassStatement
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
class Dog
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -147,7 +147,7 @@ class AboutClasses < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
__(@name)
|
@name
|
||||||
end
|
end
|
||||||
|
|
||||||
def inspect
|
def inspect
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||||
|
|
||||||
C = "top level"
|
C = "top level"
|
||||||
|
|
||||||
class AboutConstants < EdgeCase::Koan
|
class AboutConstants < Neo::Koan
|
||||||
|
|
||||||
C = "nested"
|
C = "nested"
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
def test_if_then_else_statements
|
||||||
if true
|
if true
|
||||||
@@ -131,4 +131,12 @@ class AboutControlStatements < EdgeCase::Koan
|
|||||||
assert_equal [__("FISH"), __("AND"), __("CHIPS")], result
|
assert_equal [__("FISH"), __("AND"), __("CHIPS")], result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_times_statement
|
||||||
|
sum = 0
|
||||||
|
10.times do
|
||||||
|
sum += 1
|
||||||
|
end
|
||||||
|
assert_equal __(10), sum
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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:
|
# Implement a DiceSet Class here:
|
||||||
#
|
#
|
||||||
@@ -15,7 +15,7 @@ class DiceSet
|
|||||||
end
|
end
|
||||||
|
|
||||||
#++
|
#++
|
||||||
class AboutDiceProject < EdgeCase::Koan
|
class AboutDiceProject < Neo::Koan
|
||||||
def test_can_create_a_dice_set
|
def test_can_create_a_dice_set
|
||||||
dice = DiceSet.new
|
dice = DiceSet.new
|
||||||
assert_not_nil dice
|
assert_not_nil dice
|
||||||
@@ -56,7 +56,7 @@ class AboutDiceProject < EdgeCase::Koan
|
|||||||
#
|
#
|
||||||
# If the rolls are random, then it is possible (although not
|
# If the rolls are random, then it is possible (although not
|
||||||
# likely) that two consecutive rolls are equal. What would be a
|
# likely) that two consecutive rolls are equal. What would be a
|
||||||
# better way to test this.
|
# better way to test this?
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_you_can_roll_different_numbers_of_dice
|
def test_you_can_roll_different_numbers_of_dice
|
||||||
|
|||||||
@@ -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
|
class MySpecialError < RuntimeError
|
||||||
end
|
end
|
||||||
@@ -48,7 +48,7 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
result = nil
|
result = nil
|
||||||
begin
|
begin
|
||||||
fail "Oops"
|
fail "Oops"
|
||||||
rescue StandardError => ex
|
rescue StandardError
|
||||||
# no code here
|
# no code here
|
||||||
ensure
|
ensure
|
||||||
result = :always_run
|
result = :always_run
|
||||||
|
|||||||
@@ -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
|
def test_creating_hashes
|
||||||
empty_hash = Hash.new
|
empty_hash = Hash.new
|
||||||
assert_equal __(Hash), empty_hash.class
|
assert_equal __(Hash), empty_hash.class
|
||||||
assert_equal({}, empty_hash) # __
|
assert_equal(__({}), empty_hash)
|
||||||
assert_equal __(0), empty_hash.size
|
assert_equal __(0), empty_hash.size
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
hash[:one] = "eins"
|
hash[:one] = "eins"
|
||||||
|
|
||||||
expected = { :one => __("eins"), :two => "dos" }
|
expected = { :one => __("eins"), :two => "dos" }
|
||||||
assert_equal __(true), expected == hash
|
assert_equal __(expected), hash
|
||||||
|
|
||||||
# Bonus Question: Why was "expected" broken out into a variable
|
# Bonus Question: Why was "expected" broken out into a variable
|
||||||
# rather than used as a literal?
|
# rather than used as a literal?
|
||||||
@@ -113,4 +113,14 @@ class AboutHashes < EdgeCase::Koan
|
|||||||
assert_equal __(["dos"]), hash[:two]
|
assert_equal __(["dos"]), hash[:two]
|
||||||
assert_equal __([]), hash[:three]
|
assert_equal __([]), hash[:three]
|
||||||
end
|
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
|
end
|
||||||
|
|||||||
@@ -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
|
class Dog
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
|
|||||||
@@ -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 ------------------------------------------------------
|
# -- An Aside ------------------------------------------------------
|
||||||
# Ruby 1.8 stores names as strings. Ruby 1.9 stores names as
|
# Ruby 1.8 stores names as strings. Ruby 1.9 and later stores names
|
||||||
# symbols. So we use a version dependent method "as_name" to convert
|
# as symbols. So we use a version dependent method "as_name" to
|
||||||
# to the right format in the koans. We will use "as_name" whenever
|
# convert to the right format in the koans. We will use "as_name"
|
||||||
# comparing to lists of methods.
|
# whenever comparing to lists of methods.
|
||||||
|
|
||||||
in_ruby_version("1.8") do
|
in_ruby_version("1.8") do
|
||||||
def as_name(name)
|
def as_name(name)
|
||||||
@@ -14,7 +14,7 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
in_ruby_version("1.9") do
|
in_ruby_version("1.9", "2", "3") do
|
||||||
def as_name(name)
|
def as_name(name)
|
||||||
name.to_sym
|
name.to_sym
|
||||||
end
|
end
|
||||||
@@ -39,19 +39,17 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
def test_each_can_use_curly_brace_blocks_too
|
def test_each_can_use_curly_brace_blocks_too
|
||||||
array = [1, 2, 3]
|
array = [1, 2, 3]
|
||||||
sum = 0
|
sum = 0
|
||||||
array.each { |item|
|
array.each { |item| sum += item }
|
||||||
sum += item
|
|
||||||
}
|
|
||||||
assert_equal __(6), sum
|
assert_equal __(6), sum
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_break_works_with_each_style_iterations
|
def test_break_works_with_each_style_iterations
|
||||||
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
||||||
sum = 0
|
sum = 0
|
||||||
array.each { |item|
|
array.each do |item|
|
||||||
break if item > 3
|
break if item > 3
|
||||||
sum += item
|
sum += item
|
||||||
}
|
end
|
||||||
assert_equal __(6), sum
|
assert_equal __(6), sum
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,7 +84,7 @@ class AboutIteration < EdgeCase::Koan
|
|||||||
result = [2, 3, 4].inject(0) { |sum, item| sum + item }
|
result = [2, 3, 4].inject(0) { |sum, item| sum + item }
|
||||||
assert_equal __(9), result
|
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
|
assert_equal __(24), result2
|
||||||
|
|
||||||
# Extra Credit:
|
# Extra Credit:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||||
|
|
||||||
include Java
|
include Java
|
||||||
|
|
||||||
@@ -11,7 +11,7 @@ include Java
|
|||||||
# * Calling custom java class
|
# * Calling custom java class
|
||||||
# * Calling Ruby from java???
|
# * Calling Ruby from java???
|
||||||
|
|
||||||
class AboutJavaInterop < EdgeCase::Koan
|
class AboutJavaInterop < Neo::Koan
|
||||||
def test_using_a_java_library_class
|
def test_using_a_java_library_class
|
||||||
java_array = java.util.ArrayList.new
|
java_array = java.util.ArrayList.new
|
||||||
assert_equal __(Java::JavaUtil::ArrayList), java_array.class
|
assert_equal __(Java::JavaUtil::ArrayList), java_array.class
|
||||||
|
|||||||
43
src/about_keyword_arguments.rb
Normal file
43
src/about_keyword_arguments.rb
Normal 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
|
||||||
@@ -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
|
class MessageCatcher
|
||||||
def caught?
|
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)
|
assert_equal __([3, 4, nil, 6]), mc.send(:add_a_payload, 3, 4, nil, 6)
|
||||||
end
|
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
|
class TypicalObject
|
||||||
@@ -93,11 +100,11 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
# NOTE:
|
# NOTE:
|
||||||
#
|
#
|
||||||
# In Ruby 1.8 the method_missing method is public and can be
|
# 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
|
# called as shown above. However, in Ruby 1.9 (and later versions)
|
||||||
# method is private. We explicitly made it public in the testing
|
# the method_missing method is private. We explicitly made it
|
||||||
# framework so this example works in both versions of Ruby. Just
|
# public in the testing framework so this example works in both
|
||||||
# keep in mind you can't call method_missing like that in Ruby
|
# versions of Ruby. Just keep in mind you can't call
|
||||||
# 1.9. normally.
|
# method_missing like that after Ruby 1.9 normally.
|
||||||
#
|
#
|
||||||
# Thanks. We now return you to your regularly scheduled Ruby
|
# Thanks. We now return you to your regularly scheduled Ruby
|
||||||
# Koans.
|
# Koans.
|
||||||
@@ -122,7 +129,7 @@ class AboutMessagePassing < EdgeCase::Koan
|
|||||||
def test_catching_messages_makes_respond_to_lie
|
def test_catching_messages_makes_respond_to_lie
|
||||||
catcher = AllMessageCatcher.new
|
catcher = AllMessageCatcher.new
|
||||||
|
|
||||||
assert_nothing_raised(NoMethodError) do # __
|
assert_nothing_raised do # __
|
||||||
catcher.any_method
|
catcher.any_method
|
||||||
end
|
end
|
||||||
assert_equal __(false), catcher.respond_to?(:any_method)
|
assert_equal __(false), catcher.respond_to?(:any_method)
|
||||||
|
|||||||
@@ -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)
|
def my_global_method(a,b)
|
||||||
a + b
|
a + b
|
||||||
end
|
end
|
||||||
|
|
||||||
class AboutMethods < EdgeCase::Koan
|
class AboutMethods < Neo::Koan
|
||||||
|
|
||||||
def test_calling_global_methods
|
def test_calling_global_methods
|
||||||
assert_equal __(5), my_global_method(2,3)
|
assert_equal __(5), my_global_method(2,3)
|
||||||
@@ -37,8 +37,9 @@ class AboutMethods < EdgeCase::Koan
|
|||||||
#
|
#
|
||||||
end
|
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.
|
# runtime error.
|
||||||
|
# tip: When regex contains parentheses, you must escape them with backslash.
|
||||||
def test_calling_global_methods_with_wrong_number_of_arguments
|
def test_calling_global_methods_with_wrong_number_of_arguments
|
||||||
exception = assert_raise(___(ArgumentError)) do
|
exception = assert_raise(___(ArgumentError)) do
|
||||||
my_global_method
|
my_global_method
|
||||||
@@ -126,11 +127,13 @@ class AboutMethods < EdgeCase::Koan
|
|||||||
assert_equal __("a secret"), my_private_method
|
assert_equal __("a secret"), my_private_method
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_calling_private_methods_with_an_explicit_receiver
|
if before_ruby_version("2.7") # https://github.com/edgecase/ruby_koans/issues/12
|
||||||
exception = assert_raise(___(NoMethodError)) do
|
def test_calling_private_methods_with_an_explicit_receiver
|
||||||
self.my_private_method
|
exception = assert_raise(___(NoMethodError)) do
|
||||||
|
self.my_private_method
|
||||||
|
end
|
||||||
|
assert_match /#{__("method `my_private_method'")}/, exception.message
|
||||||
end
|
end
|
||||||
assert_match /#{__("private method `my_private_method' called ")}/, exception.message
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|||||||
@@ -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
|
module Nameable
|
||||||
def set_name(new_name)
|
def set_name(new_name)
|
||||||
@name = new_name
|
@name = new_name
|
||||||
@@ -44,7 +44,7 @@ class AboutModules < EdgeCase::Koan
|
|||||||
|
|
||||||
def test_module_methods_are_also_available_in_the_object
|
def test_module_methods_are_also_available_in_the_object
|
||||||
fido = Dog.new
|
fido = Dog.new
|
||||||
assert_nothing_raised(Exception) do # __
|
assert_nothing_raised do # __
|
||||||
fido.set_name("Rover")
|
fido.set_name("Rover")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
def test_nil_is_an_object
|
||||||
assert_equal __(true), nil.is_a?(Object), "Unlike NULL in other languages"
|
assert_equal __(true), nil.is_a?(Object), "Unlike NULL in other languages"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
def test_everything_is_an_object
|
||||||
assert_equal __(true), 1.is_a?(Object)
|
assert_equal __(true), 1.is_a?(Object)
|
||||||
assert_equal __(true), 1.5.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
|
def test_every_object_has_an_id
|
||||||
obj = Object.new
|
obj = Object.new
|
||||||
assert_equal __(Fixnum), obj.object_id.class
|
assert obj.object_id.is_a?(__(Integer))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_every_object_has_different_id
|
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
|
assert_equal __(true), obj.object_id != another_obj.object_id
|
||||||
end
|
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
|
def test_small_integers_have_fixed_ids
|
||||||
assert_equal __(1), 0.object_id
|
assert_equal __(1), 0.object_id
|
||||||
assert_equal __(3), 1.object_id
|
assert_equal __(3), 1.object_id
|
||||||
|
|||||||
@@ -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
|
class Dog
|
||||||
def bark
|
def bark
|
||||||
"WOOF"
|
"WOOF"
|
||||||
@@ -30,16 +30,16 @@ class AboutOpenClasses < EdgeCase::Koan
|
|||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
class ::Integer
|
class ::Integer
|
||||||
def even?
|
def answer_to_life_universe_and_everything?
|
||||||
(self % 2) == 0
|
self == 42
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_even_existing_built_in_classes_can_be_reopened
|
def test_even_existing_built_in_classes_can_be_reopened
|
||||||
assert_equal __(false), 1.even?
|
assert_equal __(false), 1.answer_to_life_universe_and_everything?
|
||||||
assert_equal __(true), 2.even?
|
assert_equal __(true), 42.answer_to_life_universe_and_everything?
|
||||||
end
|
end
|
||||||
|
|
||||||
# NOTE: To understand why we need the :: before Integer, you need to
|
# NOTE: To understand why we need the :: before Integer, you need to
|
||||||
# become enlightened about scope.
|
# become enlightened about scope.
|
||||||
end
|
end
|
||||||
|
|||||||
215
src/about_pattern_matching.rb
Normal file
215
src/about_pattern_matching.rb
Normal 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
|
||||||
@@ -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
|
# Project: Create a Proxy Class
|
||||||
#
|
#
|
||||||
@@ -42,7 +42,7 @@ end
|
|||||||
|
|
||||||
# The proxy object should pass the following Koan:
|
# The proxy object should pass the following Koan:
|
||||||
#
|
#
|
||||||
class AboutProxyObjectProject < EdgeCase::Koan
|
class AboutProxyObjectProject < Neo::Koan
|
||||||
def test_proxy_method_returns_wrapped_object
|
def test_proxy_method_returns_wrapped_object
|
||||||
# NOTE: The Television class is defined below
|
# NOTE: The Television class is defined below
|
||||||
tv = Proxy.new(Television.new)
|
tv = Proxy.new(Television.new)
|
||||||
@@ -135,7 +135,7 @@ class Television
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Tests for the Television class. All of theses tests should pass.
|
# Tests for the Television class. All of theses tests should pass.
|
||||||
class TelevisionTest < EdgeCase::Koan
|
class TelevisionTest < Neo::Koan
|
||||||
def test_it_turns_on
|
def test_it_turns_on
|
||||||
tv = Television.new
|
tv = Television.new
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- 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
|
def test_a_pattern_is_a_regular_expression
|
||||||
assert_equal __(Regexp), /pattern/.class
|
assert_equal __(Regexp), /pattern/.class
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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)
|
def count_lines(file_name)
|
||||||
file = open(file_name)
|
file = open(file_name)
|
||||||
count = 0
|
count = 0
|
||||||
while line = file.gets
|
while file.gets
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
count
|
count
|
||||||
@@ -66,7 +66,7 @@ class AboutSandwichCode < EdgeCase::Koan
|
|||||||
def count_lines2(file_name)
|
def count_lines2(file_name)
|
||||||
file_sandwich(file_name) do |file|
|
file_sandwich(file_name) do |file|
|
||||||
count = 0
|
count = 0
|
||||||
while line = file.gets
|
while file.gets
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
count
|
count
|
||||||
@@ -99,7 +99,7 @@ class AboutSandwichCode < EdgeCase::Koan
|
|||||||
def count_lines3(file_name)
|
def count_lines3(file_name)
|
||||||
open(file_name) do |file|
|
open(file_name) do |file|
|
||||||
count = 0
|
count = 0
|
||||||
while line = file.gets
|
while file.gets
|
||||||
count += 1
|
count += 1
|
||||||
end
|
end
|
||||||
count
|
count
|
||||||
|
|||||||
@@ -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
|
module Jims
|
||||||
class Dog
|
class Dog
|
||||||
def identify
|
def identify
|
||||||
@@ -19,7 +19,7 @@ class AboutScope < EdgeCase::Koan
|
|||||||
|
|
||||||
def test_dog_is_not_available_in_the_current_scope
|
def test_dog_is_not_available_in_the_current_scope
|
||||||
assert_raise(___(NameError)) do
|
assert_raise(___(NameError)) do
|
||||||
fido = Dog.new
|
Dog.new
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
# 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
|
# points. The following "score" function will be used to calculate the
|
||||||
@@ -54,7 +54,7 @@ def score(dice)
|
|||||||
#++
|
#++
|
||||||
end
|
end
|
||||||
|
|
||||||
class AboutScoringProject < EdgeCase::Koan
|
class AboutScoringProject < Neo::Koan
|
||||||
def test_score_of_an_empty_list_is_zero
|
def test_score_of_an_empty_list_is_zero
|
||||||
assert_equal 0, score([])
|
assert_equal 0, score([])
|
||||||
end
|
end
|
||||||
@@ -90,6 +90,9 @@ class AboutScoringProject < EdgeCase::Koan
|
|||||||
def test_score_of_mixed_is_sum
|
def test_score_of_mixed_is_sum
|
||||||
assert_equal 250, score([2,5,2,2,3])
|
assert_equal 250, score([2,5,2,2,3])
|
||||||
assert_equal 550, score([5,5,5,5])
|
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
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
def test_double_quoted_strings_are_strings
|
||||||
string = "Hello, World"
|
string = "Hello, World"
|
||||||
assert_equal __(true), string.is_a?(String)
|
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 __(54), long_string.length
|
||||||
assert_equal __(3), long_string.lines.count
|
assert_equal __(3), long_string.lines.count
|
||||||
|
assert_equal __("\n"), long_string[0,1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_here_documents_can_also_handle_multiple_lines
|
def test_here_documents_can_also_handle_multiple_lines
|
||||||
@@ -51,6 +52,7 @@ It was the worst of times.
|
|||||||
EOS
|
EOS
|
||||||
assert_equal __(53), long_string.length
|
assert_equal __(53), long_string.length
|
||||||
assert_equal __(2), long_string.lines.count
|
assert_equal __(2), long_string.lines.count
|
||||||
|
assert_equal __("I"), long_string[0,1]
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_plus_will_concatenate_two_strings
|
def test_plus_will_concatenate_two_strings
|
||||||
@@ -149,7 +151,7 @@ EOS
|
|||||||
end
|
end
|
||||||
|
|
||||||
in_ruby_version("1.8") do
|
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 __(97, 'a'), ?a
|
||||||
assert_equal __(true, false), ?a == 97
|
assert_equal __(true, false), ?a == 97
|
||||||
|
|
||||||
@@ -157,8 +159,8 @@ EOS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
in_ruby_version("1.9") do
|
in_ruby_version("1.9", "2", "3") do
|
||||||
def test_in_ruby_1_9_single_characters_are_represented_by_strings
|
def test_in_modern_ruby_single_characters_are_represented_by_strings
|
||||||
assert_equal __('a'), ?a
|
assert_equal __('a'), ?a
|
||||||
assert_equal __(false), ?a == 97
|
assert_equal __(false), ?a == 97
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -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
|
def test_symbols_are_symbols
|
||||||
symbol = :ruby
|
symbol = :ruby
|
||||||
assert_equal __(true), symbol.is_a?(Symbol)
|
assert_equal __(true), symbol.is_a?(Symbol)
|
||||||
@@ -36,9 +36,9 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
in_ruby_version("mri") do
|
in_ruby_version("mri") do
|
||||||
RubyConstant = "What is the sound of one hand clapping?"
|
RubyConstant = "What is the sound of one hand clapping?"
|
||||||
def test_constants_become_symbols
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -50,14 +50,14 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
def test_symbols_with_spaces_can_be_built
|
def test_symbols_with_spaces_can_be_built
|
||||||
symbol = :"cats and dogs"
|
symbol = :"cats and dogs"
|
||||||
|
|
||||||
assert_equal symbol, __("cats and dogs").to_sym
|
assert_equal __("cats and dogs").to_sym, symbol
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_with_interpolation_can_be_built
|
def test_symbols_with_interpolation_can_be_built
|
||||||
value = "and"
|
value = "and"
|
||||||
symbol = :"cats #{value} dogs"
|
symbol = :"cats #{value} dogs"
|
||||||
|
|
||||||
assert_equal symbol, __("cats and dogs").to_sym
|
assert_equal __("cats and dogs").to_sym, symbol
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_to_s_is_called_on_interpolated_symbols
|
def test_to_s_is_called_on_interpolated_symbols
|
||||||
|
|||||||
@@ -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
|
class CanNotBeTreatedAsString
|
||||||
def to_s
|
def to_s
|
||||||
|
|||||||
@@ -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'
|
# 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
|
def test_equilateral_triangles_have_equal_sides
|
||||||
assert_equal :equilateral, triangle(2, 2, 2)
|
assert_equal :equilateral, triangle(2, 2, 2)
|
||||||
assert_equal :equilateral, triangle(10, 10, 10)
|
assert_equal :equilateral, triangle(10, 10, 10)
|
||||||
@@ -22,4 +22,3 @@ class AboutTriangleProject < EdgeCase::Koan
|
|||||||
assert_equal :scalene, triangle(5, 4, 2)
|
assert_equal :scalene, triangle(5, 4, 2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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'
|
# 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.
|
# The first assignment did not talk about how to handle errors.
|
||||||
# Let's handle that part now.
|
# Let's handle that part now.
|
||||||
def test_illegal_triangles_throw_exceptions
|
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(1, 1, 3) end
|
||||||
assert_raise(TriangleError) do triangle(2, 4, 2) end
|
assert_raise(TriangleError) do triangle(2, 4, 2) end
|
||||||
# HINT: for tips, see http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
|
# HINT: for tips, see http://stackoverflow.com/questions/3834203/ruby-koan-151-raising-exceptions
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
def truth_value(condition)
|
||||||
if condition
|
if condition
|
||||||
:true_stuff
|
:true_stuff
|
||||||
|
|||||||
@@ -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
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
Autotest.add_discovery do
|
|
||||||
"rubykoan" if File.exist? 'path_to_enlightenment.rb'
|
|
||||||
end
|
|
||||||
@@ -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
|
|
||||||
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
|
||||||
@@ -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
3
src/koans.watchr
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
watch( '.*\.rb' ) do
|
||||||
|
system 'rake'
|
||||||
|
end
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
# -*- ruby -*-
|
# -*- ruby -*-
|
||||||
|
|
||||||
require 'test/unit/assertions'
|
$VERBOSE = nil
|
||||||
|
|
||||||
begin
|
begin
|
||||||
require 'win32console'
|
require 'win32console'
|
||||||
rescue LoadError
|
rescue LoadError
|
||||||
@@ -24,6 +25,10 @@ def in_ruby_version(*versions)
|
|||||||
yield if versions.any? { |v| ruby_version?(v) }
|
yield if versions.any? { |v| ruby_version?(v) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def before_ruby_version(version)
|
||||||
|
Gem::Version.new(RUBY_VERSION) < Gem::Version.new(version)
|
||||||
|
end
|
||||||
|
|
||||||
in_ruby_version("1.8") do
|
in_ruby_version("1.8") do
|
||||||
class KeyError < StandardError
|
class KeyError < StandardError
|
||||||
end
|
end
|
||||||
@@ -65,7 +70,7 @@ class Object
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
in_ruby_version("1.9") do
|
in_ruby_version("1.9", "2", "3") do
|
||||||
public :method_missing
|
public :method_missing
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -83,7 +88,7 @@ class String
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
module EdgeCase
|
module Neo
|
||||||
class << self
|
class << self
|
||||||
def simple_output
|
def simple_output
|
||||||
ENV['SIMPLE_KOAN_OUTPUT'] == 'true'
|
ENV['SIMPLE_KOAN_OUTPUT'] == 'true'
|
||||||
@@ -122,6 +127,8 @@ module EdgeCase
|
|||||||
if ENV['ANSI_COLOR'].nil?
|
if ENV['ANSI_COLOR'].nil?
|
||||||
if using_windows?
|
if using_windows?
|
||||||
using_win32console
|
using_win32console
|
||||||
|
else
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
ENV['ANSI_COLOR'] =~ /^(t|y)/i
|
ENV['ANSI_COLOR'] =~ /^(t|y)/i
|
||||||
@@ -137,20 +144,68 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
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
|
class Sensei
|
||||||
attr_reader :failure, :failed_test, :pass_count
|
attr_reader :failure, :failed_test, :pass_count
|
||||||
|
|
||||||
in_ruby_version("1.8") do
|
FailedAssertionError = Assertions::FailedAssertionError
|
||||||
AssertionError = Test::Unit::AssertionFailedError
|
|
||||||
end
|
|
||||||
|
|
||||||
in_ruby_version("1.9") do
|
|
||||||
if defined?(MiniTest)
|
|
||||||
AssertionError = MiniTest::Assertion
|
|
||||||
else
|
|
||||||
AssertionError = Test::Unit::AssertionFailedError
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@pass_count = 0
|
@pass_count = 0
|
||||||
@@ -163,7 +218,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def add_progress(prog)
|
def add_progress(prog)
|
||||||
@_contents = nil
|
@_contents = nil
|
||||||
exists = File.exists?(PROGRESS_FILE_NAME)
|
exists = File.exist?(PROGRESS_FILE_NAME)
|
||||||
File.open(PROGRESS_FILE_NAME,'a+') do |f|
|
File.open(PROGRESS_FILE_NAME,'a+') do |f|
|
||||||
f.print "#{',' if exists}#{prog}"
|
f.print "#{',' if exists}#{prog}"
|
||||||
end
|
end
|
||||||
@@ -171,7 +226,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def progress
|
def progress
|
||||||
if @_contents.nil?
|
if @_contents.nil?
|
||||||
if File.exists?(PROGRESS_FILE_NAME)
|
if File.exist?(PROGRESS_FILE_NAME)
|
||||||
File.open(PROGRESS_FILE_NAME,'r') do |f|
|
File.open(PROGRESS_FILE_NAME,'r') do |f|
|
||||||
@_contents = f.read.to_s.gsub(/\s/,'').split(',')
|
@_contents = f.read.to_s.gsub(/\s/,'').split(',')
|
||||||
end
|
end
|
||||||
@@ -193,7 +248,7 @@ module EdgeCase
|
|||||||
@failure = step.failure
|
@failure = step.failure
|
||||||
add_progress(@pass_count)
|
add_progress(@pass_count)
|
||||||
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
||||||
throw :edgecase_exit
|
throw :neo_exit
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -202,7 +257,7 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def assert_failed?
|
def assert_failed?
|
||||||
failure.is_a?(AssertionError)
|
failure.is_a?(FailedAssertionError)
|
||||||
end
|
end
|
||||||
|
|
||||||
def instruct
|
def instruct
|
||||||
@@ -219,7 +274,7 @@ module EdgeCase
|
|||||||
|
|
||||||
def show_progress
|
def show_progress
|
||||||
bar_width = 50
|
bar_width = 50
|
||||||
total_tests = EdgeCase::Koan.total_tests
|
total_tests = Neo::Koan.total_tests
|
||||||
scale = bar_width.to_f/total_tests
|
scale = bar_width.to_f/total_tests
|
||||||
print Color.green("your path thus far [")
|
print Color.green("your path thus far [")
|
||||||
happy_steps = (pass_count*scale).to_i
|
happy_steps = (pass_count*scale).to_i
|
||||||
@@ -230,12 +285,12 @@ module EdgeCase
|
|||||||
print Color.cyan('_'*(bar_width-1-happy_steps))
|
print Color.cyan('_'*(bar_width-1-happy_steps))
|
||||||
end
|
end
|
||||||
print Color.green(']')
|
print Color.green(']')
|
||||||
print " #{pass_count}/#{total_tests}"
|
print " #{pass_count}/#{total_tests} (#{pass_count*100/total_tests}%)"
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
def end_screen
|
def end_screen
|
||||||
if EdgeCase.simple_output
|
if Neo.simple_output
|
||||||
boring_end_screen
|
boring_end_screen
|
||||||
else
|
else
|
||||||
artistic_end_screen
|
artistic_end_screen
|
||||||
@@ -266,13 +321,13 @@ module EdgeCase
|
|||||||
,:::::::::::, ::::::::::::,
|
,:::::::::::, ::::::::::::,
|
||||||
:::::::::::, ,::::::::::::
|
:::::::::::, ,::::::::::::
|
||||||
::::::::::::: ,::::::::::::
|
::::::::::::: ,::::::::::::
|
||||||
:::::::::::: Ruby Koans ::::::::::::,
|
:::::::::::: Ruby Koans ::::::::::::
|
||||||
::::::::::::#{ ruby_version },::::::::::::,
|
::::::::::::#{ ruby_version },::::::::::::
|
||||||
:::::::::::, , ::::::::::::
|
:::::::::::, , :::::::::::
|
||||||
,:::::::::::::, brought to you by ,,::::::::::::,
|
,:::::::::::::, brought to you by ,,::::::::::::
|
||||||
:::::::::::::: ,::::::::::::
|
:::::::::::::: ,::::::::::::
|
||||||
::::::::::::::, ,:::::::::::::
|
::::::::::::::, ,:::::::::::::
|
||||||
::::::::::::, EdgeCase Software Artisans , ::::::::::::
|
::::::::::::, Neo Software Artisans , ::::::::::::
|
||||||
:,::::::::: :::: :::::::::::::
|
:,::::::::: :::: :::::::::::::
|
||||||
,::::::::::: ,: ,,:::::::::::::,
|
,::::::::::: ,: ,,:::::::::::::,
|
||||||
:::::::::::: ,::::::::::::::,
|
:::::::::::: ,::::::::::::::,
|
||||||
@@ -307,11 +362,7 @@ ENDTEXT
|
|||||||
puts Color.red(indent(failure.message).join)
|
puts Color.red(indent(failure.message).join)
|
||||||
puts
|
puts
|
||||||
puts "Please meditate on the following code:"
|
puts "Please meditate on the following code:"
|
||||||
if assert_failed?
|
puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
|
||||||
puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
|
|
||||||
else
|
|
||||||
puts embolden_first_line_only(indent(failure.backtrace))
|
|
||||||
end
|
|
||||||
puts
|
puts
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -334,7 +385,7 @@ ENDTEXT
|
|||||||
|
|
||||||
def find_interesting_lines(backtrace)
|
def find_interesting_lines(backtrace)
|
||||||
backtrace.reject { |line|
|
backtrace.reject { |line|
|
||||||
line =~ /test\/unit\/|edgecase\.rb|minitest/
|
line =~ /neo\.rb/
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -364,7 +415,7 @@ ENDTEXT
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Koan
|
class Koan
|
||||||
include Test::Unit::Assertions
|
include Assertions
|
||||||
|
|
||||||
attr_reader :name, :failure, :koan_count, :step_count, :koan_file
|
attr_reader :name, :failure, :koan_count, :step_count, :koan_file
|
||||||
|
|
||||||
@@ -394,19 +445,19 @@ ENDTEXT
|
|||||||
setup
|
setup
|
||||||
begin
|
begin
|
||||||
send(name)
|
send(name)
|
||||||
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
|
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
|
||||||
failed(ex)
|
failed(ex)
|
||||||
ensure
|
ensure
|
||||||
begin
|
begin
|
||||||
teardown
|
teardown
|
||||||
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
|
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
|
||||||
failed(ex) if passed?
|
failed(ex) if passed?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
# Class methods for the EdgeCase test suite.
|
# Class methods for the Neo test suite.
|
||||||
class << self
|
class << self
|
||||||
def inherited(subclass)
|
def inherited(subclass)
|
||||||
subclasses << subclass
|
subclasses << subclass
|
||||||
@@ -463,7 +514,7 @@ ENDTEXT
|
|||||||
|
|
||||||
class ThePath
|
class ThePath
|
||||||
def walk
|
def walk
|
||||||
sensei = EdgeCase::Sensei.new
|
sensei = Neo::Sensei.new
|
||||||
each_step do |step|
|
each_step do |step|
|
||||||
sensei.observe(step.meditate)
|
sensei.observe(step.meditate)
|
||||||
end
|
end
|
||||||
@@ -471,9 +522,9 @@ ENDTEXT
|
|||||||
end
|
end
|
||||||
|
|
||||||
def each_step
|
def each_step
|
||||||
catch(:edgecase_exit) {
|
catch(:neo_exit) {
|
||||||
step_count = 0
|
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|
|
koan.testmethods.each do |method_name|
|
||||||
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
step = koan.new(method_name, koan.to_s, koan_index+1, step_count+=1)
|
||||||
yield step
|
yield step
|
||||||
@@ -485,6 +536,6 @@ ENDTEXT
|
|||||||
end
|
end
|
||||||
|
|
||||||
END {
|
END {
|
||||||
EdgeCase::Koan.command_line(ARGV)
|
Neo::Koan.command_line(ARGV)
|
||||||
EdgeCase::ThePath.new.walk
|
Neo::ThePath.new.walk
|
||||||
}
|
}
|
||||||
@@ -3,18 +3,21 @@
|
|||||||
$LOAD_PATH << File.dirname(__FILE__)
|
$LOAD_PATH << File.dirname(__FILE__)
|
||||||
|
|
||||||
require 'about_asserts'
|
require 'about_asserts'
|
||||||
require 'about_nil'
|
require 'about_true_and_false'
|
||||||
require 'about_objects'
|
|
||||||
require 'about_arrays'
|
|
||||||
require 'about_array_assignment'
|
|
||||||
require 'about_hashes'
|
|
||||||
require 'about_strings'
|
require 'about_strings'
|
||||||
require 'about_symbols'
|
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'
|
require 'about_methods'
|
||||||
|
in_ruby_version("2", "3") do
|
||||||
|
require 'about_keyword_arguments'
|
||||||
|
end
|
||||||
require 'about_constants'
|
require 'about_constants'
|
||||||
|
require 'about_regular_expressions'
|
||||||
require 'about_control_statements'
|
require 'about_control_statements'
|
||||||
require 'about_true_and_false'
|
|
||||||
require 'about_triangle_project'
|
require 'about_triangle_project'
|
||||||
require 'about_exceptions'
|
require 'about_exceptions'
|
||||||
require 'about_triangle_project_2'
|
require 'about_triangle_project_2'
|
||||||
@@ -35,4 +38,7 @@ require 'about_to_str'
|
|||||||
in_ruby_version("jruby") do
|
in_ruby_version("jruby") do
|
||||||
require 'about_java_interop'
|
require 'about_java_interop'
|
||||||
end
|
end
|
||||||
|
in_ruby_version("2.7", "3") do
|
||||||
|
require 'about_pattern_matching'
|
||||||
|
end
|
||||||
require 'about_extra_credit'
|
require 'about_extra_credit'
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
require 'test/unit'
|
|
||||||
|
|
||||||
def __
|
|
||||||
"FILL ME IN"
|
|
||||||
end
|
|
||||||
|
|
||||||
EdgeCase = Test::Unit
|
|
||||||
26
tests/check_test.rb
Normal file
26
tests/check_test.rb
Normal 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
4
tests/test_helper.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
require "minitest/autorun"
|
||||||
|
require "rake"
|
||||||
|
|
||||||
|
Rake.application.load_rakefile
|
||||||
Reference in New Issue
Block a user