这是我的自定义格式化程序:
require 'pp'
require 'ap'
require "rspec/core/formatters/base_text_formatter"
def example_passed(example)
super(example)
output.print success_color('.')
ap example
end
def example_pending(example)
super(example)
output.print pending_color('*')
end
def example_failed(example)
super(example)
output.print failure_color('F')
end
def dump_summary(duration, example_count, failure_count, pending_count)
output.print 'Yep, everything\'s all finished'
end
end
我正在创建自己的rspec格式化程序,example
哈希中有很多非常有用的数据。
查看我将example_passed
方法打印到屏幕上的方法。然而,这将它打印成一个巨大的,无懈可击的文本墙,这使得编写代码来访问这些值几乎是不可能的。
我需要pp
,并尝试pp example
。什么都不做,巨大的文字墙。
我已安装并需要ap
(awesome_print)并尝试ap example
。仍然坚持着这一巨大的文字墙。
我没有收到任何错误消息,说明不能要求任何一个库。这与example
的复杂性有关吗?它在某种程度上不仅仅是一个多维哈希吗?
这是庞然大物本身:
#<RSpec::Core::Example:0x0000010576fbf0 @example_block=#<Proc:0x0000010576fd58@/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:7>, @options={}, @example_group_class=RSpec::Core::ExampleGroup::Nested_1::Nested_1, @metadata={:example_group=>{:example_group=>{:description_args=>["my group"], :caller=>["/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:300:in `set_it_up'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:245:in `subclass'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/dsl.rb:18:in `describe'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:3:in `<top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'"], :file_path=>"./spec/example_spec.rb", :line_number=>3}, :description_args=>["correct pi"], :caller=>["/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:300:in `set_it_up'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:245:in `subclass'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:4:in `block in <top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/dsl.rb:18:in `describe'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:3:in `<top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'"], :file_path=>"./spec/example_spec.rb", :line_number=>4}, :example_group_block=>#<Proc:0x0000010534ef58@/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:4>, :description_args=>["should be right"], :caller=>["/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/metadata.rb:187:in `for_example'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example.rb:81:in `initialize'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:66:in `new'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:66:in `it'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:7:in `block (2 levels) in <top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:4:in `block in <top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `module_eval'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:246:in `subclass'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/example_group.rb:232:in `describe'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/dsl.rb:18:in `describe'", "/Users/jonathanhurley/Documents/rails/treebook/spec/example_spec.rb:3:in `<top (required)>'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:80:in `run'", "/usr/local/rvm/gems/ruby-1.9.3-p392/gems/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'"], :description=>"should be right", :execution_result=>{:started_at=>2013-12-02 15:51:51 +0000, :status=>"passed", :finished_at=>2013-12-02 15:51:51 +0000, :run_time=>0.006028}}, @exception=nil, @example_group_instance=nil, @pending_declared_in_example=false, @around_each_hooks=[#<RSpec::Core::Hooks::AroundHook:0x00000102ff7cd0 @block=#<Proc:0x00000100f18758@/usr/local/rvm/rubies/ruby-1.9.3-p392/lib/ruby/gems/1.9.1/gems/rspec-rails-2.14.0/lib/rspec/rails/adapters.rb:49>, @options={}>]>