diff --git a/CHANGELOG.md b/CHANGELOG.md index bfd14e0..13e928f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## master (unreleased) - + - Fixes struct formatting [@randyjap] - [#361] ## 1.9.2 - Tests work with Ruby 2.6.6, 2.7.2 and 3.0.0 diff --git a/awesome_print.gemspec b/awesome_print.gemspec index 29cea8d..7f237c1 100644 --- a/awesome_print.gemspec +++ b/awesome_print.gemspec @@ -26,7 +26,7 @@ Gem::Specification.new do |s| s.add_development_dependency 'rspec', '>= 3.0.0' s.add_development_dependency 'appraisal' s.add_development_dependency 'fakefs', '>= 0.2.1' - s.add_development_dependency 'sqlite3' + s.add_development_dependency 'sqlite3', '~> 1.3.6' s.add_development_dependency 'nokogiri', '>= 1.11.0' # s.add_development_dependency 'simplecov' # s.add_development_dependency 'codeclimate-test-reporter' diff --git a/lib/awesome_print/formatters/struct_formatter.rb b/lib/awesome_print/formatters/struct_formatter.rb index 18bebaa..4083769 100644 --- a/lib/awesome_print/formatters/struct_formatter.rb +++ b/lib/awesome_print/formatters/struct_formatter.rb @@ -15,7 +15,7 @@ module AwesomePrint def format vars = variables.map do |var| - property = var.to_s[1..-1].to_sym # to_s because of some monkey patching done by Puppet. + property = var.to_s.to_sym # to_s because of some monkey patching done by Puppet. accessor = if struct.respond_to?(:"#{property}=") struct.respond_to?(property) ? :accessor : :writer else diff --git a/spec/formats_spec.rb b/spec/formats_spec.rb index ac83732..b83b15c 100644 --- a/spec/formats_spec.rb +++ b/spec/formats_spec.rb @@ -604,44 +604,44 @@ EOS it 'plain multiline' do s1 = <<-EOS.strip - address = \"1313 Mockingbird Lane\", - name = \"Herman Munster\" + attr_accessor :address = \"1313 Mockingbird Lane\", + attr_accessor :name = \"Herman Munster\" EOS s2 = <<-EOS.strip - name = \"Herman Munster\", - address = \"1313 Mockingbird Lane\" + attr_accessor :name = \"Herman Munster\", + attr_accessor :address = \"1313 Mockingbird Lane\" EOS expect(@struct.ai(plain: true)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'plain multiline indented' do s1 = <<-EOS.strip - address = "1313 Mockingbird Lane", - name = "Herman Munster" + attr_accessor :address = "1313 Mockingbird Lane", + attr_accessor :name = "Herman Munster" EOS s2 = <<-EOS.strip - name = "Herman Munster", - address = "1313 Mockingbird Lane" + attr_accessor :name = "Herman Munster", + attr_accessor :address = "1313 Mockingbird Lane" EOS expect(@struct.ai(plain: true, indent: 1)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'plain single line' do - s1 = 'address = "1313 Mockingbird Lane", name = "Herman Munster"' - s2 = 'name = "Herman Munster", address = "1313 Mockingbird Lane"' + s1 = 'attr_accessor :ddress = "1313 Mockingbird Lane", attr_accessor :name = "Herman Munster"' + s2 = 'attr_accessor :name = "Herman Munster", attr_accessor :address = "1313 Mockingbird Lane"' expect(@struct.ai(plain: true, multiline: false)).to satisfy { |out| out.match(s1) || out.match(s2) } end it 'colored multiline (default)' do s1 = <<-EOS.strip - address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m, - name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m + \e[1;36mattr_accessor\e[0m \e[0;35m:address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m, + \e[1;36mattr_accessor\e[0m \e[0;35m:name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m EOS s2 = <<-EOS.strip - name\e[0;37m = \e[0m\e[0;33m\"Herman Munster\"\e[0m, - address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m + \e[1;36mattr_accessor\e[0m \e[0;35m:name\e[0;37m = \e[0m\e[0;33m\"Herman\e[1;36mattr_accessor\e[0m \e[0;35m: Munster\"\e[0m, + \e[1;36mattr_accessor\e[0m \e[0;35m:address\e[0;37m = \e[0m\e[0;33m\"1313 Mockingbird Lane\"\e[0m EOS - expect(@struct.ai).to satisfy { |out| out.include?(s1) || out.include?(s2) } + expect(@struct.ai).to satisfy { |out| out.include?(s1) && out.include?(s2) } end end