summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-06-09 17:07:20 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-06-09 17:47:23 +0300
commit6e55df5a0f54f1c549c7a3c56b3b04771b6ad1ae (patch)
tree67b00a71c2b27dc4850e42b1366baacdc1ecc4f8 /spec
parent7ce5ca70bb4a1ff447269bdde4cb5d07b8932c8a (diff)
downloadpry-6e55df5a0f54f1c549c7a3c56b3b04771b6ad1ae.tar.gz
Use Pry::Env where it makes sense
Diffstat (limited to 'spec')
-rw-r--r--spec/config_spec.rb25
-rw-r--r--spec/output_spec.rb24
-rw-r--r--spec/pry_spec.rb14
3 files changed, 31 insertions, 32 deletions
diff --git a/spec/config_spec.rb b/spec/config_spec.rb
index d2cda05e..99cce54a 100644
--- a/spec/config_spec.rb
+++ b/spec/config_spec.rb
@@ -46,8 +46,10 @@ RSpec.describe Pry::Config do
describe "#rc_file" do
context "when $PRYRC env variable is set" do
- before { ENV['PRYRC'] = '/foo/pryrc' }
- after { ENV.delete('PRYRC') }
+ before do
+ allow(Pry::Env).to receive(:[])
+ allow(Pry::Env).to receive(:[]).with('PRYRC').and_return('/foo/pryrc')
+ end
it "defaults to the value of PRYRC env variable" do
expect(subject.rc_file).to eq('/foo/pryrc')
@@ -67,29 +69,32 @@ RSpec.describe Pry::Config do
end
context "when $XDG_CONFIG_HOME is defined" do
- before { ENV['XDG_CONFIG_HOME'] = '/xdg_home' }
- after { ENV.delete('XDG_CONFIG_HOME') }
+ before do
+ allow(Pry::Env).to receive(:[])
+ allow(Pry::Env).to receive(:[])
+ .with('XDG_CONFIG_HOME').and_return('/xdg_home')
+
+ allow(File).to receive(:exist?)
+ end
- context "when ~/.pryrc exists" do
+ context "and when ~/.pryrc exists" do
before do
allow(File).to receive(:exist?)
- expect(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(true)
end
- it "defaults $XDG_CONFIG_HOME/pry/pryrc" do
+ it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
end
end
- context "when ~/.pryrc doesn't exist" do
+ context "and when ~/.pryrc doesn't exist" do
before do
allow(File).to receive(:exist?)
- expect(File).to receive(:exist?)
.with(File.expand_path('~/.pryrc')).and_return(false)
end
- it "defaults $XDG_CONFIG_HOME/pry/pryrc" do
+ it "defaults to $XDG_CONFIG_HOME/pry/pryrc" do
expect(subject.rc_file).to eq('/xdg_home/pry/pryrc')
end
end
diff --git a/spec/output_spec.rb b/spec/output_spec.rb
index d3f16dc6..f84bf364 100644
--- a/spec/output_spec.rb
+++ b/spec/output_spec.rb
@@ -212,13 +212,13 @@ RSpec.describe Pry::Output do
before do
skip("io/console doesn't support JRuby") if Pry::Helpers::Platform.jruby?
expect(output).to receive(:tty?).and_return(false)
- allow(ENV).to receive(:[])
+ allow(Pry::Env).to receive(:[])
end
context "and ENV has size info in ROWS and COLUMNS" do
before do
- expect(ENV).to receive(:[]).with('ROWS').and_return(2)
- expect(ENV).to receive(:[]).with('COLUMNS').and_return(2)
+ expect(Pry::Env).to receive(:[]).with('ROWS').and_return(2)
+ expect(Pry::Env).to receive(:[]).with('COLUMNS').and_return(2)
end
it "returns the ENV variable winsize" do
@@ -228,8 +228,8 @@ RSpec.describe Pry::Output do
context "and ENV has size info in LINES and COLUMNS" do
before do
- expect(ENV).to receive(:[]).with('LINES').and_return(3)
- expect(ENV).to receive(:[]).with('COLUMNS').and_return(2)
+ expect(Pry::Env).to receive(:[]).with('LINES').and_return(3)
+ expect(Pry::Env).to receive(:[]).with('COLUMNS').and_return(2)
end
it "returns ENV variable winsize" do
@@ -246,7 +246,7 @@ RSpec.describe Pry::Output do
expect(output).to receive(:tty?).and_return(false)
end
- allow(ENV).to receive(:[])
+ allow(Pry::Env).to receive(:[])
stub_const('Readline', readline)
end
@@ -280,7 +280,7 @@ RSpec.describe Pry::Output do
expect(output).to receive(:tty?).and_return(false)
end
- allow(ENV).to receive(:[])
+ allow(Pry::Env).to receive(:[])
stub_const('Readline', readline)
expect(readline).to receive(:respond_to?)
.with(:get_screen_size).and_return(false)
@@ -290,7 +290,7 @@ RSpec.describe Pry::Output do
context "and when it can be matched" do
context "and when the size consists of positive integers" do
before do
- expect(ENV).to receive(:[]).with('ANSICON').and_return('(5x5)')
+ expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('(5x5)')
end
it "returns the ansicon winsize" do
@@ -300,7 +300,7 @@ RSpec.describe Pry::Output do
context "and when the size has a zero column" do
before do
- expect(ENV).to receive(:[]).with('ANSICON').and_return('(0x0)')
+ expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('(0x0)')
end
it "returns the default winsize" do
@@ -311,7 +311,7 @@ RSpec.describe Pry::Output do
context "and when it cannot be matched" do
before do
- expect(ENV).to receive(:[]).with('ANSICON').and_return('5x5')
+ expect(Pry::Env).to receive(:[]).with('ANSICON').and_return('5x5')
end
it "returns the default winsize" do
@@ -336,7 +336,7 @@ RSpec.describe Pry::Output do
expect(output).to receive(:tty?).and_return(false)
end
- allow(ENV).to receive(:[])
+ allow(Pry::Env).to receive(:[])
stub_const('Readline', readline)
expect(readline).to receive(:respond_to?)
.with(:get_screen_size).and_return(false)
@@ -355,7 +355,7 @@ RSpec.describe Pry::Output do
expect(output).to receive(:tty?).and_return(false)
end
- allow(ENV).to receive(:[])
+ allow(Pry::Env).to receive(:[])
stub_const('Readline', readline)
expect(readline).to receive(:respond_to?)
.with(:get_screen_size).and_return(false)
diff --git a/spec/pry_spec.rb b/spec/pry_spec.rb
index 2b41c3cc..1ea0210d 100644
--- a/spec/pry_spec.rb
+++ b/spec/pry_spec.rb
@@ -26,11 +26,8 @@ describe Pry do
describe 'DISABLE_PRY' do
before do
- ENV['DISABLE_PRY'] = 'true'
- end
-
- after do
- ENV.delete 'DISABLE_PRY'
+ allow(Pry::Env).to receive(:[])
+ allow(Pry::Env).to receive(:[]).with('DISABLE_PRY').and_return(true)
end
it 'should not binding.pry' do
@@ -44,11 +41,8 @@ describe Pry do
describe 'FAIL_PRY' do
before do
- ENV['FAIL_PRY'] = 'true'
- end
-
- after do
- ENV.delete 'FAIL_PRY'
+ allow(Pry::Env).to receive(:[])
+ allow(Pry::Env).to receive(:[]).with('FAIL_PRY').and_return(true)
end
it 'should raise an error for binding.pry' do