From 30e1e0941eb4a195ce50dcd287be115491f530d8 Mon Sep 17 00:00:00 2001 From: Conrad Irwin Date: Tue, 27 Dec 2011 22:38:25 +0000 Subject: [PATCH] Use Helpers::BaseHelpers.? MOAR --- lib/pry/pry_class.rb | 4 ++-- lib/pry/wrapped_module.rb | 2 +- test/helper.rb | 12 +----------- test/test_completion.rb | 2 +- test/test_default_commands/test_ls.rb | 2 +- test/test_default_commands/test_shell.rb | 2 +- test/test_method.rb | 2 +- test/test_syntax_checking.rb | 2 +- 8 files changed, 9 insertions(+), 19 deletions(-) diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index f60e33c8..1ee5049f 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -215,12 +215,12 @@ class Pry config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST config.hooks = DEFAULT_HOOKS config.input_stack = [] - config.color = Pry::Helpers::BaseHelpers.use_ansi_codes? + config.color = Helpers::BaseHelpers.use_ansi_codes? config.pager = true config.system = DEFAULT_SYSTEM config.editor = default_editor_for_platform config.should_load_rc = true - config.should_trap_interrupts = defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ + config.should_trap_interrupts = Helpers::BaseHelpers.jruby? config.disable_auto_reload = false config.command_prefix = "" config.auto_indent = true diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 1fd5c3c8..c61914b6 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -54,7 +54,7 @@ class Pry def singleton_instance raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class? - if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ + if Helpers::BaseHelpers.jruby? wrapped.to_java.attached else @singleton_instance ||= ObjectSpace.each_object(wrapped).detect{ |x| (class << x; self; end) == wrapped } diff --git a/test/helper.rb b/test/helper.rb index 69657bf1..db384074 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -49,16 +49,6 @@ class MockPryException end end -# are we on Jruby platform? -def jruby? - defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/ -end - -# are we on rbx platform? -def rbx? - defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ -end - Pry.reset_defaults # this is to test exception code (cat --ex) @@ -183,7 +173,7 @@ end # to help with tracking down bugs that cause an infinite loop in the test suite if ENV["SET_TRACE_FUNC"] - require 'set_trace' if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ # gem install 'rbx-tracer' + require 'set_trace' if Pry::Helpers::BaseHelpers.rbx? set_trace_func proc { |event, file, line, id, binding, classname| STDERR.printf "%8s %s:%-2d %10s %8s\n", event, file, line, id, classname } diff --git a/test/test_completion.rb b/test/test_completion.rb index 4f9abf83..c5b04e5a 100644 --- a/test/test_completion.rb +++ b/test/test_completion.rb @@ -16,7 +16,7 @@ describe Pry::InputCompleter do end # another jruby hack :(( - if !jruby? + if !Pry::Helpers::BaseHelpers.jruby? it "should not crash if there's a Module that has a symbolic name." do completer = Pry::InputCompleter.build_completion_proc(Pry.binding_for(Object.new)) lambda{ completer.call "a.to_s." }.should.not.raise Exception diff --git a/test/test_default_commands/test_ls.rb b/test/test_default_commands/test_ls.rb index 427d1f9c..24ded147 100644 --- a/test/test_default_commands/test_ls.rb +++ b/test/test_default_commands/test_ls.rb @@ -92,7 +92,7 @@ describe "ls" do describe "when no arguments given" do describe "when at the top-level" do # rubinius has a bug that means local_variables of "main" aren't reported inside eval() - unless defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ + unless Pry::Helpers::BaseHelpers.rbx? it "should show local variables" do mock_pry("ls").should =~ /_pry_/ mock_pry("arbitrar = 1", "ls").should =~ /arbitrar/ diff --git a/test/test_default_commands/test_shell.rb b/test/test_default_commands/test_shell.rb index 88989196..9544d720 100644 --- a/test/test_default_commands/test_shell.rb +++ b/test/test_default_commands/test_shell.rb @@ -47,7 +47,7 @@ describe "Pry::DefaultCommands::Shell" do # this doesnt work so well on rbx due to differences in backtrace # so we currently skip rbx until we figure out a workaround describe "with --ex" do - if !rbx? + if !Pry::Helpers::BaseHelpers.rbx? it 'cat --ex should correctly display code that generated exception even if raised in repl' do mock_pry("this raises error", "cat --ex").should =~ /\d+:(\s*) this raises error/ end diff --git a/test/test_method.rb b/test/test_method.rb index 5fc0f2b7..cb7a7d09 100644 --- a/test/test_method.rb +++ b/test/test_method.rb @@ -98,7 +98,7 @@ describe Pry::Method do end # Our source_location trick doesn't work, due to https://github.com/rubinius/rubinius/issues/953 - unless defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/ + unless Pry::Helpers::BaseHelpers.rbx? it 'should find the super method correctly' do a = Class.new{ def gag; binding; end; def self.line; __LINE__; end } b = Class.new(a){ def gag; super; end } diff --git a/test/test_syntax_checking.rb b/test/test_syntax_checking.rb index 152e1808..f338580e 100644 --- a/test/test_syntax_checking.rb +++ b/test/test_syntax_checking.rb @@ -26,7 +26,7 @@ describe Pry do ["1 1"], ["puts :"], # in this case the syntax error is "expecting ')'". - ((defined? RUBY_ENGINE && RUBY_ENGINE == "rbx") ? nil : ["def", "method(1"]) + (Pry::Helpers::BaseHelpers.rbx? ? nil : ["def", "method(1"]) ].compact.each do |foo| it "should raise an error on invalid syntax like #{foo.inspect}" do output = StringIO.new