From e99327c2e379f9a0a996ce35314b3ed812136acd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Hendricksen?= Date: Mon, 24 Apr 2017 12:23:40 -0400 Subject: [PATCH] add a to_s method and some tests --- .gitignore | 1 + lib/hashr.rb | 4 ++++ spec/hashr/delegate/conditional_spec.rb | 2 ++ spec/hashr_spec.rb | 12 ++++++++++++ 4 files changed, 19 insertions(+) diff --git a/.gitignore b/.gitignore index b844b14..f153309 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ Gemfile.lock +.ruby-* diff --git a/lib/hashr.rb b/lib/hashr.rb index d770010..86a4070 100644 --- a/lib/hashr.rb +++ b/lib/hashr.rb @@ -100,6 +100,10 @@ def inspect "<#{self.class.name} #{@data.inspect}>" end + def to_s + to_h.to_s + end + private def to_key(key) diff --git a/spec/hashr/delegate/conditional_spec.rb b/spec/hashr/delegate/conditional_spec.rb index 5097b62..ab87be8 100644 --- a/spec/hashr/delegate/conditional_spec.rb +++ b/spec/hashr/delegate/conditional_spec.rb @@ -1,3 +1,5 @@ +require 'spec_helper' + describe Hashr::Delegate::Conditional do let(:klass) { Class.new(Hashr) { include Hashr::Delegate::Conditional } } diff --git a/spec/hashr_spec.rb b/spec/hashr_spec.rb index f8f2c11..9cdf865 100644 --- a/spec/hashr_spec.rb +++ b/spec/hashr_spec.rb @@ -263,4 +263,16 @@ def count expect(klass.new.env).to eq(ENV) end end + + describe 'pry methods' do + let(:klass) { Class.new(Hashr) { default foo: { bar: { baz: 'baz' } } } } + + example '#inspect' do + expect(klass.new.foo.inspect).to eq("\"baz\"}>}>") + end + + example '#to_s' do + expect(klass.new.foo.to_s).to eq("{:bar=>{:baz=>\"baz\"}}") + end + end end