mirror of
https://github.com/awesome-print/awesome_print
synced 2023-03-27 23:22:34 -04:00
Handle NoMethodError for IRB implicit #ai
This commit is contained in:
parent
03353b348c
commit
15cf3b4bc8
3 changed files with 20 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
||||||
## master (unreleased)
|
## master (unreleased)
|
||||||
|
- Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
|
||||||
|
|
||||||
## 1.7.0
|
## 1.7.0
|
||||||
- Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
|
- Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
|
||||||
|
@ -129,6 +129,7 @@
|
||||||
- Initial Release.
|
- Initial Release.
|
||||||
|
|
||||||
[#200]: https://github.com/awesome-print/awesome_print/pull/200
|
[#200]: https://github.com/awesome-print/awesome_print/pull/200
|
||||||
|
[#212]: https://github.com/awesome-print/awesome_print/pull/212
|
||||||
[#216]: https://github.com/awesome-print/awesome_print/pull/216
|
[#216]: https://github.com/awesome-print/awesome_print/pull/216
|
||||||
[#217]: https://github.com/awesome-print/awesome_print/pull/217
|
[#217]: https://github.com/awesome-print/awesome_print/pull/217
|
||||||
[#222]: https://github.com/awesome-print/awesome_print/pull/222
|
[#222]: https://github.com/awesome-print/awesome_print/pull/222
|
||||||
|
@ -145,6 +146,7 @@
|
||||||
[@clonezone]: https://github.com/clonezone
|
[@clonezone]: https://github.com/clonezone
|
||||||
[@cyberdelia]: https://github.com/cyberdelia
|
[@cyberdelia]: https://github.com/cyberdelia
|
||||||
[@gerrywastaken]: https://github.com/gerrywastaken
|
[@gerrywastaken]: https://github.com/gerrywastaken
|
||||||
|
[@jtnegrotto]: https://github.com/jtnegrotto
|
||||||
[@kemmason]: https://github.com/kemmason
|
[@kemmason]: https://github.com/kemmason
|
||||||
[@maurogeorge]: https://github.com/maurogeorge
|
[@maurogeorge]: https://github.com/maurogeorge
|
||||||
[@MaxPleaner]: https://github.com/MaxPleaner
|
[@MaxPleaner]: https://github.com/MaxPleaner
|
||||||
|
|
|
@ -31,6 +31,8 @@ module AwesomePrint
|
||||||
IRB::Irb.class_eval do
|
IRB::Irb.class_eval do
|
||||||
def output_value
|
def output_value
|
||||||
ap @context.last_value
|
ap @context.last_value
|
||||||
|
rescue NoMethodError
|
||||||
|
puts "(Object doesn't support #ai)"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else # MacRuby
|
else # MacRuby
|
||||||
|
@ -55,7 +57,7 @@ module AwesomePrint
|
||||||
AP = :__awesome_print__
|
AP = :__awesome_print__
|
||||||
|
|
||||||
def initialize(options = {})
|
def initialize(options = {})
|
||||||
@options = {
|
@options = {
|
||||||
:indent => 4, # Indent using 4 spaces.
|
:indent => 4, # Indent using 4 spaces.
|
||||||
:index => true, # Display array indices.
|
:index => true, # Display array indices.
|
||||||
:html => false, # Use ANSI color codes rather than HTML.
|
:html => false, # Use ANSI color codes rather than HTML.
|
||||||
|
@ -65,7 +67,7 @@ module AwesomePrint
|
||||||
:sort_keys => false, # Do not sort hash keys.
|
:sort_keys => false, # Do not sort hash keys.
|
||||||
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
:limit => false, # Limit large output for arrays and hashes. Set to a boolean or integer.
|
||||||
:new_hash_syntax => false, # Use the JSON like syntax { foo: 'bar' }, when the key is a symbol
|
:new_hash_syntax => false, # Use the JSON like syntax { foo: 'bar' }, when the key is a symbol
|
||||||
:color => {
|
:color => {
|
||||||
:args => :pale,
|
:args => :pale,
|
||||||
:array => :white,
|
:array => :white,
|
||||||
:bigdecimal => :blue,
|
:bigdecimal => :blue,
|
||||||
|
@ -104,7 +106,7 @@ module AwesomePrint
|
||||||
def increase_indentation
|
def increase_indentation
|
||||||
indentator.indent(&Proc.new)
|
indentator.indent(&Proc.new)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Dispatcher that detects data nesting and invokes object-aware formatter.
|
# Dispatcher that detects data nesting and invokes object-aware formatter.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
def awesome(object)
|
def awesome(object)
|
||||||
|
|
|
@ -246,5 +246,17 @@ EOS
|
||||||
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
|
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
|
||||||
Object.instance_eval{ remove_const :IRB }
|
Object.instance_eval{ remove_const :IRB }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "handles NoMethodError on IRB implicit #ai" do
|
||||||
|
module IRB; class Irb; end; end
|
||||||
|
irb_context = double('irb_context', last_value: BasicObject.new)
|
||||||
|
IRB.define_singleton_method :version, -> { 'test_version' }
|
||||||
|
irb = IRB::Irb.new
|
||||||
|
irb.instance_eval { @context = irb_context }
|
||||||
|
AwesomePrint.irb!
|
||||||
|
expect(irb).to receive(:puts).with("(Object doesn't support #ai)")
|
||||||
|
expect { irb.output_value }.to_not raise_error
|
||||||
|
Object.instance_eval { remove_const :IRB }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue