summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2022-03-05 19:24:27 -0300
committerAndré Luis Leal Cardoso Junior <andrehjr@gmail.com>2022-03-05 21:49:27 -0300
commit3ca4029fd5b5534328b429c6207598695a001c0d (patch)
tree356f6589f2374ef8666cce09eda47b916587936a /spec
parentb8bf4f78f5c9faad599f5380a45a9153a8e637b1 (diff)
downloadpry-3ca4029fd5b5534328b429c6207598695a001c0d.tar.gz
Fix spec/integration/cli_spec.rb for windows
Cherry-picked file changes from 7c08e24dba0d47ad09288613c834507575bba7e9 Co-Authored-by: SilverPhoenix99 <silver.phoenix99@gmail.com>
Diffstat (limited to 'spec')
-rw-r--r--spec/integration/cli_spec.rb57
1 files changed, 34 insertions, 23 deletions
diff --git a/spec/integration/cli_spec.rb b/spec/integration/cli_spec.rb
index 0ea2a12a..ec5298e7 100644
--- a/spec/integration/cli_spec.rb
+++ b/spec/integration/cli_spec.rb
@@ -3,38 +3,51 @@
require 'rbconfig'
RSpec.describe 'The bin/pry CLI' do
- let(:ruby) { RbConfig.ruby.shellescape }
- let(:pry_dir) { File.expand_path(File.join(__FILE__, '../../../lib')).shellescape }
- let(:clean_output) do
- # Pry will emit silent garbage because of our auto indent feature.
- # This lambda cleans the output of that garbage.
- ->(out) { out.strip.sub("\e[0G", "") }
+ let(:call_pry) do
+ lambda { |*args|
+ pry_dir = File.expand_path(File.join(__FILE__, '../../../lib'))
+
+ # the :err option is equivalent to 2>&1
+ out = IO.popen([RbConfig.ruby,
+ "-I",
+ pry_dir,
+ 'bin/pry',
+ *args,
+ err: [:child, :out]], &:read)
+ status = $CHILD_STATUS
+
+ # Pry will emit silent garbage because of our auto indent feature.
+ # This lambda cleans the output of that garbage.
+ out = out.strip.sub(/^\e\[0[FG]/, "")
+
+ [out, status]
+ }
end
context "ARGV forwarding" do
- let(:code) { "p(ARGV) and exit".shellescape }
+ let(:code) { "p(ARGV) and exit" }
it "forwards ARGV as an empty array when - is passed without following arguments" do
- out = clean_output.call(`#{ruby} -I#{pry_dir} bin/pry -e #{code} -`)
+ out, status = call_pry.call('-e', code, '-')
+ expect(status).to be_success
expect(out).to eq([].inspect)
end
it "forwards ARGV as an empty array when -- is passed without following arguments" do
- out = clean_output.call(`#{ruby} -I#{pry_dir} bin/pry -e #{code} --`)
+ out, status = call_pry.call('-e', code, '--')
+ expect(status).to be_success
expect(out).to eq([].inspect)
end
it "forwards its remaining arguments as ARGV when - is passed" do
- out = clean_output.call(
- `#{ruby} -I#{pry_dir} bin/pry -e #{code} - 1 -foo --bar --baz daz`
- )
+ out, status = call_pry.call('-e', code, '-', '1', '-foo', '--bar', '--baz', 'daz')
+ expect(status).to be_success
expect(out).to eq(%w[1 -foo --bar --baz daz].inspect)
end
it "forwards its remaining arguments as ARGV when -- is passed" do
- out = clean_output.call(
- `#{ruby} -I#{pry_dir} bin/pry -e #{code} -- 1 -foo --bar --baz daz`
- )
+ out, status = call_pry.call('-e', code, '--', '1', '-foo', '--bar', '--baz', 'daz')
+ expect(status).to be_success
expect(out).to eq(%w[1 -foo --bar --baz daz].inspect)
end
end
@@ -42,19 +55,17 @@ RSpec.describe 'The bin/pry CLI' do
context '-I path' do
it 'adds an additional path to $LOAD_PATH' do
code = 'p($LOAD_PATH) and exit'
- out = clean_output.call(
- `#{ruby} -I#{pry_dir} bin/pry -I /added/at/cli -e '#{code}'`
- )
+ out, status = call_pry.call('-I', '/added/at/cli', '-e', code)
+ expect(status).to be_success
expect(out).to include('/added/at/cli')
end
it 'adds multiple additional paths to $LOAD_PATH' do
code = 'p($LOAD_PATH) and exit'
- out = clean_output.call(
- # rubocop:disable Metrics/LineLength
- `#{ruby} -I#{pry_dir} bin/pry -I /added-1/at/cli -I /added/at/cli/also -e '#{code}'`
- # rubocop:enable Metrics/LineLength
- )
+ out, status = call_pry.call('-I', '/added-1/at/cli',
+ '-I', '/added/at/cli/also',
+ '-e', code)
+ expect(status).to be_success
expect(out).to include('/added-1/at/cli')
expect(out).to include('/added/at/cli/also')
end