mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-15 07:23:19 -04:00
Compare commits
4 Commits
4f2b3dd18e
...
LA_Ruby_Co
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
84433d2f52 | ||
|
|
aad3167c3c | ||
|
|
a3597acd5a | ||
|
|
d1533d4803 |
16
.github/workflows/ci.yml
vendored
16
.github/workflows/ci.yml
vendored
@@ -1,16 +0,0 @@
|
||||
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,8 +1,5 @@
|
||||
dist
|
||||
.project_env.rc
|
||||
.path_progress
|
||||
.rvmrc
|
||||
.ruby-version
|
||||
*.rbc
|
||||
koans/*
|
||||
*~
|
||||
|
||||
12
DEPLOYING
12
DEPLOYING
@@ -1,12 +0,0 @@
|
||||
= 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.
|
||||
110
README.rdoc
110
README.rdoc
@@ -1,18 +1,18 @@
|
||||
= Ruby Koans
|
||||
= EdgeCase 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 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.
|
||||
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.
|
||||
|
||||
== 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+, <em>etc</em>. 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, etc. 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,41 +23,43 @@ 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 the koans you need +ruby+ and
|
||||
+rake+ installed. To check your installations simply type:
|
||||
operating specific instructions. In order to run this you need ruby and rake
|
||||
installed. To check the 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 <code>gem install rake</code>
|
||||
If you don't have rake installed, just run `gem install rake`
|
||||
|
||||
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
|
||||
[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
|
||||
[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 +ruby_koans+ directory
|
||||
*nix platforms, from the koans directory
|
||||
|
||||
[ruby_koans] $ rake # runs the default target :walk_the_path
|
||||
[ruby_koans] $ ruby path_to_enlightenment.rb # simply call the file directly
|
||||
@@ -69,88 +71,54 @@ Windows is the same thing
|
||||
|
||||
=== Red, Green, 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>).
|
||||
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).
|
||||
|
||||
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:
|
||||
The very first time you run it you will see the following output:
|
||||
|
||||
[ ruby_koans ] $ rake
|
||||
(in /Users/person/dev/ruby_koans)
|
||||
/usr/bin/ruby1.8 path_to_enlightenment.rb
|
||||
cd koans
|
||||
|
||||
AboutAsserts#test_assert_truth has damaged your karma.
|
||||
Thinking AboutAsserts
|
||||
test_assert_truth has damaged your karma.
|
||||
|
||||
The Master says:
|
||||
You have not yet reached enlightenment.
|
||||
|
||||
The answers you seek...
|
||||
You have not yet reached enlightenment ...
|
||||
<false> is not true.
|
||||
|
||||
Please meditate on the following code:
|
||||
./about_asserts.rb:10:in `test_assert_truth'
|
||||
path_to_enlightenment.rb:38:in `each_with_index'
|
||||
path_to_enlightenment.rb:38
|
||||
path_to_enlightenment.rb:27
|
||||
|
||||
mountains are merely mountains
|
||||
your path thus far [X_________________________________________________] 0/280 (0%)
|
||||
|
||||
You have come to your first stage. Notice it is telling you where to look for
|
||||
You have come to your first stage. If you 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:38:in `each_with_index'
|
||||
path_to_enlightenment.rb:38
|
||||
path_to_enlightenment.rb:27
|
||||
|
||||
Open the +about_asserts.rb+ file and look at the first test:
|
||||
We then open up 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
|
||||
|
||||
Change the +false+ to +true+ and re-run the test. After you are
|
||||
We then change the +false+ to +true+ and run the test again. 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
|
||||
method, it will either ensure it is +true+ and continue on, or fail if in fact
|
||||
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
|
||||
@@ -177,9 +145,9 @@ Brian Marick's fantastic guide for beginners Everyday Scripting with Ruby ::
|
||||
|
||||
= Other stuff
|
||||
|
||||
Author :: Jim Weirich <jim@neo.org>
|
||||
Author :: Joe O'Brien <joe@objo.com>
|
||||
Issue Tracker :: https://github.com/edgecase/ruby_koans/issues
|
||||
Author :: Jim Weirich <jim@weirichhouse.org>
|
||||
Author :: Joe O'Brien <joe@edgecase.com>
|
||||
Issue Tracker :: http://www.pivotaltracker.com/projects/48111
|
||||
Requires :: Ruby 1.8.x or later and Rake (any recent version)
|
||||
|
||||
= License
|
||||
|
||||
47
Rakefile
Executable file → Normal file
47
Rakefile
Executable file → Normal file
@@ -2,17 +2,25 @@
|
||||
# -*- ruby -*-
|
||||
|
||||
require 'rake/clean'
|
||||
begin
|
||||
require 'rdoc/task'
|
||||
rescue LoadError => ex
|
||||
# No rdoc task availble.
|
||||
end
|
||||
|
||||
SRC_DIR = 'src'
|
||||
PROB_DIR = 'koans'
|
||||
DOWNLOAD_DIR = 'download'
|
||||
DIST_DIR = 'dist'
|
||||
|
||||
SRC_FILES = FileList["#{SRC_DIR}/*"]
|
||||
KOAN_FILES = SRC_FILES.pathmap("#{PROB_DIR}/%f")
|
||||
|
||||
ZIP_FILE = "#{DOWNLOAD_DIR}/rubykoans.zip"
|
||||
today = Time.now.strftime("%Y-%m-%d")
|
||||
TAR_FILE = "#{DIST_DIR}/rubykoans-#{today}.tgz"
|
||||
ZIP_FILE = "#{DIST_DIR}/rubykoans-#{today}.zip"
|
||||
|
||||
CLEAN.include("**/*.rbc")
|
||||
CLOBBER.include(DIST_DIR)
|
||||
|
||||
module Koans
|
||||
extend Rake::DSL if defined?(Rake::DSL)
|
||||
@@ -32,8 +40,10 @@ module Koans
|
||||
end
|
||||
|
||||
def Koans.make_koan_file(infile, outfile)
|
||||
if infile =~ /neo/
|
||||
if infile =~ /edgecase/
|
||||
cp infile, outfile
|
||||
elsif infile =~ /autotest/
|
||||
cp_r infile, outfile
|
||||
else
|
||||
open(infile) do |ins|
|
||||
open(outfile, "w") do |outs|
|
||||
@@ -78,29 +88,34 @@ end
|
||||
task :default => :walk_the_path
|
||||
|
||||
task :walk_the_path do
|
||||
cd PROB_DIR
|
||||
cd 'koans'
|
||||
ruby 'path_to_enlightenment.rb'
|
||||
end
|
||||
|
||||
directory DOWNLOAD_DIR
|
||||
directory PROB_DIR
|
||||
|
||||
desc "(re)Build zip file"
|
||||
task :zip => [:clobber_zip, :package]
|
||||
|
||||
task :clobber_zip do
|
||||
rm ZIP_FILE
|
||||
if defined?(Rake::RDocTask)
|
||||
Rake::RDocTask.new do |rd|
|
||||
rd.main = "README.rdoc"
|
||||
rd.rdoc_files.include("README.rdoc", "koans/*.rb")
|
||||
end
|
||||
end
|
||||
|
||||
file ZIP_FILE => KOAN_FILES + [DOWNLOAD_DIR] do
|
||||
directory DIST_DIR
|
||||
directory PROB_DIR
|
||||
|
||||
file ZIP_FILE => KOAN_FILES + [DIST_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 => [ZIP_FILE]
|
||||
task :package => [TAR_FILE, ZIP_FILE]
|
||||
|
||||
desc "Upload the package files to the web server"
|
||||
task :upload => [ZIP_FILE] do
|
||||
task :upload => [TAR_FILE, ZIP_FILE] do
|
||||
sh "scp #{TAR_FILE} linode:sites/onestepback.org/download"
|
||||
sh "scp #{ZIP_FILE} linode:sites/onestepback.org/download"
|
||||
end
|
||||
|
||||
@@ -125,7 +140,7 @@ end
|
||||
|
||||
task :run do
|
||||
puts 'koans'
|
||||
Dir.chdir("#{SRC_DIR}") do
|
||||
Dir.chdir("src") do
|
||||
puts "in #{Dir.pwd}"
|
||||
sh "ruby path_to_enlightenment.rb"
|
||||
end
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,9 +0,0 @@
|
||||
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__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutArrayAssignment < Neo::Koan
|
||||
class AboutArrayAssignment < EdgeCase::Koan
|
||||
def test_non_parallel_assignment
|
||||
names = ["John", "Smith"]
|
||||
assert_equal __(["John", "Smith"]), names
|
||||
@@ -24,7 +24,7 @@ class AboutArrayAssignment < Neo::Koan
|
||||
assert_equal __(["Smith","III"]), last_name
|
||||
end
|
||||
|
||||
def test_parallel_assignments_with_too_few_values
|
||||
def test_parallel_assignments_with_too_few_variables
|
||||
first_name, last_name = ["Cher"]
|
||||
assert_equal __("Cher"), first_name
|
||||
assert_equal __(nil), last_name
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutArrays < Neo::Koan
|
||||
class AboutArrays < EdgeCase::Koan
|
||||
def test_creating_arrays
|
||||
empty_array = Array.new
|
||||
assert_equal __(Array), empty_array.class
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -*- ruby -*-
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutAsserts < Neo::Koan
|
||||
class AboutAsserts < EdgeCase::Koan
|
||||
|
||||
# We shall contemplate truth by testing reality, via asserts.
|
||||
def test_assert_truth
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutBlocks < Neo::Koan
|
||||
class AboutBlocks < EdgeCase::Koan
|
||||
def method_with_block
|
||||
result = yield
|
||||
result
|
||||
@@ -23,7 +23,7 @@ class AboutBlocks < Neo::Koan
|
||||
end
|
||||
|
||||
def test_blocks_can_take_arguments
|
||||
method_with_block_arguments do |argument|
|
||||
result = method_with_block_arguments do |argument|
|
||||
assert_equal __("Jim"), argument
|
||||
end
|
||||
end
|
||||
@@ -70,7 +70,7 @@ class AboutBlocks < Neo::Koan
|
||||
add_one = lambda { |n| n + 1 }
|
||||
assert_equal __(11), add_one.call(10)
|
||||
|
||||
# Alternative calling syntax
|
||||
# Alternative calling sequence
|
||||
assert_equal __(11), add_one[10]
|
||||
end
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutClassMethods < Neo::Koan
|
||||
class AboutClassMethods < EdgeCase::Koan
|
||||
class Dog
|
||||
end
|
||||
|
||||
@@ -47,7 +47,7 @@ class AboutClassMethods < Neo::Koan
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
|
||||
class Dog2
|
||||
def wag
|
||||
:instance_level_wag
|
||||
@@ -96,13 +96,14 @@ class AboutClassMethods < Neo::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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutClasses < Neo::Koan
|
||||
class AboutClasses < EdgeCase::Koan
|
||||
class Dog
|
||||
end
|
||||
|
||||
@@ -147,7 +147,7 @@ class AboutClasses < Neo::Koan
|
||||
end
|
||||
|
||||
def to_s
|
||||
@name
|
||||
__(@name)
|
||||
end
|
||||
|
||||
def inspect
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
C = "top level"
|
||||
|
||||
class AboutConstants < Neo::Koan
|
||||
class AboutConstants < EdgeCase::Koan
|
||||
|
||||
C = "nested"
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutControlStatements < Neo::Koan
|
||||
class AboutControlStatements < EdgeCase::Koan
|
||||
|
||||
def test_if_then_else_statements
|
||||
if true
|
||||
@@ -131,12 +131,4 @@ class AboutControlStatements < Neo::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
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
# Implement a DiceSet Class here:
|
||||
#
|
||||
@@ -15,7 +15,7 @@ class DiceSet
|
||||
end
|
||||
|
||||
#++
|
||||
class AboutDiceProject < Neo::Koan
|
||||
class AboutDiceProject < EdgeCase::Koan
|
||||
def test_can_create_a_dice_set
|
||||
dice = DiceSet.new
|
||||
assert_not_nil dice
|
||||
@@ -56,7 +56,7 @@ class AboutDiceProject < Neo::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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutExceptions < Neo::Koan
|
||||
class AboutExceptions < EdgeCase::Koan
|
||||
|
||||
class MySpecialError < RuntimeError
|
||||
end
|
||||
@@ -48,7 +48,7 @@ class AboutExceptions < Neo::Koan
|
||||
result = nil
|
||||
begin
|
||||
fail "Oops"
|
||||
rescue StandardError
|
||||
rescue StandardError => ex
|
||||
# no code here
|
||||
ensure
|
||||
result = :always_run
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutHashes < Neo::Koan
|
||||
class AboutHashes < EdgeCase::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 < Neo::Koan
|
||||
hash[:one] = "eins"
|
||||
|
||||
expected = { :one => __("eins"), :two => "dos" }
|
||||
assert_equal __(expected), hash
|
||||
assert_equal __(true), expected == hash
|
||||
|
||||
# Bonus Question: Why was "expected" broken out into a variable
|
||||
# rather than used as a literal?
|
||||
@@ -113,14 +113,4 @@ class AboutHashes < Neo::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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutInheritance < Neo::Koan
|
||||
class AboutInheritance < EdgeCase::Koan
|
||||
class Dog
|
||||
attr_reader :name
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutIteration < Neo::Koan
|
||||
class AboutIteration < EdgeCase::Koan
|
||||
|
||||
# -- An Aside ------------------------------------------------------
|
||||
# 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.
|
||||
# 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.
|
||||
|
||||
in_ruby_version("1.8") do
|
||||
def as_name(name)
|
||||
@@ -14,7 +14,7 @@ class AboutIteration < Neo::Koan
|
||||
end
|
||||
end
|
||||
|
||||
in_ruby_version("1.9", "2", "3") do
|
||||
in_ruby_version("1.9") do
|
||||
def as_name(name)
|
||||
name.to_sym
|
||||
end
|
||||
@@ -39,17 +39,19 @@ class AboutIteration < Neo::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 do |item|
|
||||
array.each { |item|
|
||||
break if item > 3
|
||||
sum += item
|
||||
end
|
||||
}
|
||||
assert_equal __(6), sum
|
||||
end
|
||||
|
||||
@@ -84,7 +86,7 @@ class AboutIteration < Neo::Koan
|
||||
result = [2, 3, 4].inject(0) { |sum, item| sum + item }
|
||||
assert_equal __(9), result
|
||||
|
||||
result2 = [2, 3, 4].inject(1) { |product, item| product * item }
|
||||
result2 = [2, 3, 4].inject(1) { |sum, item| sum * item }
|
||||
assert_equal __(24), result2
|
||||
|
||||
# Extra Credit:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
include Java
|
||||
|
||||
@@ -11,7 +11,7 @@ include Java
|
||||
# * Calling custom java class
|
||||
# * Calling Ruby from java???
|
||||
|
||||
class AboutJavaInterop < Neo::Koan
|
||||
class AboutJavaInterop < EdgeCase::Koan
|
||||
def test_using_a_java_library_class
|
||||
java_array = java.util.ArrayList.new
|
||||
assert_equal __(Java::JavaUtil::ArrayList), java_array.class
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
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__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutMessagePassing < Neo::Koan
|
||||
class AboutMessagePassing < EdgeCase::Koan
|
||||
|
||||
class MessageCatcher
|
||||
def caught?
|
||||
@@ -63,13 +63,6 @@ class AboutMessagePassing < Neo::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
|
||||
@@ -100,11 +93,11 @@ class AboutMessagePassing < Neo::Koan
|
||||
# NOTE:
|
||||
#
|
||||
# In Ruby 1.8 the method_missing method is public and can be
|
||||
# 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.
|
||||
# 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.
|
||||
#
|
||||
# Thanks. We now return you to your regularly scheduled Ruby
|
||||
# Koans.
|
||||
@@ -129,7 +122,7 @@ class AboutMessagePassing < Neo::Koan
|
||||
def test_catching_messages_makes_respond_to_lie
|
||||
catcher = AllMessageCatcher.new
|
||||
|
||||
assert_nothing_raised do # __
|
||||
assert_nothing_raised(NoMethodError) do # __
|
||||
catcher.any_method
|
||||
end
|
||||
assert_equal __(false), catcher.respond_to?(:any_method)
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
def my_global_method(a,b)
|
||||
a + b
|
||||
end
|
||||
|
||||
class AboutMethods < Neo::Koan
|
||||
class AboutMethods < EdgeCase::Koan
|
||||
|
||||
def test_calling_global_methods
|
||||
assert_equal __(5), my_global_method(2,3)
|
||||
@@ -37,9 +37,8 @@ class AboutMethods < Neo::Koan
|
||||
#
|
||||
end
|
||||
|
||||
# NOTE: wrong number of arguments is not a SYNTAX error, but a
|
||||
# NOTE: wrong number of argument 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
|
||||
@@ -127,13 +126,11 @@ class AboutMethods < Neo::Koan
|
||||
assert_equal __("a secret"), my_private_method
|
||||
end
|
||||
|
||||
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
|
||||
def test_calling_private_methods_with_an_explicit_receiver
|
||||
exception = assert_raise(___(NoMethodError)) do
|
||||
self.my_private_method
|
||||
end
|
||||
assert_match /#{__("private method `my_private_method' called ")}/, exception.message
|
||||
end
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutModules < Neo::Koan
|
||||
class AboutModules < EdgeCase::Koan
|
||||
module Nameable
|
||||
def set_name(new_name)
|
||||
@name = new_name
|
||||
@@ -44,7 +44,7 @@ class AboutModules < Neo::Koan
|
||||
|
||||
def test_module_methods_are_also_available_in_the_object
|
||||
fido = Dog.new
|
||||
assert_nothing_raised do # __
|
||||
assert_nothing_raised(Exception) do # __
|
||||
fido.set_name("Rover")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutNil < Neo::Koan
|
||||
class AboutNil < EdgeCase::Koan
|
||||
def test_nil_is_an_object
|
||||
assert_equal __(true), nil.is_a?(Object), "Unlike NULL in other languages"
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutObjects < Neo::Koan
|
||||
class AboutObjects < EdgeCase::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 < Neo::Koan
|
||||
|
||||
def test_every_object_has_an_id
|
||||
obj = Object.new
|
||||
assert obj.object_id.is_a?(__(Integer))
|
||||
assert_equal __(Fixnum), obj.object_id.class
|
||||
end
|
||||
|
||||
def test_every_object_has_different_id
|
||||
@@ -30,6 +30,12 @@ class AboutObjects < Neo::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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutOpenClasses < Neo::Koan
|
||||
class AboutOpenClasses < EdgeCase::Koan
|
||||
class Dog
|
||||
def bark
|
||||
"WOOF"
|
||||
@@ -30,16 +30,16 @@ class AboutOpenClasses < Neo::Koan
|
||||
# ------------------------------------------------------------------
|
||||
|
||||
class ::Integer
|
||||
def answer_to_life_universe_and_everything?
|
||||
self == 42
|
||||
def even?
|
||||
(self % 2) == 0
|
||||
end
|
||||
end
|
||||
|
||||
def test_even_existing_built_in_classes_can_be_reopened
|
||||
assert_equal __(false), 1.answer_to_life_universe_and_everything?
|
||||
assert_equal __(true), 42.answer_to_life_universe_and_everything?
|
||||
assert_equal __(false), 1.even?
|
||||
assert_equal __(true), 2.even?
|
||||
end
|
||||
|
||||
# NOTE: To understand why we need the :: before Integer, you need to
|
||||
# become enlightened about scope.
|
||||
# become enlightened about scope.
|
||||
end
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
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__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
# Project: Create a Proxy Class
|
||||
#
|
||||
@@ -42,7 +42,7 @@ end
|
||||
|
||||
# The proxy object should pass the following Koan:
|
||||
#
|
||||
class AboutProxyObjectProject < Neo::Koan
|
||||
class AboutProxyObjectProject < EdgeCase::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 < Neo::Koan
|
||||
class TelevisionTest < EdgeCase::Koan
|
||||
def test_it_turns_on
|
||||
tv = Television.new
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutRegularExpressions < Neo::Koan
|
||||
class AboutRegularExpressions < EdgeCase::Koan
|
||||
def test_a_pattern_is_a_regular_expression
|
||||
assert_equal __(Regexp), /pattern/.class
|
||||
end
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutSandwichCode < Neo::Koan
|
||||
class AboutSandwichCode < EdgeCase::Koan
|
||||
|
||||
def count_lines(file_name)
|
||||
file = open(file_name)
|
||||
count = 0
|
||||
while file.gets
|
||||
while line = file.gets
|
||||
count += 1
|
||||
end
|
||||
count
|
||||
@@ -66,7 +66,7 @@ class AboutSandwichCode < Neo::Koan
|
||||
def count_lines2(file_name)
|
||||
file_sandwich(file_name) do |file|
|
||||
count = 0
|
||||
while file.gets
|
||||
while line = file.gets
|
||||
count += 1
|
||||
end
|
||||
count
|
||||
@@ -99,7 +99,7 @@ class AboutSandwichCode < Neo::Koan
|
||||
def count_lines3(file_name)
|
||||
open(file_name) do |file|
|
||||
count = 0
|
||||
while file.gets
|
||||
while line = file.gets
|
||||
count += 1
|
||||
end
|
||||
count
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutScope < Neo::Koan
|
||||
class AboutScope < EdgeCase::Koan
|
||||
module Jims
|
||||
class Dog
|
||||
def identify
|
||||
@@ -19,7 +19,7 @@ class AboutScope < Neo::Koan
|
||||
|
||||
def test_dog_is_not_available_in_the_current_scope
|
||||
assert_raise(___(NameError)) do
|
||||
Dog.new
|
||||
fido = Dog.new
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
# 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 < Neo::Koan
|
||||
class AboutScoringProject < EdgeCase::Koan
|
||||
def test_score_of_an_empty_list_is_zero
|
||||
assert_equal 0, score([])
|
||||
end
|
||||
@@ -90,9 +90,6 @@ class AboutScoringProject < Neo::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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutStrings < Neo::Koan
|
||||
class AboutStrings < EdgeCase::Koan
|
||||
def test_double_quoted_strings_are_strings
|
||||
string = "Hello, World"
|
||||
assert_equal __(true), string.is_a?(String)
|
||||
@@ -42,7 +42,6 @@ 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
|
||||
@@ -52,7 +51,6 @@ 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
|
||||
@@ -151,7 +149,7 @@ EOS
|
||||
end
|
||||
|
||||
in_ruby_version("1.8") do
|
||||
def test_in_older_ruby_single_characters_are_represented_by_integers
|
||||
def test_in_ruby_1_8_single_characters_are_represented_by_integers
|
||||
assert_equal __(97, 'a'), ?a
|
||||
assert_equal __(true, false), ?a == 97
|
||||
|
||||
@@ -159,8 +157,8 @@ EOS
|
||||
end
|
||||
end
|
||||
|
||||
in_ruby_version("1.9", "2", "3") do
|
||||
def test_in_modern_ruby_single_characters_are_represented_by_strings
|
||||
in_ruby_version("1.9") do
|
||||
def test_in_ruby_1_9_single_characters_are_represented_by_strings
|
||||
assert_equal __('a'), ?a
|
||||
assert_equal __(false), ?a == 97
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutSymbols < Neo::Koan
|
||||
class AboutSymbols < EdgeCase::Koan
|
||||
def test_symbols_are_symbols
|
||||
symbol = :ruby
|
||||
assert_equal __(true), symbol.is_a?(Symbol)
|
||||
@@ -36,9 +36,9 @@ class AboutSymbols < Neo::Koan
|
||||
in_ruby_version("mri") do
|
||||
RubyConstant = "What is the sound of one hand clapping?"
|
||||
def test_constants_become_symbols
|
||||
all_symbols_as_strings = Symbol.all_symbols.map { |x| x.to_s }
|
||||
all_symbols = Symbol.all_symbols
|
||||
|
||||
assert_equal __(true), all_symbols_as_strings.include?(__("RubyConstant"))
|
||||
assert_equal __(true), all_symbols.include?(__(:RubyConstant))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -50,14 +50,14 @@ class AboutSymbols < Neo::Koan
|
||||
def test_symbols_with_spaces_can_be_built
|
||||
symbol = :"cats and dogs"
|
||||
|
||||
assert_equal __("cats and dogs").to_sym, symbol
|
||||
assert_equal symbol, __("cats and dogs").to_sym
|
||||
end
|
||||
|
||||
def test_symbols_with_interpolation_can_be_built
|
||||
value = "and"
|
||||
symbol = :"cats #{value} dogs"
|
||||
|
||||
assert_equal __("cats and dogs").to_sym, symbol
|
||||
assert_equal symbol, __("cats and dogs").to_sym
|
||||
end
|
||||
|
||||
def test_to_s_is_called_on_interpolated_symbols
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutToStr < Neo::Koan
|
||||
class AboutToStr < EdgeCase::Koan
|
||||
|
||||
class CanNotBeTreatedAsString
|
||||
def to_s
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
# You need to write the triangle method in the file 'triangle.rb'
|
||||
require './triangle'
|
||||
require 'triangle.rb'
|
||||
|
||||
class AboutTriangleProject < Neo::Koan
|
||||
class AboutTriangleProject < EdgeCase::Koan
|
||||
def test_equilateral_triangles_have_equal_sides
|
||||
assert_equal :equilateral, triangle(2, 2, 2)
|
||||
assert_equal :equilateral, triangle(10, 10, 10)
|
||||
@@ -22,3 +22,4 @@ class AboutTriangleProject < Neo::Koan
|
||||
assert_equal :scalene, triangle(5, 4, 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
# You need to write the triangle method in the file 'triangle.rb'
|
||||
require './triangle.rb'
|
||||
require 'triangle.rb'
|
||||
|
||||
class AboutTriangleProject2 < Neo::Koan
|
||||
class AboutTriangleProject2 < EdgeCase::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,5 +12,6 @@ class AboutTriangleProject2 < Neo::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
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/neo')
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
|
||||
class AboutTrueAndFalse < Neo::Koan
|
||||
class AboutTrueAndFalse < EdgeCase::Koan
|
||||
def truth_value(condition)
|
||||
if condition
|
||||
:true_stuff
|
||||
|
||||
47
src/array_test.rb
Normal file
47
src/array_test.rb
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
|
||||
3
src/autotest/discover.rb
Normal file
3
src/autotest/discover.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
Autotest.add_discovery do
|
||||
"rubykoan" if File.exist? 'path_to_enlightenment.rb'
|
||||
end
|
||||
24
src/autotest/rubykoan.rb
Normal file
24
src/autotest/rubykoan.rb
Normal file
@@ -0,0 +1,24 @@
|
||||
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
src/code_mash.rb
Normal file
1
src/code_mash.rb
Normal file
@@ -0,0 +1 @@
|
||||
require File.expand_path(File.dirname(__FILE__) + '/edgecase')
|
||||
@@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
# -*- ruby -*-
|
||||
|
||||
$VERBOSE = nil
|
||||
|
||||
require 'test/unit/assertions'
|
||||
begin
|
||||
require 'win32console'
|
||||
rescue LoadError
|
||||
@@ -25,10 +24,6 @@ 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
|
||||
@@ -70,7 +65,7 @@ class Object
|
||||
end
|
||||
end
|
||||
|
||||
in_ruby_version("1.9", "2", "3") do
|
||||
in_ruby_version("1.9") do
|
||||
public :method_missing
|
||||
end
|
||||
end
|
||||
@@ -88,7 +83,7 @@ class String
|
||||
end
|
||||
end
|
||||
|
||||
module Neo
|
||||
module EdgeCase
|
||||
class << self
|
||||
def simple_output
|
||||
ENV['SIMPLE_KOAN_OUTPUT'] == 'true'
|
||||
@@ -127,8 +122,6 @@ module Neo
|
||||
if ENV['ANSI_COLOR'].nil?
|
||||
if using_windows?
|
||||
using_win32console
|
||||
else
|
||||
return true
|
||||
end
|
||||
else
|
||||
ENV['ANSI_COLOR'] =~ /^(t|y)/i
|
||||
@@ -144,68 +137,20 @@ module Neo
|
||||
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
|
||||
|
||||
FailedAssertionError = Assertions::FailedAssertionError
|
||||
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
|
||||
|
||||
def initialize
|
||||
@pass_count = 0
|
||||
@@ -218,7 +163,7 @@ module Neo
|
||||
|
||||
def add_progress(prog)
|
||||
@_contents = nil
|
||||
exists = File.exist?(PROGRESS_FILE_NAME)
|
||||
exists = File.exists?(PROGRESS_FILE_NAME)
|
||||
File.open(PROGRESS_FILE_NAME,'a+') do |f|
|
||||
f.print "#{',' if exists}#{prog}"
|
||||
end
|
||||
@@ -226,7 +171,7 @@ module Neo
|
||||
|
||||
def progress
|
||||
if @_contents.nil?
|
||||
if File.exist?(PROGRESS_FILE_NAME)
|
||||
if File.exists?(PROGRESS_FILE_NAME)
|
||||
File.open(PROGRESS_FILE_NAME,'r') do |f|
|
||||
@_contents = f.read.to_s.gsub(/\s/,'').split(',')
|
||||
end
|
||||
@@ -248,7 +193,7 @@ module Neo
|
||||
@failure = step.failure
|
||||
add_progress(@pass_count)
|
||||
@observations << Color.red("#{step.koan_file}##{step.name} has damaged your karma.")
|
||||
throw :neo_exit
|
||||
throw :edgecase_exit
|
||||
end
|
||||
end
|
||||
|
||||
@@ -257,7 +202,7 @@ module Neo
|
||||
end
|
||||
|
||||
def assert_failed?
|
||||
failure.is_a?(FailedAssertionError)
|
||||
failure.is_a?(AssertionError)
|
||||
end
|
||||
|
||||
def instruct
|
||||
@@ -274,7 +219,7 @@ module Neo
|
||||
|
||||
def show_progress
|
||||
bar_width = 50
|
||||
total_tests = Neo::Koan.total_tests
|
||||
total_tests = EdgeCase::Koan.total_tests
|
||||
scale = bar_width.to_f/total_tests
|
||||
print Color.green("your path thus far [")
|
||||
happy_steps = (pass_count*scale).to_i
|
||||
@@ -285,12 +230,12 @@ module Neo
|
||||
print Color.cyan('_'*(bar_width-1-happy_steps))
|
||||
end
|
||||
print Color.green(']')
|
||||
print " #{pass_count}/#{total_tests} (#{pass_count*100/total_tests}%)"
|
||||
print " #{pass_count}/#{total_tests}"
|
||||
puts
|
||||
end
|
||||
|
||||
def end_screen
|
||||
if Neo.simple_output
|
||||
if EdgeCase.simple_output
|
||||
boring_end_screen
|
||||
else
|
||||
artistic_end_screen
|
||||
@@ -321,13 +266,13 @@ module Neo
|
||||
,:::::::::::, ::::::::::::,
|
||||
:::::::::::, ,::::::::::::
|
||||
::::::::::::: ,::::::::::::
|
||||
:::::::::::: Ruby Koans ::::::::::::
|
||||
::::::::::::#{ ruby_version },::::::::::::
|
||||
:::::::::::, , :::::::::::
|
||||
,:::::::::::::, brought to you by ,,::::::::::::
|
||||
:::::::::::: Ruby Koans ::::::::::::,
|
||||
::::::::::::#{ ruby_version },::::::::::::,
|
||||
:::::::::::, , ::::::::::::
|
||||
,:::::::::::::, brought to you by ,,::::::::::::,
|
||||
:::::::::::::: ,::::::::::::
|
||||
::::::::::::::, ,:::::::::::::
|
||||
::::::::::::, Neo Software Artisans , ::::::::::::
|
||||
::::::::::::, EdgeCase Software Artisans , ::::::::::::
|
||||
:,::::::::: :::: :::::::::::::
|
||||
,::::::::::: ,: ,,:::::::::::::,
|
||||
:::::::::::: ,::::::::::::::,
|
||||
@@ -362,7 +307,11 @@ ENDTEXT
|
||||
puts Color.red(indent(failure.message).join)
|
||||
puts
|
||||
puts "Please meditate on the following code:"
|
||||
puts embolden_first_line_only(indent(find_interesting_lines(failure.backtrace)))
|
||||
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
|
||||
end
|
||||
|
||||
@@ -385,7 +334,7 @@ ENDTEXT
|
||||
|
||||
def find_interesting_lines(backtrace)
|
||||
backtrace.reject { |line|
|
||||
line =~ /neo\.rb/
|
||||
line =~ /test\/unit\/|edgecase\.rb|minitest/
|
||||
}
|
||||
end
|
||||
|
||||
@@ -415,7 +364,7 @@ ENDTEXT
|
||||
end
|
||||
|
||||
class Koan
|
||||
include Assertions
|
||||
include Test::Unit::Assertions
|
||||
|
||||
attr_reader :name, :failure, :koan_count, :step_count, :koan_file
|
||||
|
||||
@@ -445,19 +394,19 @@ ENDTEXT
|
||||
setup
|
||||
begin
|
||||
send(name)
|
||||
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
|
||||
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
|
||||
failed(ex)
|
||||
ensure
|
||||
begin
|
||||
teardown
|
||||
rescue StandardError, Neo::Sensei::FailedAssertionError => ex
|
||||
rescue StandardError, EdgeCase::Sensei::AssertionError => ex
|
||||
failed(ex) if passed?
|
||||
end
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
# Class methods for the Neo test suite.
|
||||
# Class methods for the EdgeCase test suite.
|
||||
class << self
|
||||
def inherited(subclass)
|
||||
subclasses << subclass
|
||||
@@ -514,7 +463,7 @@ ENDTEXT
|
||||
|
||||
class ThePath
|
||||
def walk
|
||||
sensei = Neo::Sensei.new
|
||||
sensei = EdgeCase::Sensei.new
|
||||
each_step do |step|
|
||||
sensei.observe(step.meditate)
|
||||
end
|
||||
@@ -522,9 +471,9 @@ ENDTEXT
|
||||
end
|
||||
|
||||
def each_step
|
||||
catch(:neo_exit) {
|
||||
catch(:edgecase_exit) {
|
||||
step_count = 0
|
||||
Neo::Koan.subclasses.each_with_index do |koan,koan_index|
|
||||
EdgeCase::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
|
||||
@@ -536,6 +485,6 @@ ENDTEXT
|
||||
end
|
||||
|
||||
END {
|
||||
Neo::Koan.command_line(ARGV)
|
||||
Neo::ThePath.new.walk
|
||||
EdgeCase::Koan.command_line(ARGV)
|
||||
EdgeCase::ThePath.new.walk
|
||||
}
|
||||
11
src/first_test.rb
Normal file
11
src/first_test.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
require 'test/unit'
|
||||
|
||||
class TestSomething < Test::Unit::TestCase
|
||||
def test_assert
|
||||
assert true
|
||||
assert_equal 1, 1
|
||||
assert_equal 1, 1.0
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
watch( '.*\.rb' ) do
|
||||
system 'rake'
|
||||
end
|
||||
@@ -3,21 +3,18 @@
|
||||
$LOAD_PATH << File.dirname(__FILE__)
|
||||
|
||||
require 'about_asserts'
|
||||
require 'about_true_and_false'
|
||||
require 'about_strings'
|
||||
require 'about_symbols'
|
||||
require 'about_nil'
|
||||
require 'about_objects'
|
||||
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_strings'
|
||||
require 'about_symbols'
|
||||
require 'about_regular_expressions'
|
||||
require 'about_methods'
|
||||
require 'about_constants'
|
||||
require 'about_control_statements'
|
||||
require 'about_true_and_false'
|
||||
require 'about_triangle_project'
|
||||
require 'about_exceptions'
|
||||
require 'about_triangle_project_2'
|
||||
@@ -38,7 +35,4 @@ 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'
|
||||
|
||||
7
src/test_helper.rb
Normal file
7
src/test_helper.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require 'test/unit'
|
||||
|
||||
def __
|
||||
"FILL ME IN"
|
||||
end
|
||||
|
||||
EdgeCase = Test::Unit
|
||||
@@ -1,26 +0,0 @@
|
||||
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
|
||||
@@ -1,4 +0,0 @@
|
||||
require "minitest/autorun"
|
||||
require "rake"
|
||||
|
||||
Rake.application.load_rakefile
|
||||
Reference in New Issue
Block a user