[macruby-changes] [4440] MacRuby/trunk/spec/frozen
source_changes at macosforge.org
source_changes at macosforge.org
Sun Aug 22 06:15:36 PDT 2010
Revision: 4440
http://trac.macosforge.org/projects/ruby/changeset/4440
Author: eloy.de.enige at gmail.com
Date: 2010-08-22 06:15:35 -0700 (Sun, 22 Aug 2010)
Log Message:
-----------
Update RubySpec to 0bbe4d3ddcb78c5c1bf12821acfe167f868715e9
Modified Paths:
--------------
MacRuby/trunk/spec/frozen/command_line/dash_d_spec.rb
MacRuby/trunk/spec/frozen/command_line/dash_r_spec.rb
MacRuby/trunk/spec/frozen/command_line/dash_upper_i_spec.rb
MacRuby/trunk/spec/frozen/command_line/dash_upper_w_spec.rb
MacRuby/trunk/spec/frozen/command_line/dash_v_spec.rb
MacRuby/trunk/spec/frozen/command_line/dash_w_spec.rb
MacRuby/trunk/spec/frozen/command_line/shared/verbose.rb
MacRuby/trunk/spec/frozen/core/array/combination_spec.rb
MacRuby/trunk/spec/frozen/core/array/delete_if_spec.rb
MacRuby/trunk/spec/frozen/core/array/element_reference_spec.rb
MacRuby/trunk/spec/frozen/core/array/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/array/join_spec.rb
MacRuby/trunk/spec/frozen/core/array/multiply_spec.rb
MacRuby/trunk/spec/frozen/core/array/new_spec.rb
MacRuby/trunk/spec/frozen/core/array/pack_spec.rb
MacRuby/trunk/spec/frozen/core/array/product_spec.rb
MacRuby/trunk/spec/frozen/core/array/reject_spec.rb
MacRuby/trunk/spec/frozen/core/array/shared/slice.rb
MacRuby/trunk/spec/frozen/core/array/sort_by_spec.rb
MacRuby/trunk/spec/frozen/core/array/sort_spec.rb
MacRuby/trunk/spec/frozen/core/array/to_a_spec.rb
MacRuby/trunk/spec/frozen/core/bignum/divmod_spec.rb
MacRuby/trunk/spec/frozen/core/bignum/left_shift_spec.rb
MacRuby/trunk/spec/frozen/core/bignum/right_shift_spec.rb
MacRuby/trunk/spec/frozen/core/class/new_spec.rb
MacRuby/trunk/spec/frozen/core/dir/shared/open.rb
MacRuby/trunk/spec/frozen/core/enumerable/each_entry_spec.rb
MacRuby/trunk/spec/frozen/core/enumerable/slice_before_spec.rb
MacRuby/trunk/spec/frozen/core/env/shared/store.rb
MacRuby/trunk/spec/frozen/core/file/expand_path_spec.rb
MacRuby/trunk/spec/frozen/core/file/size_spec.rb
MacRuby/trunk/spec/frozen/core/fixnum/element_reference_spec.rb
MacRuby/trunk/spec/frozen/core/fixnum/left_shift_spec.rb
MacRuby/trunk/spec/frozen/core/fixnum/right_shift_spec.rb
MacRuby/trunk/spec/frozen/core/float/to_s_spec.rb
MacRuby/trunk/spec/frozen/core/hash/element_reference_spec.rb
MacRuby/trunk/spec/frozen/core/hash/merge_spec.rb
MacRuby/trunk/spec/frozen/core/hash/shared/key.rb
MacRuby/trunk/spec/frozen/core/hash/shared/replace.rb
MacRuby/trunk/spec/frozen/core/hash/shared/store.rb
MacRuby/trunk/spec/frozen/core/io/open_spec.rb
MacRuby/trunk/spec/frozen/core/io/reopen_spec.rb
MacRuby/trunk/spec/frozen/core/io/select_spec.rb
MacRuby/trunk/spec/frozen/core/io/ungetc_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/Array_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/caller_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/kernel/instance_eval_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/remove_instance_variable_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/respond_to_missing_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/respond_to_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/spawn_spec.rb
MacRuby/trunk/spec/frozen/core/kernel/system_spec.rb
MacRuby/trunk/spec/frozen/core/math/log2_spec.rb
MacRuby/trunk/spec/frozen/core/math/log_spec.rb
MacRuby/trunk/spec/frozen/core/method/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/method/to_proc_spec.rb
MacRuby/trunk/spec/frozen/core/module/alias_method_spec.rb
MacRuby/trunk/spec/frozen/core/module/autoload_spec.rb
MacRuby/trunk/spec/frozen/core/module/extend_object_spec.rb
MacRuby/trunk/spec/frozen/core/module/fixtures/autoload_k.rb
MacRuby/trunk/spec/frozen/core/module/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/module/include_spec.rb
MacRuby/trunk/spec/frozen/core/module/method_defined_spec.rb
MacRuby/trunk/spec/frozen/core/module/name_spec.rb
MacRuby/trunk/spec/frozen/core/module/private_spec.rb
MacRuby/trunk/spec/frozen/core/module/protected_spec.rb
MacRuby/trunk/spec/frozen/core/module/public_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/coerce_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/comparison_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/div_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/divmod_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/eql_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/numeric/floor_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/initialize_copy_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/integer_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/modulo_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/nonzero_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/quo_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/remainder_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/round_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/shared/abs.rb
MacRuby/trunk/spec/frozen/core/numeric/singleton_method_added_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/step_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/to_int_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/truncate_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/uplus_spec.rb
MacRuby/trunk/spec/frozen/core/numeric/zero_spec.rb
MacRuby/trunk/spec/frozen/core/regexp/inspect_spec.rb
MacRuby/trunk/spec/frozen/core/signal/trap_spec.rb
MacRuby/trunk/spec/frozen/core/string/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/string/inspect_spec_disabled.rb
MacRuby/trunk/spec/frozen/core/string/split_spec.rb
MacRuby/trunk/spec/frozen/core/string/sub_spec.rb
MacRuby/trunk/spec/frozen/core/string/to_i_spec.rb
MacRuby/trunk/spec/frozen/core/string/unpack_spec.rb
MacRuby/trunk/spec/frozen/core/struct/each_pair_spec.rb
MacRuby/trunk/spec/frozen/core/struct/each_spec.rb
MacRuby/trunk/spec/frozen/core/struct/element_reference_spec.rb
MacRuby/trunk/spec/frozen/core/struct/element_set_spec.rb
MacRuby/trunk/spec/frozen/core/struct/eql_spec.rb
MacRuby/trunk/spec/frozen/core/struct/fixtures/classes.rb
MacRuby/trunk/spec/frozen/core/struct/hash_spec.rb
MacRuby/trunk/spec/frozen/core/struct/initialize_spec.rb
MacRuby/trunk/spec/frozen/core/struct/inspect_spec.rb
MacRuby/trunk/spec/frozen/core/struct/length_spec.rb
MacRuby/trunk/spec/frozen/core/struct/members_spec.rb
MacRuby/trunk/spec/frozen/core/struct/new_spec.rb
MacRuby/trunk/spec/frozen/core/struct/select_spec.rb
MacRuby/trunk/spec/frozen/core/struct/shared/equal_value.rb
MacRuby/trunk/spec/frozen/core/struct/size_spec.rb
MacRuby/trunk/spec/frozen/core/struct/struct_spec.rb
MacRuby/trunk/spec/frozen/core/struct/to_a_spec.rb
MacRuby/trunk/spec/frozen/core/struct/to_s_spec.rb
MacRuby/trunk/spec/frozen/core/struct/values_at_spec.rb
MacRuby/trunk/spec/frozen/core/struct/values_spec.rb
MacRuby/trunk/spec/frozen/core/time/eql_spec.rb
MacRuby/trunk/spec/frozen/core/time/shared/gmt_offset.rb
MacRuby/trunk/spec/frozen/language/constants_spec.rb
MacRuby/trunk/spec/frozen/language/defined_spec.rb
MacRuby/trunk/spec/frozen/language/encoding_spec.rb
MacRuby/trunk/spec/frozen/language/ensure_spec.rb
MacRuby/trunk/spec/frozen/language/file_spec.rb
MacRuby/trunk/spec/frozen/language/fixtures/super.rb
MacRuby/trunk/spec/frozen/language/line_spec.rb
MacRuby/trunk/spec/frozen/language/module_spec.rb
MacRuby/trunk/spec/frozen/language/next_spec.rb
MacRuby/trunk/spec/frozen/language/predefined_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/anchors_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/back-references_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/character_classes_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/encoding_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/escapes_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/grouping_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/interpolation_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/modifiers_spec.rb
MacRuby/trunk/spec/frozen/language/regexp/repetition_spec.rb
MacRuby/trunk/spec/frozen/language/rescue_spec.rb
MacRuby/trunk/spec/frozen/language/super_spec.rb
MacRuby/trunk/spec/frozen/language/symbol_spec.rb
MacRuby/trunk/spec/frozen/library/complex/math/atanh_spec.rb
MacRuby/trunk/spec/frozen/library/date/parse_spec.rb
MacRuby/trunk/spec/frozen/library/delegate/fixtures/classes.rb
MacRuby/trunk/spec/frozen/library/digest/sha1/file_spec.rb
MacRuby/trunk/spec/frozen/library/digest/sha256/file_spec.rb
MacRuby/trunk/spec/frozen/library/digest/sha384/file_spec.rb
MacRuby/trunk/spec/frozen/library/digest/sha512/file_spec.rb
MacRuby/trunk/spec/frozen/library/drb/stop_service_spec.rb
MacRuby/trunk/spec/frozen/library/fiber/resume_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/build_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/each_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/each_with_index_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/empty_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/exponent_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/inv_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/inverse_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/minor_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/new_spec.rb
MacRuby/trunk/spec/frozen/library/matrix/shared/equal_value.rb
MacRuby/trunk/spec/frozen/library/matrix/vector/each2_spec.rb
MacRuby/trunk/spec/frozen/library/ping/pingecho_spec.rb
MacRuby/trunk/spec/frozen/library/set/reject_spec.rb
MacRuby/trunk/spec/frozen/library/socket/basicsocket/do_not_reverse_lookup_spec.rb
MacRuby/trunk/spec/frozen/library/socket/basicsocket/for_fd_spec.rb
MacRuby/trunk/spec/frozen/library/socket/ipsocket/addr_spec.rb
MacRuby/trunk/spec/frozen/library/socket/ipsocket/peeraddr_spec.rb
MacRuby/trunk/spec/frozen/library/socket/socket/getaddrinfo_spec.rb
MacRuby/trunk/spec/frozen/library/socket/socket/getnameinfo_spec.rb
MacRuby/trunk/spec/frozen/library/socket/tcpserver/accept_nonblock_spec.rb
MacRuby/trunk/spec/frozen/library/socket/tcpsocket/shared/new.rb
MacRuby/trunk/spec/frozen/library/socket/udpsocket/bind_spec.rb
MacRuby/trunk/spec/frozen/library/uri/join_spec.rb
MacRuby/trunk/spec/frozen/library/uri/uri_spec.rb
MacRuby/trunk/spec/frozen/shared/file/size.rb
MacRuby/trunk/spec/frozen/upstream
Removed Paths:
-------------
MacRuby/trunk/spec/frozen/core/dir/new_spec.rb
MacRuby/trunk/spec/frozen/language/else_spec.rb
MacRuby/trunk/spec/frozen/language/false_spec.rb
MacRuby/trunk/spec/frozen/language/nil_spec.rb
MacRuby/trunk/spec/frozen/language/self_spec.rb
MacRuby/trunk/spec/frozen/language/shared/pseudo_variable.rb
MacRuby/trunk/spec/frozen/language/true_spec.rb
MacRuby/trunk/spec/frozen/library/delegate/frozen_spec.rb
MacRuby/trunk/spec/frozen/library/delegate/marshal_spec.rb
MacRuby/trunk/spec/frozen/library/delegate/method_spec.rb
MacRuby/trunk/spec/frozen/library/delegate/send_spec.rb
MacRuby/trunk/spec/frozen/library/uri/route_to.rb
MacRuby/trunk/spec/frozen/shared/array/join.rb
Modified: MacRuby/trunk/spec/frozen/command_line/dash_d_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_d_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_d_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)
describe "The -d command line option" do
+ before :each do
+ @script = fixture __FILE__, "debug.rb"
+ end
+
it "sets $DEBUG to true" do
- ruby_exe("fixtures/debug.rb", :options => "-d", :dir => File.dirname(__FILE__)).chomp.should == "true"
+ ruby_exe(@script, :options => "-d", :args => "2> #{dev_null()}").chomp.should == "true"
end
end
Modified: MacRuby/trunk/spec/frozen/command_line/dash_r_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_r_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_r_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,13 @@
require File.expand_path('../../spec_helper', __FILE__)
describe "The -r command line option" do
+ before :each do
+ @script = fixture __FILE__, "require.rb"
+ @test_file = fixture __FILE__, "test_file"
+ end
+
it "requires the specified file" do
- ruby_exe("fixtures/require.rb", :options => "-r ./fixtures/test_file", :dir => File.dirname(__FILE__)).chomp.should include("fixtures/test_file.rb")
+ result = ruby_exe(@script, :options => "-r #{@test_file}")
+ result.should include(@test_file + ".rb")
end
end
Modified: MacRuby/trunk/spec/frozen/command_line/dash_upper_i_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_upper_i_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_upper_i_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)
describe "The -I command line option" do
+ before :each do
+ @script = fixture __FILE__, "loadpath.rb"
+ end
+
it "adds the path to the load path ($:)" do
- ruby_exe("fixtures/loadpath.rb", :options => "-I fixtures", :dir => File.dirname(__FILE__)).chomp.should include("fixtures")
+ ruby_exe(@script, :options => "-I fixtures").should include("fixtures")
end
end
Modified: MacRuby/trunk/spec/frozen/command_line/dash_upper_w_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_upper_w_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_upper_w_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,15 +2,19 @@
require File.expand_path('../shared/verbose', __FILE__)
describe "The -W command line option" do
+ before :each do
+ @script = fixture __FILE__, "verbose.rb"
+ end
+
it "with 0 sets $VERBOSE to nil" do
- ruby_exe("fixtures/verbose.rb", :options => "-W0", :dir => File.dirname(__FILE__)).chomp.should == "nil"
+ ruby_exe(@script, :options => "-W0").chomp.should == "nil"
end
it "with 1 sets $VERBOSE to false" do
- ruby_exe("fixtures/verbose.rb", :options => "-W1", :dir => File.dirname(__FILE__)).chomp.should == "false"
+ ruby_exe(@script, :options => "-W1").chomp.should == "false"
end
end
describe "The -W command line option with 2" do
- it_behaves_like "sets $VERBOSE to true", "-W2"
+ it_behaves_like :command_line_verbose, "-W2"
end
Modified: MacRuby/trunk/spec/frozen/command_line/dash_v_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_v_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_v_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,5 +2,5 @@
require File.expand_path('../shared/verbose', __FILE__)
describe "The -v command line option" do
- it_behaves_like "sets $VERBOSE to true", "-v"
+ it_behaves_like :command_line_verbose, "-v"
end
Modified: MacRuby/trunk/spec/frozen/command_line/dash_w_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/dash_w_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/dash_w_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,5 +2,5 @@
require File.expand_path('../shared/verbose', __FILE__)
describe "The -w command line option" do
- it_behaves_like "sets $VERBOSE to true", "-w"
+ it_behaves_like :command_line_verbose, "-w"
end
Modified: MacRuby/trunk/spec/frozen/command_line/shared/verbose.rb
===================================================================
--- MacRuby/trunk/spec/frozen/command_line/shared/verbose.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/command_line/shared/verbose.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,9 @@
-describe "sets $VERBOSE to true", :shared => true do
+describe :command_line_verbose, :shared => true do
+ before :each do
+ @script = fixture __FILE__, "verbose.rb"
+ end
+
it "sets $VERBOSE to true" do
- ruby_exe("fixtures/verbose.rb", :options => @method, :dir => "#{File.dirname(__FILE__)}/..").chomp.match(/true$/).should_not == nil
+ ruby_exe(@script, :options => @method).chomp.split.last.should == "true"
end
end
Modified: MacRuby/trunk/spec/frozen/core/array/combination_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/combination_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/combination_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -40,7 +40,7 @@
end
it "yields a partition consisting of only singletons" do
- @array.combination(1).to_a.should == [[1],[2],[3],[4]]
+ @array.combination(1).to_a.sort.should == [[1],[2],[3],[4]]
end
end
end
Modified: MacRuby/trunk/spec/frozen/core/array/delete_if_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/delete_if_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/delete_if_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -19,6 +19,12 @@
it_behaves_like :enumeratorize, :delete_if
+ it "returns self when called on an Array emptied with #shift" do
+ array = [1]
+ array.shift
+ array.delete_if { |x| true }.should equal(array)
+ end
+
ruby_version_is '1.8.7' do
it "returns an Enumerator if no block given, and the enumerator can modify the original array" do
enum = @a.delete_if
Modified: MacRuby/trunk/spec/frozen/core/array/element_reference_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/element_reference_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/element_reference_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -36,9 +36,19 @@
EOS
end
end
-
- it "returns an instance of the subtype when called on an Array subclass" do
- ArraySub = Class.new Array
- ArraySub[1,2].should be_kind_of(ArraySub)
+
+ describe "with a subclass of Array" do
+ before :each do
+ ScratchPad.clear
+ end
+
+ it "returns an instance of the subclass" do
+ ArraySpecs::MyArray[1, 2, 3].should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "does not call #initialize on the subclass instance" do
+ ArraySpecs::MyArray[1, 2, 3].should == [1, 2, 3]
+ ScratchPad.recorded.should be_nil
+ end
end
end
Modified: MacRuby/trunk/spec/frozen/core/array/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,3 +1,13 @@
+class Object
+ # This helper is defined here rather than in MSpec because
+ # it is only used in #pack specs.
+ def pack_format(count=nil, repeat=nil)
+ format = "#{instance_variable_get(:@method)}#{count}"
+ format *= repeat if repeat
+ format
+ end
+end
+
module ArraySpecs
not_compliant_on :rubinius do
def self.max_32bit_size
@@ -44,7 +54,15 @@
a
end
- class MyArray < Array; end
+ class MyArray < Array
+ # The #initialize method has a different signature than Array to help
+ # catch places in the specs that do not assert the #initialize is not
+ # called when Array methods make new instances.
+ def initialize(a, b)
+ self << a << b
+ ScratchPad.record :my_array_initialize
+ end
+ end
class Sexp < Array
def initialize(*args)
@@ -153,4 +171,366 @@
args
end
end
+
+ LargeArray = ["test_create_table_with_force_true_does_not_drop_nonexisting_table",
+ "test_add_table",
+ "assert_difference",
+ "assert_operator",
+ "instance_variables",
+ "class",
+ "instance_variable_get",
+ "__class__",
+ "expects",
+ "assert_no_difference",
+ "name",
+ "assert_blank",
+ "assert_not_same",
+ "is_a?",
+ "test_add_table_with_decimals",
+ "test_create_table_with_timestamps_should_create_datetime_columns",
+ "assert_present",
+ "assert_no_match",
+ "__instance_of__",
+ "assert_deprecated",
+ "assert",
+ "assert_throws",
+ "kind_of?",
+ "try",
+ "__instance_variable_get__",
+ "object_id",
+ "timeout",
+ "instance_variable_set",
+ "assert_nothing_thrown",
+ "__instance_variable_set__",
+ "copy_object",
+ "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
+ "assert_not_deprecated",
+ "assert_in_delta",
+ "id",
+ "copy_metaclass",
+ "test_create_table_without_a_block",
+ "dup",
+ "assert_not_nil",
+ "send",
+ "__instance_variables__",
+ "to_sql",
+ "mock",
+ "assert_send",
+ "instance_variable_defined?",
+ "clone",
+ "require",
+ "test_migrator",
+ "__instance_variable_defined_eh__",
+ "frozen?",
+ "test_add_column_not_null_with_default",
+ "freeze",
+ "test_migrator_one_up",
+ "test_migrator_one_down",
+ "singleton_methods",
+ "method_exists?",
+ "create_fixtures",
+ "test_migrator_one_up_one_down",
+ "test_native_decimal_insert_manual_vs_automatic",
+ "instance_exec",
+ "__is_a__",
+ "test_migrator_double_up",
+ "stub",
+ "private_methods",
+ "stubs",
+ "test_migrator_double_down",
+ "fixture_path",
+ "private_singleton_methods",
+ "stub_everything",
+ "test_migrator_one_up_with_exception_and_rollback",
+ "sequence",
+ "protected_methods",
+ "enum_for",
+ "test_finds_migrations",
+ "run_before_mocha",
+ "states",
+ "protected_singleton_methods",
+ "to_json",
+ "instance_values",
+ "==",
+ "mocha_setup",
+ "public_methods",
+ "test_finds_pending_migrations",
+ "mocha_verify",
+ "assert_kind_of",
+ "===",
+ "=~",
+ "test_relative_migrations",
+ "mocha_teardown",
+ "gem",
+ "mocha",
+ "test_only_loads_pending_migrations",
+ "test_add_column_with_precision_and_scale",
+ "require_or_load",
+ "eql?",
+ "require_dependency",
+ "test_native_types",
+ "test_target_version_zero_should_run_only_once",
+ "extend",
+ "to_matcher",
+ "unloadable",
+ "require_association",
+ "hash",
+ "__id__",
+ "load_dependency",
+ "equals",
+ "test_migrator_db_has_no_schema_migrations_table",
+ "test_migrator_verbosity",
+ "kind_of",
+ "to_yaml",
+ "to_bool",
+ "test_migrator_verbosity_off",
+ "taint",
+ "test_migrator_going_down_due_to_version_target",
+ "tainted?",
+ "mocha_inspect",
+ "test_migrator_rollback",
+ "vim",
+ "untaint",
+ "taguri=",
+ "test_migrator_forward",
+ "test_schema_migrations_table_name",
+ "test_proper_table_name",
+ "all_of",
+ "test_add_drop_table_with_prefix_and_suffix",
+ "_setup_callbacks",
+ "setup",
+ "Not",
+ "test_create_table_with_binary_column",
+ "assert_not_equal",
+ "enable_warnings",
+ "acts_like?",
+ "Rational",
+ "_removed_setup_callbacks",
+ "Table",
+ "bind",
+ "any_of",
+ "__method__",
+ "test_migrator_with_duplicates",
+ "_teardown_callbacks",
+ "method",
+ "test_migrator_with_duplicate_names",
+ "_removed_teardown_callbacks",
+ "any_parameters",
+ "test_migrator_with_missing_version_numbers",
+ "test_add_remove_single_field_using_string_arguments",
+ "test_create_table_with_custom_sequence_name",
+ "test_add_remove_single_field_using_symbol_arguments",
+ "_one_time_conditions_valid_14?",
+ "_one_time_conditions_valid_16?",
+ "run_callbacks",
+ "anything",
+ "silence_warnings",
+ "instance_variable_names",
+ "_fixture_path",
+ "copy_instance_variables_from",
+ "fixture_path?",
+ "has_entry",
+ "__marshal__",
+ "_fixture_table_names",
+ "__kind_of__",
+ "fixture_table_names?",
+ "test_add_rename",
+ "assert_equal",
+ "_fixture_class_names",
+ "fixture_class_names?",
+ "has_entries",
+ "_use_transactional_fixtures",
+ "people",
+ "test_rename_column_using_symbol_arguments",
+ "use_transactional_fixtures?",
+ "instance_eval",
+ "blank?",
+ "with_warnings",
+ "__nil__",
+ "load",
+ "metaclass",
+ "_use_instantiated_fixtures",
+ "has_key",
+ "class_eval",
+ "present?",
+ "test_rename_column",
+ "teardown",
+ "use_instantiated_fixtures?",
+ "method_name",
+ "silence_stderr",
+ "presence",
+ "test_rename_column_preserves_default_value_not_null",
+ "silence_stream",
+ "_pre_loaded_fixtures",
+ "__metaclass__",
+ "__fixnum__",
+ "pre_loaded_fixtures?",
+ "has_value",
+ "suppress",
+ "to_yaml_properties",
+ "test_rename_nonexistent_column",
+ "test_add_index",
+ "includes",
+ "find_correlate_in",
+ "equality_predicate_sql",
+ "assert_nothing_raised",
+ "let",
+ "not_predicate_sql",
+ "test_rename_column_with_sql_reserved_word",
+ "singleton_class",
+ "test_rename_column_with_an_index",
+ "display",
+ "taguri",
+ "to_yaml_style",
+ "test_remove_column_with_index",
+ "size",
+ "current_adapter?",
+ "test_remove_column_with_multi_column_index",
+ "respond_to?",
+ "test_change_type_of_not_null_column",
+ "is_a",
+ "to_a",
+ "test_rename_table_for_sqlite_should_work_with_reserved_words",
+ "require_library_or_gem",
+ "setup_fixtures",
+ "equal?",
+ "teardown_fixtures",
+ "nil?",
+ "fixture_table_names",
+ "fixture_class_names",
+ "test_create_table_without_id",
+ "use_transactional_fixtures",
+ "test_add_column_with_primary_key_attribute",
+ "repair_validations",
+ "use_instantiated_fixtures",
+ "instance_of?",
+ "test_create_table_adds_id",
+ "test_rename_table",
+ "pre_loaded_fixtures",
+ "to_enum",
+ "test_create_table_with_not_null_column",
+ "instance_of",
+ "test_change_column_nullability",
+ "optionally",
+ "test_rename_table_with_an_index",
+ "run",
+ "test_change_column",
+ "default_test",
+ "assert_raise",
+ "test_create_table_with_defaults",
+ "assert_nil",
+ "flunk",
+ "regexp_matches",
+ "duplicable?",
+ "reset_mocha",
+ "stubba_method",
+ "filter_backtrace",
+ "test_create_table_with_limits",
+ "responds_with",
+ "stubba_object",
+ "test_change_column_with_nil_default",
+ "assert_block",
+ "__show__",
+ "assert_date_from_db",
+ "__respond_to_eh__",
+ "run_in_transaction?",
+ "inspect",
+ "assert_sql",
+ "test_change_column_with_new_default",
+ "yaml_equivalent",
+ "build_message",
+ "to_s",
+ "test_change_column_default",
+ "assert_queries",
+ "pending",
+ "as_json",
+ "assert_no_queries",
+ "test_change_column_quotes_column_names",
+ "assert_match",
+ "test_keeping_default_and_notnull_constaint_on_change",
+ "methods",
+ "connection_allow_concurrency_setup",
+ "connection_allow_concurrency_teardown",
+ "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
+ "__send__",
+ "make_connection",
+ "assert_raises",
+ "tap",
+ "with_kcode",
+ "assert_instance_of",
+ "test_create_table_with_primary_key_prefix_as_table_name",
+ "assert_respond_to",
+ "test_change_column_default_to_null",
+ "assert_same",
+ "__extend__"]
+
+ LargeTestArraySorted = ["test_add_column_not_null_with_default",
+ "test_add_column_with_precision_and_scale",
+ "test_add_column_with_primary_key_attribute",
+ "test_add_drop_table_with_prefix_and_suffix",
+ "test_add_index",
+ "test_add_remove_single_field_using_string_arguments",
+ "test_add_remove_single_field_using_symbol_arguments",
+ "test_add_rename",
+ "test_add_table",
+ "test_add_table_with_decimals",
+ "test_change_column",
+ "test_change_column_default",
+ "test_change_column_default_to_null",
+ "test_change_column_nullability",
+ "test_change_column_quotes_column_names",
+ "test_change_column_with_new_default",
+ "test_change_column_with_nil_default",
+ "test_change_type_of_not_null_column",
+ "test_create_table_adds_id",
+ "test_create_table_with_binary_column",
+ "test_create_table_with_custom_sequence_name",
+ "test_create_table_with_defaults",
+ "test_create_table_with_force_true_does_not_drop_nonexisting_table",
+ "test_create_table_with_limits",
+ "test_create_table_with_not_null_column",
+ "test_create_table_with_primary_key_prefix_as_table_name",
+ "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
+ "test_create_table_with_timestamps_should_create_datetime_columns",
+ "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
+ "test_create_table_without_a_block",
+ "test_create_table_without_id",
+ "test_finds_migrations",
+ "test_finds_pending_migrations",
+ "test_keeping_default_and_notnull_constaint_on_change",
+ "test_migrator",
+ "test_migrator_db_has_no_schema_migrations_table",
+ "test_migrator_double_down",
+ "test_migrator_double_up",
+ "test_migrator_forward",
+ "test_migrator_going_down_due_to_version_target",
+ "test_migrator_one_down",
+ "test_migrator_one_up",
+ "test_migrator_one_up_one_down",
+ "test_migrator_one_up_with_exception_and_rollback",
+ "test_migrator_rollback",
+ "test_migrator_verbosity",
+ "test_migrator_verbosity_off",
+ "test_migrator_with_duplicate_names",
+ "test_migrator_with_duplicates",
+ "test_migrator_with_missing_version_numbers",
+ "test_native_decimal_insert_manual_vs_automatic",
+ "test_native_types",
+ "test_only_loads_pending_migrations",
+ "test_proper_table_name",
+ "test_relative_migrations",
+ "test_remove_column_with_index",
+ "test_remove_column_with_multi_column_index",
+ "test_rename_column",
+ "test_rename_column_preserves_default_value_not_null",
+ "test_rename_column_using_symbol_arguments",
+ "test_rename_column_with_an_index",
+ "test_rename_column_with_sql_reserved_word",
+ "test_rename_nonexistent_column",
+ "test_rename_table",
+ "test_rename_table_for_sqlite_should_work_with_reserved_words",
+ "test_rename_table_with_an_index",
+ "test_schema_migrations_table_name",
+ "test_target_version_zero_should_run_only_once"]
+
end
Modified: MacRuby/trunk/spec/frozen/core/array/join_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/join_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/join_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-require File.dirname(__FILE__) + '/../../shared/array/join'
+require File.expand_path('../shared/join', __FILE__)
describe "Array#join" do
Modified: MacRuby/trunk/spec/frozen/core/array/multiply_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/multiply_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/multiply_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
-require File.dirname(__FILE__) + '/../../shared/array/join'
+require File.expand_path('../shared/join', __FILE__)
describe "Array#*" do
it "tries to convert the passed argument to a String using #to_str" do
@@ -68,11 +68,24 @@
lambda { [ 1, 2, 3 ] * -1 }.should raise_error(ArgumentError)
lambda { [] * -1 }.should raise_error(ArgumentError)
end
-
- it "returns subclass instance with Array subclasses" do
- (ArraySpecs::MyArray[1, 2, 3] * 0).should be_kind_of(ArraySpecs::MyArray)
- (ArraySpecs::MyArray[1, 2, 3] * 1).should be_kind_of(ArraySpecs::MyArray)
- (ArraySpecs::MyArray[1, 2, 3] * 2).should be_kind_of(ArraySpecs::MyArray)
+
+ describe "with a subclass of Array" do
+ before :each do
+ ScratchPad.clear
+
+ @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
+ end
+
+ it "returns a subclass instance" do
+ (@array * 0).should be_an_instance_of(ArraySpecs::MyArray)
+ (@array * 1).should be_an_instance_of(ArraySpecs::MyArray)
+ (@array * 2).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "does not call #initialize on the subclass instance" do
+ (@array * 2).should == [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]
+ ScratchPad.recorded.should be_nil
+ end
end
ruby_version_is '' ... '1.8' do
Modified: MacRuby/trunk/spec/frozen/core/array/new_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/new_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/new_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -7,7 +7,7 @@
end
it "returns an instance of a subclass" do
- ArraySpecs::MyArray.new.should be_kind_of(ArraySpecs::MyArray)
+ ArraySpecs::MyArray.new(1, 2).should be_an_instance_of(ArraySpecs::MyArray)
end
it "raise an ArgumentError if passed 3 or more arguments" do
Modified: MacRuby/trunk/spec/frozen/core/array/pack_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/pack_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/pack_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1950,6 +1950,24 @@
["abcd"].pack('M').encoding.should == Encoding::US_ASCII
end
end
+
+ ruby_version_is ""..."1.9" do
+
+ describe "with a multibyte $KCODE" do
+ before :each do
+ @kcode = $KCODE
+ end
+
+ after :each do
+ $KCODE = @kcode
+ end
+
+ it "encodes multibyte characters" do
+ $KCODE = "UTF8"
+ ["あ"].pack('M').should == "=E3=81=82=\n"
+ end
+ end
+ end
end
describe "Array#pack with format 'm'" do
Modified: MacRuby/trunk/spec/frozen/core/array/product_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/product_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/product_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -36,7 +36,9 @@
[1,2].product([3,4,5],[],[6,8]){|array| acc << array}
acc.should be_empty
end
+ end
+ describe "when given an empty block" do
it "returns self" do
arr = [1,2]
arr.product([3,4,5],[6,8]){}.should equal(arr)
Modified: MacRuby/trunk/spec/frozen/core/array/reject_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/reject_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/reject_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -13,6 +13,12 @@
ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
end
+ it "returns self when called on an Array emptied with #shift" do
+ array = [1]
+ array.shift
+ array.reject { |x| true }.should == []
+ end
+
it "properly handles recursive arrays" do
empty = ArraySpecs.empty_recursive_array
empty.reject { false }.should == [empty]
@@ -75,6 +81,12 @@
array.should == []
end
+ it "returns nil when called on an Array emptied with #shift" do
+ array = [1]
+ array.shift
+ array.reject! { |x| true }.should == nil
+ end
+
it "returns nil if no changes are made" do
a = [1, 2, 3]
Modified: MacRuby/trunk/spec/frozen/core/array/shared/slice.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/shared/slice.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/shared/slice.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -343,7 +343,7 @@
[1, 2, 3, 4, 5].send(@method, 0...-1).should == [1, 2, 3, 4]
end
- it "returns [3] for [2..-1] out of [1, 2, 3] <Specifies bug found by brixen, Defiler, mae>" do
+ it "returns [3] for [2..-1] out of [1, 2, 3]" do
[1,2,3].send(@method, 2..-1).should == [3]
end
@@ -369,11 +369,72 @@
a.should == [1, 2]
end
- it "returns a subclass instance when called on a subclass of Array" do
- ary = ArraySpecs::MyArray[1, 2, 3]
- ary.send(@method, 0, 0).should be_kind_of(ArraySpecs::MyArray)
- ary.send(@method, 0, 2).should be_kind_of(ArraySpecs::MyArray)
- ary.send(@method, 0..10).should be_kind_of(ArraySpecs::MyArray)
+ describe "with a subclass of Array" do
+ before :each do
+ ScratchPad.clear
+
+ @array = ArraySpecs::MyArray[1, 2, 3, 4, 5]
+ end
+
+ it "returns a subclass instance with [n, m]" do
+ @array.send(@method, 0, 2).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns a subclass instance with [-n, m]" do
+ @array.send(@method, -3, 2).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns a subclass instance with [n..m]" do
+ @array.send(@method, 1..3).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns a subclass instance with [n...m]" do
+ @array.send(@method, 1...3).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns a subclass instance with [-n..-m]" do
+ @array.send(@method, -3..-1).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns a subclass instance with [-n...-m]" do
+ @array.send(@method, -3...-1).should be_an_instance_of(ArraySpecs::MyArray)
+ end
+
+ it "returns an empty array when m == n with [m...n]" do
+ @array.send(@method, 1...1).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns an empty array with [0...0]" do
+ @array.send(@method, 0...0).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns an empty array when m > n and m, n are positive with [m..n]" do
+ @array.send(@method, 3..2).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns an empty array when m > n and m, n are negative with [m..n]" do
+ @array.send(@method, -2..-3).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns [] if index == array.size with [index, length]" do
+ @array.send(@method, 5, 2).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns [] if the index is valid but length is zero with [index, length]" do
+ @array.send(@method, 0, 0).should == []
+ @array.send(@method, 2, 0).should == []
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "does not call #initialize on the subclass instance" do
+ @array.send(@method, 0, 3).should == [1, 2, 3]
+ ScratchPad.recorded.should be_nil
+ end
end
not_compliant_on :rubinius do
Modified: MacRuby/trunk/spec/frozen/core/array/sort_by_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/sort_by_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/sort_by_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -5,9 +5,9 @@
describe "Array#sort_by!" do
it "sorts array in place by passing each element to the given block" do
- a = [1, -2, 3, 9, 1, 5, -5, 1000, -5, 2, -10, 14, 6, 23, 0]
+ a = [-100, -2, 1, 200, 30000]
a.sort_by!{ |e| e.to_s.size }
- a.should == [1, 6, 3, 9, 1, 5, 2, 0, -5, -5, 23, -2, 14, -10, 1000]
+ a.should == [1, -2, 200, -100, 30000]
end
it "returns an Enumerator if not given a block" do
Modified: MacRuby/trunk/spec/frozen/core/array/sort_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/sort_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/sort_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -121,6 +121,12 @@
a=[ArraySpecs::Uncomparable.new, ArraySpecs::Uncomparable.new]
lambda {a.sort}.should raise_error(ArgumentError)
end
+
+ # From a strange Rubinius bug
+ it "handles a large array that has been pruned" do
+ pruned = ArraySpecs::LargeArray.dup.delete_if { |n| n !~ /^test./ }
+ pruned.sort.should == ArraySpecs::LargeTestArraySorted
+ end
end
describe "Array#sort!" do
Modified: MacRuby/trunk/spec/frozen/core/array/to_a_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/array/to_a_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/array/to_a_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -9,10 +9,9 @@
end
it "does not return subclass instance on Array subclasses" do
- e = ArraySpecs::MyArray.new
- e << 1
+ e = ArraySpecs::MyArray.new(1, 2)
e.to_a.should be_kind_of(Array)
- e.to_a.should == [1]
+ e.to_a.should == [1, 2]
end
it "properly handles recursive arrays" do
Modified: MacRuby/trunk/spec/frozen/core/bignum/divmod_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/bignum/divmod_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/bignum/divmod_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -27,6 +27,32 @@
(10**50).divmod(-(10**40 + 1)).should == [-10000000000, -10000000000]
end
+ describe "with q = floor(x/y), a = q*b + r," do
+ it "returns [q,r] when a < 0, b > 0 and |a| < b" do
+ a = - at bignum + 1
+ b = @bignum
+ a.divmod(b).should == [-1, 1]
+ end
+
+ it "returns [q,r] when a > 0, b < 0 and a > |b|" do
+ b = - at bignum + 1
+ a = @bignum
+ a.divmod(b).should == [-2, - at bignum + 2]
+ end
+
+ it "returns [q,r] when a > 0, b < 0 and a < |b|" do
+ a = @bignum - 1
+ b = - at bignum
+ a.divmod(b).should == [-1, -1]
+ end
+
+ it "returns [q,r] when a < 0, b < 0 and |a| < |b|" do
+ a = - at bignum + 1
+ b = - at bignum
+ a.divmod(b).should == [0, - at bignum + 1]
+ end
+ end
+
it "raises a ZeroDivisionError when the given argument is 0" do
lambda { @bignum.divmod(0) }.should raise_error(ZeroDivisionError)
lambda { (- at bignum).divmod(0) }.should raise_error(ZeroDivisionError)
Modified: MacRuby/trunk/spec/frozen/core/bignum/left_shift_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/bignum/left_shift_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/bignum/left_shift_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,57 +1,81 @@
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Bignum#<<" do
+describe "Bignum#<< with n << m" do
before(:each) do
- @bignum = bignum_value(9)
+ @bignum = bignum_value() * 16
end
-
- it "returns self shifted the given amount of bits to the left" do
- (@bignum << 4).should == 147573952589676413072
- (@bignum << 9).should == 4722366482869645218304
+
+ it "returns n shifted left m bits when n > 0, m > 0" do
+ (@bignum << 4).should == 2361183241434822606848
end
- it "performs a right-shift if given a negative value" do
- (@bignum << -2).should == (@bignum >> 2)
- (@bignum << -4).should == (@bignum >> 4)
+ it "returns n shifted left m bits when n < 0, m > 0" do
+ (- at bignum << 9).should == -75557863725914323419136
end
- it "tries to convert the given argument to an Integer using to_int" do
- (@bignum << 4.5).should == 147573952589676413072
-
- (obj = mock('4')).should_receive(:to_int).and_return(4)
- (@bignum << obj).should == 147573952589676413072
+ it "returns n shifted right m bits when n > 0, m < 0" do
+ (@bignum << -1).should == 73786976294838206464
end
- it "raises a TypeError when the given argument can't be converted to Integer" do
- obj = mock("Converted to Integer")
- lambda { @bignum << obj }.should raise_error(TypeError)
-
- obj.should_receive(:to_int).and_return("asdf")
- lambda { @bignum << obj }.should raise_error(TypeError)
+ it "returns n shifted right m bits when n < 0, m < 0" do
+ (- at bignum << -2).should == -36893488147419103232
end
- platform_is :wordsize => 32 do
- it "raises a RangeError when the given argument is a Bignum" do
- lambda { @bignum << bignum_value }.should raise_error(RangeError)
- lambda { - at bignum << bignum_value }.should raise_error(RangeError)
-
- obj = mock("Converted to Integer")
- obj.should_receive(:to_int).exactly(2).times.and_return(bignum_value)
- lambda { @bignum << obj }.should raise_error(RangeError)
- lambda { - at bignum << obj }.should raise_error(RangeError)
+ it "returns n when n > 0, m == 0" do
+ (@bignum << 0).should == @bignum
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (- at bignum << 0).should == - at bignum
+ end
+
+ it "returns 0 when m < 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (@bignum << -68).should == 0
+ end
+
+ not_compliant_on :rubinius, :jruby do
+ it "returns 0 when m < 0 and m is a Bignum" do
+ (@bignum << -bignum_value()).should == 0
end
end
- platform_is :wordsize => 64 do
- it "raises a RangeError when the given argument is a Bignum" do
- # check against 2**64 for 64-bit machines.
- lambda { @bignum << (bignum_value << 1) }.should raise_error(RangeError)
- lambda { - at bignum << (bignum_value << 1) }.should raise_error(RangeError)
-
- obj = mock("Converted to Integer")
- obj.should_receive(:to_int).exactly(2).times.and_return(bignum_value << 1)
- lambda { @bignum << obj }.should raise_error(RangeError)
- lambda { - at bignum << obj }.should raise_error(RangeError)
+ deviates_on :rubinius do
+ it "raises a RangeError when m < 0 and m is a Bignum" do
+ lambda { @bignum << -bignum_value() }.should raise_error(RangeError)
end
end
+
+ it "returns a Fixnum == fixnum_max() when (fixnum_max() * 2) << -1 and n > 0" do
+ result = (fixnum_max() * 2) << -1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_max()
+ end
+
+ it "returns a Fixnum == fixnum_min() when (fixnum_min() * 2) << -1 and n < 0" do
+ result = (fixnum_min() * 2) << -1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_min()
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("4")
+ obj.should_receive(:to_int).and_return(4)
+
+ (@bignum << obj).should == 2361183241434822606848
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { @bignum << obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { @bignum << nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { @bignum << "4" }.should raise_error(TypeError)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/bignum/right_shift_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/bignum/right_shift_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/bignum/right_shift_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,48 +1,81 @@
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Bignum#>>" do
- before(:each) do
- @bignum = bignum_value(90812)
+describe "Bignum#>> with n >> m" do
+ before(:each) do
+ @bignum = bignum_value() * 16
end
- it "returns self shifted the given amount of bits to the right" do
- (@bignum >> 1).should == 4611686018427433310
- (@bignum >> 3).should == 1152921504606858327
+ it "returns n shifted right m bits when n > 0, m > 0" do
+ (@bignum >> 1).should == 73786976294838206464
end
- it "performs a left-shift if given a negative value" do
- (@bignum >> -1).should == (@bignum << 1)
- (@bignum >> -3).should == (@bignum << 3)
+ it "returns n shifted right m bits when n < 0, m > 0" do
+ (- at bignum >> 2).should == -36893488147419103232
end
-
- it "tries to convert the given argument to an Integer using to_int" do
- (@bignum >> 1.3).should == 4611686018427433310
-
- (obj = mock('1')).should_receive(:to_int).and_return(1)
- (@bignum >> obj).should == 4611686018427433310
+
+ it "returns n shifted left m bits when n > 0, m < 0" do
+ (@bignum >> -2).should == 590295810358705651712
end
-
- it "raises a TypeError when the given argument can't be converted to Integer" do
- obj = mock('asdf')
- lambda { @bignum >> obj }.should raise_error(TypeError)
-
+
+ it "returns n shifted left m bits when n < 0, m < 0" do
+ (- at bignum >> -3).should == -1180591620717411303424
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (@bignum >> 0).should == @bignum
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (- at bignum >> 0).should == - at bignum
+ end
+
+ it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (@bignum >> 68).should == 0
+ end
+
+ not_compliant_on :rubinius do
+ it "returns 0 when m is a Bignum" do
+ (@bignum >> bignum_value()).should == 0
+ end
+ end
+
+ deviates_on :rubinius do
+ it "raises a RangeError when m is a Bignum" do
+ lambda { @bignum >> bignum_value() }.should raise_error(RangeError)
+ end
+ end
+
+ it "returns a Fixnum == fixnum_max() when (fixnum_max() * 2) >> 1 and n > 0" do
+ result = (fixnum_max() * 2) >> 1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_max()
+ end
+
+ it "returns a Fixnum == fixnum_min() when (fixnum_min() * 2) >> 1 and n < 0" do
+ result = (fixnum_min() * 2) >> 1
+ result.should be_an_instance_of(Fixnum)
+ result.should == fixnum_min()
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("2")
+ obj.should_receive(:to_int).and_return(2)
+
+ (@bignum >> obj).should == 36893488147419103232
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
+
lambda { @bignum >> obj }.should raise_error(TypeError)
end
- it "returns 0 when the given argument is a Bignum and self is positive" do
- (@bignum >> bignum_value).should == 0
-
- obj = mock("Converted to Integer")
- obj.should_receive(:to_int).and_return(bignum_value)
- (@bignum >> obj).should == 0
+ it "raises a TypeError when passed nil" do
+ lambda { @bignum >> nil }.should raise_error(TypeError)
end
-
- it "returns -1 when the given argument is a Bignum and self is negative" do
- (- at bignum >> bignum_value).should == -1
- obj = mock("Converted to Integer")
- obj.should_receive(:to_int).and_return(bignum_value)
- (- at bignum >> obj).should == -1
+ it "raises a TypeError when passed a String" do
+ lambda { @bignum >> "4" }.should raise_error(TypeError)
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/spec/frozen/core/class/new_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/class/new_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/class/new_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -37,7 +37,6 @@
klass.superclass.should == sc
klass.new.message.should == "text"
klass.new.message2.should == "hello"
- klass.dup.body.should == klass
end
end
Deleted: MacRuby/trunk/spec/frozen/core/dir/new_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/dir/new_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/dir/new_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/common', __FILE__)
-
-describe "Dir.new" do
- it "needs to be reviewed for spec completeness"
-end
Modified: MacRuby/trunk/spec/frozen/core/dir/shared/open.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/dir/shared/open.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/dir/shared/open.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -37,6 +37,14 @@
lambda { @closed_dir.close }.should raise_error(IOError)
end
+ ruby_version_is ""..."1.9" do
+ it "calls #to_str on non-String arguments" do
+ p = mock('path')
+ p.should_receive(:to_str).and_return(DirSpecs.mock_dir)
+ Dir.send(@method, p) { true }
+ end
+ end
+
ruby_version_is "1.9" do
it "calls #to_path on non-String arguments" do
p = mock('path')
Modified: MacRuby/trunk/spec/frozen/core/enumerable/each_entry_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/enumerable/each_entry_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/enumerable/each_entry_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '1.9' do
Modified: MacRuby/trunk/spec/frozen/core/enumerable/slice_before_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/enumerable/slice_before_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/enumerable/slice_before_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,4 @@
-require File.dirname(__FILE__) + '/../../spec_helper'
+require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is '1.9' do
Modified: MacRuby/trunk/spec/frozen/core/env/shared/store.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/env/shared/store.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/env/shared/store.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,13 +1,21 @@
describe :env_store, :shared => true do
it "sets the environment variable to the given value" do
ENV.send(@method, "foo", "bar")
- env.key?("foo").should == true
- env.value?("bar").should == true
+ env.key?("foo").should be_true
+ env.value?("bar").should be_true
ENV.delete "foo"
- ENV["foo"].should == nil
+ ENV["foo"].should be_nil
ENV.store "foo", "bar"
- env.key?("foo").should == true
- env.value?("bar").should == true
+ env.key?("foo").should be_true
+ env.value?("bar").should be_true
ENV.delete "foo"
end
+
+ it 'deletes key if value is nil' do
+ ENV.send(@method, 'foo', 'bar')
+ ENV.has_key?('foo').should be_true
+ ENV.send(@method, 'foo', nil)
+ ENV.has_key?('foo').should be_false
+ end
+
end
Modified: MacRuby/trunk/spec/frozen/core/file/expand_path_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/file/expand_path_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/file/expand_path_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/common', __FILE__)
describe "File.expand_path" do
before :each do
@@ -151,4 +152,23 @@
Encoding.default_external = old_external
end
end
+
+ it "does not modify the string argument" do
+ str = "./a/b/../c"
+ File.expand_path(str, @base).should == "#{@base}/a/c"
+ str.should == "./a/b/../c"
+ end
+
+ it "does not modify a HOME string argument" do
+ str = "~/a"
+ File.expand_path(str).should == "#{home_directory.tr('\\', '/')}/a"
+ str.should == "~/a"
+ end
+
+ it "returns a String when passed a String subclass" do
+ str = FileSpecs::SubString.new "./a/b/../c"
+ path = File.expand_path(str, @base)
+ path.should == "#{@base}/a/c"
+ path.should be_an_instance_of(String)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/file/size_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/file/size_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/file/size_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -6,6 +6,10 @@
end
describe "File.size?" do
+ it_behaves_like :file_size_to_io, :size?, File
+end
+
+describe "File.size?" do
it_behaves_like :file_size_nil_when_missing, :size?, File
end
@@ -22,6 +26,10 @@
end
describe "File.size" do
+ it_behaves_like :file_size_to_io, :size, File
+end
+
+describe "File.size" do
it_behaves_like :file_size_raise_when_missing, :size, File
end
@@ -60,9 +68,11 @@
@file.size.should == 8
end
- it "returns the cached size of the file if subsequently deleted" do
- rm_r @file
- @file.size.should == 8
+ platform_is_not :windows do # impossible to remove opened file on Windows
+ it "returns the cached size of the file if subsequently deleted" do
+ rm_r @file
+ @file.size.should == 8
+ end
end
it "returns the file's current size even if modified" do
@@ -70,11 +80,9 @@
@file.size.should == 9
end
- it "returns 0 for an empty file" do
- @file = File.open(@file.path, 'w')
- @file.truncate(0)
- @file.size.should == 0
+ it "raises an IOError on a closed file" do
@file.close
+ lambda { @file.size }.should raise_error(IOError)
end
platform_is_not :windows do
@@ -93,4 +101,22 @@
end
end
end
+
+ describe "File#size for an empty file" do
+ before :each do
+ @name = tmp('empty')
+ touch(@name)
+ @file = File.new @name
+ end
+
+ after :each do
+ @file.close unless @file.closed?
+ rm_r @name
+ end
+
+ it "returns 0" do
+ @file.size.should == 0
+ end
+ end
+
end
Modified: MacRuby/trunk/spec/frozen/core/fixnum/element_reference_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/fixnum/element_reference_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/fixnum/element_reference_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,38 +1,64 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Fixnum#[]" do
- it "returns the nth bit in the binary representation of self" do
- 2[3].should == 0
+ it "returns 1 if the nth bit is set" do
15[1].should == 1
+ end
+ it "returns 0 if the nth bit is not set" do
+ 8[2].should == 0
+ end
+
+ it "returns 0 if the nth bit is greater than the most significant bit" do
2[3].should == 0
- 3[0xffffffff].should == 0
- 3[-0xffffffff].should == 0
end
-
- it "tries to convert the given argument to an Integer using #to_int" do
- 15[1.3].should == 15[1]
-
- (obj = mock('1')).should_receive(:to_int).and_return(1)
+
+ it "returns 0 when passed a negative argument" do
+ 3[-1].should == 0
+ end
+
+ it "calls #to_int to convert the argument to an Integer and returns 1 if the nth bit is set" do
+ obj = mock('1')
+ obj.should_receive(:to_int).and_return(1)
+
2[obj].should == 1
end
- it "raises a TypeError when the given argument can't be converted to Integer" do
+ it "calls #to_int to convert the argument to an Integer and returns 0 if the nth bit is set" do
+ obj = mock('0')
+ obj.should_receive(:to_int).and_return(0)
+
+ 2[obj].should == 0
+ end
+
+ it "accepts a Float argument and returns 0 if the bit at the truncated value is not set" do
+ 13[1.3].should == 0
+ end
+
+ it "accepts a Float argument and returns 1 if the bit at the truncated value is set" do
+ 13[2.1].should == 1
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { 3["3"] }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
obj = mock('asdf')
- lambda { 3[obj] }.should raise_error(TypeError)
-
obj.should_receive(:to_int).and_return("asdf")
lambda { 3[obj] }.should raise_error(TypeError)
end
ruby_bug "#", "1.8.6" do # Fixed at MRI 1.8.7
- it "coerces arguments correctly even if it is a Bignum" do
- (obj = mock('large value')).should_receive(:to_int).and_return(8000_0000_0000_0000_0000)
+ it "calls #to_int to coerce a String to a Bignum and returns 0" do
+ obj = mock('bignum value')
+ obj.should_receive(:to_int).and_return(bignum_value())
+
3[obj].should == 0
- obj = 8e19
-
- 3[obj].should == 0
end
end
+ it "returns 0 when passed a Float in the range of a Bignum" do
+ 3[bignum_value().to_f].should == 0
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/fixnum/left_shift_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/fixnum/left_shift_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/fixnum/left_shift_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,51 +1,81 @@
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Fixnum#<<" do
- it "returns self shifted the given amount of bits to the left" do
- (7 << 2).should == 28
- (9 << 4).should == 144
- (1 <<30).should == 1073741824
- (1 <<31).should == 2147483648
- (1 <<32).should == 4294967296
- (-1<<31).should == -2147483648
- (-1<<32).should == -4294967296
- (1 <<62).should == 4611686018427387904
- (1 <<63).should == 9223372036854775808
- (1 <<64).should == 18446744073709551616
- (-1<<63).should == -9223372036854775808
- (-1<<64).should == -18446744073709551616
+describe "Fixnum#<< with n << m" do
+ it "returns n shifted left m bits when n > 0, m > 0" do
+ (1 << 1).should == 2
end
- it "performs a right-shift if given a negative value" do
- (7 << -2).should == (7 >> 2)
- (9 << -4).should == (9 >> 4)
+ it "returns n shifted left m bits when n < 0, m > 0" do
+ (-1 << 1).should == -2
end
-
- it "coerces result on overflow and return self shifted left other bits" do
- (9 << 4.2).should == 144
- (6 << 0xff).should == 347376267711948586270712955026063723559809953996921692118372752023739388919808
+
+ it "returns n shifted right m bits when n > 0, m < 0" do
+ (2 << -1).should == 1
end
-
- it "tries to convert its argument to an Integer using to_int" do
- (5 << 4.3).should == 80
-
- (obj = mock('4')).should_receive(:to_int).and_return(4)
+
+ it "returns n shifted right m bits when n < 0, m < 0" do
+ (-2 << -1).should == -1
+ end
+
+ it "returns 0 when n == 0" do
+ (0 << 1).should == 0
+ end
+
+ it "returns n when n > 0, m == 0" do
+ (1 << 0).should == 1
+ end
+
+ it "returns n when n < 0, m == 0" do
+ (-1 << 0).should == -1
+ end
+
+ it "returns 0 when m < 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (4 << -3).should == 0
+ end
+
+ not_compliant_on :rubinius, :jruby do
+ it "returns 0 when m < 0 and m is a Bignum" do
+ (3 << -bignum_value()).should == 0
+ end
+ end
+
+ deviates_on :rubinius do
+ it "raises a RangeError when m < 0 and m is a Bignum" do
+ lambda { 3 << -bignum_value() }.should raise_error(RangeError)
+ end
+ end
+
+ it "returns a Bignum == fixnum_max() * 2 when fixnum_max() << 1 and n > 0" do
+ result = fixnum_max() << 1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_max() * 2
+ end
+
+ it "returns a Bignum == fixnum_min() * 2 when fixnum_min() << 1 and n < 0" do
+ result = fixnum_min() << 1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_min() * 2
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("4")
+ obj.should_receive(:to_int).and_return(4)
+
(3 << obj).should == 48
end
-
- it "raises a TypeError when the given argument can't be converted to Integer" do
- obj = mock('asdf')
- lambda { 3 << obj }.should raise_error(TypeError)
-
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
obj.should_receive(:to_int).and_return("asdf")
+
lambda { 3 << obj }.should raise_error(TypeError)
end
- it "raises a RangeError when the given argument is out of range of Fixnum" do
- (obj = mock('large value')).should_receive(:to_int).and_return(8000_0000_0000_0000_0000)
- lambda { 3 << obj }.should raise_error(RangeError)
+ it "raises a TypeError when passed nil" do
+ lambda { 3 << nil }.should raise_error(TypeError)
+ end
- obj = 8e19
- lambda { 3 << obj }.should raise_error(RangeError)
+ it "raises a TypeError when passed a String" do
+ lambda { 3 << "4" }.should raise_error(TypeError)
end
end
Modified: MacRuby/trunk/spec/frozen/core/fixnum/right_shift_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/fixnum/right_shift_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/fixnum/right_shift_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,53 +1,81 @@
require File.expand_path('../../../spec_helper', __FILE__)
-describe "Fixnum#>>" do
- it "returns self shifted the given amount of bits to the right" do
- (7 >> 1).should == 3
- (4095 >> 3).should == 511
- (9245278 >> 1).should == 4622639
+describe "Fixnum#>> with n >> m" do
+ it "returns n shifted right m bits when n > 0, m > 0" do
+ (2 >> 1).should == 1
end
- it "performs a left-shift if given a negative value" do
- (7 >> -1).should == (7 << 1)
- (4095 >> -3).should == (4095 << 3)
+ it "returns n shifted right m bits when n < 0, m > 0" do
+ (-2 >> 1).should == -1
end
-
- it "performs a right-shift if given a negative value" do
- (-7 >> 1).should == -4
- (-4095 >> 3).should == -512
+
+ it "returns n shifted left m bits when n > 0, m < 0" do
+ (1 >> -1).should == 2
end
-
- it "tries to convert it's argument to an Integer using to_int" do
- (7 >> 1.3).should == 3
-
- (obj = mock('1')).should_receive(:to_int).and_return(1)
- (7 >> obj).should == 3
+
+ it "returns n shifted left m bits when n < 0, m < 0" do
+ (-1 >> -1).should == -2
end
-
- it "raises a TypeError when the given argument can't be converted to Integer" do
- obj = mock('asdf')
- lambda { 3 >> obj }.should raise_error(TypeError)
-
- obj.should_receive(:to_int).and_return("asdf")
- lambda { 3 >> obj }.should raise_error(TypeError)
+
+ it "returns 0 when n == 0" do
+ (0 >> 1).should == 0
end
- it "does not raise RangeError when the given argument is out of range of Fixnum" do
- (obj1 = mock('large value')).should_receive(:to_int).and_return(8000_0000_0000_0000_0000)
- (obj2 = mock('large value')).should_receive(:to_int).and_return(8000_0000_0000_0000_0000)
- (3 >> obj1).should == 0
- (-3 >> obj2).should == -1
+ it "returns n when n > 0, m == 0" do
+ (1 >> 0).should == 1
+ end
- obj = 8e19
- (3 >> obj).should == 0
- (-3 >> obj).should == -1
+ it "returns n when n < 0, m == 0" do
+ (-1 >> 0).should == -1
end
- it "wraps to 0 when shifting all bits off" do
- # test for both Fixnum size boundaries
- (5 >> 32).should == 0
- (5 >> 64).should == 0
+ it "returns 0 when m > 0 and m == p where 2**p > n >= 2**(p-1)" do
+ (4 >> 3).should == 0
end
+ not_compliant_on :rubinius do
+ it "returns 0 when m is a Bignum" do
+ (3 >> bignum_value()).should == 0
+ end
+ end
+ deviates_on :rubinius do
+ it "raises a RangeError when m is a Bignum" do
+ lambda { 3 >> bignum_value() }.should raise_error(RangeError)
+ end
+ end
+
+ it "returns a Bignum == fixnum_max() * 2 when fixnum_max() >> -1 and n > 0" do
+ result = fixnum_max() >> -1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_max() * 2
+ end
+
+ it "returns a Bignum == fixnum_min() * 2 when fixnum_min() >> -1 and n < 0" do
+ result = fixnum_min() >> -1
+ result.should be_an_instance_of(Bignum)
+ result.should == fixnum_min() * 2
+ end
+
+ it "calls #to_int to convert the argument to an Integer" do
+ obj = mock("2")
+ obj.should_receive(:to_int).and_return(2)
+
+ (8 >> obj).should == 2
+ end
+
+ it "raises a TypeError when #to_int does not return an Integer" do
+ obj = mock("a string")
+ obj.should_receive(:to_int).and_return("asdf")
+
+ lambda { 3 >> obj }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed nil" do
+ lambda { 3 >> nil }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError when passed a String" do
+ lambda { 3 >> "4" }.should raise_error(TypeError)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/float/to_s_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/float/to_s_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/float/to_s_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,49 +1,103 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Float#to_s" do
- it "returns a string representation of self, possibly Nan, -Infinity, +Infinity" do
- 0.551e7.to_s.should == "5510000.0"
- -3.14159.to_s.should == "-3.14159"
+ it "returns 'NaN' for NaN" do
+ nan_value().to_s.should == 'NaN'
+ end
+
+ it "returns 'Infinity' for positive infinity" do
+ infinity_value().to_s.should == 'Infinity'
+ end
+
+ it "returns '-Infinity' for negative infinity" do
+ (-infinity_value()).to_s.should == '-Infinity'
+ end
+
+ it "returns '0.0' for 0.0" do
0.0.to_s.should == "0.0"
- 1000000000000.to_f.to_s.should == "1000000000000.0"
- 10000000000000.to_f.to_s.should == "10000000000000.0"
- -10000000000000.to_f.to_s.should == "-10000000000000.0"
- 1.87687113714737e-40.to_s.should == "1.87687113714737e-40"
- (0.0 / 0.0).to_s.should == "NaN"
- (1.0 / 0.0).to_s.should == "Infinity"
- (-1.0 / 0.0).to_s.should == "-Infinity"
- 1.50505000e-20.to_s.should == "1.50505e-20"
end
+ platform_is_not :openbsd do
+ it "emits '-' for -0.0" do
+ -0.0.to_s.should == "-0.0"
+ end
+ end
+
+ it "emits a '-' for negative values" do
+ -3.14.to_s.should == "-3.14"
+ end
+
+ it "emits a trailing '.0' for a whole number" do
+ 50.0.to_s.should == "50.0"
+ end
+
+ it "emits a trailing '.0' for the mantissa in e format" do
+ 1.0e20.to_s.should == "1.0e+20"
+ end
+
+ it "uses non-e format for a positive value with fractional part having 4 decimal places" do
+ 0.0001.to_s.should == "0.0001"
+ end
+
+ it "uses non-e format for a negative value with fractional part having 4 decimal places" do
+ -0.0001.to_s.should == "-0.0001"
+ end
+
+ it "uses e format for a positive value with fractional part having 5 decimal places" do
+ 0.00001.to_s.should == "1.0e-05"
+ end
+
+ it "uses e format for a negative value with fractional part having 5 decimal places" do
+ -0.00001.to_s.should == "-1.0e-05"
+ end
+
+ it "uses non-e format for a positive value with whole part having 14 decimal places" do
+ 10000000000000.0.to_s.should == "10000000000000.0"
+ end
+
+ it "uses non-e format for a negative value with whole part having 14 decimal places" do
+ -10000000000000.0.to_s.should == "-10000000000000.0"
+ end
+
ruby_version_is "" ... "1.9" do
- it "returns a string representation of self" do
- 100000000000000.to_f.to_s.should == "1.0e+14"
- -100000000000000.to_f.to_s.should == "-1.0e+14"
+ it "uses e format for a positive value with whole part having 15 decimal places" do
+ 100000000000000.0.to_s.should == "1.0e+14"
end
+
+ it "uses e format for a negative value with whole part having 15 decimal places" do
+ -100000000000000.0.to_s.should == "-1.0e+14"
+ end
end
ruby_version_is "1.9" do
- it "returns a string representation of self" do
- 100000000000000.to_f.to_s.should == "100000000000000.0"
- -100000000000000.to_f.to_s.should == "-100000000000000.0"
+ it "uses non-e format for a positive value with whole part having 16 decimal places" do
+ 1000000000000000.0.to_s.should == "1000000000000000.0"
end
- end
- ruby_bug "#3273", "1.8.7" do
- it "outputs the necessary number of digits to represent the float" do
- 0.21611564636388508.to_s.to_f.should == 0.21611564636388508
+ it "uses non-e format for a negative value with whole part having 15 decimal places" do
+ -1000000000000000.0.to_s.should == "-1000000000000000.0"
end
- end
- ruby_bug "#3273", "1.8" do
- it "outputs a minimal form to represent the float" do
- 0.56.to_s.should == "0.56"
+ it "uses e format for a positive value with whole part having 16 decimal places" do
+ 10000000000000000.0.to_s.should == "1.0e+16"
end
+
+ it "uses e format for a negative value with whole part having 16 decimal places" do
+ -10000000000000000.0.to_s.should == "-1.0e+16"
+ end
end
- platform_is_not :openbsd do
- it "returns the correct values for -0.0" do
- -0.0.to_s.should == "-0.0"
+ ruby_bug "#3273", "1.8.7" do
+ it "outputs the minimal, unique form necessary to recreate the value" do
+ value = 0.21611564636388508
+ string = "0.21611564636388508"
+
+ value.to_s.should == string
+ string.to_f.should == value
end
end
+
+ it "outputs the minimal, unique form to represent the value" do
+ 0.56.to_s.should == "0.56"
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/hash/element_reference_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/hash/element_reference_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/hash/element_reference_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -81,38 +81,28 @@
h[x].should == nil
end
- it "does not compare key with unknown hash codes via eql?" do
+ it "does not compare keys with different #hash values via #eql?" do
x = mock('x')
+ x.should_not_receive(:eql?)
+ x.stub!(:hash).and_return(0)
+
y = mock('y')
- def x.eql?(o) raise("Shouldn't receive eql?") end
+ y.should_not_receive(:eql?)
+ y.stub!(:hash).and_return(1)
- x.should_receive(:hash).and_return(0)
- y.should_receive(:hash).and_return(1)
-
new_hash(y => 1)[x].should == nil
end
- it "compares key with found hash code via eql?" do
- y = mock('0')
- y.should_receive(:hash).twice.and_return(0)
+ it "compares keys with the same #hash value via #eql?" do
+ x = mock('x')
+ x.should_receive(:eql?).and_return(true)
+ x.stub!(:hash).and_return(42)
- x = mock('0')
- def x.hash()
- def self.eql?(o) taint; false; end
- return 0
- end
+ y = mock('y')
+ y.should_not_receive(:eql?)
+ y.stub!(:hash).and_return(42)
- new_hash(y => 1)[x].should == nil
- x.tainted?.should == true
-
- x = mock('0')
- def x.hash()
- def self.eql?(o) taint; true; end
- return 0
- end
-
new_hash(y => 1)[x].should == 1
- x.tainted?.should == true
end
end
Modified: MacRuby/trunk/spec/frozen/core/hash/merge_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/hash/merge_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/hash/merge_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -59,7 +59,7 @@
it_behaves_like(:hash_update, :merge!)
# see http://redmine.ruby-lang.org/issues/show/1535
- ruby_bug "#1535", "1.8.7.248" do
+ ruby_bug "#1535", "1.8.8" do
it "raises a RuntimeError if a new key is added during iteration" do
hash = {1 => 2, 3 => 4, 5 => 6}
hash2 = {:foo => :bar, :baz => :qux}
Modified: MacRuby/trunk/spec/frozen/core/hash/shared/key.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/hash/shared/key.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/hash/shared/key.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -22,11 +22,13 @@
new_hash(nil => nil).send(@method, nil).should == true
end
- it "returns false for objects with the same hash" do
+ it "compares keys with the same #hash value via #eql?" do
x = mock('x')
+ x.stub!(:hash).and_return(42)
+
y = mock('y')
- x.should_receive(:hash).and_return(0)
- y.should_receive(:hash).and_return(0)
+ y.stub!(:hash).and_return(42)
+ y.should_receive(:eql?).and_return(false)
new_hash(x => nil).send(@method, y).should == false
end
Modified: MacRuby/trunk/spec/frozen/core/hash/shared/replace.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/hash/shared/replace.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/hash/shared/replace.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -38,11 +38,19 @@
end
ruby_version_is ""..."1.9" do
- it "raises a TypeError if called on a frozen instance" do
- HashSpecs.frozen_hash.send(@method, HashSpecs.frozen_hash) # ok, nothing changed
- block = lambda { HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash) }
- block.should raise_error(TypeError)
+ it "raises a RuntimeError if called on a frozen instance that is modified" do
+ lambda do
+ HashSpecs.frozen_hash.send(@method, HashSpecs.empty_frozen_hash)
+ end.should raise_error(TypeError)
end
+
+ ruby_bug "#1571, [ruby-core:23714]", "1.8.8" do
+ it "raises a RuntimeError if called on a frozen instance that would not be modified" do
+ lambda do
+ HashSpecs.frozen_hash.send(@method, HashSpecs.frozen_hash)
+ end.should raise_error(TypeError)
+ end
+ end
end
ruby_version_is "1.9" do
Modified: MacRuby/trunk/spec/frozen/core/hash/shared/store.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/hash/shared/store.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/hash/shared/store.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -50,7 +50,7 @@
end
# see http://redmine.ruby-lang.org/issues/show/1535
- ruby_bug "#1535", "1.8.7.248" do
+ ruby_bug "#1535", "1.8.8" do
it "raises a RuntimeError if a new key is added during iteration" do
hash = {1 => 2, 3 => 4, 5 => 6}
lambda{
Modified: MacRuby/trunk/spec/frozen/core/io/open_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/io/open_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/io/open_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -60,4 +60,14 @@
end
ScratchPad.recorded.should == :called
end
+
+ it "does not set last error when a StandardError raised by #close" do
+ IO.open(@fd, "w") do |io|
+ IOSpecs.io_mock(io, :close) do
+ super()
+ raise StandardError
+ end
+ end
+ $!.should == nil
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/io/reopen_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/io/reopen_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/io/reopen_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../fixtures/classes', __FILE__)
+require 'fcntl'
+
describe "IO#reopen" do
before :each do
@name = tmp("io_reopen.txt")
@@ -63,11 +65,13 @@
@other_name = tmp("io_reopen.txt")
touch @other_name
@io = IOSpecs.io_fixture "lines.txt"
+
+ @tmp_file = tmp("reopen")
end
after :each do
@io.close unless @io.closed?
- rm_r @other_name
+ rm_r @other_name, @tmp_file
end
it "does not raise an exception when called on a closed stream with a path" do
@@ -92,6 +96,18 @@
@io.gets.should == "Line 1: One\n"
end
+ platform_is_not :windows do
+ it "passes all mode flags through" do
+ @io.reopen(@name, "ab")
+ (@io.fcntl(Fcntl::F_GETFL) & File::APPEND).should == File::APPEND
+ end
+ end
+
+ it "effects exec/system/fork performed after it" do
+ ruby_exe fixture(__FILE__, "reopen_stdout.rb"), :args => @tmp_file
+ @tmp_file.should have_data("from system\nfrom exec", "r")
+ end
+
ruby_version_is "1.9" do
it "calls #to_path on non-String arguments" do
obj = mock('path')
@@ -106,7 +122,7 @@
@name = tmp("io_reopen.txt")
@other_name = tmp("io_reopen_other.txt")
- @io = new_io @name, "w"
+ rm_r @other_name
end
after :each do
@@ -115,16 +131,53 @@
end
it "opens a path after writing to the original file descriptor" do
+ @io = new_io @name, "w"
+
@io.print "original data"
- @io.reopen @other_name, "w"
+ @io.reopen @other_name
@io.print "new data"
@io.flush
@name.should have_data("original data")
@other_name.should have_data("new data")
end
+
+ it "creates the file if it doesn't exist if the IO is opened in write mode" do
+ @io = new_io @name, "w"
+
+ @io.reopen(@other_name)
+ File.exists?(@other_name).should be_true
+ end
+
+ it "creates the file if it doesn't exist if the IO is opened in write mode" do
+ @io = new_io @name, "a"
+
+ @io.reopen(@other_name)
+ File.exists?(@other_name).should be_true
+ end
end
+describe "IO#reopen with a String" do
+ before :each do
+ @name = tmp("io_reopen.txt")
+ @other_name = tmp("io_reopen_other.txt")
+
+ touch @name
+ rm_r @other_name
+ end
+
+ after :each do
+ # Do not close @io, the exception leaves MRI with an invalid
+ # IO and an Errno::EBADF will be raised on #close.
+ rm_r @name, @other_name
+ end
+
+ it "raises an Errno::ENOENT if the file does not exist and the IO is not opened in write mode" do
+ @io = new_io @name, "r"
+ lambda { @io.reopen(@other_name) }.should raise_error(Errno::ENOENT)
+ end
+end
+
describe "IO#reopen with an IO" do
before :each do
@name = tmp("io_reopen.txt")
@@ -198,4 +251,9 @@
@io.reopen @other_io
@io.should be_an_instance_of(File)
end
+
+ it "sets path equals to the other IO's path if other IO is File" do
+ @io.reopen @other_io
+ @io.path.should == @other_io.path
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/io/select_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/io/select_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/io/select_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -34,6 +34,14 @@
result.should == [[@rd], [], []]
end
+ it "leaves out IO objects for which there is no I/O ready" do
+ @wr.write "be ready"
+ # Order matters here. We want to see that @wr doesn't expand the size
+ # of the returned array, so it must be 1st.
+ result = IO.select [@wr, @rd], nil, nil, nil
+ result.should == [[@rd], [], []]
+ end
+
it "returns supplied objects correctly even when monitoring the same object in different arrays" do
filename = tmp("IO_select_pipe_file") + $$.to_s
io = File.open(filename, 'w+')
Modified: MacRuby/trunk/spec/frozen/core/io/ungetc_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/io/ungetc_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/io/ungetc_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/classes', __FILE__)
ruby_version_is "1.9" do
class IO
Modified: MacRuby/trunk/spec/frozen/core/kernel/Array_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/Array_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/Array_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -27,6 +27,12 @@
Array(obj).should == [1, 2, 3]
end
+ it "tries to call #to_a on the given argument if #to_ary is provided and it returns nil" do
+ (obj = mock('[4,5,6]')).should_receive(:to_ary).and_return(nil)
+ obj.should_receive(:to_a).and_return([4, 5, 6])
+ Array(obj).should == [4, 5, 6]
+ end
+
it "tries to call #to_a on the given argument if #to_ary is not provided" do
(obj = mock('[4,5,6]')).should_receive(:to_a).and_return([4, 5, 6])
Array(obj).should == [4, 5, 6]
Modified: MacRuby/trunk/spec/frozen/core/kernel/caller_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/caller_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/caller_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -14,24 +14,24 @@
b(skip)
end
end
-
+
it "is a private method" do
Kernel.should have_private_instance_method(:caller)
end
-
+
it "returns the current call stack" do
stack = c 0
stack[0].should =~ /caller_spec.rb.*?8.*?`a'/
stack[1].should =~ /caller_spec.rb.*?11.*?`b'/
stack[2].should =~ /caller_spec.rb.*?14.*?`c'/
end
-
+
it "omits a number of frames corresponding to the parameter" do
c(0)[1..-1].should == c(1)
c(0)[2..-1].should == c(2)
c(0)[3..-1].should == c(3)
end
-
+
it "defaults to omitting one frame" do
caller.should == caller(1)
end
@@ -89,7 +89,7 @@
stack[3].should =~/caller_spec\.rb:85/
end
end
-
+
ruby_version_is "1.9" do
it "returns the definition trace of a block when evaluated in a Proc binding" do
stack = CallerFixture.caller_of(CallerFixture.block)
@@ -140,7 +140,7 @@
it "shows the current line in the calling block twice when evaled" do
stack = CallerFixture.eval_caller(0)
-
+
stack[0].should == "(eval):1:in `eval_caller'"
stack[1].should =~/caller_fixture2\.rb:23:in `eval'/
stack[2].should =~/caller_fixture2\.rb:23:in `eval_caller'/
@@ -150,8 +150,6 @@
end
describe "Kernel.caller" do
- it "needs to be reviewed for spec completeness"
-
ruby_bug("redmine:3011", "1.8.7") do
it "returns one entry per call, even for recursive methods" do
two = CallerSpecs::recurse(2)
Modified: MacRuby/trunk/spec/frozen/core/kernel/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -295,6 +295,12 @@
"Done #{method}(#{args})"
end
end
+
+ class Ivar
+ def initialize
+ @greeting = "hello"
+ end
+ end
end
class EvalSpecs
Modified: MacRuby/trunk/spec/frozen/core/kernel/instance_eval_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/instance_eval_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/instance_eval_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -103,6 +103,17 @@
end
end
+ ruby_version_is ""..."1.9" do
+ it "makes the receiver metaclass the scoped class when used with a string" do
+ obj = Object.new
+ klass = obj.instance_eval %{
+ class B; end
+ B
+ }
+ klass.name.should =~ /(.+)::B/
+ end
+ end
+
it "gets constants in the receiver if a string given" do
KernelSpecs::InstEvalOuter::Inner::X_BY_STR.should == 2
end
Modified: MacRuby/trunk/spec/frozen/core/kernel/remove_instance_variable_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/remove_instance_variable_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/remove_instance_variable_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -5,4 +5,34 @@
it "is a private method" do
Kernel.should have_private_instance_method(:remove_instance_variable)
end
+
+ it "removes an ivar of a given name and return it's value" do
+ val = KernelSpecs::Ivar.new.send :remove_instance_variable, :@greeting
+ val.should == "hello"
+ end
+
+ it "supports the name being a string" do
+ val = KernelSpecs::Ivar.new.send :remove_instance_variable, "@greeting"
+ val.should == "hello"
+ end
+
+ it "tries to call #to_str if it's not a String or Symbol" do
+ s = mock("str")
+ s.should_receive(:to_str).and_return("@greeting")
+
+ val = KernelSpecs::Ivar.new.send :remove_instance_variable, s
+ val.should == "hello"
+ end
+
+ it "raises NameError if the ivar isn't defined" do
+ lambda {
+ KernelSpecs::Ivar.new.send :remove_instance_variable, :@unknown
+ }.should raise_error(NameError)
+ end
+
+ it "rejects unknown argument types" do
+ lambda {
+ KernelSpecs::Ivar.new.send :remove_instance_variable, Object
+ }.should raise_error(TypeError)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/kernel/respond_to_missing_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/respond_to_missing_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/respond_to_missing_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -60,11 +60,11 @@
@a.respond_to?(:pub_method, true).should be_true
end
- it "isn't called when obj responds to the given protected method" do
+ it "isn't called when obj responds to the given protected method, include_private = false" do
@a.should_not_receive(:respond_to_missing?)
@a.respond_to?(:protected_method, false).should be_true
end
-
+
it "isn't called when obj responds to the given protected method, include_private = true" do
@a.should_not_receive(:respond_to_missing?)
@a.respond_to?(:protected_method, true).should be_true
Modified: MacRuby/trunk/spec/frozen/core/kernel/respond_to_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/respond_to_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/respond_to_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -20,37 +20,26 @@
end
it "returns true if obj responds to the given public method" do
- @a.respond_to?("five").should == false
@a.respond_to?(:pub_method).should == true
@a.respond_to?("pub_method").should == true
end
- it "returns true if obj responds to the given protected method" do
- @a.respond_to?("five", true).should == false
- @a.respond_to?(:protected_method, false).should == true
- @a.respond_to?("protected_method", false).should == true
+ it "returns true if obj responds to the given protected method (include_private = true)" do
+ @a.respond_to?(:protected_method, true).should == true
+ @a.respond_to?("protected_method", true).should == true
end
- it "returns true if obj responds to the given protected method, include_private = true" do
- @a.respond_to?("seven").should == false
- @a.respond_to?(:protected_method).should == true
- @a.respond_to?("protected_method").should == true
- end
-
- it "returns true if obj responds to the given protected method" do
- @a.respond_to?("seven", true).should == false
+ it "returns true if obj responds to the given protected method (include_private = false)" do
@a.respond_to?(:protected_method, false).should == true
@a.respond_to?("protected_method", false).should == true
end
-
- it "returns true if obj responds to the given private method, include_private = true" do
- @a.respond_to?("six").should == false
- @a.respond_to?(:private_method).should == false
- @a.respond_to?("private_method").should == false
+
+ it "returns false even if obj responds to the given private method (include_private = false)" do
+ @a.respond_to?(:private_method, false).should == false
+ @a.respond_to?("private_method", false).should == false
end
- it "returns true if obj responds to the given private method" do
- @a.respond_to?("six", true).should == false
+ it "returns true if obj responds to the given private method (include_private = true)" do
@a.respond_to?(:private_method, true).should == true
@a.respond_to?("private_method", true).should == true
end
Modified: MacRuby/trunk/spec/frozen/core/kernel/spawn_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/spawn_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/spawn_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,155 +2,150 @@
ruby_version_is "1.9" do
describe "Kernel.spawn" do
- before(:each) do
- @f = tmp("spawn-#{rand}-#{$$}")
- @ruby = MSpecScript.config[:target]
+ before :each do
+ @name = tmp("kernel_spawn.txt")
+ rm_r @name
end
- after(:each) do
- File.unlink(@f) if File.exists?(@f)
+ after :each do
+ rm_r @name
end
it "executes the given command" do
- File.exists?(@f).should be_false
- pid = spawn("#{@ruby} -e 'print :spawn' >#{@f}")
+ pid = spawn("#{RUBY_EXE} -e 'print :spawn' >#{@name}")
Process.wait pid
- File.exists?(@f).should be_true
- File.read(@f).should == "spawn"
+ @name.should have_data("spawn")
end
it "executes the given command as a new process" do
- pid = spawn("#{@ruby} -v >#{@f}")
+ pid = spawn("#{RUBY_EXE} -v >#{@name}")
Process.wait pid
pid.should_not == Process.pid
end
it "returns the process ID of the new process as a Fixnum" do
- pid = spawn("#{@ruby} -v >#{@f}")
+ pid = spawn("#{RUBY_EXE} -v >#{@name}")
Process.wait pid
pid.should be_an_instance_of(Fixnum)
end
it "returns immediately" do
start = Time.now
- pid = spawn("#{@ruby} -e 'sleep 10'")
- (Time.now - start).should < 1
+ pid = spawn("#{RUBY_EXE} -e 'sleep 10'")
+ (Time.now - start).should < 5
Process.kill :KILL, pid
Process.wait pid
end
it "sets the child's environment variables according to a supplied hash" do
- pid = spawn({"spawn_of_ruby" => 'yes'}, "#{@ruby} -e 'print ENV[\"spawn_of_ruby\"]' >#{@f}")
+ pid = spawn({"spawn_of_ruby" => 'yes'}, "#{RUBY_EXE} -e 'print ENV[\"spawn_of_ruby\"]' >#{@name}")
Process.wait pid
- File.exists?(@f).should be_true
- File.read(@f).should == "yes"
+ @name.should have_data("yes")
end
platform_is_not :windows do
it "joins the current process group by default" do
- pid = spawn("#{@ruby} -e 'print Process.getpgid(Process.pid)' >#{@f}")
+ pid = spawn("#{RUBY_EXE} -e 'print Process.getpgid(Process.pid)' >#{@name}")
Process.wait pid
- File.exists?(@f).should be_true
- pgid = File.read(@f).to_i
+ pgid = File.read(@name).to_i
pgid.should == Process.getpgid(Process.pid)
end
it "joins a new process group if :pgroup => true" do
- pid = spawn("#{@ruby} -e 'print Process.getpgid(Process.pid)' >#{@f}", {:pgroup => true})
+ pid = spawn("#{RUBY_EXE} -e 'print Process.getpgid(Process.pid)' >#{@name}", {:pgroup => true})
Process.wait pid
- File.exists?(@f).should be_true
- pgid = File.read(@f).to_i
+ pgid = File.read(@name).to_i
pgid.should_not == Process.getpgid(Process.pid)
end
end
it "uses the current working directory as its working directory" do
- pid = spawn("#{@ruby} -e 'print Dir.pwd' >#{@f}")
+ pid = spawn("#{RUBY_EXE} -e 'print Dir.pwd' >#{@name}")
Process.wait pid
- File.exists?(@f).should be_true
- File.read(@f).should == Dir.pwd
+ @name.should have_data(Dir.pwd)
end
it "uses the given working directory if :chdir => dir is supplied" do
dir = File.expand_path('../')
dir.should_not == Dir.pwd
- pid = spawn("#{@ruby} -e 'print Dir.pwd' >#{@f}", {:chdir => dir})
+ pid = spawn("#{RUBY_EXE} -e 'print Dir.pwd' >#{@name}", {:chdir => dir})
Process.wait pid
- File.exists?(@f).should be_true
- File.read(@f).should == dir
+ @name.should have_data(dir)
end
it "redirects STDOUT to the given file descriptior if :out => Fixnum" do
- file = File.open(@f, 'w')
- fd = file.fileno
- pid = spawn("#{@ruby} -e 'print(:glark)'", {:out => fd})
+ file = File.open(@name, 'w')
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark)'", {:out => file.fileno})
Process.wait pid
file.close
- File.read(@f).should =~ /glark/
+ @name.should have_data("glark")
end
it "redirects STDOUT to the given file if :out => String" do
- pid = spawn("#{@ruby} -e 'print(:glark)'", {:out => @f})
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark)'", {:out => @name})
Process.wait pid
- File.read(@f).should =~ /glark/
+ @name.should have_data("glark")
end
it "redirects STDOUT to the given file if :out => IO" do
r, w = IO.pipe
- pid = spawn("#{@ruby} -e 'print(:glark)'", {:out => w})
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark)'", {:out => w})
Process.wait pid
w.close
- r.read.should =~ /glark/
+ r.read.should == "glark"
end
it "redirects STDERR to the given file descriptior if :err => Fixnum" do
- file = File.open(@f, 'w')
- fd = file.fileno
- pid = spawn("#{@ruby} -e 'warn(:glark)'", {:err => fd})
+ file = File.open(@name, 'w')
+ pid = spawn("#{RUBY_EXE} -e 'STDERR.print :glark'", {:err => file.fileno})
Process.wait pid
- File.read(@f).should =~ /glark/
file.close
+ @name.should have_data("glark")
end
it "redirects STDERR to the given file if :err => String" do
- pid = spawn("#{@ruby} -e 'warn(:glark)'", {:err => @f})
+ pid = spawn("#{RUBY_EXE} -e 'STDERR.print :glark'", {:err => @name})
Process.wait pid
- File.read(@f).should =~ /glark/
+ @name.should have_data("glark")
end
- it "redirects STDOUT to the given file if :err => IO" do
+ it "redirects STDERR to the given file descriptor if :err => IO" do
r, w = IO.pipe
- pid = spawn("#{@ruby} -e 'warn(:glark)'", {:err => w})
+ pid = spawn("#{RUBY_EXE} -e 'STDERR.print :glark'", {:err => w})
Process.wait pid
w.close
- r.read.should =~ /glark/
+ r.read.should == "glark"
end
- it "redirects both STDERR and STDOUT to the given file descriptior, name or IO" do
- file = File.open(@f, 'w')
- pid = spawn("#{@ruby} -e 'print(:glark); warn(:bang)'", {[:out, :err] => file.fileno})
+ it "redirects both STDERR and STDOUT to the given file descriptior" do
+ file = File.open(@name, 'w')
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark); STDOUT.flush; STDERR.print(:bang)'",
+ {[:out, :err] => file.fileno})
Process.wait pid
file.close
- File.read(@f).should =~ /glark/
- File.read(@f).should =~ /bang/
+ @name.should have_data("glarkbang")
+ end
- pid = spawn("#{@ruby} -e 'print(:glark); warn(:bang)'", {[:out, :err] => @f})
+ it "does NOT redirect both STDERR and STDOUT at the time to the given name" do
+ # this behavior is not guaranteed; it may be changed after 1.9.3 or later. [ruby-dev:41433]
+ File.open(@name, "w").close # touch @name
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark); STDOUT.flush; STDERR.print(:bang)'",
+ {[:out, :err] => @name})
Process.wait pid
- File.read(@f).should =~ /glark/
- File.read(@f).should =~ /bang/
+ @name.should have_data("")
+ end
+ it "redirects both STDERR and STDOUT to the given IO" do
r, w = IO.pipe
- pid = spawn("#{@ruby} -e 'print(:glark); warn(:bang)'", {[:out, :err] => w})
+ pid = spawn("#{RUBY_EXE} -e 'print(:glark); STDOUT.flush; STDERR.print(:bang)'", {[:out, :err] => w})
Process.wait pid
w.close
- tmp = r.read
- tmp.should =~ /glark/
- tmp.should =~ /bang/
+ r.read.should == "glarkbang"
end
- it 'generates a process of a command based on the given set of strings, regarding the first as the command and the others as the arguments' do
- Process.wait spawn('echo', 'a b', :out => @f)
- File.read(@f).should == "a b\n"
+ it "generates a process of a command based on the given set of strings, regarding the first as the command and the others as the arguments" do
+ Process.wait spawn('echo', 'a b', :out => @name)
+ File.read(@name).should == "a b\n"
end
end
end
Modified: MacRuby/trunk/spec/frozen/core/kernel/system_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/kernel/system_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/kernel/system_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Kernel#system" do
before do
- @ruby = MSpecScript.config[:target]
+ @ruby = ENV['RUBY_EXE']
end
it "can run basic things that exist" do
Modified: MacRuby/trunk/spec/frozen/core/math/log2_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/math/log2_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/math/log2_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -32,6 +32,33 @@
ruby_version_is "1.9" do
describe "Math.log2" do
- it "needs to be reviewed for spec completeness"
+ it "returns a float" do
+ Math.log2(5.79).should be_close(2.53356334821451, TOLERANCE)
+ end
+
+ it "returns the natural logarithm of the argument" do
+ Math.log2(1.1).should be_close(0.137503523749935, TOLERANCE)
+ Math.log2(3.14).should be_close(1.6507645591169, TOLERANCE)
+ end
+
+ it "raises an Errno::EDOM if the argument is less than 0" do
+ lambda { Math.log2(-1e-15) }.should raise_error( Math::DomainError)
+ end
+
+ it "raises an TypeError if the argument cannot be coerced with Float()" do
+ lambda { Math.log2("test") }.should raise_error(TypeError)
+ end
+
+ it "raises an TypeError if passed a numerical argument as a string" do
+ lambda { Math.log2("1.0") }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError if the argument is nil" do
+ lambda { Math.log2(nil) }.should raise_error(TypeError)
+ end
+
+ it "accepts any argument that can be coerced with Float()" do
+ Math.log2(MathSpecs::Float.new).should be_close(0.0, TOLERANCE)
+ end
end
end
Modified: MacRuby/trunk/spec/frozen/core/math/log_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/math/log_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/math/log_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -6,37 +6,56 @@
it "returns a float" do
Math.log(1).should be_kind_of(Float)
end
-
- it "returns the natural logarithm of the argument" do
+
+ it "returns the natural logarithm of the argument" do
Math.log(0.0001).should be_close(-9.21034037197618, TOLERANCE)
Math.log(0.000000000001e-15).should be_close(-62.1697975108392, TOLERANCE)
Math.log(1).should be_close(0.0, TOLERANCE)
Math.log(10).should be_close( 2.30258509299405, TOLERANCE)
Math.log(10e15).should be_close(36.8413614879047, TOLERANCE)
end
-
+
conflicts_with :Complex do
- it "raises an Errno::EDOM if the argument is less than 0" do
+ it "raises an Errno::EDOM if the argument is less than 0" do
lambda { Math.log(-1e-15) }.should raise_error(Errno::EDOM)
end
end
-
+
ruby_version_is ""..."1.9" do
- it "raises an ArgumentError if the argument cannot be coerced with Float()" do
+ it "raises an ArgumentError if the argument cannot be coerced with Float()" do
lambda { Math.log("test") }.should raise_error(ArgumentError)
end
+
+ it "accepts numerical values as string" do
+ Math.log("10").should be_close( 2.30258509299405, TOLERANCE)
+ Math.log("10e15").should be_close(36.8413614879047, TOLERANCE)
+ end
end
-
+
ruby_version_is "1.9" do
- it "raises a TypeError if the argument cannot be coerced with Float()" do
+ it "raises a TypeError if the argument cannot be coerced with Float()" do
lambda { Math.log("test") }.should raise_error(TypeError)
end
+
+ it "raises a TypeError for numerical values passed as string" do
+ lambda { Math.log("10") }.should raise_error(TypeError)
+ end
+
+ it "accepts a second argument for the base" do
+ Math.log(9, 3).should be_close(2, TOLERANCE)
+ Math.log(8, 1.4142135623730951).should be_close(6, TOLERANCE)
+ end
+
+ it "raises a TypeError when the numerical base cannot be coerced to a float" do
+ lambda { Math.log(10, "2") }.should raise_error(TypeError)
+ lambda { Math.log(10, nil) }.should raise_error(TypeError)
+ end
end
it "raises a TypeError if the argument is nil" do
lambda { Math.log(nil) }.should raise_error(TypeError)
end
-
+
it "accepts any argument that can be coerced with Float()" do
Math.log(MathSpecs::Float.new).should be_close(0.0, TOLERANCE)
end
Modified: MacRuby/trunk/spec/frozen/core/method/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/method/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/method/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -134,4 +134,24 @@
end
end
+
+ class ToProc
+ def method_called(a, b)
+ ScratchPad << [a, b]
+ end
+
+ def to_proc
+ method(:method_called).to_proc
+ end
+ end
+
+ class ToProcBeta
+ def method_called(a)
+ a
+ end
+
+ def to_proc
+ method(:method_called).to_proc
+ end
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/method/to_proc_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/method/to_proc_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/method/to_proc_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,6 +3,8 @@
describe "Method#to_proc" do
before(:each) do
+ ScratchPad.record []
+
@m = MethodSpecs::Methods.new
@meth = @m.method(:foo)
end
@@ -47,4 +49,20 @@
x.bar(&m).should == []
x.baz(1,2,3,&m).should == [1,2,3]
end
+
+ ruby_version_is ""..."1.9" do
+ it "returns a proc that accepts passed arguments like a block would" do
+ obj = MethodSpecs::ToProc.new
+
+ array = [["text", :comment], ["space", :chunk]]
+ array.each(&obj)
+
+ ScratchPad.recorded.should == array = [["text", :comment], ["space", :chunk]]
+ end
+ end
+
+ it "can be called directly and not unwrap arguments like a block" do
+ obj = MethodSpecs::ToProcBeta.new
+ obj.to_proc.call([1]).should == [1]
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/module/alias_method_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/alias_method_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/alias_method_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -55,5 +55,11 @@
ModuleSpecs::ReopeningModule.foo.should == true
lambda { ModuleSpecs::ReopeningModule.foo2 }.should_not raise_error(NoMethodError)
end
-
+
+ it "accesses a method defined on Object from Kernel" do
+ Kernel.should_not have_public_instance_method(:module_specs_public_method_on_object)
+
+ Kernel.should have_public_instance_method(:module_specs_alias_on_kernel)
+ Object.should have_public_instance_method(:module_specs_alias_on_kernel)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/module/autoload_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/autoload_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/autoload_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -104,13 +104,14 @@
it "does not load the file if the file is manually required" do
filename = fixture(__FILE__, "autoload_k.rb")
- ModuleSpecs::Autoload.autoload :K, filename
+ ModuleSpecs::Autoload.autoload :KHash, filename
require filename
ScratchPad.recorded.should == :loaded
ScratchPad.clear
- ModuleSpecs::Autoload::K.should == :autoload_k
+ ModuleSpecs::Autoload::KHash.should be_kind_of(Class)
+ ModuleSpecs::Autoload::KHash::K.should == :autoload_k
ScratchPad.recorded.should be_nil
end
Modified: MacRuby/trunk/spec/frozen/core/module/extend_object_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/extend_object_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/extend_object_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,32 +2,27 @@
require File.expand_path('../fixtures/classes', __FILE__)
describe "Module#extend_object" do
- it "extends the given object with constants and methods of self" do
- m = Module.new do
- const_set :C, "test"
- def test() "hello" end
- end
-
- o = mock('test')
- m.send(:extend_object, o)
-
- o.test.should == "hello"
- (class << o; C; end).should == "test"
+ before :each do
+ ScratchPad.clear
end
-
- it "is called when an object gets extended with self" do
- begin
- m = Module.new do
- def self.extend_object(o)
- $extended_object = o
- end
- end
-
- (o = mock('x')).extend(m)
-
- $extended_object.should == o
- ensure
- $extended_object = nil
- end
+
+ it "is called when #extend is called on an object" do
+ ModuleSpecs::ExtendObject.should_receive(:extend_object)
+ obj = mock("extended object")
+ obj.extend ModuleSpecs::ExtendObject
end
+
+ it "extends the given object with its constants and methods by default" do
+ obj = mock("extended direct")
+ ModuleSpecs::ExtendObject.send :extend_object, obj
+
+ obj.test_method.should == "hello test"
+ obj.metaclass.const_get(:C).should == :test
+ end
+
+ it "is called even when private" do
+ obj = mock("extended private")
+ obj.extend ModuleSpecs::ExtendObjectPrivate
+ ScratchPad.recorded.should == :extended
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/module/fixtures/autoload_k.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/fixtures/autoload_k.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/fixtures/autoload_k.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,7 @@
module ModuleSpecs::Autoload
- K = :autoload_k
+ class KHash < Hash
+ K = :autoload_k
+ end
end
ScratchPad.record :loaded
Modified: MacRuby/trunk/spec/frozen/core/module/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -364,6 +364,48 @@
module CyclicAppendB
include CyclicAppendA
end
+
+ module ExtendObject
+ C = :test
+ def test_method
+ "hello test"
+ end
+ end
+
+ module ExtendObjectPrivate
+ class << self
+ def extend_object(obj)
+ ScratchPad.record :extended
+ end
+ private :extend_object
+ end
+ end
end
+class Object
+ def module_specs_public_method_on_object; end
+
+ def module_specs_private_method_on_object; end
+ private :module_specs_private_method_on_object
+
+ def module_specs_protected_method_on_object; end
+ protected :module_specs_private_method_on_object
+
+ def module_specs_private_method_on_object_for_kernel_public; end
+ private :module_specs_private_method_on_object_for_kernel_public
+
+ def module_specs_public_method_on_object_for_kernel_protected; end
+ def module_specs_public_method_on_object_for_kernel_private; end
+end
+
+module Kernel
+ def module_specs_public_method_on_kernel; end
+
+ alias_method :module_specs_alias_on_kernel, :module_specs_public_method_on_object
+
+ public :module_specs_private_method_on_object_for_kernel_public
+ protected :module_specs_public_method_on_object_for_kernel_protected
+ private :module_specs_public_method_on_object_for_kernel_private
+end
+
ModuleSpecs::Nesting[:root_level] = Module.nesting
Modified: MacRuby/trunk/spec/frozen/core/module/include_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/include_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/include_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -263,6 +263,10 @@
ModuleSpecs::Basic.include?(ModuleSpecs::Super).should == false
end
+ it "returns false if given module is equal to self" do
+ ModuleSpecs.include?(ModuleSpecs).should == false
+ end
+
it "raises a TypeError when no module was given" do
lambda { ModuleSpecs::Child.include?("Test") }.should raise_error(TypeError)
lambda { ModuleSpecs::Child.include?(ModuleSpecs::Parent) }.should raise_error(TypeError)
Modified: MacRuby/trunk/spec/frozen/core/module/method_defined_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/method_defined_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/method_defined_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -23,6 +23,13 @@
ModuleSpecs::Child.method_defined?(:private_super_module).should == false
end
+ # unlike alias_method, module_function, public, and friends,
+ it "does not search Object or Kernel when called on a module" do
+ m = Module.new
+
+ m.method_defined?(:module_specs_public_method_on_kernel).should be_false
+ end
+
it "raises a TypeError when the given object is not a string/symbol/fixnum" do
c = Class.new
o = mock('123')
Modified: MacRuby/trunk/spec/frozen/core/module/name_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/name_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/name_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -15,10 +15,12 @@
Class.new.name.should be_nil
end
- require File.expand_path('../fixtures/name', __FILE__)
- # http://redmine.ruby-lang.org/issues/show/1833
- it "preserves the encoding in which the class was defined" do
- ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
+ not_compliant_on :jruby do
+ require File.expand_path('../fixtures/name', __FILE__)
+ # http://redmine.ruby-lang.org/issues/show/1833
+ it "preserves the encoding in which the class was defined" do
+ ModuleSpecs::NameEncoding.new.name.encoding.should == Encoding::UTF_8
+ end
end
end
Modified: MacRuby/trunk/spec/frozen/core/module/private_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/private_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/private_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -16,4 +16,22 @@
lambda { obj.foo }.should raise_error(NoMethodError)
end
+
+ it "makes a public Object instance method private in a new module" do
+ m = Module.new do
+ private :module_specs_public_method_on_object
+ end
+
+ m.should have_private_instance_method(:module_specs_public_method_on_object)
+
+ # Ensure we did not change Object's method
+ Object.should_not have_private_instance_method(:module_specs_public_method_on_object)
+ end
+
+ it "makes a public Object instance method private in Kernel" do
+ Kernel.should have_private_instance_method(
+ :module_specs_public_method_on_object_for_kernel_private)
+ Object.should_not have_private_instance_method(
+ :module_specs_public_method_on_object_for_kernel_private)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/module/protected_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/protected_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/protected_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -18,6 +18,23 @@
lambda { ModuleSpecs::Parent.protected_method_1 }.should raise_error(NoMethodError)
end
-
+
+ it "makes a public Object instance method protected in a new module" do
+ m = Module.new do
+ protected :module_specs_public_method_on_object
+ end
+
+ m.should have_protected_instance_method(:module_specs_public_method_on_object)
+
+ # Ensure we did not change Object's method
+ Object.should_not have_protected_instance_method(:module_specs_public_method_on_object)
+ end
+
+ it "makes a public Object instance method protected in Kernel" do
+ Kernel.should have_protected_instance_method(
+ :module_specs_public_method_on_object_for_kernel_protected)
+ Object.should_not have_protected_instance_method(
+ :module_specs_public_method_on_object_for_kernel_protected)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/module/public_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/module/public_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/module/public_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -5,4 +5,22 @@
it "on a superclass method calls the redefined method" do
ModuleSpecs::ChildPrivateMethodMadePublic.new.private_method_redefined.should == :after_redefinition
end
+
+ it "makes a private Object instance method public in a new module" do
+ m = Module.new do
+ public :module_specs_private_method_on_object
+ end
+
+ m.should have_public_instance_method(:module_specs_private_method_on_object)
+
+ # Ensure we did not change Object's method
+ Object.should_not have_public_instance_method(:module_specs_private_method_on_object)
+ end
+
+ it "makes a private Object instance method public in Kernel" do
+ Kernel.should have_public_instance_method(
+ :module_specs_private_method_on_object_for_kernel_public)
+ Object.should_not have_public_instance_method(
+ :module_specs_private_method_on_object_for_kernel_public)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/numeric/coerce_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/coerce_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/coerce_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,13 +3,13 @@
describe "Numeric#coerce" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
@obj.should_receive(:to_f).any_number_of_times.and_return(10.5)
end
it "returns [other, self] if self and other are instances of the same class" do
- a = NumericSub.new
- b = NumericSub.new
+ a = NumericSpecs::Subclass.new
+ b = NumericSpecs::Subclass.new
a.coerce(b).should == [b, a]
end
@@ -18,8 +18,8 @@
# of the behavior until we find out if it's a bug.
quarantine! do
it "considers the presense of a metaclass when checking the class of the objects" do
- a = NumericSub.new
- b = NumericSub.new
+ a = NumericSpecs::Subclass.new
+ b = NumericSpecs::Subclass.new
# inject a metaclass on a
class << a; true; end
@@ -30,7 +30,7 @@
end
it "calls #to_f to convert other if self responds to #to_f" do
- # Do not use NumericSub here, because coerce checks the classes of the receiver
+ # Do not use NumericSpecs::Subclass here, because coerce checks the classes of the receiver
# and arguments before calling #to_f.
other = mock("numeric")
lambda { @obj.coerce(other) }.should raise_error(TypeError)
Modified: MacRuby/trunk/spec/frozen/core/numeric/comparison_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/comparison_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/comparison_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,17 +3,46 @@
describe "Numeric#<=>" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "returns 0 if self equals other" do
(@obj <=> @obj).should == 0
end
-
+
it "returns nil if self does not equal other" do
- (@obj <=> NumericSub.new).should == nil
+ (@obj <=> NumericSpecs::Subclass.new).should == nil
(@obj <=> 10).should == nil
(@obj <=> -3.5).should == nil
(@obj <=> bignum_value).should == nil
end
-end
\ No newline at end of file
+
+ describe "with subclasses of Numeric" do
+ before :each do
+ @a = NumericSpecs::Comparison.new
+ @b = NumericSpecs::Comparison.new
+
+ ScratchPad.clear
+ end
+
+ it "is called when instances are compared with #<" do
+ (@a < @b).should be_false
+ ScratchPad.recorded.should == :numeric_comparison
+ end
+
+ it "is called when instances are compared with #<=" do
+ (@a <= @b).should be_false
+ ScratchPad.recorded.should == :numeric_comparison
+ end
+
+ it "is called when instances are compared with #>" do
+ (@a > @b).should be_true
+ ScratchPad.recorded.should == :numeric_comparison
+ end
+
+ it "is called when instances are compared with #>=" do
+ (@a >= @b).should be_true
+ ScratchPad.recorded.should == :numeric_comparison
+ end
+ end
+end
Modified: MacRuby/trunk/spec/frozen/core/numeric/div_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/div_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/div_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#div" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
ruby_version_is ""..."1.9" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/divmod_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/divmod_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/divmod_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#divmod" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
ruby_version_is ""..."1.9" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/eql_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/eql_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/eql_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#eql?" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "returns false if self's and other's types don't match" do
@@ -14,7 +14,7 @@
end
it "returns the result of calling self#== with other when self's and other's types match" do
- other = NumericSub.new
+ other = NumericSpecs::Subclass.new
@obj.should_receive(:==).with(other).and_return("result", nil)
@obj.should eql(other)
@obj.should_not eql(other)
Modified: MacRuby/trunk/spec/frozen/core/numeric/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,17 @@
-class NumericSub < Numeric
- # Allow methods to be mocked
- def singleton_method_added(val)
+module NumericSpecs
+ class Comparison < Numeric
+ # This method is used because we cannot define
+ # singleton methods on subclasses of Numeric,
+ # which is needed for a.should_receive to work.
+ def <=>(other)
+ ScratchPad.record :numeric_comparison
+ 1
+ end
end
-end
\ No newline at end of file
+
+ class Subclass < Numeric
+ # Allow methods to be mocked
+ def singleton_method_added(val)
+ end
+ end
+end
Modified: MacRuby/trunk/spec/frozen/core/numeric/floor_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/floor_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/floor_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#floor" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "converts self to a Float (using #to_f) and returns the #floor'ed result" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/initialize_copy_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/initialize_copy_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/initialize_copy_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,7 +4,7 @@
describe "Numeric#singleton_method_added" do
it "raises a TypeError when trying to #dup a Numeric" do
lambda do
- a = NumericSub.new
+ a = NumericSpecs::Subclass.new
a.dup
end.should raise_error(TypeError)
Modified: MacRuby/trunk/spec/frozen/core/numeric/integer_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/integer_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/integer_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,6 +3,6 @@
describe "Numeric#integer?" do
it "returns false" do
- NumericSub.new.integer?.should == false
+ NumericSpecs::Subclass.new.integer?.should == false
end
end
Modified: MacRuby/trunk/spec/frozen/core/numeric/modulo_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/modulo_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/modulo_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,7 +4,7 @@
describe "Numeric#modulo" do
ruby_version_is "".."1.9" do
it "returns the result of calling self#% with other" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.should_receive(:%).with(20).and_return(:result)
obj.modulo(20).should == :result
@@ -13,7 +13,7 @@
ruby_version_is "1.9" do
it "returns the result of self#- (self#/ other) * other" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.should_receive(:/).with(15).and_return(13)
obj.should_receive(:-).with(195).and_return(5)
# 200 % 15 == 5
Modified: MacRuby/trunk/spec/frozen/core/numeric/nonzero_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/nonzero_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/nonzero_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#nonzero?" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "returns self if self#zero? is false" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/quo_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/quo_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/quo_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,7 +4,7 @@
describe "Numeric#quo" do
ruby_version_is ""..."1.9" do
it "returns the result of calling self#/ with other" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.should_receive(:/).with(19).and_return(:result)
obj.quo(19).should == :result
@@ -13,7 +13,7 @@
ruby_version_is "1.9" do
it "returns the result of calling self#/ with other" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.should_receive(:coerce).twice.and_return([19,19])
obj.should_receive(:<=>).any_number_of_times.and_return(1)
obj.should_receive(:/).and_return(20)
Modified: MacRuby/trunk/spec/frozen/core/numeric/remainder_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/remainder_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/remainder_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#remainder" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
@result = mock("Numeric#% result")
@other = mock("Passed Object")
end
Modified: MacRuby/trunk/spec/frozen/core/numeric/round_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/round_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/round_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#round" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "converts self to a Float (using #to_f) and returns the #round'ed result" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/shared/abs.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/shared/abs.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/shared/abs.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe :numeric_abs, :shared => true do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "returns self when self is greater than 0" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/singleton_method_added_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/singleton_method_added_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/singleton_method_added_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,14 +3,14 @@
describe "Numeric#singleton_method_added" do
before(:all) do
- class ::NumericSub
+ class ::NumericSpecs::Subclass
# We want restore default Numeric behaviour for this particular test
remove_method :singleton_method_added
end
end
after(:all) do
- class ::NumericSub
+ class ::NumericSpecs::Subclass
# Allow mocking methods again
def singleton_method_added(val)
end
@@ -19,7 +19,7 @@
it "raises a TypeError when trying to define a singleton method on a Numeric" do
lambda do
- a = NumericSub.new
+ a = NumericSpecs::Subclass.new
def a.test; end
end.should raise_error(TypeError)
Modified: MacRuby/trunk/spec/frozen/core/numeric/step_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/step_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/step_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#step with [stop, step]" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "raises an ArgumentError when step is 0" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/to_int_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/to_int_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/to_int_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#to_int" do
it "returns self#to_i" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.should_receive(:to_i).and_return(:result)
obj.to_int.should == :result
end
Modified: MacRuby/trunk/spec/frozen/core/numeric/truncate_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/truncate_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/truncate_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#truncate" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "converts self to a Float (using #to_f) and returns the #truncate'd result" do
Modified: MacRuby/trunk/spec/frozen/core/numeric/uplus_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/uplus_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/uplus_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#+@" do
it "returns self" do
- obj = NumericSub.new
+ obj = NumericSpecs::Subclass.new
obj.send(:+@).should == obj
end
end
Modified: MacRuby/trunk/spec/frozen/core/numeric/zero_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/numeric/zero_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/numeric/zero_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Numeric#zero?" do
before(:each) do
- @obj = NumericSub.new
+ @obj = NumericSpecs::Subclass.new
end
it "returns true if self is 0" do
Modified: MacRuby/trunk/spec/frozen/core/regexp/inspect_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/regexp/inspect_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/regexp/inspect_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -17,4 +17,12 @@
it "doesn't over escape forward slashes" do
/\/foo\/bar/.inspect.should == '/\/foo\/bar/'
end
+
+ it "escapes 2 slashes in a row properly" do
+ Regexp.new("//").inspect.should == '/\/\//'
+ end
+
+ it "does not over escape" do
+ Regexp.new('\\\/').inspect.should == "/\\\\\\//"
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/signal/trap_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/signal/trap_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/signal/trap_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,85 @@
require File.expand_path('../../../spec_helper', __FILE__)
describe "Signal.trap" do
- it "needs to be reviewed for spec completeness"
+ before :each do
+ ScratchPad.clear
+
+ @proc = lambda { ScratchPad.record :proc_trap }
+ @saved_trap = Signal.trap(:HUP, @proc)
+ end
+
+ after :each do
+ Signal.trap(:HUP, @saved_trap) if @saved_trap
+ end
+
+ it "returns the previous handler" do
+ Signal.trap(:HUP, @saved_trap).should equal(@proc)
+ end
+
+ it "accepts a block in place of a proc/command argument" do
+ Signal.trap(:HUP) { ScratchPad.record :block_trap }
+ Process.kill :HUP, Process.pid
+ sleep 0.5
+ ScratchPad.recorded.should == :block_trap
+ end
+
+ ruby_version_is ""..."1.9" do
+ it "ignores the signal when passed nil" do
+ Signal.trap :HUP, nil
+ Signal.trap(:HUP, @saved_trap).should == "IGNORE"
+ end
+
+ it "uses the command argument when passed both a command and block" do
+ Signal.trap(:HUP, @proc) { ScratchPad.record :block_trap }
+ Process.kill :HUP, Process.pid
+ ScratchPad.recorded.should == :proc_trap
+ end
+ end
+
+ ruby_version_is "1.9" do
+ it "ignores the signal when passed nil" do
+ Signal.trap :HUP, nil
+ Signal.trap(:HUP, @saved_trap).should be_nil
+ end
+ end
+
+ it "accepts long names as Strings" do
+ Signal.trap "SIGHUP", @proc
+ Signal.trap("SIGHUP", @saved_trap).should equal(@proc)
+ end
+
+ it "acceps short names as Strings" do
+ Signal.trap "HUP", @proc
+ Signal.trap("HUP", @saved_trap).should equal(@proc)
+ end
+
+ it "accepts long names as Symbols" do
+ Signal.trap :SIGHUP, @proc
+ Signal.trap(:SIGHUP, @saved_trap).should equal(@proc)
+ end
+
+ it "accepts short names as Symbols" do
+ Signal.trap :HUP, @proc
+ Signal.trap(:HUP, @saved_trap).should equal(@proc)
+ end
+
+ it "accepts 'SIG_DFL' in place of a proc" do
+ Signal.trap :HUP, "SIG_DFL"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ end
+
+ it "accepts 'DEFAULT' in place of a proc" do
+ Signal.trap :HUP, "DEFAULT"
+ Signal.trap(:HUP, @saved_trap).should == "DEFAULT"
+ end
+
+ it "accepts 'SIG_IGN' in place of a proc" do
+ Signal.trap :HUP, "SIG_IGN"
+ Signal.trap(:HUP, "SIG_IGN").should == "IGNORE"
+ end
+
+ it "accepts 'IGNORE' in place of a proc" do
+ Signal.trap :HUP, "IGNORE"
+ Signal.trap(:HUP, "IGNORE").should == "IGNORE"
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/string/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,3 +1,13 @@
+class Object
+ # This helper is defined here rather than in MSpec because
+ # it is only used in #unpack specs.
+ def unpack_format(count=nil, repeat=nil)
+ format = "#{instance_variable_get(:@method)}#{count}"
+ format *= repeat if repeat
+ format
+ end
+end
+
module StringSpecs
class MyString < String; end
class MyArray < Array; end
Modified: MacRuby/trunk/spec/frozen/core/string/inspect_spec_disabled.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/inspect_spec_disabled.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/inspect_spec_disabled.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,75 +3,671 @@
require File.expand_path('../fixtures/classes.rb', __FILE__)
describe "String#inspect" do
- ruby_version_is ""..."1.9" do
- # Older versions of MRI wrongly print \b as \010
- it "returns a string with nonprinting charaters replaced by escaped-numeric notation" do
- ("\000".."A").to_a.to_s.inspect.should == "\"\\000\\001\\002\\003\\004\\005\\006\\a\\b\\t\\n\\v\\f\\r\\016\\017\\020\\021\\022\\023\\024\\025\\026\\027\\030\\031\\032\\e\\034\\035\\036\\037 !\\\"\\\#$%&'()*+,-./0123456789\""
- end
+ it "taints the result if self is tainted" do
+ "foo".taint.inspect.tainted?.should == true
+ "foo\n".taint.inspect.tainted?.should == true
end
- ruby_version_is "1.9" do
- it "returns a string with nonprinting characters replaced by \\x notation" do
- ("\000".."A").to_a.join('').should == "\x00\x01\x02\x03\x04\x05\x06\a\b\t\n\v\f\r\x0E\x0F\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\e\x1C\x1D\x1E\x1F !\"\#$%&'()*+,-./0123456789:;<=>?@A"
- end
- it "returns a string with nonprinting, non-ASCII characters replaced by \\u notation for Unicode strings" do
- (127..150).map{|o| o.chr('utf-8')}.to_a.join('').inspect.should == "\u007F\u0080\u0081\u0082\u0083\u0084\u0085\u0086\u0087\u0088\u0089\u008A\u008B\u008C\u008D\u008E\u008F\u0090\u0091\u0092\u0093\u0094\u0095\u0096".inspect
- end
+ it "does not return subclass instances" do
+ str = StringSpecs::MyString.new
+ str << "test"
+ str.should == "test"
+ str.inspect.should be_an_instance_of(String)
end
- # $KCODE is deprecated/removed on 1.9
+ it "returns a string with special characters replaced with \\<char> notation" do
+ [ ["\a", '"\\a"'],
+ ["\b", '"\\b"'],
+ ["\t", '"\\t"'],
+ ["\n", '"\\n"'],
+ ["\v", '"\\v"'],
+ ["\f", '"\\f"'],
+ ["\r", '"\\r"'],
+ ["\e", '"\\e"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with \" and \\ escaped with a backslash" do
+ [ ["\"", '"\\""'],
+ ["\\", '"\\\\"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with \\#<char> when # is followed by $, @, {" do
+ [ ["\#$", '"\\#$"'],
+ ["\#@", '"\\#@"'],
+ ["\#{", '"\\#{"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with # not escaped when followed by any other character" do
+ [ ["#", '"#"'],
+ ["#1", '"#1"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with printable non-alphanumeric characters unescaped" do
+ [ [" ", '" "'],
+ ["!", '"!"'],
+ ["$", '"$"'],
+ ["%", '"%"'],
+ ["&", '"&"'],
+ ["'", '"\'"'],
+ ["(", '"("'],
+ [")", '")"'],
+ ["*", '"*"'],
+ ["+", '"+"'],
+ [",", '","'],
+ ["-", '"-"'],
+ [".", '"."'],
+ ["/", '"/"'],
+ [":", '":"'],
+ [";", '";"'],
+ ["<", '"<"'],
+ ["=", '"="'],
+ [">", '">"'],
+ ["?", '"?"'],
+ ["@", '"@"'],
+ ["[", '"["'],
+ ["]", '"]"'],
+ ["^", '"^"'],
+ ["_", '"_"'],
+ ["`", '"`"'],
+ ["{", '"{"'],
+ ["|", '"|"'],
+ ["}", '"}"'],
+ ["~", '"~"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with numeric characters unescaped" do
+ [ ["0", '"0"'],
+ ["1", '"1"'],
+ ["2", '"2"'],
+ ["3", '"3"'],
+ ["4", '"4"'],
+ ["5", '"5"'],
+ ["6", '"6"'],
+ ["7", '"7"'],
+ ["8", '"8"'],
+ ["9", '"9"'],
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with upper-case alpha characters unescaped" do
+ [ ["A", '"A"'],
+ ["B", '"B"'],
+ ["C", '"C"'],
+ ["D", '"D"'],
+ ["E", '"E"'],
+ ["F", '"F"'],
+ ["G", '"G"'],
+ ["H", '"H"'],
+ ["I", '"I"'],
+ ["J", '"J"'],
+ ["K", '"K"'],
+ ["L", '"L"'],
+ ["M", '"M"'],
+ ["N", '"N"'],
+ ["O", '"O"'],
+ ["P", '"P"'],
+ ["Q", '"Q"'],
+ ["R", '"R"'],
+ ["S", '"S"'],
+ ["T", '"T"'],
+ ["U", '"U"'],
+ ["V", '"V"'],
+ ["W", '"W"'],
+ ["X", '"X"'],
+ ["Y", '"Y"'],
+ ["Z", '"Z"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with lower-case alpha characters unescaped" do
+ [ ["a", '"a"'],
+ ["b", '"b"'],
+ ["c", '"c"'],
+ ["d", '"d"'],
+ ["e", '"e"'],
+ ["f", '"f"'],
+ ["g", '"g"'],
+ ["h", '"h"'],
+ ["i", '"i"'],
+ ["j", '"j"'],
+ ["k", '"k"'],
+ ["l", '"l"'],
+ ["m", '"m"'],
+ ["n", '"n"'],
+ ["o", '"o"'],
+ ["p", '"p"'],
+ ["q", '"q"'],
+ ["r", '"r"'],
+ ["s", '"s"'],
+ ["t", '"t"'],
+ ["u", '"u"'],
+ ["v", '"v"'],
+ ["w", '"w"'],
+ ["x", '"x"'],
+ ["y", '"y"'],
+ ["z", '"z"']
+ ].should be_computed_by(:inspect)
+ end
+
ruby_version_is ""..."1.9" do
- it "produces different output based on $KCODE" do
- old_kcode = $KCODE
+ it "returns a string with non-printing characters replaced with \\0nn notation" do
+ [ ["\000", '"\\000"'],
+ ["\001", '"\\001"'],
+ ["\002", '"\\002"'],
+ ["\003", '"\\003"'],
+ ["\004", '"\\004"'],
+ ["\005", '"\\005"'],
+ ["\006", '"\\006"'],
+ ["\016", '"\\016"'],
+ ["\017", '"\\017"'],
+ ["\020", '"\\020"'],
+ ["\021", '"\\021"'],
+ ["\022", '"\\022"'],
+ ["\023", '"\\023"'],
+ ["\024", '"\\024"'],
+ ["\025", '"\\025"'],
+ ["\026", '"\\026"'],
+ ["\027", '"\\027"'],
+ ["\030", '"\\030"'],
+ ["\031", '"\\031"'],
+ ["\032", '"\\032"'],
+ ["\034", '"\\034"'],
+ ["\035", '"\\035"'],
+ ["\036", '"\\036"'],
+ ["\177", '"\\177"'],
+ ["\200", '"\\200"'],
+ ["\201", '"\\201"'],
+ ["\202", '"\\202"'],
+ ["\203", '"\\203"'],
+ ["\204", '"\\204"'],
+ ["\205", '"\\205"'],
+ ["\206", '"\\206"'],
+ ["\207", '"\\207"'],
+ ["\210", '"\\210"'],
+ ["\211", '"\\211"'],
+ ["\212", '"\\212"'],
+ ["\213", '"\\213"'],
+ ["\214", '"\\214"'],
+ ["\215", '"\\215"'],
+ ["\216", '"\\216"'],
+ ["\217", '"\\217"'],
+ ["\220", '"\\220"'],
+ ["\221", '"\\221"'],
+ ["\222", '"\\222"'],
+ ["\223", '"\\223"'],
+ ["\224", '"\\224"'],
+ ["\225", '"\\225"'],
+ ["\226", '"\\226"'],
+ ["\227", '"\\227"'],
+ ["\230", '"\\230"'],
+ ["\231", '"\\231"'],
+ ["\232", '"\\232"'],
+ ["\233", '"\\233"'],
+ ["\234", '"\\234"'],
+ ["\235", '"\\235"'],
+ ["\236", '"\\236"'],
+ ["\237", '"\\237"'],
+ ["\240", '"\\240"'],
+ ["\241", '"\\241"'],
+ ["\242", '"\\242"'],
+ ["\243", '"\\243"'],
+ ["\244", '"\\244"'],
+ ["\245", '"\\245"'],
+ ["\246", '"\\246"'],
+ ["\247", '"\\247"'],
+ ["\250", '"\\250"'],
+ ["\251", '"\\251"'],
+ ["\252", '"\\252"'],
+ ["\253", '"\\253"'],
+ ["\254", '"\\254"'],
+ ["\255", '"\\255"'],
+ ["\256", '"\\256"'],
+ ["\257", '"\\257"'],
+ ["\260", '"\\260"'],
+ ["\261", '"\\261"'],
+ ["\262", '"\\262"'],
+ ["\263", '"\\263"'],
+ ["\264", '"\\264"'],
+ ["\265", '"\\265"'],
+ ["\266", '"\\266"'],
+ ["\267", '"\\267"'],
+ ["\270", '"\\270"'],
+ ["\271", '"\\271"'],
+ ["\272", '"\\272"'],
+ ["\273", '"\\273"'],
+ ["\274", '"\\274"'],
+ ["\275", '"\\275"'],
+ ["\276", '"\\276"'],
+ ["\277", '"\\277"'],
+ ["\300", '"\\300"'],
+ ["\301", '"\\301"'],
+ ["\302", '"\\302"'],
+ ["\303", '"\\303"'],
+ ["\304", '"\\304"'],
+ ["\305", '"\\305"'],
+ ["\306", '"\\306"'],
+ ["\307", '"\\307"'],
+ ["\310", '"\\310"'],
+ ["\311", '"\\311"'],
+ ["\312", '"\\312"'],
+ ["\313", '"\\313"'],
+ ["\314", '"\\314"'],
+ ["\315", '"\\315"'],
+ ["\316", '"\\316"'],
+ ["\317", '"\\317"'],
+ ["\320", '"\\320"'],
+ ["\321", '"\\321"'],
+ ["\322", '"\\322"'],
+ ["\323", '"\\323"'],
+ ["\324", '"\\324"'],
+ ["\325", '"\\325"'],
+ ["\326", '"\\326"'],
+ ["\327", '"\\327"'],
+ ["\330", '"\\330"'],
+ ["\331", '"\\331"'],
+ ["\332", '"\\332"'],
+ ["\333", '"\\333"'],
+ ["\334", '"\\334"'],
+ ["\335", '"\\335"'],
+ ["\336", '"\\336"'],
+ ["\337", '"\\337"'],
+ ["\340", '"\\340"'],
+ ["\341", '"\\341"'],
+ ["\342", '"\\342"'],
+ ["\343", '"\\343"'],
+ ["\344", '"\\344"'],
+ ["\345", '"\\345"'],
+ ["\346", '"\\346"'],
+ ["\347", '"\\347"'],
+ ["\350", '"\\350"'],
+ ["\351", '"\\351"'],
+ ["\352", '"\\352"'],
+ ["\353", '"\\353"'],
+ ["\354", '"\\354"'],
+ ["\355", '"\\355"'],
+ ["\356", '"\\356"'],
+ ["\357", '"\\357"'],
+ ["\360", '"\\360"'],
+ ["\361", '"\\361"'],
+ ["\362", '"\\362"'],
+ ["\363", '"\\363"'],
+ ["\364", '"\\364"'],
+ ["\365", '"\\365"'],
+ ["\366", '"\\366"'],
+ ["\367", '"\\367"'],
+ ["\370", '"\\370"'],
+ ["\371", '"\\371"'],
+ ["\372", '"\\372"'],
+ ["\373", '"\\373"'],
+ ["\374", '"\\374"'],
+ ["\375", '"\\375"'],
+ ["\376", '"\\376"'],
+ ["\377", '"\\377"']
+ ].should be_computed_by(:inspect)
+ end
- begin
+ describe "with $KCODE" do
+ before :each do
+ @kcode = $KCODE
+ end
+
+ after :each do
+ $KCODE = @kcode
+ end
+
+ it "returns a string with bytes represented in \\0nn notation when $KCODE == 'NONE'" do
$KCODE = "NONE"
"äöü".inspect.should == "\"\\303\\244\\303\\266\\303\\274\""
+ end
+ it "returns a string with extended character set when $KCODE == 'UTF-8'" do
$KCODE = "UTF-8"
"äöü".inspect.should == "\"äöü\""
- ensure
- $KCODE = old_kcode
end
- end
- it "can handle malformed UTF-8 string when $KCODE is UTF-8" do
- old_kcode = $KCODE
-
- begin
+ it "can handle malformed UTF-8 string when $KCODE is UTF-8" do
$KCODE = "UTF-8"
# malformed UTF-8 sequence
"\007äöüz\303".inspect.should == "\"\\aäöüz\\303\""
- ensure
- $KCODE = old_kcode
end
end
end
ruby_version_is "1.9" do
+ it "returns a string with non-printing characters replaced by \\x notation" do
+ # Avoid the file encoding by computing the string with #chr.
+ [ [0000.chr, '"\\x00"'],
+ [0001.chr, '"\\x01"'],
+ [0002.chr, '"\\x02"'],
+ [0003.chr, '"\\x03"'],
+ [0004.chr, '"\\x04"'],
+ [0005.chr, '"\\x05"'],
+ [0006.chr, '"\\x06"'],
+ [0016.chr, '"\\x0E"'],
+ [0017.chr, '"\\x0F"'],
+ [0020.chr, '"\\x10"'],
+ [0021.chr, '"\\x11"'],
+ [0022.chr, '"\\x12"'],
+ [0023.chr, '"\\x13"'],
+ [0024.chr, '"\\x14"'],
+ [0025.chr, '"\\x15"'],
+ [0026.chr, '"\\x16"'],
+ [0027.chr, '"\\x17"'],
+ [0030.chr, '"\\x18"'],
+ [0031.chr, '"\\x19"'],
+ [0032.chr, '"\\x1A"'],
+ [0034.chr, '"\\x1C"'],
+ [0035.chr, '"\\x1D"'],
+ [0036.chr, '"\\x1E"'],
+ [0037.chr, '"\\x1F"'],
+ [0177.chr, '"\\x7F"'],
+ [0200.chr, '"\\x80"'],
+ [0201.chr, '"\\x81"'],
+ [0202.chr, '"\\x82"'],
+ [0203.chr, '"\\x83"'],
+ [0204.chr, '"\\x84"'],
+ [0205.chr, '"\\x85"'],
+ [0206.chr, '"\\x86"'],
+ [0207.chr, '"\\x87"'],
+ [0210.chr, '"\\x88"'],
+ [0211.chr, '"\\x89"'],
+ [0212.chr, '"\\x8A"'],
+ [0213.chr, '"\\x8B"'],
+ [0214.chr, '"\\x8C"'],
+ [0215.chr, '"\\x8D"'],
+ [0216.chr, '"\\x8E"'],
+ [0217.chr, '"\\x8F"'],
+ [0220.chr, '"\\x90"'],
+ [0221.chr, '"\\x91"'],
+ [0222.chr, '"\\x92"'],
+ [0223.chr, '"\\x93"'],
+ [0224.chr, '"\\x94"'],
+ [0225.chr, '"\\x95"'],
+ [0226.chr, '"\\x96"'],
+ [0227.chr, '"\\x97"'],
+ [0230.chr, '"\\x98"'],
+ [0231.chr, '"\\x99"'],
+ [0232.chr, '"\\x9A"'],
+ [0233.chr, '"\\x9B"'],
+ [0234.chr, '"\\x9C"'],
+ [0235.chr, '"\\x9D"'],
+ [0236.chr, '"\\x9E"'],
+ [0237.chr, '"\\x9F"'],
+ [0240.chr, '"\\xA0"'],
+ [0241.chr, '"\\xA1"'],
+ [0242.chr, '"\\xA2"'],
+ [0243.chr, '"\\xA3"'],
+ [0244.chr, '"\\xA4"'],
+ [0245.chr, '"\\xA5"'],
+ [0246.chr, '"\\xA6"'],
+ [0247.chr, '"\\xA7"'],
+ [0250.chr, '"\\xA8"'],
+ [0251.chr, '"\\xA9"'],
+ [0252.chr, '"\\xAA"'],
+ [0253.chr, '"\\xAB"'],
+ [0254.chr, '"\\xAC"'],
+ [0255.chr, '"\\xAD"'],
+ [0256.chr, '"\\xAE"'],
+ [0257.chr, '"\\xAF"'],
+ [0260.chr, '"\\xB0"'],
+ [0261.chr, '"\\xB1"'],
+ [0262.chr, '"\\xB2"'],
+ [0263.chr, '"\\xB3"'],
+ [0264.chr, '"\\xB4"'],
+ [0265.chr, '"\\xB5"'],
+ [0266.chr, '"\\xB6"'],
+ [0267.chr, '"\\xB7"'],
+ [0270.chr, '"\\xB8"'],
+ [0271.chr, '"\\xB9"'],
+ [0272.chr, '"\\xBA"'],
+ [0273.chr, '"\\xBB"'],
+ [0274.chr, '"\\xBC"'],
+ [0275.chr, '"\\xBD"'],
+ [0276.chr, '"\\xBE"'],
+ [0277.chr, '"\\xBF"'],
+ [0300.chr, '"\\xC0"'],
+ [0301.chr, '"\\xC1"'],
+ [0302.chr, '"\\xC2"'],
+ [0303.chr, '"\\xC3"'],
+ [0304.chr, '"\\xC4"'],
+ [0305.chr, '"\\xC5"'],
+ [0306.chr, '"\\xC6"'],
+ [0307.chr, '"\\xC7"'],
+ [0310.chr, '"\\xC8"'],
+ [0311.chr, '"\\xC9"'],
+ [0312.chr, '"\\xCA"'],
+ [0313.chr, '"\\xCB"'],
+ [0314.chr, '"\\xCC"'],
+ [0315.chr, '"\\xCD"'],
+ [0316.chr, '"\\xCE"'],
+ [0317.chr, '"\\xCF"'],
+ [0320.chr, '"\\xD0"'],
+ [0321.chr, '"\\xD1"'],
+ [0322.chr, '"\\xD2"'],
+ [0323.chr, '"\\xD3"'],
+ [0324.chr, '"\\xD4"'],
+ [0325.chr, '"\\xD5"'],
+ [0326.chr, '"\\xD6"'],
+ [0327.chr, '"\\xD7"'],
+ [0330.chr, '"\\xD8"'],
+ [0331.chr, '"\\xD9"'],
+ [0332.chr, '"\\xDA"'],
+ [0333.chr, '"\\xDB"'],
+ [0334.chr, '"\\xDC"'],
+ [0335.chr, '"\\xDD"'],
+ [0336.chr, '"\\xDE"'],
+ [0337.chr, '"\\xDF"'],
+ [0340.chr, '"\\xE0"'],
+ [0341.chr, '"\\xE1"'],
+ [0342.chr, '"\\xE2"'],
+ [0343.chr, '"\\xE3"'],
+ [0344.chr, '"\\xE4"'],
+ [0345.chr, '"\\xE5"'],
+ [0346.chr, '"\\xE6"'],
+ [0347.chr, '"\\xE7"'],
+ [0350.chr, '"\\xE8"'],
+ [0351.chr, '"\\xE9"'],
+ [0352.chr, '"\\xEA"'],
+ [0353.chr, '"\\xEB"'],
+ [0354.chr, '"\\xEC"'],
+ [0355.chr, '"\\xED"'],
+ [0356.chr, '"\\xEE"'],
+ [0357.chr, '"\\xEF"'],
+ [0360.chr, '"\\xF0"'],
+ [0361.chr, '"\\xF1"'],
+ [0362.chr, '"\\xF2"'],
+ [0363.chr, '"\\xF3"'],
+ [0364.chr, '"\\xF4"'],
+ [0365.chr, '"\\xF5"'],
+ [0366.chr, '"\\xF6"'],
+ [0367.chr, '"\\xF7"'],
+ [0370.chr, '"\\xF8"'],
+ [0371.chr, '"\\xF9"'],
+ [0372.chr, '"\\xFA"'],
+ [0373.chr, '"\\xFB"'],
+ [0374.chr, '"\\xFC"'],
+ [0375.chr, '"\\xFD"'],
+ [0376.chr, '"\\xFE"'],
+ [0377.chr, '"\\xFF"']
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with non-printing, characters replaced by \\u notation for Unicode strings" do
+ [ [0000.chr('utf-8'), '"\u0000"'],
+ [0001.chr('utf-8'), '"\u0001"'],
+ [0002.chr('utf-8'), '"\u0002"'],
+ [0003.chr('utf-8'), '"\u0003"'],
+ [0004.chr('utf-8'), '"\u0004"'],
+ [0005.chr('utf-8'), '"\u0005"'],
+ [0006.chr('utf-8'), '"\u0006"'],
+ [0016.chr('utf-8'), '"\u000E"'],
+ [0017.chr('utf-8'), '"\u000F"'],
+ [0020.chr('utf-8'), '"\u0010"'],
+ [0021.chr('utf-8'), '"\u0011"'],
+ [0022.chr('utf-8'), '"\u0012"'],
+ [0023.chr('utf-8'), '"\u0013"'],
+ [0024.chr('utf-8'), '"\u0014"'],
+ [0025.chr('utf-8'), '"\u0015"'],
+ [0026.chr('utf-8'), '"\u0016"'],
+ [0027.chr('utf-8'), '"\u0017"'],
+ [0030.chr('utf-8'), '"\u0018"'],
+ [0031.chr('utf-8'), '"\u0019"'],
+ [0032.chr('utf-8'), '"\u001A"'],
+ [0034.chr('utf-8'), '"\u001C"'],
+ [0035.chr('utf-8'), '"\u001D"'],
+ [0036.chr('utf-8'), '"\u001E"'],
+ [0037.chr('utf-8'), '"\u001F"'],
+ [0177.chr('utf-8'), '"\u007F"'],
+ [0200.chr('utf-8'), '"\u0080"'],
+ [0201.chr('utf-8'), '"\u0081"'],
+ [0202.chr('utf-8'), '"\u0082"'],
+ [0203.chr('utf-8'), '"\u0083"'],
+ [0204.chr('utf-8'), '"\u0084"'],
+ [0206.chr('utf-8'), '"\u0086"'],
+ [0207.chr('utf-8'), '"\u0087"'],
+ [0210.chr('utf-8'), '"\u0088"'],
+ [0211.chr('utf-8'), '"\u0089"'],
+ [0212.chr('utf-8'), '"\u008A"'],
+ [0213.chr('utf-8'), '"\u008B"'],
+ [0214.chr('utf-8'), '"\u008C"'],
+ [0215.chr('utf-8'), '"\u008D"'],
+ [0216.chr('utf-8'), '"\u008E"'],
+ [0217.chr('utf-8'), '"\u008F"'],
+ [0220.chr('utf-8'), '"\u0090"'],
+ [0221.chr('utf-8'), '"\u0091"'],
+ [0222.chr('utf-8'), '"\u0092"'],
+ [0223.chr('utf-8'), '"\u0093"'],
+ [0224.chr('utf-8'), '"\u0094"'],
+ [0225.chr('utf-8'), '"\u0095"'],
+ [0226.chr('utf-8'), '"\u0096"'],
+ [0227.chr('utf-8'), '"\u0097"'],
+ [0230.chr('utf-8'), '"\u0098"'],
+ [0231.chr('utf-8'), '"\u0099"'],
+ [0232.chr('utf-8'), '"\u009A"'],
+ [0233.chr('utf-8'), '"\u009B"'],
+ [0234.chr('utf-8'), '"\u009C"'],
+ [0235.chr('utf-8'), '"\u009D"'],
+ [0236.chr('utf-8'), '"\u009E"'],
+ [0237.chr('utf-8'), '"\u009F"'],
+ ].should be_computed_by(:inspect)
+ end
+
+ it "returns a string with extended characters for Unicode strings" do
+ [ [0240.chr('utf-8'), '" "'],
+ [0241.chr('utf-8'), '"¡"'],
+ [0242.chr('utf-8'), '"¢"'],
+ [0243.chr('utf-8'), '"£"'],
+ [0244.chr('utf-8'), '"¤"'],
+ [0245.chr('utf-8'), '"¥"'],
+ [0246.chr('utf-8'), '"¦"'],
+ [0247.chr('utf-8'), '"§"'],
+ [0250.chr('utf-8'), '"¨"'],
+ [0251.chr('utf-8'), '"©"'],
+ [0252.chr('utf-8'), '"ª"'],
+ [0253.chr('utf-8'), '"«"'],
+ [0254.chr('utf-8'), '"¬"'],
+ [0255.chr('utf-8'), '""'],
+ [0256.chr('utf-8'), '"®"'],
+ [0257.chr('utf-8'), '"¯"'],
+ [0260.chr('utf-8'), '"°"'],
+ [0261.chr('utf-8'), '"±"'],
+ [0262.chr('utf-8'), '"²"'],
+ [0263.chr('utf-8'), '"³"'],
+ [0264.chr('utf-8'), '"´"'],
+ [0265.chr('utf-8'), '"µ"'],
+ [0266.chr('utf-8'), '"¶"'],
+ [0267.chr('utf-8'), '"·"'],
+ [0270.chr('utf-8'), '"¸"'],
+ [0271.chr('utf-8'), '"¹"'],
+ [0272.chr('utf-8'), '"º"'],
+ [0273.chr('utf-8'), '"»"'],
+ [0274.chr('utf-8'), '"¼"'],
+ [0275.chr('utf-8'), '"½"'],
+ [0276.chr('utf-8'), '"¾"'],
+ [0277.chr('utf-8'), '"¿"'],
+ [0300.chr('utf-8'), '"À"'],
+ [0301.chr('utf-8'), '"Á"'],
+ [0302.chr('utf-8'), '"Â"'],
+ [0303.chr('utf-8'), '"Ã"'],
+ [0304.chr('utf-8'), '"Ä"'],
+ [0305.chr('utf-8'), '"Å"'],
+ [0306.chr('utf-8'), '"Æ"'],
+ [0307.chr('utf-8'), '"Ç"'],
+ [0310.chr('utf-8'), '"È"'],
+ [0311.chr('utf-8'), '"É"'],
+ [0312.chr('utf-8'), '"Ê"'],
+ [0313.chr('utf-8'), '"Ë"'],
+ [0314.chr('utf-8'), '"Ì"'],
+ [0315.chr('utf-8'), '"Í"'],
+ [0316.chr('utf-8'), '"Î"'],
+ [0317.chr('utf-8'), '"Ï"'],
+ [0320.chr('utf-8'), '"Ð"'],
+ [0321.chr('utf-8'), '"Ñ"'],
+ [0322.chr('utf-8'), '"Ò"'],
+ [0323.chr('utf-8'), '"Ó"'],
+ [0324.chr('utf-8'), '"Ô"'],
+ [0325.chr('utf-8'), '"Õ"'],
+ [0326.chr('utf-8'), '"Ö"'],
+ [0327.chr('utf-8'), '"×"'],
+ [0330.chr('utf-8'), '"Ø"'],
+ [0331.chr('utf-8'), '"Ù"'],
+ [0332.chr('utf-8'), '"Ú"'],
+ [0333.chr('utf-8'), '"Û"'],
+ [0334.chr('utf-8'), '"Ü"'],
+ [0335.chr('utf-8'), '"Ý"'],
+ [0336.chr('utf-8'), '"Þ"'],
+ [0337.chr('utf-8'), '"ß"'],
+ [0340.chr('utf-8'), '"à"'],
+ [0341.chr('utf-8'), '"á"'],
+ [0342.chr('utf-8'), '"â"'],
+ [0343.chr('utf-8'), '"ã"'],
+ [0344.chr('utf-8'), '"ä"'],
+ [0345.chr('utf-8'), '"å"'],
+ [0346.chr('utf-8'), '"æ"'],
+ [0347.chr('utf-8'), '"ç"'],
+ [0350.chr('utf-8'), '"è"'],
+ [0351.chr('utf-8'), '"é"'],
+ [0352.chr('utf-8'), '"ê"'],
+ [0353.chr('utf-8'), '"ë"'],
+ [0354.chr('utf-8'), '"ì"'],
+ [0355.chr('utf-8'), '"í"'],
+ [0356.chr('utf-8'), '"î"'],
+ [0357.chr('utf-8'), '"ï"'],
+ [0360.chr('utf-8'), '"ð"'],
+ [0361.chr('utf-8'), '"ñ"'],
+ [0362.chr('utf-8'), '"ò"'],
+ [0363.chr('utf-8'), '"ó"'],
+ [0364.chr('utf-8'), '"ô"'],
+ [0365.chr('utf-8'), '"õ"'],
+ [0366.chr('utf-8'), '"ö"'],
+ [0367.chr('utf-8'), '"÷"'],
+ [0370.chr('utf-8'), '"ø"'],
+ [0371.chr('utf-8'), '"ù"'],
+ [0372.chr('utf-8'), '"ú"'],
+ [0373.chr('utf-8'), '"û"'],
+ [0374.chr('utf-8'), '"ü"'],
+ [0375.chr('utf-8'), '"ý"'],
+ [0376.chr('utf-8'), '"þ"'],
+ [0377.chr('utf-8'), '"ÿ"']
+ ].should be_computed_by(:inspect)
+ end
+
+ # TODO: these specs need to be fixed, they are testing the result of
+ # #force_encoding being called *after* #inspect.
it "produces different output based on #force_encoding" do
- "äöü".inspect.force_encoding('UTF-8').should ==
- "\"\xC3\xA4\xC3\xB6\xC3\xBC\""
- "äöü".inspect.force_encoding('ASCII').should ==
- "\"äöü\"".force_encoding('ASCII')
+ "äöü".inspect.force_encoding('UTF-8').should == "\"\xC3\xA4\xC3\xB6\xC3\xBC\""
+ "äöü".inspect.force_encoding('ASCII').should == "\"äöü\"".force_encoding('ASCII')
end
it "can handle malformed UTF-8 string for #force_encoding('UTF-8')" do
# malformed UTF-8 sequence
- "\007äöüz\303".inspect.force_encoding('UTF-8').should ==
+ "\007äöüz\303".inspect.force_encoding('UTF-8').should ==
"\"\\aäöüz\\xC3\"".force_encoding('UTF-8')
end
end
-
- it "taints the result if self is tainted" do
- "foo".taint.inspect.tainted?.should == true
- "foo\n".taint.inspect.tainted?.should == true
- end
-
- it "does not return subclass instances" do
- str = StringSpecs::MyString.new
- str << "test"
- str.should == "test"
- str.inspect.class.should_not == StringSpecs::MyString
- end
end
Modified: MacRuby/trunk/spec/frozen/core/string/split_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/split_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/split_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -247,6 +247,16 @@
ary.should == ["こ", "に", "ち", "わ"]
end
+ it "respects the encoding of the regexp when splitting between characters" do
+ str = "\303\202"
+
+ $KCODE = "a"
+
+ ary = str.split(//u)
+ ary.size.should == 1
+ ary.should == ["\303\202"]
+ end
+
it "includes all captures in the result array" do
"hello".split(/(el)/).should == ["h", "el", "lo"]
"hi!".split(/()/).should == ["h", "", "i", "", "!"]
Modified: MacRuby/trunk/spec/frozen/core/string/sub_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/sub_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/sub_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -396,13 +396,13 @@
end
ruby_version_is ""..."1.9" do
- it "raises a TypeError when self is frozen" do
+ it "raises a RuntimeError when self is frozen" do
s = "hello"
s.freeze
s.sub!(/ROAR/) { "x" } # ok
- lambda { s.sub!(/e/) { "e" } }.should raise_error(TypeError)
- lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(TypeError)
+ lambda { s.sub!(/e/) { "e" } }.should raise_error(RuntimeError)
+ lambda { s.sub!(/[aeiou]/) { '*' } }.should raise_error(RuntimeError)
end
end
Modified: MacRuby/trunk/spec/frozen/core/string/to_i_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/to_i_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/to_i_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -132,4 +132,26 @@
lambda { "".to_i(-1) }.should raise_error(ArgumentError)
lambda { "".to_i(37) }.should raise_error(ArgumentError)
end
+
+ it "returns a Fixnum for long strings with trailing spaces" do
+ "0 ".to_i.should == 0
+ "0 ".to_i.should be_an_instance_of(Fixnum)
+
+ "10 ".to_i.should == 10
+ "10 ".to_i.should be_an_instance_of(Fixnum)
+
+ "-10 ".to_i.should == -10
+ "-10 ".to_i.should be_an_instance_of(Fixnum)
+ end
+
+ it "returns a Fixnum for long strings with leading spaces" do
+ " 0".to_i.should == 0
+ " 0".to_i.should be_an_instance_of(Fixnum)
+
+ " 10".to_i.should == 10
+ " 10".to_i.should be_an_instance_of(Fixnum)
+
+ " -10".to_i.should == -10
+ " -10".to_i.should be_an_instance_of(Fixnum)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/string/unpack_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/string/unpack_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/string/unpack_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -100,6 +100,10 @@
"\x80\x02\x00\x42\xFF\x87\xF3\x00".unpack('c*').should == [-128, 2, 0, 66, -1, -121, -13, 0]
"\xF3\x02\x00\x42\x32\x87\xF3\x02".unpack('c0C*').should == [243, 2, 0, 66, 50, 135, 243, 2]
end
+
+ it "decodes respective of the already decoded data" do
+ "\0\0\0\1hello".unpack("iC5").last.should == 111
+ end
end
describe "String#unpack with 'Q' and 'q' directives" do
Modified: MacRuby/trunk/spec/frozen/core/struct/each_pair_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/each_pair_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/each_pair_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct#each_pair" do
it "passes each key value pair to the given block" do
- car = Struct::Car.new('Ford', 'Ranger', 2001)
+ car = StructClasses::Car.new('Ford', 'Ranger', 2001)
car.each_pair do |key, value|
value.should == car[key]
end
@@ -11,14 +11,14 @@
ruby_version_is "" ... "1.8.7" do
it "fails if not passed a block" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car.each_pair }.should raise_error(LocalJumpError)
end
end
ruby_version_is "1.8.7" do
it "returns an Enumerator if not passed a block" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
car.each_pair.should be_an_instance_of(enumerator_class)
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/each_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/each_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/each_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct#each" do
it "passes each value to the given block" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
i = -1
car.each do |value|
value.should == car[i += 1]
@@ -12,14 +12,14 @@
ruby_version_is "" ... "1.8.7" do
it "fails if not passed a block" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car.each }.should raise_error(LocalJumpError)
end
end
ruby_version_is "1.8.7" do
it "returns an Enumerator if not passed a block" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
car.each.should be_an_instance_of(enumerator_class)
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/element_reference_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/element_reference_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/element_reference_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,13 +3,13 @@
describe "Struct[]" do
it "is a synonym for new" do
- Struct::Ruby['2.0', 'i686'].should be_kind_of(Struct::Ruby)
+ StructClasses::Ruby['2.0', 'i686'].should be_kind_of(StructClasses::Ruby)
end
end
describe "Struct#[]" do
it "returns the attribute referenced" do
- car = Struct::Car.new('Ford', 'Ranger', 1983)
+ car = StructClasses::Car.new('Ford', 'Ranger', 1983)
car['make'].should == 'Ford'
car['model'].should == 'Ranger'
car['year'].should == 1983
@@ -25,7 +25,7 @@
end
it "fails when it does not know about the requested attribute" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car[3] }.should raise_error(IndexError)
lambda { car[-4] }.should raise_error(IndexError)
lambda { car[:body] }.should raise_error(NameError)
@@ -33,12 +33,12 @@
end
it "fails if passed too many arguments" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car[:make, :model] }.should raise_error(ArgumentError)
end
it "fails if not passed a string, symbol, or integer" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car[Object.new] }.should raise_error(TypeError)
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/element_set_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/element_set_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/element_set_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct#[]=" do
it "assigns the passed value" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
car[:model] = 'Escape'
car[:model].should == 'Escape'
@@ -19,7 +19,7 @@
end
it "fails when trying to assign attributes which don't exist" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car[:something] = true }.should raise_error(NameError)
lambda { car[3] = true }.should raise_error(IndexError)
Modified: MacRuby/trunk/spec/frozen/core/struct/eql_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/eql_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/eql_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -6,8 +6,8 @@
it_behaves_like(:struct_equal_value, :eql?)
it "returns false if any corresponding elements are not #eql?" do
- car = Struct::Car.new("Honda", "Accord", 1998)
- similar_car = Struct::Car.new("Honda", "Accord", 1998.0)
+ car = StructClasses::Car.new("Honda", "Accord", 1998)
+ similar_car = StructClasses::Car.new("Honda", "Accord", 1998.0)
car.send(@method, similar_car).should be_false
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,10 +1,26 @@
-class Apple < Struct; end
+module StructClasses
-Struct.new('Ruby', :version, :platform)
-Struct.new('Car', :make, :model, :year)
-class Honda < Struct::Car
- def initialize(*args)
- self.make = "Honda"
- super(*args)
+ class Apple < Struct; end
+
+ Ruby = Struct.new(:version, :platform)
+
+ Car = Struct.new(:make, :model, :year)
+
+ class Honda < Car
+ def initialize(*args)
+ self.make = "Honda"
+ super(*args)
+ end
end
+
+ class SubclassX < Struct
+ end
+
+ class SubclassX
+ attr_reader :key
+ def initialize(*)
+ @key = :value
+ super
+ end
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/hash_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/hash_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/hash_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,25 +2,26 @@
require File.expand_path('../fixtures/classes', __FILE__)
describe "Struct#hash" do
-
+
it "returns the same fixnum for structs with the same content" do
- [Struct::Ruby.new("1.8.6", "PPC"), Struct::Car.new("Hugo", "Foo", "1972")].each do |stc|
+ [StructClasses::Ruby.new("1.8.6", "PPC"),
+ StructClasses::Car.new("Hugo", "Foo", "1972")].each do |stc|
stc.hash.should == stc.dup.hash
stc.hash.should be_kind_of(Fixnum)
end
end
-
+
it "returns the same value if structs are #eql?" do
- car = Struct::Car.new("Honda", "Accord", "1998")
- similar_car = Struct::Car.new("Honda", "Accord", "1998")
+ car = StructClasses::Car.new("Honda", "Accord", "1998")
+ similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
car.should eql(similar_car)
car.hash.should == similar_car.hash
end
-
+
ruby_bug "redmine #1852", "1.9.1" do
it "returns the same hash for recursive structs" do
- car = Struct::Car.new("Honda", "Accord", "1998")
- similar_car = Struct::Car.new("Honda", "Accord", "1998")
+ car = StructClasses::Car.new("Honda", "Accord", "1998")
+ similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
car[:make] = car
similar_car[:make] = car
car.hash.should == similar_car.hash
@@ -30,4 +31,4 @@
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/spec/frozen/core/struct/initialize_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/initialize_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/initialize_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,17 +4,21 @@
describe "Struct#initialize" do
it "is private" do
- Struct::Car.should have_private_instance_method(:initialize)
+ StructClasses::Car.should have_private_instance_method(:initialize)
end
it "does nothing when passed a set of fields equal to self" do
- car = same_car = Struct::Car.new("Honda", "Accord", "1998")
+ car = same_car = StructClasses::Car.new("Honda", "Accord", "1998")
car.instance_eval { initialize("Honda", "Accord", "1998") }
car.should == same_car
end
it "explicitly sets instance variables to nil when args not provided to initialize" do
- car = Honda.new
+ car = StructClasses::Honda.new
car.make.should == nil # still nil despite override in Honda#initialize b/c of super order
end
+
+ it "can be overriden" do
+ StructClasses::SubclassX.new(:y).new.key.should == :value
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/inspect_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/inspect_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/inspect_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,8 +4,8 @@
describe "Struct#inspect" do
it "returns a string representation of some kind" do
- car = Struct::Car.new('Ford', 'Ranger')
- car.inspect.should == '#<struct Struct::Car make="Ford", model="Ranger", year=nil>'
+ car = StructClasses::Car.new('Ford', 'Ranger')
+ car.inspect.should == '#<struct StructClasses::Car make="Ford", model="Ranger", year=nil>'
# ujihisa reported in http://rubyspec.org/issues/show/130 that the
# following example failed under mspec. Prefixing 'Whiskey' with a double
# colon causes it to work. Given that this is an mspec bug, as opposed to
Modified: MacRuby/trunk/spec/frozen/core/struct/length_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/length_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/length_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct#length" do
it "returns the number of attributes" do
- Struct::Car.new('Cadillac', 'DeVille').length.should == 3
- Struct::Car.new.length.should == 3
+ StructClasses::Car.new('Cadillac', 'DeVille').length.should == 3
+ StructClasses::Car.new.length.should == 3
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/members_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/members_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/members_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,17 +4,17 @@
describe "Struct#members" do
ruby_version_is ""..."1.9" do
it "returns an array of attribute names" do
- Struct::Car.new.members.should == %w(make model year)
- Struct::Car.new('Cadillac').members.should == %w(make model year)
- Struct::Ruby.members.should == %w(version platform)
+ StructClasses::Car.new.members.should == %w(make model year)
+ StructClasses::Car.new('Cadillac').members.should == %w(make model year)
+ StructClasses::Ruby.members.should == %w(version platform)
end
end
ruby_version_is "1.9" do
it "returns an array of attribute names" do
- Struct::Car.new.members.should == [:make, :model, :year]
- Struct::Car.new('Cadillac').members.should == [:make, :model, :year]
- Struct::Ruby.members.should == [:version, :platform]
+ StructClasses::Car.new.members.should == [:make, :model, :year]
+ StructClasses::Car.new('Cadillac').members.should == [:make, :model, :year]
+ StructClasses::Ruby.members.should == [:version, :platform]
end
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/spec/frozen/core/struct/new_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/new_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/new_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -63,8 +63,8 @@
end
it "does not create a constant with symbol as first argument" do
- struct = Struct.new(:Animal, :name, :legs, :eyeballs)
- struct.should_not == Struct::Animal
+ struct = Struct.new(:Animal2, :name, :legs, :eyeballs)
+ Struct.const_defined?("Animal2").should be_false
end
@@ -119,25 +119,25 @@
end
it "creates a constant in subclass' namespace" do
- struct = Apple.new('Computer', :size)
- struct.should == Apple::Computer
+ struct = StructClasses::Apple.new('Computer', :size)
+ struct.should == StructClasses::Apple::Computer
end
it "creates an instance" do
- Struct::Ruby.new.kind_of?(Struct::Ruby).should == true
+ StructClasses::Ruby.new.kind_of?(StructClasses::Ruby).should == true
end
it "creates reader methods" do
- Struct::Ruby.new.should have_method(:version)
- Struct::Ruby.new.should have_method(:platform)
+ StructClasses::Ruby.new.should have_method(:version)
+ StructClasses::Ruby.new.should have_method(:platform)
end
it "creates writer methods" do
- Struct::Ruby.new.should have_method(:version=)
- Struct::Ruby.new.should have_method(:platform=)
+ StructClasses::Ruby.new.should have_method(:version=)
+ StructClasses::Ruby.new.should have_method(:platform=)
end
it "fails with too many arguments" do
- lambda { Struct::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
+ lambda { StructClasses::Ruby.new('2.0', 'i686', true) }.should raise_error(ArgumentError)
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/select_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/select_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/select_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,16 +3,16 @@
describe "Struct#select" do
it "raises an ArgumentError if given any non-block arguments" do
- lambda { Struct::Car.new.select(1) { } }.should raise_error(ArgumentError)
+ lambda { StructClasses::Car.new.select(1) { } }.should raise_error(ArgumentError)
end
it "returns a new array of elements for which block is true" do
- struct = Struct::Car.new("Toyota", "Tercel", "2000")
+ struct = StructClasses::Car.new("Toyota", "Tercel", "2000")
struct.select { |i| i == "2000" }.should == [ "2000" ]
end
it "returns an instance of Array" do
- struct = Struct::Car.new("Ford", "Escort", "1995")
+ struct = StructClasses::Car.new("Ford", "Escort", "1995")
struct.select { true }.should be_kind_of(Array)
end
-end
\ No newline at end of file
+end
Modified: MacRuby/trunk/spec/frozen/core/struct/shared/equal_value.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/shared/equal_value.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/shared/equal_value.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,28 +1,28 @@
describe :struct_equal_value, :shared => true do
it "returns true if the other is the same object" do
- car = same_car = Struct::Car.new("Honda", "Accord", "1998")
+ car = same_car = StructClasses::Car.new("Honda", "Accord", "1998")
car.send(@method, same_car).should == true
end
it "returns true if the other has all the same fields" do
- car = Struct::Car.new("Honda", "Accord", "1998")
- similar_car = Struct::Car.new("Honda", "Accord", "1998")
+ car = StructClasses::Car.new("Honda", "Accord", "1998")
+ similar_car = StructClasses::Car.new("Honda", "Accord", "1998")
car.send(@method, similar_car).should == true
end
it "returns false if the other is a different object or has different fields" do
- car = Struct::Car.new("Honda", "Accord", "1998")
- different_car = Struct::Car.new("Honda", "Accord", "1995")
+ car = StructClasses::Car.new("Honda", "Accord", "1998")
+ different_car = StructClasses::Car.new("Honda", "Accord", "1995")
car.send(@method, different_car).should == false
end
ruby_bug "redmine #1885", "1.8" do
it "handles recursive structures by returning false if a difference can be found" do
MyClass = Struct.new(:foo)
- x = Struct::Car.new("Honda", "Accord", "1998")
+ x = StructClasses::Car.new("Honda", "Accord", "1998")
x[:make] = x
- stepping = Struct::Car.new("Honda", "Accord", "1998")
- stone = Struct::Car.new(stepping, "Accord", "1998")
+ stepping = StructClasses::Car.new("Honda", "Accord", "1998")
+ stone = StructClasses::Car.new(stepping, "Accord", "1998")
stepping[:make] = stone
x.send(@method, stepping).should == true
Modified: MacRuby/trunk/spec/frozen/core/struct/size_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/size_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/size_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,6 +3,6 @@
describe "Struct#size" do
it "is a synonym for length" do
- Struct::Car.new.size.should == Struct::Car.new.length
+ StructClasses::Car.new.size.should == StructClasses::Car.new.length
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/struct_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/struct_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/struct_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct anonymous class instance methods" do
it "Enumerable methods should work" do
- car = Struct::Car.new('Ford', 'Ranger', '2001')
+ car = StructClasses::Car.new('Ford', 'Ranger', '2001')
car.detect { |value| value.include? 'F' }.should == 'Ford'
car.reject { |value| value.include? 'F' }.should == ['Ranger', '2001']
end
@@ -16,12 +16,12 @@
end
it "reader method should not interfere with undefined methods" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car.something_weird }.should raise_error(NoMethodError)
end
it "writer method be a synonym for []=" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
car.model.should == 'Ranger'
car.model = 'F150'
car.model.should == 'F150'
@@ -33,7 +33,7 @@
describe "Struct subclasses" do
it "can be subclassed" do
- compact = Class.new Struct::Car
+ compact = Class.new StructClasses::Car
compact.new.class.should == compact
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/to_a_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/to_a_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/to_a_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,7 +3,7 @@
describe "Struct#to_a" do
it "returns the values for this instance as an array" do
- Struct::Car.new('Geo', 'Metro', 1995).to_a.should == ['Geo', 'Metro', 1995]
- Struct::Car.new('Ford').to_a.should == ['Ford', nil, nil]
+ StructClasses::Car.new('Geo', 'Metro', 1995).to_a.should == ['Geo', 'Metro', 1995]
+ StructClasses::Car.new('Ford').to_a.should == ['Ford', nil, nil]
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/to_s_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/to_s_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/to_s_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,7 +4,7 @@
describe "Struct#to_s" do
it "is a synonym for inspect" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
car.inspect.should == car.to_s
end
Modified: MacRuby/trunk/spec/frozen/core/struct/values_at_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/values_at_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/values_at_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -10,7 +10,7 @@
end
it "fails when passed unsupported types" do
- car = Struct::Car.new('Ford', 'Ranger')
+ car = StructClasses::Car.new('Ford', 'Ranger')
lambda { car.values_at('make') }.should raise_error(TypeError)
end
end
Modified: MacRuby/trunk/spec/frozen/core/struct/values_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/struct/values_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/struct/values_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,9 +3,9 @@
describe "Struct#values" do
it "is a synonym for to_a" do
- car = Struct::Car.new('Nissan', 'Maxima')
+ car = StructClasses::Car.new('Nissan', 'Maxima')
car.values.should == car.to_a
- Struct::Car.new.values.should == Struct::Car.new.to_a
+ StructClasses::Car.new.values.should == StructClasses::Car.new.to_a
end
end
Modified: MacRuby/trunk/spec/frozen/core/time/eql_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/time/eql_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/time/eql_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -7,4 +7,10 @@
Time.at(100, 100).should_not eql(Time.at(100, 99))
Time.at(100, 100).should_not eql(Time.at(99, 100))
end
+
+ it "returns false when given a non-time value" do
+ Time.at(100, 100).should_not eql("100")
+ Time.at(100, 100).should_not eql(100)
+ Time.at(100, 100).should_not eql(100.1)
+ end
end
Modified: MacRuby/trunk/spec/frozen/core/time/shared/gmt_offset.rb
===================================================================
--- MacRuby/trunk/spec/frozen/core/time/shared/gmt_offset.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/core/time/shared/gmt_offset.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,4 +4,25 @@
Time.new.send(@method).should == 10800
end
end
+
+ it "returns the correct offset for US Eastern time zone around daylight savings time change" do
+ with_timezone("EST5EDT") do
+ Time.local(2010,3,14,1,59,59).send(@method).should == -5*60*60
+ Time.local(2010,3,14,2,0,0).send(@method).should == -4*60*60
+ end
+ end
+
+ it "returns the correct offset for Hawaii around daylight savings time change" do
+ with_timezone("Pacific/Honolulu") do
+ Time.local(2010,3,14,1,59,59).send(@method).should == -10*60*60
+ Time.local(2010,3,14,2,0,0).send(@method).should == -10*60*60
+ end
+ end
+
+ it "returns the correct offset for New Zealand around daylight savings time change" do
+ with_timezone("Pacific/Auckland") do
+ Time.local(2010,4,4,1,59,59).send(@method).should == 13*60*60
+ Time.local(2010,4,4,3,0,0).send(@method).should == 12*60*60
+ end
+ end
end
Modified: MacRuby/trunk/spec/frozen/language/constants_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/constants_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/constants_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -35,6 +35,12 @@
CS_CONST10.should == :const10_1
end
+ it "searches Object after searching other scopes" do
+ module ConstantSpecs::SpecAdded1
+ CS_CONST10.should == :const10_1
+ end
+ end
+
it "searches Object if a toplevel qualifier (::X) is given" do
::CS_CONST1.should == :const1
::CS_CONST10.should == :const10_1
Modified: MacRuby/trunk/spec/frozen/language/defined_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/defined_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/defined_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -272,78 +272,210 @@
end
end
- it "returns nil for an expression with 'not' and an undefined method" do
- defined?(not defined_specs_undefined_method).should be_nil
- end
+ describe "with logical connectives" do
+ it "returns nil for an expression with '!' and an undefined method" do
+ defined?(!defined_specs_undefined_method).should be_nil
+ end
- it "returns nil for an expression with 'not' and an unset class variable" do
- defined?(not @@defined_specs_undefined_class_variable).should be_nil
- end
+ it "returns nil for an expression with '!' and an unset class variable" do
+ defined?(!@@defined_specs_undefined_class_variable).should be_nil
+ end
- it "does not propagate an exception raised by a method in a 'not' expression" do
- defined?(not DefinedSpecs.exception_method).should be_nil
- ScratchPad.recorded.should == :defined_specs_exception
- end
+ it "returns nil for an expression with 'not' and an undefined method" do
+ defined?(not defined_specs_undefined_method).should be_nil
+ end
- ruby_version_is ""..."1.9" do
- it "calls a method in a 'not' expression and returns 'expression'" do
- defined?(not DefinedSpecs.side_effects).should == "expression"
- ScratchPad.recorded.should == :defined_specs_side_effects
+ it "returns nil for an expression with 'not' and an unset class variable" do
+ defined?(not @@defined_specs_undefined_class_variable).should be_nil
end
- it "returns 'expression' for an expression with 'not' and an unset global variable" do
- defined?(not $defined_specs_undefined_global_variable).should == "expression"
+ it "does not propagate an exception raised by a method in a 'not' expression" do
+ defined?(not DefinedSpecs.exception_method).should be_nil
+ ScratchPad.recorded.should == :defined_specs_exception
end
- it "returns 'expression' for an expression with 'not' and an unset instance variable" do
- defined?(not @defined_specs_undefined_global_variable).should == "expression"
+ it "returns 'expression' for an expression with '&&/and' and an unset global variable" do
+ defined?($defined_specs_undefined_global_variable && true).should == "expression"
+ defined?(true && $defined_specs_undefined_global_variable).should == "expression"
+ defined?($defined_specs_undefined_global_variable and true).should == "expression"
end
- end
- ruby_version_is "1.9" do
- it "returns 'method' for a 'not' expression with a method" do
- defined?(not DefinedSpecs.side_effects).should == "method"
+ it "returns 'expression' for an expression with '&&/and' and an unset instance variable" do
+ defined?(@defined_specs_undefined_instance_variable && true).should == "expression"
+ defined?(true && @defined_specs_undefined_instance_variable).should == "expression"
+ defined?(@defined_specs_undefined_instance_variable and true).should == "expression"
end
- it "calls a method in a 'not' expression and returns 'method'" do
- defined?(not DefinedSpecs.side_effects).should == "method"
- ScratchPad.recorded.should == :defined_specs_side_effects
+ it "returns 'expression' for an expression '&&/and' regardless of its truth value" do
+ defined?(true && false).should == "expression"
+ defined?(true and false).should == "expression"
end
- it "returns nil for an expression with 'not' and an unset global variable" do
- defined?(not $defined_specs_undefined_global_variable).should be_nil
+ it "returns 'expression' for an expression with '||/or' and an unset global variable" do
+ defined?($defined_specs_undefined_global_variable || true).should == "expression"
+ defined?(true || $defined_specs_undefined_global_variable).should == "expression"
+ defined?($defined_specs_undefined_global_variable or true).should == "expression"
end
- it "returns nil for an expression with 'not' and an unset instance variable" do
- defined?(not @defined_specs_undefined_global_variable).should be_nil
+ it "returns 'expression' for an expression with '||/or' and an unset instance variable" do
+ defined?(@defined_specs_undefined_instance_variable || true).should == "expression"
+ defined?(true || @defined_specs_undefined_instance_variable).should == "expression"
+ defined?(@defined_specs_undefined_instance_variable or true).should == "expression"
end
- end
- it "returns nil for an expression with '!' and an undefined method" do
- defined?(!defined_specs_undefined_method).should be_nil
- end
+ it "returns 'expression' for an expression '||/or' regardless of its truth value" do
+ defined?(true || false).should == "expression"
+ defined?(true or false).should == "expression"
+ end
- it "returns nil for an expression with '!' and an unset class variable" do
- defined?(!@@defined_specs_undefined_class_variable).should be_nil
- end
+ ruby_version_is ""..."1.9" do
+ it "returns 'expression' for an expression with '!' and an unset global variable" do
+ defined?(!$defined_specs_undefined_global_variable).should == "expression"
+ end
- ruby_version_is ""..."1.9" do
- it "returns 'expression' for an expression with '!' and an unset global variable" do
- defined?(!$defined_specs_undefined_global_variable).should == "expression"
- end
+ it "returns 'expression' for an expression with '!' and an unset instance variable" do
+ defined?(!@defined_specs_undefined_instance_variable).should == "expression"
+ end
- it "returns 'expression' for an expression with '!' and an unset instance variable" do
- defined?(!@defined_specs_undefined_global_variable).should == "expression"
- end
- end
+ it "calls a method in a 'not' expression and returns 'expression'" do
+ defined?(not DefinedSpecs.side_effects).should == "expression"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
- ruby_version_is "1.9" do
- it "returns nil for an expression with '!' and an unset global variable" do
- defined?(!$defined_specs_undefined_global_variable).should be_nil
+ it "returns 'expression' for an expression with 'not' and an unset global variable" do
+ defined?(not $defined_specs_undefined_global_variable).should == "expression"
+ end
+
+ it "returns 'expression' for an expression with 'not' and an unset instance variable" do
+ defined?(not @defined_specs_undefined_instance_variable).should == "expression"
+ end
+
+ it "returns nil for an expression with '&&/and' and an undefined method" do
+ defined?(defined_specs_undefined_method && true).should be_nil
+ defined?(defined_specs_undefined_method or true).should be_nil
+ end
+
+ it "returns nil for an expression with '&&/and' and an unset class variable" do
+ defined?(@@defined_specs_undefined_class_variable && true).should be_nil
+ defined?(@@defined_specs_undefined_class_variable or true).should be_nil
+ end
+
+ it "does not propagate an exception raised by a method in an '&&' expression" do
+ defined?(DefinedSpecs.exception_method && true).should be_nil
+ ScratchPad.recorded.should == :defined_specs_exception
+ end
+
+ it "calls a method in an '&&' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects && true).should == "expression"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
+
+ it "does not propagate an exception raised by a method in an 'and' expression" do
+ defined?(DefinedSpecs.exception_method and true).should be_nil
+ ScratchPad.recorded.should == :defined_specs_exception
+ end
+
+ it "calls a method in an 'and' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects and true).should == "expression"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
+
+ it "returns nil for an expression with '||/or' and an undefined method" do
+ defined?(defined_specs_undefined_method || true).should be_nil
+ defined?(defined_specs_undefined_method or true).should be_nil
+ end
+
+ it "returns nil for an expression with '||/or' and an unset class variable" do
+ defined?(@@defined_specs_undefined_class_variable || true).should be_nil
+ defined?(@@defined_specs_undefined_class_variable or true).should be_nil
+ end
+
+ it "does not propagate an exception raised by a method in an '||' expression" do
+ defined?(DefinedSpecs.exception_method || true).should be_nil
+ ScratchPad.recorded.should == :defined_specs_exception
+ end
+
+ it "calls a method in an '||' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects || true).should == "expression"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
+
+ it "does not propagate an exception raised by a method in an 'or' expression" do
+ defined?(DefinedSpecs.exception_method or true).should be_nil
+ ScratchPad.recorded.should == :defined_specs_exception
+ end
+
+ it "calls a method in an 'or' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects or true).should == "expression"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
end
- it "returns nil for an expression with '!' and an unset instance variable" do
- defined?(!@defined_specs_undefined_global_variable).should be_nil
+ ruby_version_is "1.9" do
+ it "returns nil for an expression with '!' and an unset global variable" do
+ defined?(!$defined_specs_undefined_global_variable).should be_nil
+ end
+
+ it "returns nil for an expression with '!' and an unset instance variable" do
+ defined?(!@defined_specs_undefined_instance_variable).should be_nil
+ end
+
+ it "returns 'method' for a 'not' expression with a method" do
+ defined?(not DefinedSpecs.side_effects).should == "method"
+ end
+
+ it "calls a method in a 'not' expression and returns 'method'" do
+ defined?(not DefinedSpecs.side_effects).should == "method"
+ ScratchPad.recorded.should == :defined_specs_side_effects
+ end
+
+ it "returns nil for an expression with 'not' and an unset global variable" do
+ defined?(not $defined_specs_undefined_global_variable).should be_nil
+ end
+
+ it "returns nil for an expression with 'not' and an unset instance variable" do
+ defined?(not @defined_specs_undefined_instance_variable).should be_nil
+ end
+
+ it "returns 'expression' for an expression with '&&/and' and an undefined method" do
+ defined?(defined_specs_undefined_method && true).should == "expression"
+ defined?(defined_specs_undefined_method and true).should == "expression"
+ end
+
+ it "returns 'expression' for an expression with '&&/and' and an unset class variable" do
+ defined?(@@defined_specs_undefined_class_variable && true).should == "expression"
+ defined?(@@defined_specs_undefined_class_variable and true).should == "expression"
+ end
+
+ it "does not call a method in an '&&' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects && true).should == "expression"
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "does not call a method in an 'and' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects and true).should == "expression"
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "returns 'expression' for an expression with '||/or' and an undefined method" do
+ defined?(defined_specs_undefined_method || true).should == "expression"
+ defined?(defined_specs_undefined_method or true).should == "expression"
+ end
+
+ it "returns 'expression' for an expression with '||/or' and an unset class variable" do
+ defined?(@@defined_specs_undefined_class_variable || true).should == "expression"
+ defined?(@@defined_specs_undefined_class_variable or true).should == "expression"
+ end
+
+ it "does not call a method in an '||' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects || true).should == "expression"
+ ScratchPad.recorded.should be_nil
+ end
+
+ it "does not call a method in an 'or' expression and returns 'expression'" do
+ defined?(DefinedSpecs.side_effects or true).should == "expression"
+ ScratchPad.recorded.should be_nil
+ end
end
end
Deleted: MacRuby/trunk/spec/frozen/language/else_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/else_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/else_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1 +0,0 @@
-require File.expand_path('../../spec_helper', __FILE__)
Modified: MacRuby/trunk/spec/frozen/language/encoding_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/encoding_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/encoding_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,4 @@
require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
ruby_version_is "1.9" do
describe "The __ENCODING__ pseudo-variable" do
@@ -24,6 +23,8 @@
eval(code).should == Encoding::US_ASCII
end
- it_behaves_like :language_pseudo_variable, "__ENCODING__", nil
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("__ENCODING__ = 1") }.should raise_error(SyntaxError)
+ end
end
end
Modified: MacRuby/trunk/spec/frozen/language/ensure_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/ensure_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/ensure_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -56,17 +56,16 @@
it "is executed when nothing is raised or thrown in it's corresponding begin block" do
begin
ScratchPad << :begin
- raise "An exception occured!"
rescue
ScratchPad << :rescue
ensure
ScratchPad << :ensure
end
- ScratchPad.recorded.should == [:begin, :rescue, :ensure]
+ ScratchPad.recorded.should == [:begin, :ensure]
end
- it "has non return value" do
+ it "has no return value" do
begin
:begin
ensure
Deleted: MacRuby/trunk/spec/frozen/language/false_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/false_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/false_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +0,0 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
-
-describe "The false pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "false", "something else".dump
-end
-
Modified: MacRuby/trunk/spec/frozen/language/file_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/file_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/file_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,10 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/code_loading', __FILE__)
require File.expand_path('../shared/__FILE__', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
describe "The __FILE__ pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "__FILE__", "/an/example/file/path.rb".dump
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("__FILE__ = 1") }.should raise_error(SyntaxError)
+ end
it "equals (eval) inside an eval" do
eval("__FILE__").should == "(eval)"
Modified: MacRuby/trunk/spec/frozen/language/fixtures/super.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/fixtures/super.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/fixtures/super.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -259,4 +259,35 @@
# Otherwise, Alias2 is next, which is where name was to begin with,
# causing the wrong #name method to be called.
end
+
+ module AliasWithSuper
+ module AS1
+ def foo
+ :a
+ end
+ end
+
+ module BS1
+ def foo
+ [:b, super]
+ end
+ end
+
+ class Base
+ extend AS1
+ extend BS1
+ end
+
+ class Trigger < Base
+ class << self
+ def foo_quux
+ foo_baz
+ end
+
+ alias_method :foo_baz, :foo
+ alias_method :foo, :foo_quux
+ end
+ end
+ end
+
end
Modified: MacRuby/trunk/spec/frozen/language/line_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/line_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/line_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,10 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/code_loading', __FILE__)
require File.expand_path('../shared/__LINE__', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
describe "The __LINE__ pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "__FILE__", "/an/example/file/path.rb".dump
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("__LINE__ = 1") }.should raise_error(SyntaxError)
+ end
before :each do
ScratchPad.record []
Modified: MacRuby/trunk/spec/frozen/language/module_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/module_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/module_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -16,6 +16,24 @@
LangModuleSpec::Anon = Module.new
LangModuleSpec::Anon.name.should == "LangModuleSpec::Anon"
end
+
+ it "raises a TypeError if the constant is a class" do
+ class LangModuleSpec::C1; end
+
+ lambda {
+ module LangModuleSpec::C1; end
+ }.should raise_error(TypeError)
+ end
+
+ it "raises a TypeError if the constant is not a module" do
+ module LangModuleSpec
+ C2 = 2
+ end
+
+ lambda {
+ module LangModuleSpec::C2; end
+ }.should raise_error(TypeError)
+ end
end
describe "An anonymous module" do
Modified: MacRuby/trunk/spec/frozen/language/next_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/next_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/next_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,13 +1,11 @@
require File.expand_path('../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/next', __FILE__)
-class NextSpecs
- def self.yielding_method(expected)
- yield.should == expected
- :method_return_value
+describe "The next statement from within the block" do
+ before :each do
+ ScratchPad.record []
end
-end
-describe "The next statement from within the block" do
it "ends block execution" do
a = []
lambda {
@@ -71,8 +69,244 @@
ChainedNextTest.enclosing_method.should == :method_return_value
end
+ it "causes ensure blocks to run" do
+ [1].each do |i|
+ begin
+ ScratchPad << :begin
+ next
+ ensure
+ ScratchPad << :ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "skips following code outside an exception block" do
+ 3.times do |i|
+ begin
+ ScratchPad << :begin
+ next if i == 0
+ break if i == 2
+ ScratchPad << :begin_end
+ ensure
+ ScratchPad << :ensure
+ end
+
+ ScratchPad << :after
+ end
+
+ ScratchPad.recorded.should == [
+ :begin, :ensure, :begin, :begin_end, :ensure, :after, :begin, :ensure]
+ end
end
+describe "The next statement" do
+ before :each do
+ ScratchPad.record []
+ end
+
+ describe "in a while loop" do
+ describe "when not passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.while_next(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.while_within_iter(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ describe "when passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.while_next(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.while_within_iter(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ it "causes nested ensure blocks to run" do
+ x = true
+ while x
+ begin
+ ScratchPad << :outer_begin
+ x = false
+ begin
+ ScratchPad << :inner_begin
+ next
+ ensure
+ ScratchPad << :inner_ensure
+ end
+ ensure
+ ScratchPad << :outer_ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:outer_begin, :inner_begin, :inner_ensure, :outer_ensure]
+ end
+
+ it "causes ensure blocks to run when mixed with break" do
+ x = 1
+ while true
+ begin
+ ScratchPad << :begin
+ break if x > 1
+ x += 1
+ next
+ ensure
+ ScratchPad << :ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure, :begin, :ensure]
+ end
+ end
+
+ describe "in an until loop" do
+ describe "when not passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.until_next(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.until_within_iter(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ describe "when passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.until_next(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.until_within_iter(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ it "causes nested ensure blocks to run" do
+ x = false
+ until x
+ begin
+ ScratchPad << :outer_begin
+ x = true
+ begin
+ ScratchPad << :inner_begin
+ next
+ ensure
+ ScratchPad << :inner_ensure
+ end
+ ensure
+ ScratchPad << :outer_ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:outer_begin, :inner_begin, :inner_ensure, :outer_ensure]
+ end
+
+ it "causes ensure blocks to run when mixed with break" do
+ x = 1
+ until false
+ begin
+ ScratchPad << :begin
+ break if x > 1
+ x += 1
+ next
+ ensure
+ ScratchPad << :ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure, :begin, :ensure]
+ end
+ end
+
+ describe "in a loop" do
+ describe "when not passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.loop_next(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.loop_within_iter(false)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ describe "when passed an argument" do
+ it "causes ensure blocks to run" do
+ NextSpecs.loop_next(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+
+ it "causes ensure blocks to run when nested in an block" do
+ NextSpecs.loop_within_iter(true)
+
+ ScratchPad.recorded.should == [:begin, :ensure]
+ end
+ end
+
+ it "causes nested ensure blocks to run" do
+ x = 1
+ loop do
+ break if x == 2
+
+ begin
+ ScratchPad << :outer_begin
+ begin
+ ScratchPad << :inner_begin
+ x += 1
+ next
+ ensure
+ ScratchPad << :inner_ensure
+ end
+ ensure
+ ScratchPad << :outer_ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:outer_begin, :inner_begin, :inner_ensure, :outer_ensure]
+ end
+
+ it "causes ensure blocks to run when mixed with break" do
+ x = 1
+ loop do
+ begin
+ ScratchPad << :begin
+ break if x > 1
+ x += 1
+ next
+ ensure
+ ScratchPad << :ensure
+ end
+ end
+
+ ScratchPad.recorded.should == [:begin, :ensure, :begin, :ensure]
+ end
+ end
+end
+
describe "Assignment via next" do
it "assigns objects" do
def r(val); a = yield(); val.should == a; end
Deleted: MacRuby/trunk/spec/frozen/language/nil_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/nil_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/nil_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +0,0 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
-
-describe "The nil pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "nil", "something else".dump
-end
Modified: MacRuby/trunk/spec/frozen/language/predefined_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/predefined_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/predefined_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -357,7 +357,80 @@
$: << "foo"
$:.should include("foo")
end
+
+ it "is read-only" do
+ lambda {
+ $: = []
+ }.should raise_error(NameError)
+
+ lambda {
+ $LOAD_PATH = []
+ }.should raise_error(NameError)
+
+ lambda {
+ $-I = []
+ }.should raise_error(NameError)
+ end
end
+
+describe "Global variable $\"" do
+ it "is an alias for $LOADED_FEATURES" do
+ $".object_id.should == $LOADED_FEATURES.object_id
+ end
+
+ it "is read-only" do
+ lambda {
+ $" = []
+ }.should raise_error(NameError)
+
+ lambda {
+ $LOADED_FEATURES = []
+ }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $<" do
+ it "is read-only" do
+ lambda {
+ $< = nil
+ }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $FILENAME" do
+ it "is read-only" do
+ lambda {
+ $FILENAME = "-"
+ }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $?" do
+ it "is read-only" do
+ lambda {
+ $? = nil
+ }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $-a" do
+ it "is read-only" do
+ lambda { $-a = true }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $-l" do
+ it "is read-only" do
+ lambda { $-l = true }.should raise_error(NameError)
+ end
+end
+
+describe "Global variable $-p" do
+ it "is read-only" do
+ lambda { $-p = true }.should raise_error(NameError)
+ end
+end
+
=begin
Standard Objects
---------------------------------------------------------------------------------------------------
@@ -394,32 +467,38 @@
it "is an instance of NilClass" do
nil.should be_kind_of(NilClass)
end
-
- # this needs to be tested with a subprocess because
- # MRI aborts reading in the file
- it "raises a SyntaxError if assigned to"
+
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("nil = true") }.should raise_error(SyntaxError)
+ end
end
describe "The predefined standard object true" do
it "is an instance of TrueClass" do
true.should be_kind_of(TrueClass)
end
-
- # this needs to be tested with a subprocess because
- # MRI aborts reading in the file
- it "raises a SyntaxError if assigned to"
+
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("true = false") }.should raise_error(SyntaxError)
+ end
end
describe "The predefined standard object false" do
it "is an instance of FalseClass" do
false.should be_kind_of(FalseClass)
end
-
- # this needs to be tested with a subprocess because
- # MRI aborts reading in the file
- it "raises a SyntaxError if assigned to"
+
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("false = nil") }.should raise_error(SyntaxError)
+ end
end
+describe "The self pseudo-variable" do
+ it "raises a SyntaxError if assigned to" do
+ lambda { eval("self = 1") }.should raise_error(SyntaxError)
+ end
+end
+
=begin
Global Constants
---------------------------------------------------------------------------------------------------
Modified: MacRuby/trunk/spec/frozen/language/regexp/anchors_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/anchors_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/anchors_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with anchors" do
it 'supports ^ (line start anchor)' do
Modified: MacRuby/trunk/spec/frozen/language/regexp/back-references_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/back-references_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/back-references_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with back-references" do
it 'saves match data in the $~ pseudo-global variable' do
Modified: MacRuby/trunk/spec/frozen/language/regexp/character_classes_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/character_classes_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/character_classes_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexp with character classes" do
it 'supports \w (word character)' do
Modified: MacRuby/trunk/spec/frozen/language/regexp/encoding_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/encoding_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/encoding_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with encoding modifiers" do
Modified: MacRuby/trunk/spec/frozen/language/regexp/escapes_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/escapes_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/escapes_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with escape characters" do
it "they're supported" do
Modified: MacRuby/trunk/spec/frozen/language/regexp/grouping_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/grouping_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/grouping_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with grouping" do
it 'support ()' do
Modified: MacRuby/trunk/spec/frozen/language/regexp/interpolation_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/interpolation_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/interpolation_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with interpolation" do
Modified: MacRuby/trunk/spec/frozen/language/regexp/modifiers_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/modifiers_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/modifiers_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with modifers" do
it 'supports /i (case-insensitive)' do
Modified: MacRuby/trunk/spec/frozen/language/regexp/repetition_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/regexp/repetition_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/regexp/repetition_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path(File.dirname(__FILE__) + '/../fixtures/classes')
+require File.expand_path('../../fixtures/classes', __FILE__)
describe "Regexps with repetition" do
it 'supports * (0 or more of previous subexpression)' do
Modified: MacRuby/trunk/spec/frozen/language/rescue_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/rescue_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/rescue_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -8,6 +8,10 @@
[SpecificExampleException, ZeroDivisionError]
end
describe "The rescue keyword" do
+ before :each do
+ ScratchPad.record []
+ end
+
it "can be used to handle a specific exception" do
lambda do
begin
@@ -69,6 +73,43 @@
end.should raise_error(OtherCustomException)
end
+ it "will execute an else block only if no exceptions were raised" do
+ begin
+ ScratchPad << :one
+ rescue
+ ScratchPad << :does_not_run
+ else
+ ScratchPad << :two
+ end
+ ScratchPad.recorded.should == [:one, :two]
+ end
+
+ it "will not execute an else block if an exception was raised" do
+ begin
+ ScratchPad << :one
+ raise "an error occurred"
+ rescue
+ ScratchPad << :two
+ else
+ ScratchPad << :does_not_run
+ end
+ ScratchPad.recorded.should == [:one, :two]
+ end
+
+ it "will not rescue errors raised in an else block in the rescue block above it" do
+ lambda do
+ begin
+ ScratchPad << :one
+ rescue Exception => e
+ ScratchPad << :does_not_run
+ else
+ ScratchPad << :two
+ raise SpecificExampleException, "an error from else"
+ end
+ end.should raise_error(SpecificExampleException)
+ ScratchPad.recorded.should == [:one, :two]
+ end
+
ruby_version_is "1.9" do
it "parses 'a += b rescue c' as 'a += (b rescue c)'" do
a = 'a'
Deleted: MacRuby/trunk/spec/frozen/language/self_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/self_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/self_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +0,0 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
-
-describe "The self pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "self", "something else".dump
-end
-
Deleted: MacRuby/trunk/spec/frozen/language/shared/pseudo_variable.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/shared/pseudo_variable.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/shared/pseudo_variable.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,13 +0,0 @@
-describe :language_pseudo_variable, :shared => true do
- before do
- @name = @method
- @assigned_expression = @object
- end
-
- it "is syntactically inassignable" do
- lambda {
- eval("#{@name} = #{@assigned_expression}")
- }.should raise_error(SyntaxError)
- end
-end
-
Modified: MacRuby/trunk/spec/frozen/language/super_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/super_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/super_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -143,4 +143,10 @@
Super::Alias3.new.name3.should == [:alias2, :alias1]
}.should_not raise_error(RuntimeError)
end
+
+ it "sees the included version of a module a method is alias from" do
+ lambda {
+ Super::AliasWithSuper::Trigger.foo.should == [:b, :a]
+ }.should_not raise_error(NoMethodError)
+ end
end
Modified: MacRuby/trunk/spec/frozen/language/symbol_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/symbol_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/symbol_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -66,9 +66,17 @@
}
end
- it "does not contain null in the string" do
- lambda { eval ':"\0" ' }.should raise_error(SyntaxError)
+ ruby_version_is ""..."1.9" do
+ it "does not contain null in the string" do
+ lambda { eval ':"\0" ' }.should raise_error(SyntaxError)
+ end
end
+
+ ruby_version_is "1.9" do
+ it "can contain null in the string" do
+ eval(':"\0" ').inspect.should == ':"\\x00"'
+ end
+ end
end
language_version __FILE__, 'symbol'
Deleted: MacRuby/trunk/spec/frozen/language/true_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/language/true_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/language/true_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +0,0 @@
-require File.expand_path('../../spec_helper', __FILE__)
-require File.expand_path('../shared/pseudo_variable', __FILE__)
-
-describe "The true pseudo-variable" do
- it_behaves_like :language_pseudo_variable, "true", "something else".dump
-end
-
Modified: MacRuby/trunk/spec/frozen/library/complex/math/atanh_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/complex/math/atanh_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/complex/math/atanh_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -8,7 +8,7 @@
it_behaves_like :math_atanh_base, :atanh, IncludesMath.new
it_behaves_like :complex_math_atanh_complex, :atanh, IncludesMath.new
- it_behaves_like :math_atanh_private, :atanh
+ it_behaves_like :math_atanh_private, :atanh, IncludesMath.new
end
ruby_version_is ""..."1.9" do
@@ -17,7 +17,7 @@
it_behaves_like :math_atanh_no_complex, :atanh!, IncludesMath.new
it_behaves_like :complex_math_atanh_no_complex, :atanh!, IncludesMath.new
- it_behaves_like :math_atanh_private, :atanh!
+ it_behaves_like :math_atanh_private, :atanh!, IncludesMath.new
end
end
@@ -29,7 +29,7 @@
ruby_version_is ""..."1.9" do
describe "Math.atanh!" do
it_behaves_like :math_atanh_base, :atanh!, Math
- it_behaves_like :math_atanh_no_complex, :atanh!, IncludesMath.new
+ it_behaves_like :math_atanh_no_complex, :atanh!, Math
it_behaves_like :complex_math_atanh_no_complex, :atanh!, Math
end
end
Modified: MacRuby/trunk/spec/frozen/library/date/parse_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/date/parse_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/date/parse_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -148,19 +148,19 @@
ruby_version_is "" ... "1.9" do
it "parses a YY.MM.DD string into a Date object" do
- d = Date.parse("10.01.07")
- d.year.should == 10
- d.month.should == 1
- d.day.should == 7
+ d = Date.parse("10.01.07")
+ d.year.should == 10
+ d.month.should == 1
+ d.day.should == 7
end
end
ruby_version_is "1.9" do
it "parses a YY.MM.DD string into a Date object" do
- d = Date.parse("10.01.07")
- d.year.should == 2010
- d.month.should == 1
- d.day.should == 7
+ d = Date.parse("10.01.07")
+ d.year.should == 2010
+ d.month.should == 1
+ d.day.should == 7
end
end
Modified: MacRuby/trunk/spec/frozen/library/delegate/fixtures/classes.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/delegate/fixtures/classes.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/delegate/fixtures/classes.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,3 +1,4 @@
+require 'delegate'
module DelegateSpecs
class Simple
def pub
@@ -3,10 +4,10 @@
:foo
end
-
+
def respond_to_missing?(method, priv=false)
method == :pub_too ||
(priv && method == :priv_too)
end
-
+
def method_missing(method, *args)
super unless respond_to_missing?(method, true)
@@ -19,6 +20,46 @@
[:priv, arg]
end
private :priv
-
+
+ def prot
+ :protected
+ end
+ protected :prot
end
+
+ module Extra
+ def extra
+ :cheese
+ end
+
+ def extra_private
+ :bar
+ end
+ private :extra_private
+
+ def extra_protected
+ :baz
+ end
+ protected :extra_protected
+ end
+
+ class Delegator < ::Delegator
+ attr_accessor :data
+
+ attr_reader :__getobj__
+ def __setobj__(o)
+ @__getobj__ = o
+ end
+
+ # Needed for 1.8.x compatibility
+ def initialize(obj)
+ super
+ __setobj__(obj)
+ end
+ include Extra
+ end
+
+ class DelegateClass < DelegateClass(Simple)
+ include Extra
+ end
end
Deleted: MacRuby/trunk/spec/frozen/library/delegate/frozen_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/delegate/frozen_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/delegate/frozen_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,49 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'delegate'
-
-describe "SimpleDelegator when frozen" do
- before :each do
- @array = [42, :hello]
- @delegate = SimpleDelegator.new(@array)
- @delegate.freeze
- end
-
- it "is still readable" do
- @delegate.should == [42, :hello]
- @delegate.include?("bar").should be_false
- end
-
- it "is frozen" do
- @delegate.frozen?.should be_true
- end
-
- ruby_bug "redmine:2221", "1.8.7" do
- it "is not writeable" do
- lambda{ @delegate[0] += 2 }.should raise_error( RuntimeError )
- end
-
- it "creates a frozen clone" do
- @delegate.clone.frozen?.should be_true
- end
- end
-
- it "creates an unfrozen dup" do
- @delegate.dup.frozen?.should be_false
- end
-
- ruby_version_is "" ... "1.9" do
- it "causes mutative calls to raise TypeError" do
- lambda{ @delegate.__setobj__("hola!") }.should raise_error( TypeError )
- end
- end
-
- ruby_version_is "1.9" do
- it "causes mutative calls to raise RuntimeError" do
- lambda{ @delegate.__setobj__("hola!") }.should raise_error( RuntimeError )
- end
- end
-
- it "returns false if only the delegated object is frozen" do
- SimpleDelegator.new([1,2,3].freeze).frozen?.should be_false
- end
-end
Deleted: MacRuby/trunk/spec/frozen/library/delegate/marshal_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/delegate/marshal_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/delegate/marshal_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,23 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'delegate'
-
-describe "SimpleDelegator" do
- before :each do
- @obj = "hello"
- @delegate = SimpleDelegator.new(@obj)
- end
-
- it "can be marshalled" do
- m = Marshal.load(Marshal.dump(@delegate))
- m.class.should == SimpleDelegator
- (m == @obj).should be_true
- end
-
- ruby_bug "redmine:1744", "1.8.7" do
- it "can be marshalled with its instance variables intact" do
- @delegate.instance_variable_set(:@foo, "bar")
- m = Marshal.load(Marshal.dump(@delegate))
- m.instance_variable_get(:@foo).should == "bar"
- end
- end
-end
Deleted: MacRuby/trunk/spec/frozen/library/delegate/method_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/delegate/method_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/delegate/method_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,38 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require 'delegate'
-
-describe "SimpleDelegator#method" do
- before :each do
- @simple = DelegateSpecs::Simple.new
- @delegate = SimpleDelegator.new(@simple)
- end
-
- it "returns a method object for a valid method" do
- m = @delegate.method(:pub)
- m.should be_an_instance_of(Method)
- m.call.should == :foo
- end
-
- it "raises a NameError for an invalid method name" do
- lambda {
- @delegate.method(:invalid_and_silly_method_name)
- }.should raise_error(NameError)
- end
-
- ruby_version_is "1.9" do
- it "returns a method that respond_to_missing?" do
- m = @delegate.method(:pub_too)
- m.should be_an_instance_of(Method)
- m.call.should == :pub_too
- end
- end
-
- it "raises a NameError if method is no longer valid because object has changed" do
- m = @delegate.method(:pub)
- @delegate.__setobj__([1,2,3])
- lambda {
- m.call
- }.should raise_error(NameError)
- end
-end
Deleted: MacRuby/trunk/spec/frozen/library/delegate/send_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/delegate/send_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/delegate/send_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,35 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require File.expand_path('../fixtures/classes', __FILE__)
-require 'delegate'
-
-describe "SimpleDelegator.new" do
- before :each do
- @simple = DelegateSpecs::Simple.new
- @delegate = SimpleDelegator.new(@simple)
- end
-
- it "forwards public method calls" do
- @delegate.pub.should == :foo
- end
-
- it "doesn't forward private method calls" do
- lambda{ @delegate.priv }.should raise_error( NoMethodError )
- end
-
- ruby_version_is "" ... "1.9" do
- ruby_bug "redmine:2206", "1.8.7" do
- it "forwards private method calls made via send or __send__" do
- @delegate.send(:priv, 42).should == [:priv, 42]
- @delegate.__send__(:priv, 42).should == [:priv, 42]
- lambda{ @delegate.__send__(:priv, 42){@delegate.priv} }.should raise_error( NoMethodError )
- end
- end
- end
-
- ruby_version_is "1.9" do
- it "doesn't forward private method calls even via send or __send__" do
- lambda{ @delegate.send(:priv, 42) }.should raise_error( NoMethodError )
- lambda{ @delegate.__send__(:priv, 42) }.should raise_error( NoMethodError )
- end
- end
-end
Modified: MacRuby/trunk/spec/frozen/library/digest/sha1/file_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/digest/sha1/file_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/digest/sha1/file_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,6 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../../../../core/file/shared/read', __FILE__)
describe "Digest::SHA1.file" do
Modified: MacRuby/trunk/spec/frozen/library/digest/sha256/file_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/digest/sha256/file_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/digest/sha256/file_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,6 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../../../../core/file/shared/read', __FILE__)
describe "Digest::SHA256.file" do
Modified: MacRuby/trunk/spec/frozen/library/digest/sha384/file_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/digest/sha384/file_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/digest/sha384/file_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,6 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../../../../core/file/shared/read', __FILE__)
describe "Digest::SHA384.file" do
Modified: MacRuby/trunk/spec/frozen/library/digest/sha512/file_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/digest/sha512/file_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/digest/sha512/file_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,6 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../shared/constants', __FILE__)
+require File.expand_path('../../../../core/file/shared/read', __FILE__)
describe "Digest::SHA512.file" do
Modified: MacRuby/trunk/spec/frozen/library/drb/stop_service_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/drb/stop_service_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/drb/stop_service_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../fixtures/test_server', __FILE__)
+require 'drb'
describe "DRb.stop_service" do
before :all do
Modified: MacRuby/trunk/spec/frozen/library/fiber/resume_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/fiber/resume_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/fiber/resume_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,6 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
with_feature :fiber_library do
+ require 'fiber'
+
describe "Fiber#resume" do
it "raises a FiberError if the Fiber has transfered control to another Fiber" do
fiber1 = Fiber.new { true }
Modified: MacRuby/trunk/spec/frozen/library/matrix/build_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/build_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/build_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-ruby_version_is "1.9" do
+ruby_version_is "1.8.8" do
describe "Matrix.build" do
it "returns a Matrix object of the given size" do
Modified: MacRuby/trunk/spec/frozen/library/matrix/each_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/each_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/each_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-ruby_version_is "1.9" do
+ruby_version_is "1.8.8" do
describe "Matrix#each" do
before :all do
@m = Matrix[ [1, 2, 3], [4, 5, 6] ]
Modified: MacRuby/trunk/spec/frozen/library/matrix/each_with_index_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/each_with_index_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/each_with_index_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-ruby_version_is "1.9" do
+ruby_version_is "1.8.8" do
describe "Matrix#each_with_index" do
before :all do
@m = Matrix[ [1, 2, 3], [4, 5, 6] ]
Modified: MacRuby/trunk/spec/frozen/library/matrix/empty_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/empty_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/empty_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,7 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-ruby_version_is "1.9" do
+ruby_version_is "1.8.8" do
describe "Matrix#empty?" do
it "returns true when the Matrix is empty" do
Matrix[ ].empty?.should be_true
Modified: MacRuby/trunk/spec/frozen/library/matrix/exponent_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/exponent_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/exponent_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -35,14 +35,14 @@
end
end
- ruby_version_is "" ... "1.9" do
+ ruby_version_is "" ... "1.8.8" do
it "raises a ErrOperationNotDefined exception for powers that aren't Integers" do
lambda {Matrix[ [1,2], [8,2] ] ** 2.5}.should \
raise_error(Matrix::ErrOperationNotDefined)
end
end
- ruby_version_is "1.9" do
+ ruby_version_is "1.8.8" do
it "raises a ErrOperationNotImplemented exception for powers that aren't Integers" do
lambda {Matrix[ [1,2], [8,2] ] ** 2.5}.should \
raise_error(Matrix::ErrOperationNotImplemented)
Modified: MacRuby/trunk/spec/frozen/library/matrix/inv_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/inv_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/inv_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,4 +1,5 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../spec_helper', __FILE__)
require File.expand_path('../shared/inverse', __FILE__)
require 'matrix'
Modified: MacRuby/trunk/spec/frozen/library/matrix/inverse_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/inverse_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/inverse_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,5 +1,6 @@
require File.expand_path('../../../spec_helper', __FILE__)
+require File.expand_path('../spec_helper', __FILE__)
require File.expand_path('../shared/inverse', __FILE__)
require 'matrix'
Modified: MacRuby/trunk/spec/frozen/library/matrix/minor_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/minor_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/minor_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -13,10 +13,10 @@
end
ruby_bug "redmine:1532", "1.8.7" do
- it "returns an empty Matrix unless nrows and ncols are greater than 0" do
+ it "returns an empty Matrix if nrows or ncols is 0" do
@matrix.minor(0,0,0,0).should == Matrix[]
@matrix.minor(1,0,1,0).should == Matrix[]
- @matrix.minor(1,0,1,1).should == Matrix.columns([])
+ @matrix.minor(1,0,1,1).should == Matrix.columns([[]])
@matrix.minor(1,1,1,0).should == Matrix[[]]
end
@@ -43,7 +43,7 @@
it "returns empty matrices for extreme start_row/col" do
@matrix.minor(3,10,1,10).should == Matrix.columns([[]])
@matrix.minor(1,10,2,10).should == Matrix[[], []]
- @matrix.minor(3,0,0,10).should == Matrix[]
+ @matrix.minor(3,0,0,10).should == Matrix.columns([[], []])
end
it "ignores big nrows or ncols" do
Modified: MacRuby/trunk/spec/frozen/library/matrix/new_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/new_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/new_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,10 +1,8 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'matrix'
-describe "Matrix#new" do
-
- it "is not accessible" do
- lambda { Matrix.new }.should raise_error(NoMethodError)
+describe "Matrix.new" do
+ it "is private" do
+ Matrix.should have_private_method(:new)
end
-
end
Modified: MacRuby/trunk/spec/frozen/library/matrix/shared/equal_value.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/shared/equal_value.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/shared/equal_value.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -18,4 +18,13 @@
@matrix.send(@method, Matrix[ [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7] ]).should be_false
@matrix.send(@method, Matrix[ [1, 2, 3], [2, 3, 4] ]).should be_false
end
-end
+
+ ruby_version_is "1.8.8" do
+ it "returns false for different empty matrices" do
+ Matrix.empty(42, 0).send(@method, Matrix.empty(6, 0)).should be_false
+ Matrix.empty(0, 42).send(@method, Matrix.empty(0, 6)).should be_false
+ Matrix.empty(0, 0).send(@method, Matrix.empty(6, 0)).should be_false
+ Matrix.empty(0, 0).send(@method, Matrix.empty(0, 6)).should be_false
+ end
+ end
+end
\ No newline at end of file
Modified: MacRuby/trunk/spec/frozen/library/matrix/vector/each2_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/matrix/vector/each2_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/matrix/vector/each2_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -42,7 +42,7 @@
end
end
- ruby_version_is "1.9" do
+ ruby_version_is "1.8.8" do
it "returns an enumerator if no block given" do
enum = @v.each2(@v2)
enum.should be_an_instance_of(enumerator_class)
Modified: MacRuby/trunk/spec/frozen/library/ping/pingecho_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/ping/pingecho_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/ping/pingecho_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,31 +1,29 @@
require File.expand_path('../../../spec_helper', __FILE__)
ruby_version_is ""..."1.9" do
-
require 'ping'
describe "Ping.pingecho" do
-
- it "responds to pingecho method" do
- Ping.should respond_to(:pingecho)
- end
-
it "pings a host using the correct number of arguments" do
Ping.pingecho('127.0.0.1', 10, 7).should be_true
Ping.pingecho('127.0.0.1', 10).should be_true
Ping.pingecho('127.0.0.1').should be_true
end
- it "raises ArgumentError for wrong number of arguments" do
- lambda { Ping.pingecho }.should raise_error(ArgumentError)
- lambda { Ping.pingecho 'one', 'two', 'three', 'four' }.should raise_error(ArgumentError)
+ it "returns false if the port is invalid" do
+ Ping.pingecho('127.0.0.1', 5, 'invalid port').should be_false
end
- it "returns false for invalid parameters" do
- Ping.pingecho('127.0.0.1', 5, 'invalid port').should be_false
+ it "returns false if the timeout value is invalid" do
Ping.pingecho('127.0.0.1', 'invalid timeout').should be_false
- Ping.pingecho(123).should be_false
end
+ # Is it ever possible to spec invalid hosts? I think the consensus
+ # is building towards "no".
+ quarantine! do
+ it "returns false if the host is invalid" do
+ Ping.pingecho(0).should be_false
+ end
+ end
end
end
Modified: MacRuby/trunk/spec/frozen/library/set/reject_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/set/reject_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/set/reject_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -5,22 +5,22 @@
before(:each) do
@set = Set["one", "two", "three"]
end
-
+
it "yields every element of self" do
ret = []
@set.reject! { |x| ret << x }
ret.sort.should == ["one", "two", "three"].sort
end
-
+
it "deletes every element from self for which the passed block returns true" do
@set.reject! { |x| x.size == 3 }
@set.size.should eql(1)
-
+
@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
end
-
+
it "returns self when self was modified" do
@set.reject! { |x| true }.should equal(@set)
end
@@ -28,20 +28,20 @@
it "returns nil when self was not modified" do
@set.reject! { |x| false }.should be_nil
end
-
+
ruby_version_is "" ... "1.8.8" do
it "raises a LocalJumpError when passed no block" do
lambda { @set.reject! }.should raise_error(LocalJumpError)
end
end
-
+
ruby_version_is "1.8.8" do
it "returns an Enumerator when passed no block" do
enum = @set.reject!
enum.should be_an_instance_of(enumerator_class)
-
+
enum.each { |x| x.size == 3 }
-
+
@set.should_not include("one")
@set.should_not include("two")
@set.should include("three")
Modified: MacRuby/trunk/spec/frozen/library/socket/basicsocket/do_not_reverse_lookup_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/basicsocket/do_not_reverse_lookup_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/basicsocket/do_not_reverse_lookup_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,6 +3,10 @@
ruby_version_is ""..."1.9" do
describe "BasicSocket.do_not_reverse_lookup" do
+ before :all do
+ @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
+ end
+
before(:each) do
@server = TCPServer.new('127.0.0.1', SocketSpecs.port)
@socket = TCPSocket.new('127.0.0.1', SocketSpecs.port)
@@ -12,6 +16,14 @@
@socket.close unless @socket.closed?
@server.close unless @server.closed?
end
+
+ after :all do
+ BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
+ end
+
+ it "defaults to false" do
+ BasicSocket.do_not_reverse_lookup.should be_false
+ end
it "causes 'peeraddr' to avoid name lookups" do
BasicSocket.do_not_reverse_lookup = true
@@ -41,6 +53,10 @@
@server.close unless @server.closed?
@socket.close unless @socket.closed?
end
+
+ it "defaults to true" do
+ BasicSocket.do_not_reverse_lookup.should be_true
+ end
it "causes 'peeraddr' to avoid name lookups" do
@socket.do_not_reverse_lookup = true
Modified: MacRuby/trunk/spec/frozen/library/socket/basicsocket/for_fd_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/basicsocket/for_fd_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/basicsocket/for_fd_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,2 +1,38 @@
require File.expand_path('../../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)
+
+describe "BasicSocket#for_fd" do
+ before :each do
+ @server = TCPServer.new(SocketSpecs.port)
+ @s2 = nil
+ end
+
+ after :each do
+ # UG. We can't use the new_fd helper, because we need fds that are
+ # associated with sockets. But for_fd has the same issue as IO#new, it
+ # creates a fd aliasing issue with closing, causing EBADF errors.
+ #
+ # Thusly, the rescue for EBADF here. I'd love a better solution, but
+ # I'm not aware of one.
+
+ begin
+ @server.close unless @server.closed?
+ rescue Errno::EBADF
+ # I hate this API
+ end
+
+ begin
+ if @s2
+ @s2.close unless @s2.closed?
+ end
+ rescue Errno::EBADF
+ # I hate this API
+ end
+ end
+
+ it "return a Socket instance wrapped around the descriptor" do
+ @s2 = TCPServer.for_fd(@server.fileno)
+ @s2.should be_kind_of(TCPServer)
+ @s2.fileno.should == @server.fileno
+ end
+end
Modified: MacRuby/trunk/spec/frozen/library/socket/ipsocket/addr_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/ipsocket/addr_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/ipsocket/addr_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,6 +2,10 @@
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#addr" do
+ before :all do
+ @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
+ end
+
before :each do
@socket = TCPServer.new("127.0.0.1", SocketSpecs.port)
@@ -12,6 +16,10 @@
BasicSocket.do_not_reverse_lookup = false
end
+ after :all do
+ BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
+ end
+
ruby_version_is ""..."1.9" do
it "returns an array with the socket's information" do
BasicSocket.do_not_reverse_lookup = false
Modified: MacRuby/trunk/spec/frozen/library/socket/ipsocket/peeraddr_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/ipsocket/peeraddr_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/ipsocket/peeraddr_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,6 +2,10 @@
require File.expand_path('../../fixtures/classes', __FILE__)
describe "Socket::IPSocket#peeraddr" do
+ before :all do
+ @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
+ end
+
before :each do
@server = TCPServer.new("127.0.0.1", SocketSpecs.port)
@client = TCPSocket.new("127.0.0.1", SocketSpecs.port)
@@ -13,6 +17,10 @@
BasicSocket.do_not_reverse_lookup = false
end
+ after :all do
+ BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
+ end
+
it "raises error if socket is not connected" do
lambda { @server.peeraddr }.should raise_error
end
Modified: MacRuby/trunk/spec/frozen/library/socket/socket/getaddrinfo_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/socket/getaddrinfo_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/socket/getaddrinfo_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -4,6 +4,10 @@
require 'socket'
describe "Socket#getaddrinfo" do
+ before :all do
+ @do_not_reverse_lookup = BasicSocket.do_not_reverse_lookup
+ end
+
before :each do
BasicSocket.do_not_reverse_lookup = false
end
@@ -12,6 +16,10 @@
BasicSocket.do_not_reverse_lookup = false
end
+ after :all do
+ BasicSocket.do_not_reverse_lookup = @do_not_reverse_lookup
+ end
+
it "gets the address information" do
BasicSocket.do_not_reverse_lookup = true
expected = []
@@ -89,8 +97,11 @@
Socket::IPPROTO_TCP,
Socket::AI_PASSIVE)
- expected = [["AF_INET6", 80, "::", "::", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP]]
- res.should == expected
+ expected = [
+ ["AF_INET6", 80, "::", "::", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP],
+ ["AF_INET6", 80, "0:0:0:0:0:0:0:0", "0:0:0:0:0:0:0:0", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP]
+ ]
+ res.each { |a| expected.should include (a) }
end
it "accepts empty addresses for IPv6 non-passive sockets" do
@@ -101,8 +112,11 @@
Socket::IPPROTO_TCP,
0)
- expected = [["AF_INET6", 80, "::1", "::1", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP]]
- res.should == expected
+ expected = [
+ ["AF_INET6", 80, "::1", "::1", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP],
+ ["AF_INET6", 80, "0:0:0:0:0:0:0:1", "0:0:0:0:0:0:0:1", Socket::AF_INET6, Socket::SOCK_STREAM, Socket::IPPROTO_TCP]
+ ]
+ res.each { |a| expected.should include (a) }
end
end
Modified: MacRuby/trunk/spec/frozen/library/socket/socket/getnameinfo_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/socket/getnameinfo_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/socket/getnameinfo_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -18,7 +18,7 @@
name_info = Socket.getnameinfo(sockaddr, Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
end
-
+
it "gets the name information and resolve the host" do
sockaddr = Socket.sockaddr_in SocketSpecs.port, '127.0.0.1'
name_info = Socket.getnameinfo(sockaddr, Socket::NI_NUMERICSERV)
@@ -33,4 +33,25 @@
# see http://www.iana.org/assignments/port-numbers
name_info[1].should =~ /^(www|http|www-http)$/
end
+
+ it "gets a 3-element array and doesn't resolve hostname" do
+ name_info = Socket.getnameinfo(["AF_INET", SocketSpecs.port, '127.0.0.1'], Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
+ name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
+ end
+
+ it "gets a 3-element array and esolves the service" do
+ name_info = Socket.getnameinfo ["AF_INET", 80, '127.0.0.1']
+ name_info[1].should =~ /^(www|http|www-http)$/
+ end
+
+ it "gets a 4-element array and doesn't resolve hostname" do
+ name_info = Socket.getnameinfo(["AF_INET", SocketSpecs.port, 'foo', '127.0.0.1'], Socket::NI_NUMERICHOST | Socket::NI_NUMERICSERV)
+ name_info.should == ['127.0.0.1', "#{SocketSpecs.port}"]
+ end
+
+ it "gets a 4-element array and esolves the service" do
+ name_info = Socket.getnameinfo ["AF_INET", 80, 'foo', '127.0.0.1']
+ name_info[1].should =~ /^(www|http|www-http)$/
+ end
+
end
Modified: MacRuby/trunk/spec/frozen/library/socket/tcpserver/accept_nonblock_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/tcpserver/accept_nonblock_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/tcpserver/accept_nonblock_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -15,6 +15,7 @@
lambda { @server.accept_nonblock}.should raise_error(Errno::EAGAIN)
c = TCPSocket.new("127.0.0.1", SocketSpecs.port)
+ sleep 0.1
s = @server.accept_nonblock
# commenting while we get some input on the current JRuby situation
Modified: MacRuby/trunk/spec/frozen/library/socket/tcpsocket/shared/new.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/tcpsocket/shared/new.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/tcpsocket/shared/new.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -3,14 +3,16 @@
describe :tcpsocket_new, :shared => true do
before :each do
- @hostname = Socket.getaddrinfo("127.0.0.1", nil)[0][2]
+ addrinfo = Socket.getaddrinfo(Socket.gethostname, nil)[0]
+ @hostname = addrinfo[2]
+ @addr = addrinfo[3]
end
it "requires a hostname and a port as arguments" do
lambda { TCPSocket.send(@method) }.should raise_error(ArgumentError)
end
it "refuses the connection when there is no server to connect to" do
- lambda { TCPSocket.send(@method, '127.0.0.1', SocketSpecs.port) }.should raise_error(Errno::ECONNREFUSED)
+ lambda { TCPSocket.send(@method, @hostname, SocketSpecs.port) }.should raise_error(Errno::ECONNREFUSED)
end
it "connects to a listening server" do
@@ -35,7 +37,7 @@
it "has an address once it has connected to a listening server" do
ready = false
thread = Thread.new do
- server = TCPServer.new('127.0.0.1', SocketSpecs.port)
+ server = TCPServer.new(@hostname, SocketSpecs.port)
ready = true
conn = server.accept
conn.recv(50)
@@ -44,15 +46,24 @@
end
Thread.pass while (thread.status and thread.status != 'sleep') or !ready
thread.status.should_not be_nil
- sock = TCPSocket.send(@method, '127.0.0.1', SocketSpecs.port)
- sock.addr[0].should == "AF_INET"
- sock.addr[1].should be_kind_of(Fixnum)
- # on some platforms (Mac), MRI
- # returns comma at the end. Other
- # platforms such as OpenBSD setup the
- # localhost as localhost.domain.com
- sock.addr[2].should =~ /^#{@hostname}/
- sock.addr[3].should == "127.0.0.1"
+ sock = TCPSocket.send(@method, @hostname, SocketSpecs.port)
+
+ if sock.addr[0] == "AF_INET"
+ sock.addr[0].should == "AF_INET"
+ sock.addr[1].should be_kind_of(Fixnum)
+ # on some platforms (Mac), MRI
+ # returns comma at the end. Other
+ # platforms such as OpenBSD setup the
+ # localhost as localhost.domain.com
+ sock.addr[2].should =~ /^#{@hostname}/
+ sock.addr[3].should == @addr
+ else
+ sock.addr[0].should == "AF_INET6"
+ sock.addr[1].should be_kind_of(Fixnum)
+ sock.addr[2].should =~ /^#{@hostname}/
+ sock.addr[3].should == @addr
+ end
+
sock.close
thread.join
end
Modified: MacRuby/trunk/spec/frozen/library/socket/udpsocket/bind_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/socket/udpsocket/bind_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/socket/udpsocket/bind_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,7 +2,7 @@
require File.expand_path('../../fixtures/classes', __FILE__)
describe "UDPSocket.bind" do
-
+
before :each do
@socket = UDPSocket.new
end
@@ -17,18 +17,22 @@
lambda { @socket.bind(SocketSpecs.hostname, SocketSpecs.port) }.should raise_error
end
- it "receives a hostname and a port" do
- @socket.bind(SocketSpecs.hostname, SocketSpecs.port)
-
- port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
-
- host.should == "127.0.0.1"
- port.should == SocketSpecs.port
+ # This is quarantined because it fails randomly on linux.
+ # I believe it's because of ipv4/ipv6 interaction
+ quarantine! do
+ it "receives a hostname and a port" do
+ @socket.bind(SocketSpecs.hostname, SocketSpecs.port)
+
+ port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
+
+ host.should == "127.0.0.1"
+ port.should == SocketSpecs.port
+ end
end
it "binds to INADDR_ANY if the hostname is empty" do
@socket.bind("", SocketSpecs.port)
port, host = Socket.unpack_sockaddr_in(@socket.getsockname)
- host.should == "0.0.0.0"
+ host.should == "0.0.0.0"
end
end
Modified: MacRuby/trunk/spec/frozen/library/uri/join_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/uri/join_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/uri/join_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -2,13 +2,43 @@
require 'uri'
describe "URI.join" do
- it "returns a URI object of the concatonation of a protocol and domain, and a path" do
+ it "returns a URI object of the concatenation of a protocol and domain, and a path" do
URI.join("http://localhost/","main.rbx").should == URI.parse("http://localhost/main.rbx")
end
-
- it "doesn't create redundent '/'s" do
+
+ ruby_bug "redmine:3505", "1.9.2" do
+ it "accepts URI objects" do
+ URI.join(URI("http://localhost/"),"main.rbx").should == URI.parse("http://localhost/main.rbx")
+ URI.join("http://localhost/",URI("main.rbx")).should == URI.parse("http://localhost/main.rbx")
+ URI.join(URI("http://localhost/"),URI("main.rbx")).should == URI.parse("http://localhost/main.rbx")
+ end
+ end
+
+ ruby_bug "redmine:3506", "1.9.2" do
+ it "accepts string-like arguments with to_str" do
+ str = mock('string-like')
+ str.should_receive(:to_str).and_return("http://ruby-lang.org")
+ str2 = mock('string-like also')
+ str2.should_receive(:to_str).and_return("foo/bar")
+ URI.join(str, str2).should == URI.parse("http://ruby-lang.org/foo/bar")
+ end
+ end
+
+ it "raises an error if given no argument" do
+ lambda{ URI.join }.should raise_error
+ end
+
+ it "doesn't create redundant '/'s" do
URI.join("http://localhost/", "/main.rbx").should == URI.parse("http://localhost/main.rbx")
end
+
+ it "discards arguments given before an absolute uri" do
+ URI.join("http://localhost/a/b/c/d", "http://ruby-lang.com/foo", "bar").should == URI.parse("http://ruby-lang.com/bar")
+ end
+
+ it "resolves .. in paths" do
+ URI.join("http://localhost/a/b/c/d", "../../e/f", "g/h/../i").to_s.should == "http://localhost/a/e/g/i"
+ end
end
Deleted: MacRuby/trunk/spec/frozen/library/uri/route_to.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/uri/route_to.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/uri/route_to.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,21 +0,0 @@
-require File.expand_path('../../../spec_helper', __FILE__)
-require 'uri'
-
-describe "URI#route_to" do
-
- #this could be split out a good bit better
- it "gives the minimal difference between the current URI and the target" do
- URI("http://example.com/a.html").route_to('http://example.com/a.html').to_s.should == ""
- URI("http://example.com/a.html").route_to('http://example.com/b.html').to_s.should == "b.html"
- URI("http://example.com/a/").route_to('http://example.com/b/').to_s.should == "../b/"
- URI("http://example.com/a/c").route_to('http://example.com/b/').to_s.should == "../b/"
- URI("http://example.com/a/b/").route_to('http://example.com/b/').to_s.should == "../../b/"
- URI("http://example.com/a/b/").route_to('http://EXAMPLE.cOm/b/').to_s.should == "../../b/"
- URI("http://example.com/a/b/").route_to('http://example.net/b/').to_s.should == "//example.net/b/"
- URI("mailto:foo at example.com").route_to('mailto:foo at example.com#bar').to_s.should == "#bar"
-
- #this was a little surprising to me
- URI("mailto:foo at example.com#bar").route_to('mailto:foo at example.com').to_s.should == ""
- end
-
-end
\ No newline at end of file
Modified: MacRuby/trunk/spec/frozen/library/uri/uri_spec.rb
===================================================================
--- MacRuby/trunk/spec/frozen/library/uri/uri_spec.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/library/uri/uri_spec.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -10,6 +10,19 @@
URI("http://ruby-lang.org").should == result
Kernel::URI("http://ruby-lang.org").should == result
end
+
+ it "converts its argument with to_str" do
+ str = mock('string-like')
+ str.should_receive(:to_str).and_return("http://ruby-lang.org")
+ URI(str).should == URI.parse("http://ruby-lang.org")
+ end
+
+ ruby_bug "redmine:3505", "1.9.2" do
+ it "returns the argument if it is a URI object" do
+ result = URI.parse("http://ruby-lang.org")
+ URI(result).should equal(result)
+ end
+ end
#apparently this was a concern? imported from MRI tests
it "does not add a URI method to Object instances" do
Deleted: MacRuby/trunk/spec/frozen/shared/array/join.rb
===================================================================
--- MacRuby/trunk/spec/frozen/shared/array/join.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/shared/array/join.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,159 +0,0 @@
-describe :array_join, :shared => true do
- it "returns an empty string if the Array is empty" do
- a = @object.new
- a.send(@method, ':').should == ''
- end
-
- ruby_version_is ""..."1.9" do
- it "returns a string formed by concatenating each element.to_s separated by separator without trailing separator" do
- obj = mock('foo')
- def obj.to_s() 'foo' end
- @object.new(1, 2, 3, 4, obj).send(@method, ' | ').should == '1 | 2 | 3 | 4 | foo'
-
- obj = mock('o')
- class << obj; undef :to_s; end
- obj.should_receive(:method_missing).with(:to_s).and_return("o")
- @object.new(1, obj).send(@method, ":").should == "1:o"
- end
- end
-
- ruby_version_is "1.9" do
- it "returns a string formed by concatenating each element.to_str separated by separator without trailing separator" do
- obj = mock('foo')
- def obj.to_s() 'foo' end
- @object.new(1, 2, 3, 4, obj).send(@method, ' | ').should == '1 | 2 | 3 | 4 | foo'
-
- obj = mock('o')
- obj.should_receive(:method_missing).with(:to_str).and_return("o")
- @object.new(1, obj).send(@method, ":").should == "1:o"
- end
- end
-
- it "raises a NoMethodError if an element does not respond to #to_s" do
- obj = mock('o')
- class << obj; undef :to_s; end
- lambda{ @object.new(1,obj).send(@method, ':') }.should raise_error(NoMethodError)
- end
-
- it "uses the same separator with nested arrays" do
- @object.new(1, @object.new(2, @object.new(3, 4), 5), 6).send(@method, ":").should == "1:2:3:4:5:6"
- @object.new(1, @object.new(2, ArraySpecs::MyArray[3, 4], 5), 6).send(@method, ":").should == "1:2:3:4:5:6"
- end
-
- it "tries to convert the passed separator to a String using #to_str" do
- obj = mock('::')
- obj.should_receive(:to_str).and_return("::")
- @object.new(1, 2, 3, 4).send(@method, obj).should == '1::2::3::4'
- end
-
- ruby_version_is ""..."1.9" do
- # Detail of joining recursive arrays is implementation dependent: [ruby-dev:37021]
- it "handles recursive arrays" do
- x = @object.new
- x << x
- x.send(@method, ':').should be_kind_of(String)
-
- x = @object.new("one", "two")
- x << x
- str = x.send(@method, '/')
- str.should include("one/two")
-
- x << "three"
- x << "four"
- str = x.send(@method, '/')
- str.should include("one/two")
- str.should include("three/four")
-
- # nested and recursive
- x = @object.new(@object.new("one", "two"), @object.new("three", "four"))
- x << x
- str = x.send(@method, '/')
- str.should include("one/two")
- str.should include("three/four")
-
- x = @object.new
- y = @object.new
- y << 9 << x << 8 << y << 7
- x << 1 << x << 2 << y << 3
- # representations when recursing from x
- # these are here to make it easier to understand what is happening
- str = x.send(@method, ':')
- str.should include('1')
- str.should include('2')
- str.should include('3')
- end
- end
-
- ruby_version_is "1.9" do
- it "raises an ArgumentError when the Array is recursive" do
- x = @object.new
- x << x
- lambda { x.send(@method, ':') }.should raise_error(ArgumentError)
-
- x = @object.new("one", "two")
- x << x
- lambda { x.send(@method, '/') }.should raise_error(ArgumentError)
-
- # nested and recursive
- x = @object.new(@object.new("one", "two"), @object.new("three", "four"))
- x << x
- lambda { x.send(@method, '/') }.should raise_error(ArgumentError)
- end
- end
-
- it "does not consider taint of either the array or the separator when the array is empty" do
- @object.new.send(@method, ":").tainted?.should == false
- @object.new.taint.send(@method, ":").tainted?.should == false
- @object.new.send(@method, ":".taint).tainted?.should == false
- @object.new.taint.send(@method, ":".taint).tainted?.should == false
- end
-
- # This doesn't work for Enumerable#join on 1.9. See bug #1732
- it "returns a string which would be infected with taint of the array, its elements or the separator when the array is not empty" do
- @object.new("a", "b").send(@method, ":").tainted?.should == false
- @object.new("a", "b").send(@method, ":".taint).tainted?.should == true
- @object.new("a", "b").taint.send(@method, ":").tainted?.should == true
- @object.new("a", "b").taint.send(@method, ":".taint).tainted?.should == true
- @object.new("a", "b".taint).send(@method, ":").tainted?.should == true
- @object.new("a", "b".taint).send(@method, ":".taint).tainted?.should == true
- @object.new("a", "b".taint).taint.send(@method, ":").tainted?.should == true
- @object.new("a", "b".taint).taint.send(@method, ":".taint).tainted?.should == true
- @object.new("a".taint, "b").send(@method, ":").tainted?.should == true
- @object.new("a".taint, "b").send(@method, ":".taint).tainted?.should == true
- @object.new("a".taint, "b").taint.send(@method, ":").tainted?.should == true
- @object.new("a".taint, "b").taint.send(@method, ":".taint).tainted?.should == true
- @object.new("a".taint, "b".taint).send(@method, ":").tainted?.should == true
- @object.new("a".taint, "b".taint).send(@method, ":".taint).tainted?.should == true
- @object.new("a".taint, "b".taint).taint.send(@method, ":").tainted?.should == true
- @object.new("a".taint, "b".taint).taint.send(@method, ":".taint).tainted?.should == true
- end
-
- ruby_version_is '1.9' do
- it "does not consider untrustworthiness of either the array or the separator when the array is empty" do
- @object.new.send(@method, ":").untrusted?.should == false
- @object.new.untrust.send(@method, ":").untrusted?.should == false
- @object.new.send(@method, ":".untrust).untrusted?.should == false
- @object.new.untrust.send(@method, ":".untrust).untrusted?.should == false
- end
-
- # This doesn't work for Enumerable#join on 1.9. See bug #1732
- it "returns a string which would be infected with untrustworthiness of the array, its elements or the separator when the array is not empty" do
- @object.new("a", "b").send(@method, ":").untrusted?.should == false
- @object.new("a", "b").send(@method, ":".untrust).untrusted?.should == true
- @object.new("a", "b").untrust.send(@method, ":").untrusted?.should == true
- @object.new("a", "b").untrust.send(@method, ":".untrust).untrusted?.should == true
- @object.new("a", "b".untrust).send(@method, ":").untrusted?.should == true
- @object.new("a", "b".untrust).send(@method, ":".untrust).untrusted?.should == true
- @object.new("a", "b".untrust).untrust.send(@method, ":").untrusted?.should == true
- @object.new("a", "b".untrust).untrust.send(@method, ":".untrust).untrusted?.should == true
- @object.new("a".untrust, "b").send(@method, ":").untrusted?.should == true
- @object.new("a".untrust, "b").send(@method, ":".untrust).untrusted?.should == true
- @object.new("a".untrust, "b").untrust.send(@method, ":").untrusted?.should == true
- @object.new("a".untrust, "b").untrust.send(@method, ":".untrust).untrusted?.should == true
- @object.new("a".untrust, "b".untrust).send(@method, ":").untrusted?.should == true
- @object.new("a".untrust, "b".untrust).send(@method, ":".untrust).untrusted?.should == true
- @object.new("a".untrust, "b".untrust).untrust.send(@method, ":").untrusted?.should == true
- @object.new("a".untrust, "b".untrust).untrust.send(@method, ":".untrust).untrusted?.should == true
- end
- end
-end
Modified: MacRuby/trunk/spec/frozen/shared/file/size.rb
===================================================================
--- MacRuby/trunk/spec/frozen/shared/file/size.rb 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/shared/file/size.rb 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1,7 +1,7 @@
describe :file_size, :shared => true do
before :each do
@exists = tmp('i_exist')
- File.open(@exists,'w') { |f| f.write 'rubinius' }
+ touch(@exists) { |f| f.write 'rubinius' }
end
after :each do
@@ -26,6 +26,26 @@
end
end
+describe :file_size_to_io, :shared => true do
+ before :each do
+ @exists = tmp('i_exist')
+ touch(@exists) { |f| f.write 'rubinius' }
+ @file = File.open(@exists, 'r')
+ end
+
+ after :each do
+ @file.close unless @file.closed?
+ rm_r @exists
+ end
+
+ it "calls #to_io to convert the argument to an IO" do
+ obj = mock("io like")
+ obj.should_receive(:to_io).and_return(@file)
+
+ @object.send(@method, obj).should == 8
+ end
+end
+
describe :file_size_raise_when_missing, :shared => true do
before :each do
# TODO: missing_file
Modified: MacRuby/trunk/spec/frozen/upstream
===================================================================
--- MacRuby/trunk/spec/frozen/upstream 2010-08-22 13:13:15 UTC (rev 4439)
+++ MacRuby/trunk/spec/frozen/upstream 2010-08-22 13:15:35 UTC (rev 4440)
@@ -1 +1 @@
-2113588fc23df1d2750e2b81d34defa97030cf3b
\ No newline at end of file
+0bbe4d3ddcb78c5c1bf12821acfe167f868715e9
\ No newline at end of file
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100822/b58ca668/attachment-0001.html>
More information about the macruby-changes
mailing list