summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2018-11-02 00:16:35 +0800
committerKyrylo Silin <silin@kyrylo.org>2018-11-02 01:52:09 +0800
commit187c199e7773e1e5227a13ee69433b382f6c0b5f (patch)
tree2d220ef85847fe6da27cdf05e77a071484ed528d
parent4ff2eb7207d9b583a904a186ca22b93c97ffee48 (diff)
downloadpry-187c199e7773e1e5227a13ee69433b382f6c0b5f.tar.gz
Deprecate Pry::Platform and introduce Pry::Helpers::Platform
`Pry::Platform` really looks like a helper and therefore should be defined as one. Invoking `Pry::Platform` emits a warning now. Users are encouraged to use `Pry::Helpers::Platform`.
-rw-r--r--lib/pry/commands/clear_screen.rb2
-rw-r--r--lib/pry/commands/easter_eggs.rb2
-rw-r--r--lib/pry/commands/ls.rb2
-rw-r--r--lib/pry/commands/ls/constants.rb2
-rw-r--r--lib/pry/commands/ls/methods_helper.rb2
-rw-r--r--lib/pry/config/default.rb4
-rw-r--r--lib/pry/core_extensions.rb2
-rw-r--r--lib/pry/editor.rb7
-rw-r--r--lib/pry/helpers.rb1
-rw-r--r--lib/pry/helpers/base_helpers.rb3
-rw-r--r--lib/pry/helpers/platform.rb58
-rw-r--r--lib/pry/indent.rb2
-rw-r--r--lib/pry/pager.rb4
-rw-r--r--lib/pry/platform.rb167
-rw-r--r--lib/pry/pry_class.rb11
-rw-r--r--lib/pry/pry_instance.rb4
-rw-r--r--lib/pry/repl.rb4
-rw-r--r--lib/pry/terminal.rb2
-rw-r--r--lib/pry/wrapped_module.rb4
-rw-r--r--spec/commands/edit_spec.rb2
-rw-r--r--spec/commands/ls_spec.rb18
-rw-r--r--spec/completion_spec.rb16
-rw-r--r--spec/editor_spec.rb22
-rw-r--r--spec/helper.rb11
-rw-r--r--spec/pry_spec.rb4
-rw-r--r--spec/pryrc_spec.rb2
26 files changed, 197 insertions, 161 deletions
diff --git a/lib/pry/commands/clear_screen.rb b/lib/pry/commands/clear_screen.rb
index 30781b2a..aa5e2ecf 100644
--- a/lib/pry/commands/clear_screen.rb
+++ b/lib/pry/commands/clear_screen.rb
@@ -4,7 +4,7 @@ class Pry::Command::ClearScreen < Pry::ClassCommand
description 'Clear the contents of the screen/window Pry is running in.'
def process
- if windows?
+ if Helpers::Platform.windows?
_pry_.config.system.call(_pry_.output, 'cls', _pry_)
else
_pry_.config.system.call(_pry_.output, 'clear', _pry_)
diff --git a/lib/pry/commands/easter_eggs.rb b/lib/pry/commands/easter_eggs.rb
index ed863b7a..9ceb5960 100644
--- a/lib/pry/commands/easter_eggs.rb
+++ b/lib/pry/commands/easter_eggs.rb
@@ -95,7 +95,7 @@ TEXT
\____/ \________________________|
EOS
- if windows_ansi?
+ if Helpers::Platform.windows_ansi?
move_up = proc { |n| "\e[#{n}F" }
else
move_up = proc { |n| "\e[#{n}A\e[0G" }
diff --git a/lib/pry/commands/ls.rb b/lib/pry/commands/ls.rb
index da5961d2..daaab305 100644
--- a/lib/pry/commands/ls.rb
+++ b/lib/pry/commands/ls.rb
@@ -64,7 +64,7 @@ class Pry
if Object.respond_to?(:deprecate_constant)
opt.on :d, :dconstants, "Show deprecated constants"
end
- if jruby?
+ if Helpers::Platform.jruby?
opt.on :J, "all-java", "Show all the aliases for methods from java (default is to show only prettiest)"
end
end
diff --git a/lib/pry/commands/ls/constants.rb b/lib/pry/commands/ls/constants.rb
index 516ce06e..61d31f4f 100644
--- a/lib/pry/commands/ls/constants.rb
+++ b/lib/pry/commands/ls/constants.rb
@@ -4,7 +4,7 @@ class Pry
class Command::Ls < Pry::ClassCommand
class Constants < Pry::Command::Ls::Formatter
DEPRECATED_CONSTANTS = [:Data, :Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE]
- DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Pry::Helpers::BaseHelpers.jruby?
+ DEPRECATED_CONSTANTS << :JavaPackageModuleTemplate if Helpers::Platform.jruby?
include Pry::Command::Ls::Interrogatable
def initialize(interrogatee, no_user_opts, opts, _pry_)
diff --git a/lib/pry/commands/ls/methods_helper.rb b/lib/pry/commands/ls/methods_helper.rb
index f0b4414d..88fde051 100644
--- a/lib/pry/commands/ls/methods_helper.rb
+++ b/lib/pry/commands/ls/methods_helper.rb
@@ -14,7 +14,7 @@ module Pry::Command::Ls::MethodsHelper
Pry::Method.all_from_obj(@interrogatee)
end
- if Pry::Helpers::BaseHelpers.jruby? && !@jruby_switch
+ if Pry::Helpers::Platform.jruby? && !@jruby_switch
methods = trim_jruby_aliases(methods)
end
diff --git a/lib/pry/config/default.rb b/lib/pry/config/default.rb
index 8a6b3204..7d441e21 100644
--- a/lib/pry/config/default.rb
+++ b/lib/pry/config/default.rb
@@ -52,7 +52,7 @@ class Pry
},
editor: proc {
Pry.default_editor_for_platform
- }, # TODO: Pry::Platform.editor
+ },
should_load_rc: proc {
true
},
@@ -60,7 +60,7 @@ class Pry
true
},
should_trap_interrupts: proc {
- Pry::Platform.jruby?
+ Pry::Helpers::Platform.jruby?
},
disable_auto_reload: proc {
false
diff --git a/lib/pry/core_extensions.rb b/lib/pry/core_extensions.rb
index be311965..dcaa669d 100644
--- a/lib/pry/core_extensions.rb
+++ b/lib/pry/core_extensions.rb
@@ -81,7 +81,7 @@ class Object
# This fixes the following two spec failures, at https://travis-ci.org/pry/pry/jobs/274470002
# 1) ./spec/pry_spec.rb:360:in `block in (root)'
# 2) ./spec/pry_spec.rb:366:in `block in (root)'
- return class_eval {binding} if Pry::Helpers::BaseHelpers.jruby? and self.name == nil
+ return class_eval {binding} if Pry::Helpers::Platform.jruby? and self.name == nil
# class_eval sets both self and the default definee to this class.
return class_eval("binding")
diff --git a/lib/pry/editor.rb b/lib/pry/editor.rb
index 9acdbe39..c5a13200 100644
--- a/lib/pry/editor.rb
+++ b/lib/pry/editor.rb
@@ -1,6 +1,5 @@
class Pry
class Editor
- include Pry::Helpers::BaseHelpers
include Pry::Helpers::CommandHelpers
attr_reader :_pry_
@@ -25,7 +24,7 @@ class Pry
editor_invocation = build_editor_invocation_string(file, line, blocking)
return nil unless editor_invocation
- if jruby?
+ if Helpers::Platform.jruby?
open_editor_on_jruby(editor_invocation)
else
open_editor(editor_invocation)
@@ -43,7 +42,7 @@ class Pry
args = [file, line, blocking][0...(_pry_.config.editor.arity)]
_pry_.config.editor.call(*args)
else
- sanitized_file = windows? ? file : Shellwords.escape(file)
+ sanitized_file = Helpers::Platform.windows? ? file : Shellwords.escape(file)
"#{_pry_.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
end
end
@@ -104,7 +103,7 @@ class Pry
when /^redcar/
"-l#{line_number} #{file_name}"
else
- if windows?
+ if Helpers::Platform.windows?
"#{file_name}"
else
"+#{line_number} #{file_name}"
diff --git a/lib/pry/helpers.rb b/lib/pry/helpers.rb
index f59c3080..faaced9b 100644
--- a/lib/pry/helpers.rb
+++ b/lib/pry/helpers.rb
@@ -3,3 +3,4 @@ require "pry/helpers/options_helpers"
require "pry/helpers/command_helpers"
require "pry/helpers/text"
require "pry/helpers/table"
+require "pry/helpers/platform"
diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb
index e42dbfaf..c1324e3a 100644
--- a/lib/pry/helpers/base_helpers.rb
+++ b/lib/pry/helpers/base_helpers.rb
@@ -1,6 +1,5 @@
module Pry::Helpers; end
module Pry::Helpers::BaseHelpers
- include Pry::Platform
extend self
def silence_warnings
@@ -42,7 +41,7 @@ module Pry::Helpers::BaseHelpers
end
def use_ansi_codes?
- windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
+ Pry::Helpers::Platform.windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
end
def colorize_code(code)
diff --git a/lib/pry/helpers/platform.rb b/lib/pry/helpers/platform.rb
new file mode 100644
index 00000000..157e586f
--- /dev/null
+++ b/lib/pry/helpers/platform.rb
@@ -0,0 +1,58 @@
+class Pry
+ module Helpers
+ # Contains methods for querying the platform that Pry is running on
+ # @api public
+ # @since v0.12.0
+ # rubocop:disable Style/DoubleNegation
+ module Platform
+ # @return [Boolean]
+ def self.mac_osx?
+ !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
+ end
+
+ # @return [Boolean]
+ def self.linux?
+ !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
+ end
+
+ # @return [Boolean] true when Pry is running on Windows with ANSI support,
+ # false otherwise
+ def self.windows?
+ !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
+ end
+
+ # @return [Boolean]
+ def self.windows_ansi?
+ return false unless windows?
+
+ !!(defined?(Win32::Console) || ENV['ANSICON'] || mri_2?)
+ end
+
+ # @return [Boolean]
+ def self.jruby?
+ RbConfig::CONFIG['ruby_install_name'] == 'jruby'
+ end
+
+ # @return [Boolean]
+ def self.jruby_19?
+ jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
+ end
+
+ # @return [Boolean]
+ def self.mri?
+ RbConfig::CONFIG['ruby_install_name'] == 'ruby'
+ end
+
+ # @return [Boolean]
+ def self.mri_19?
+ !!(mri? && RUBY_VERSION.start_with?('1.9'))
+ end
+
+ # @return [Boolean]
+ def self.mri_2?
+ !!(mri? && RUBY_VERSION.start_with?('2'))
+ end
+ end
+ # rubocop:enable Style/DoubleNegation
+ end
+end
diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb
index 2a77c0a8..49b0437a 100644
--- a/lib/pry/indent.rb
+++ b/lib/pry/indent.rb
@@ -395,7 +395,7 @@ class Pry
cols = Terminal.width!
lines = cols == 0 ? 1 : (line_to_measure.length / cols + 1).to_i
- if Pry::Helpers::BaseHelpers.windows_ansi?
+ if Helpers::Platform.windows_ansi?
move_up = "\e[#{lines}F"
move_down = "\e[#{lines}E"
else
diff --git a/lib/pry/pager.rb b/lib/pry/pager.rb
index 3d92f3ab..e13a6ed4 100644
--- a/lib/pry/pager.rb
+++ b/lib/pry/pager.rb
@@ -51,7 +51,7 @@ class Pry::Pager
def best_available
if !_pry_.config.pager
NullPager.new(_pry_.output)
- elsif !SystemPager.available? || Pry::Helpers::BaseHelpers.jruby?
+ elsif !SystemPager.available? || Helpers::Platform.jruby?
SimplePager.new(_pry_.output)
else
SystemPager.new(_pry_.output)
@@ -139,7 +139,7 @@ class Pry::Pager
if @system_pager.nil?
@system_pager = begin
pager_executable = default_pager.split(' ').first
- if Pry::Helpers::BaseHelpers.windows? || Pry::Helpers::BaseHelpers.windows_ansi?
+ if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
`where /Q #{pager_executable}`
else
`which #{pager_executable}`
diff --git a/lib/pry/platform.rb b/lib/pry/platform.rb
index f1d2dc49..98a86efb 100644
--- a/lib/pry/platform.rb
+++ b/lib/pry/platform.rb
@@ -1,94 +1,99 @@
-module Pry::Platform
- extend self
+class Pry
+ module Platform
+ extend self
- #
- # @return [Boolean]
- # Returns true if Pry is running on Mac OSX.
- #
- # @note
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
- #
- def mac_osx?
- !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
- end
+ #
+ # @return [Boolean]
+ # Returns true if Pry is running on Mac OSX.
+ #
+ # @note
+ # Queries RbConfig::CONFIG['host_os'] with a best guess.
+ #
+ def mac_osx?
+ !!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
+ end
- #
- # @return [Boolean]
- # Returns true if Pry is running on Linux.
- #
- # @note
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
- #
- def linux?
- !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
- end
+ #
+ # @return [Boolean]
+ # Returns true if Pry is running on Linux.
+ #
+ # @note
+ # Queries RbConfig::CONFIG['host_os'] with a best guess.
+ #
+ def linux?
+ !!(RbConfig::CONFIG['host_os'] =~ /linux/i)
+ end
- #
- # @return [Boolean]
- # Returns true if Pry is running on Windows.
- #
- # @note
- # Queries RbConfig::CONFIG['host_os'] with a best guess.
- #
- def windows?
- !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
- end
+ #
+ # @return [Boolean]
+ # Returns true if Pry is running on Windows.
+ #
+ # @note
+ # Queries RbConfig::CONFIG['host_os'] with a best guess.
+ #
+ def windows?
+ !!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is running on Windows with ANSI support.
- #
- def windows_ansi?
- return false if not windows?
+ #
+ # @return [Boolean]
+ # Returns true when Pry is running on Windows with ANSI support.
+ #
+ def windows_ansi?
+ return false if not windows?
- !!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
- end
+ !!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is being run from JRuby.
- #
- def jruby?
- RbConfig::CONFIG['ruby_install_name'] == 'jruby'
- end
+ #
+ # @return [Boolean]
+ # Returns true when Pry is being run from JRuby.
+ #
+ def jruby?
+ RbConfig::CONFIG['ruby_install_name'] == 'jruby'
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is being run from JRuby in 1.9 mode.
- #
- def jruby_19?
- jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
- end
+ #
+ # @return [Boolean]
+ # Returns true when Pry is being run from JRuby in 1.9 mode.
+ #
+ def jruby_19?
+ jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is being run from MRI (CRuby).
- #
- def mri?
- RbConfig::CONFIG['ruby_install_name'] == 'ruby'
- end
+ #
+ # @return [Boolean]
+ # Returns true when Pry is being run from MRI (CRuby).
+ #
+ def mri?
+ RbConfig::CONFIG['ruby_install_name'] == 'ruby'
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is being run from MRI v1.9+ (CRuby).
- #
- def mri_19?
- !!(mri? and RUBY_VERSION =~ /\A1\.9/)
- end
+ #
+ # @return [Boolean]
+ # Returns true when Pry is being run from MRI v1.9+ (CRuby).
+ #
+ def mri_19?
+ !!(mri? and RUBY_VERSION =~ /\A1\.9/)
+ end
- #
- # @return [Boolean]
- # Returns true when Pry is being run from MRI v2+ (CRuby).
- #
- def mri_2?
- !!(mri? and RUBY_VERSION =~ /\A2/)
- end
+ #
+ # @return [Boolean]
+ # Returns true when Pry is being run from MRI v2+ (CRuby).
+ #
+ def mri_2?
+ !!(mri? and RUBY_VERSION =~ /\A2/)
+ end
- #
- # @return [Array<Symbol>]
- # Returns an Array of Ruby engines that Pry is known to run on.
- #
- def known_engines
- [:jruby, :mri]
+ #
+ # @return [Array<Symbol>]
+ # Returns an Array of Ruby engines that Pry is known to run on.
+ #
+ def known_engines
+ [:jruby, :mri]
+ end
end
+
+ # Not supported on MRI 2.2 and lower.
+ deprecate_constant(:Platform) if respond_to?(:deprecate_constant)
end
diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb
index 356a2127..82235422 100644
--- a/lib/pry/pry_class.rb
+++ b/lib/pry/pry_class.rb
@@ -157,7 +157,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
load_requires if Pry.config.should_load_requires
load_history if Pry.config.history.should_load
load_traps if Pry.config.should_trap_interrupts
- load_win32console if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi?
+ load_win32console if Helpers::Platform.windows? && !Helpers::Platform.windows_ansi?
end
# Start a Pry REPL.
@@ -296,13 +296,10 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
def self.default_editor_for_platform
return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
+ return 'notepad' if Helpers::Platform.windows?
- if Helpers::BaseHelpers.windows?
- 'notepad'
- else
- %w(editor nano vi).detect do |editor|
- system("which #{editor} > /dev/null 2>&1")
- end
+ %w(editor nano vi).detect do |editor|
+ system("which #{editor} > /dev/null 2>&1")
end
end
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index 04a963eb..17d61f85 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -332,7 +332,7 @@ class Pry
# This workaround has a side effect: java exceptions specified
# in `Pry.config.exception_whitelist` are ignored.
jruby_exceptions = []
- if Pry::Helpers::BaseHelpers.jruby?
+ if Helpers::Platform.jruby?
jruby_exceptions << Java::JavaLang::Exception
end
@@ -347,7 +347,7 @@ class Pry
# Eliminate following warning:
# warning: singleton on non-persistent Java type X
# (http://wiki.jruby.org/Persistence)
- if Pry::Helpers::BaseHelpers.jruby? && e.class.respond_to?('__persistent__')
+ if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
e.class.__persistent__ = true
end
self.last_exception = e
diff --git a/lib/pry/repl.rb b/lib/pry/repl.rb
index afc7864d..ff96c2d2 100644
--- a/lib/pry/repl.rb
+++ b/lib/pry/repl.rb
@@ -49,7 +49,7 @@ class Pry
# Clear the line before starting Pry. This fixes issue #566.
if pry.config.correct_indent
- Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
+ Kernel.print(Helpers::Platform.windows_ansi? ? "\e[0F" : "\e[0G")
end
end
@@ -220,7 +220,7 @@ class Pry
def piping?
return false unless $stdout.respond_to?(:tty?)
- !$stdout.tty? && $stdin.tty? && !Pry::Helpers::BaseHelpers.windows?
+ !$stdout.tty? && $stdin.tty? && !Helpers::Platform.windows?
end
# @return [void]
diff --git a/lib/pry/terminal.rb b/lib/pry/terminal.rb
index edf1d892..aa6c3726 100644
--- a/lib/pry/terminal.rb
+++ b/lib/pry/terminal.rb
@@ -41,7 +41,7 @@ class Pry::Terminal
end
def screen_size_according_to_io_console
- return if Pry::Helpers::BaseHelpers.jruby?
+ return if Pry::Helpers::Platform.jruby?
begin
require 'io/console'
diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb
index f22dd859..75ffc943 100644
--- a/lib/pry/wrapped_module.rb
+++ b/lib/pry/wrapped_module.rb
@@ -136,7 +136,7 @@ class Pry
def singleton_instance
raise ArgumentError, "tried to get instance of non singleton class" unless singleton_class?
- if Helpers::BaseHelpers.jruby?
+ if Helpers::Platform.jruby?
wrapped.to_java.attached
else
@singleton_instance ||= ObjectSpace.each_object(wrapped).detect{ |x| (class << x; self; end) == wrapped }
@@ -251,7 +251,7 @@ class Pry
y.yield candidate(num)
end
end
- Pry::Helpers::BaseHelpers.jruby_19? ? enum.to_a : enum
+ Helpers::Platform.jruby_19? ? enum.to_a : enum
end
# @return [Boolean] Whether YARD docs are available for this module.
diff --git a/spec/commands/edit_spec.rb b/spec/commands/edit_spec.rb
index a1b7296e..abe357e6 100644
--- a/spec/commands/edit_spec.rb
+++ b/spec/commands/edit_spec.rb
@@ -20,7 +20,7 @@ describe "edit" do
# OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's
# something "Temp".
@tf_dir =
- if Pry::Helpers::BaseHelpers.mri_19?
+ if Pry::Helpers::Platform.mri_19?
Pathname.new(Dir::Tmpname.tmpdir)
else
Pathname.new(Dir.tmpdir)
diff --git a/spec/commands/ls_spec.rb b/spec/commands/ls_spec.rb
index c0ffe924..30ddc99d 100644
--- a/spec/commands/ls_spec.rb
+++ b/spec/commands/ls_spec.rb
@@ -238,17 +238,15 @@ describe "ls" do
end
end
- if Pry::Helpers::BaseHelpers.jruby?
- describe 'on java objects' do
- it 'should omit java-esque aliases by default' do
- expect(pry_eval('ls java.lang.Thread.current_thread')).to match(/\bthread_group\b/)
- expect(pry_eval('ls java.lang.Thread.current_thread')).not_to match(/\bgetThreadGroup\b/)
- end
+ describe 'on java objects', skip: !Pry::Helpers::Platform.jruby? do
+ it 'should omit java-esque aliases by default' do
+ expect(pry_eval('ls java.lang.Thread.current_thread')).to match(/\bthread_group\b/)
+ expect(pry_eval('ls java.lang.Thread.current_thread')).not_to match(/\bgetThreadGroup\b/)
+ end
- it 'should include java-esque aliases if requested' do
- expect(pry_eval('ls java.lang.Thread.current_thread -J')).to match(/\bthread_group\b/)
- expect(pry_eval('ls java.lang.Thread.current_thread -J')).to match(/\bgetThreadGroup\b/)
- end
+ it 'should include java-esque aliases if requested' do
+ expect(pry_eval('ls java.lang.Thread.current_thread -J')).to match(/\bthread_group\b/)
+ expect(pry_eval('ls java.lang.Thread.current_thread -J')).to match(/\bgetThreadGroup\b/)
end
end
end
diff --git a/spec/completion_spec.rb b/spec/completion_spec.rb
index 2d3c260e..942ec270 100644
--- a/spec/completion_spec.rb
+++ b/spec/completion_spec.rb
@@ -27,11 +27,9 @@ describe Pry::InputCompleter do
Object.remove_const :SymbolyName
end
- # another jruby hack :((
- if !Pry::Helpers::BaseHelpers.jruby?
- it "should not crash if there's a Module that has a symbolic name." do
- expect { Pry::InputCompleter.new(Readline).call "a.to_s.", target: Pry.binding_for(Object.new) }.not_to raise_error
- end
+ it "should not crash if there's a Module that has a symbolic name." do
+ skip unless Pry::Helpers::Platform.jruby?
+ expect { Pry::InputCompleter.new(Readline).call "a.to_s.", target: Pry.binding_for(Object.new) }.not_to raise_error
end
it 'should take parenthesis and other characters into account for symbols' do
@@ -225,10 +223,12 @@ describe Pry::InputCompleter do
completer_test(self, nil, false).call("[].size.parse_printf_format")
end
- if !Pry::Helpers::BaseHelpers.jruby?
+ unless Pry::Helpers::Platform.jruby?
# Classes that override .hash are still hashable in JRuby, for some reason.
it 'ignores methods from modules that override Object#hash incompatibly' do
- _m = Module.new do
+ # skip unless Pry::Helpers::Platform.jruby?
+
+ m = Module.new do
def self.hash(a, b)
end
@@ -236,7 +236,7 @@ describe Pry::InputCompleter do
end
end
- completer_test(self, nil, false).call("[].size.aaaa")
+ completer_test(m, nil, false).call("[].size.aaaa")
end
end
end
diff --git a/spec/editor_spec.rb b/spec/editor_spec.rb
index 1fd30046..6f996ec3 100644
--- a/spec/editor_spec.rb
+++ b/spec/editor_spec.rb
@@ -10,7 +10,7 @@ describe Pry::Editor do
# OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's
# something "Temp".
@tf_dir =
- if Pry::Helpers::BaseHelpers.mri_19?
+ if Pry::Helpers::Platform.mri_19?
Pathname.new(Dir::Tmpname.tmpdir)
else
Pathname.new(Dir.tmpdir)
@@ -21,26 +21,16 @@ describe Pry::Editor do
@editor = Pry::Editor.new(Pry.new)
end
- unless Pry::Helpers::BaseHelpers.windows?
- describe "build_editor_invocation_string" do
- it 'should shell-escape files' do
- invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
- expect(invocation_str).to match(/#@tf_dir.+hello\\ world\.rb/)
- end
+ describe "build_editor_invocation_string", skip: !Pry::Helpers::Platform.windows? do
+ it 'should shell-escape files' do
+ invocation_str = @editor.build_editor_invocation_string(@tf_path, 5, true)
+ expect(invocation_str).to match(/#@tf_dir.+hello\\ world\.rb/)
end
end
describe "build_editor_invocation_string on windows" do
before do
- class Pry::Editor
- def windows?; true; end
- end
- end
-
- after do
- class Pry::Editor
- undef windows?
- end
+ allow(Pry::Helpers::Platform).to receive(:windows?).and_return(true)
end
it "should not shell-escape files" do
diff --git a/spec/helper.rb b/spec/helper.rb
index 04e67a88..efe48af7 100644
--- a/spec/helper.rb
+++ b/spec/helper.rb
@@ -43,17 +43,6 @@ RSpec.configure do |config|
config.include Pry::Testable::Utility
include Pry::Testable::Evalable
include Pry::Testable::Variables
-
- # Optionally skip a test on specific Ruby engine(s).
- # Please use this feature sparingly! It is better that a feature works than not.
- # Inapplicable features are OK.
- config.before(:each) do |example|
- Pry::Platform.known_engines.each do |engine|
- example.metadata[:expect_failure].to_a.include?(engine) and
- Pry::Platform.public_send(:"#{engine}?") and
- skip("This spec is failing or inapplicable on #{engine}.")
- end
- end
end
puts "Ruby v#{RUBY_VERSION} (#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby"}), Pry v#{Pry::VERSION}, method_source v#{MethodSource::VERSION}, CodeRay v#{CodeRay::VERSION}, Pry::Slop v#{Pry::Slop::VERSION}"
diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb
index 3be96b06..01a1b8c0 100644
--- a/spec/pry_spec.rb
+++ b/spec/pry_spec.rb
@@ -369,9 +369,9 @@ describe Pry do
it 'should define a method on the class of an object when performing "def meth;end" inside an immediate value or Numeric' do
# JRuby behaves different than CRuby here (seems it always has to some extent, see 'unless' below).
# It didn't seem trivial to work around. Skip for now.
- skip "JRuby incompatibility" if Pry::Helpers::BaseHelpers.jruby?
+ skip "JRuby incompatibility" if Pry::Helpers::Platform.jruby?
[:test, 0, true, false, nil,
- (0.0 unless Pry::Helpers::BaseHelpers.jruby?)].each do |val|
+ (0.0 unless Pry::Helpers::Platform.jruby?)].each do |val|
pry_eval(val, "def hello; end");
expect(val.class.instance_methods(false).map(&:to_sym).include?(:hello)).to eq true
end
diff --git a/spec/pryrc_spec.rb b/spec/pryrc_spec.rb
index 5afe2de3..7c8a056b 100644
--- a/spec/pryrc_spec.rb
+++ b/spec/pryrc_spec.rb
@@ -26,7 +26,7 @@ describe Pry do
end
# Resolving symlinks doesn't work on jruby 1.9 [jruby issue #538]
- unless Pry::Helpers::BaseHelpers.jruby_19?
+ unless Pry::Helpers::Platform.jruby_19?
it "should not load the rc file twice if it's symlinked differently" do
Pry::HOME_RC_FILE.replace "spec/fixtures/testrc"
Pry::LOCAL_RC_FILE.replace "spec/fixtures/testlinkrc"