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

Original PR by @jtnegrotto. #253 was only to rebase the work on master.
This commit is contained in:
Gerry 2016-07-01 16:30:49 +10:00 committed by GitHub
commit 86134031c9
3 changed files with 20 additions and 4 deletions

View file

@ -1,5 +1,5 @@
## master (unreleased)
- Handles NoMethodError for IRB implicit `ai` [@jtnegrotto] - [#212]
## 1.7.0
- Refactoring by extracting formatters into their own classes [@waldyr] - [#237]
@ -129,6 +129,7 @@
- Initial Release.
[#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
[#217]: https://github.com/awesome-print/awesome_print/pull/217
[#222]: https://github.com/awesome-print/awesome_print/pull/222
@ -145,6 +146,7 @@
[@clonezone]: https://github.com/clonezone
[@cyberdelia]: https://github.com/cyberdelia
[@gerrywastaken]: https://github.com/gerrywastaken
[@jtnegrotto]: https://github.com/jtnegrotto
[@kemmason]: https://github.com/kemmason
[@maurogeorge]: https://github.com/maurogeorge
[@MaxPleaner]: https://github.com/MaxPleaner

View file

@ -31,6 +31,8 @@ module AwesomePrint
IRB::Irb.class_eval do
def output_value
ap @context.last_value
rescue NoMethodError
puts "(Object doesn't support #ai)"
end
end
else # MacRuby

View file

@ -246,5 +246,17 @@ EOS
expect(capture! { ap({ :a => 1 }) }).to eq(nil)
Object.instance_eval{ remove_const :IRB }
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