mirror of
https://github.com/zhigang1992/RubyMotion.git
synced 2026-04-24 04:46:05 +08:00
add core/nil specs
This commit is contained in:
9
test/test-android/app/core/nil/and_spec.rb
Normal file
9
test/test-android/app/core/nil/and_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "NilClass#&" do
|
||||
it "returns false" do
|
||||
(nil & nil).should == false
|
||||
(nil & true).should == false
|
||||
(nil & false).should == false
|
||||
(nil & "").should == false
|
||||
(nil & mock('x')).should == false
|
||||
end
|
||||
end
|
||||
5
test/test-android/app/core/nil/dup_spec.rb
Normal file
5
test/test-android/app/core/nil/dup_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
describe "NilClass#dup" do
|
||||
it "raises a TypeError" do
|
||||
lambda { nil.dup }.should raise_error(TypeError)
|
||||
end
|
||||
end
|
||||
5
test/test-android/app/core/nil/inspect_spec.rb
Normal file
5
test/test-android/app/core/nil/inspect_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
describe "NilClass#inspect" do
|
||||
it "returns the string 'nil'" do
|
||||
nil.inspect.should == "nil"
|
||||
end
|
||||
end
|
||||
5
test/test-android/app/core/nil/nil_spec.rb
Normal file
5
test/test-android/app/core/nil/nil_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
describe "NilClass#nil?" do
|
||||
it "returns true" do
|
||||
nil.nil?.should == true
|
||||
end
|
||||
end
|
||||
9
test/test-android/app/core/nil/or_spec.rb
Normal file
9
test/test-android/app/core/nil/or_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "NilClass#|" do
|
||||
it "returns false if other is nil or false, otherwise true" do
|
||||
(nil | nil).should == false
|
||||
(nil | true).should == true
|
||||
(nil | false).should == false
|
||||
(nil | "").should == true
|
||||
(nil | mock('x')).should == true
|
||||
end
|
||||
end
|
||||
5
test/test-android/app/core/nil/to_a_spec.rb
Normal file
5
test/test-android/app/core/nil/to_a_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
describe "NilClass#to_a" do
|
||||
it "returns an empty array" do
|
||||
nil.to_a.should == []
|
||||
end
|
||||
end
|
||||
9
test/test-android/app/core/nil/to_f_spec.rb
Normal file
9
test/test-android/app/core/nil/to_f_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "NilClass#to_f" do
|
||||
it "returns 0.0" do
|
||||
nil.to_f.should == 0.0
|
||||
end
|
||||
|
||||
it "does not cause NilClass to be coerced to Float" do
|
||||
(0.0 == nil).should == false
|
||||
end
|
||||
end
|
||||
9
test/test-android/app/core/nil/to_i_spec.rb
Normal file
9
test/test-android/app/core/nil/to_i_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "NilClass#to_i" do
|
||||
it "returns 0" do
|
||||
nil.to_i.should == 0
|
||||
end
|
||||
|
||||
it "does not cause NilClass to be coerced to Fixnum" do
|
||||
(0 == nil).should == false
|
||||
end
|
||||
end
|
||||
5
test/test-android/app/core/nil/to_s_spec.rb
Normal file
5
test/test-android/app/core/nil/to_s_spec.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
describe "NilClass#to_s" do
|
||||
it "returns the string ''" do
|
||||
nil.to_s.should == ""
|
||||
end
|
||||
end
|
||||
9
test/test-android/app/core/nil/xor_spec.rb
Normal file
9
test/test-android/app/core/nil/xor_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
describe "NilClass#^" do
|
||||
it "returns false if other is nil or false, otherwise true" do
|
||||
(nil ^ nil).should == false
|
||||
(nil ^ true).should == true
|
||||
(nil ^ false).should == false
|
||||
(nil ^ "").should == true
|
||||
(nil ^ mock('x')).should == true
|
||||
end
|
||||
end
|
||||
@@ -163,6 +163,24 @@ class Object
|
||||
end
|
||||
end
|
||||
|
||||
def raise_error(klass)
|
||||
lambda do |obj, res|
|
||||
begin
|
||||
obj.call
|
||||
if !res
|
||||
puts "Expectation failed (expected `#{klass}' to be raised, but nothing happened)"
|
||||
$expectations_failures += 1
|
||||
end
|
||||
rescue => e
|
||||
if (e.is_a?(klass)) != res
|
||||
puts "Expectation failed (expected `#{klass}' to be raised, got `#{e}')"
|
||||
$expectations_failures += 1
|
||||
end
|
||||
end
|
||||
$expectations_total += 1
|
||||
end
|
||||
end
|
||||
|
||||
def mock(obj)
|
||||
# XXX we probably should be smarter here.
|
||||
obj
|
||||
|
||||
Reference in New Issue
Block a user