1
0
Fork 0
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:
Julien Negrotto 2015-12-18 18:12:14 -06:00 committed by Gerard Caulfield
parent 03353b348c
commit 15cf3b4bc8
No known key found for this signature in database
GPG key ID: 623B327128A9BEC3
3 changed files with 20 additions and 4 deletions

View file

@ -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

View file

@ -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

View file

@ -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