mirror of
https://github.com/edgecase/ruby_koans.git
synced 2026-04-17 07:53:20 -04:00
Compare commits
1 Commits
rubykoans-
...
more_jruby
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e26666280c |
@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
|
|
||||||
assert_equal __, result
|
assert_equal __, result
|
||||||
|
|
||||||
assert_equal __, ex.is_a?(StandardError), "Should be a Standard Error"
|
assert ex.is_a?(___), "Failure message."
|
||||||
assert_equal __, ex.is_a?(RuntimeError), "Should be a Runtime Error"
|
assert ex.is_a?(___), "Failure message."
|
||||||
|
|
||||||
assert RuntimeError.ancestors.include?(StandardError),
|
assert RuntimeError.ancestors.include?(StandardError),
|
||||||
"RuntimeError is a subclass of StandardError"
|
"RuntimeError is a subclass of StandardError"
|
||||||
|
|||||||
@@ -95,6 +95,21 @@ class AboutJavaInterop < EdgeCase::Koan
|
|||||||
assert_equal __, java_array.toString.is_a?(java.lang.String)
|
assert_equal __, java_array.toString.is_a?(java.lang.String)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_some_ruby_objects_can_be_coerced_to_java
|
||||||
|
assert_equal __, "ruby string".to_java.class
|
||||||
|
assert_equal __, 1.to_java.class
|
||||||
|
assert_equal __, 9.32.to_java.class
|
||||||
|
assert_equal __, false.to_java.class
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_some_ruby_objects_can_NOT_be_coerced_to_java
|
||||||
|
[[], {}, Object.new].each do |ruby_object|
|
||||||
|
assert_raise(___) do
|
||||||
|
ruby_object.to_java_class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_java_collections_are_enumerable
|
def test_java_collections_are_enumerable
|
||||||
java_array = java.util.ArrayList.new
|
java_array = java.util.ArrayList.new
|
||||||
java_array << "one" << "two" << "three"
|
java_array << "one" << "two" << "three"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
assert_equal symbol, __.to_sym
|
assert_equal symbol, __.to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_with_interpolation_can_be_built
|
def test_symbols_with_spaces_can_be_built
|
||||||
value = "and"
|
value = "and"
|
||||||
symbol = :"cats #{value} dogs"
|
symbol = :"cats #{value} dogs"
|
||||||
|
|
||||||
|
|||||||
@@ -93,29 +93,16 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(string, color_value)
|
def colorize(string, color_value)
|
||||||
if use_colors?
|
if ENV['NO_COLOR']
|
||||||
color(color_value) + string + color(COLORS[:clear])
|
|
||||||
else
|
|
||||||
string
|
string
|
||||||
|
else
|
||||||
|
color(color_value) + string + color(COLORS[:clear])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def color(color_value)
|
def color(color_value)
|
||||||
"\e[#{color_value}m"
|
"\e[#{color_value}m"
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_colors?
|
|
||||||
return false if ENV['NO_COLOR']
|
|
||||||
if ENV['ANSI_COLOR'].nil?
|
|
||||||
! using_windows?
|
|
||||||
else
|
|
||||||
ENV['ANSI_COLOR'] =~ /^(t|y)/i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def using_windows?
|
|
||||||
File::ALT_SEPARATOR
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Sensei
|
class Sensei
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ class AboutExceptions < EdgeCase::Koan
|
|||||||
|
|
||||||
assert_equal __(:exception_handled), result
|
assert_equal __(:exception_handled), result
|
||||||
|
|
||||||
assert_equal __(true), ex.is_a?(StandardError), "Should be a Standard Error"
|
assert ex.is_a?(___(StandardError)), "Failure message."
|
||||||
assert_equal __(true), ex.is_a?(RuntimeError), "Should be a Runtime Error"
|
assert ex.is_a?(___(RuntimeError)), "Failure message."
|
||||||
|
|
||||||
assert RuntimeError.ancestors.include?(StandardError), # __
|
assert RuntimeError.ancestors.include?(StandardError), # __
|
||||||
"RuntimeError is a subclass of StandardError"
|
"RuntimeError is a subclass of StandardError"
|
||||||
|
|||||||
@@ -95,6 +95,21 @@ class AboutJavaInterop < EdgeCase::Koan
|
|||||||
assert_equal __(false), java_array.toString.is_a?(java.lang.String)
|
assert_equal __(false), java_array.toString.is_a?(java.lang.String)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_some_ruby_objects_can_be_coerced_to_java
|
||||||
|
assert_equal __(Java::JavaLang::String), "ruby string".to_java.class
|
||||||
|
assert_equal __(Java::JavaLang::Long), 1.to_java.class
|
||||||
|
assert_equal __(Java::JavaLang::Double), 9.32.to_java.class
|
||||||
|
assert_equal __(Java::JavaLang::Boolean), false.to_java.class
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_some_ruby_objects_can_NOT_be_coerced_to_java
|
||||||
|
[[], {}, Object.new].each do |ruby_object|
|
||||||
|
assert_raise(___(NoMethodError)) do
|
||||||
|
ruby_object.to_java_class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_java_collections_are_enumerable
|
def test_java_collections_are_enumerable
|
||||||
java_array = java.util.ArrayList.new
|
java_array = java.util.ArrayList.new
|
||||||
java_array << "one" << "two" << "three"
|
java_array << "one" << "two" << "three"
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class AboutSymbols < EdgeCase::Koan
|
|||||||
assert_equal symbol, __("cats and dogs").to_sym
|
assert_equal symbol, __("cats and dogs").to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_symbols_with_interpolation_can_be_built
|
def test_symbols_with_spaces_can_be_built
|
||||||
value = "and"
|
value = "and"
|
||||||
symbol = :"cats #{value} dogs"
|
symbol = :"cats #{value} dogs"
|
||||||
|
|
||||||
|
|||||||
@@ -93,29 +93,16 @@ module EdgeCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def colorize(string, color_value)
|
def colorize(string, color_value)
|
||||||
if use_colors?
|
if ENV['NO_COLOR']
|
||||||
color(color_value) + string + color(COLORS[:clear])
|
|
||||||
else
|
|
||||||
string
|
string
|
||||||
|
else
|
||||||
|
color(color_value) + string + color(COLORS[:clear])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def color(color_value)
|
def color(color_value)
|
||||||
"\e[#{color_value}m"
|
"\e[#{color_value}m"
|
||||||
end
|
end
|
||||||
|
|
||||||
def use_colors?
|
|
||||||
return false if ENV['NO_COLOR']
|
|
||||||
if ENV['ANSI_COLOR'].nil?
|
|
||||||
! using_windows?
|
|
||||||
else
|
|
||||||
ENV['ANSI_COLOR'] =~ /^(t|y)/i
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def using_windows?
|
|
||||||
File::ALT_SEPARATOR
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
class Sensei
|
class Sensei
|
||||||
|
|||||||
Reference in New Issue
Block a user