mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Test Formatter#to_hash.
This commit is contained in:
parent
4391b7175c
commit
f6f3914bae
1 changed files with 51 additions and 0 deletions
|
@ -708,5 +708,56 @@ EOS
|
|||
my = My.new
|
||||
expect { my.methods.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
describe "should handle a class that defines its own #to_hash method" do
|
||||
it "that takes arguments" do
|
||||
class My
|
||||
def to_hash(a, b)
|
||||
end
|
||||
end
|
||||
|
||||
my = My.new
|
||||
expect { my.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "that returns nil" do
|
||||
class My
|
||||
def to_hash()
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
my = My.new
|
||||
expect { my.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "that returns an object that doesn't support #keys" do
|
||||
class My
|
||||
def to_hash()
|
||||
object = Object.new
|
||||
object.define_singleton_method('[]') { return nil }
|
||||
|
||||
return object
|
||||
end
|
||||
end
|
||||
|
||||
my = My.new
|
||||
expect { my.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
|
||||
it "that returns an object that doesn't support subscripting" do
|
||||
class My
|
||||
def to_hash()
|
||||
object = Object.new
|
||||
object.define_singleton_method(:keys) { return [:foo] }
|
||||
|
||||
return object
|
||||
end
|
||||
end
|
||||
|
||||
my = My.new
|
||||
expect { my.ai(:plain => true) }.not_to raise_error
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue