summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2019-06-15 18:56:37 +0300
committerKyrylo Silin <silin@kyrylo.org>2019-06-15 18:56:37 +0300
commit56e72ce958b2c818637aa2cb04beceae84842252 (patch)
treefeb28be0819b158124a358cd0ae11b3cde933566 /spec
parent93628e01026ac894d5dc6ae1049083ebbd30b16f (diff)
downloadpry-56e72ce958b2c818637aa2cb04beceae84842252.tar.gz
spec/commands/show_source: pass binding to pry_eval to fix failures
There are sporadic failures with some of the tests (seems to be isolated to the code that uses `Pry.config.commands`). Passing `binding` to `pry_eval` seems to be fixing them. To be quite fair, I'm not sure why that happens but it feels like the right fix because we do the same in many other tests.
Diffstat (limited to 'spec')
-rw-r--r--spec/commands/show_source_spec.rb46
1 files changed, 20 insertions, 26 deletions
diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb
index 93b0eaa5..d436ef2a 100644
--- a/spec/commands/show_source_spec.rb
+++ b/spec/commands/show_source_spec.rb
@@ -802,51 +802,45 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength
end
describe "on commands" do
- before do
- @oldset = Pry.config.commands
- @set = Pry.config.commands = Pry::CommandSet.new do
- import Pry::Commands
- end
- end
+ let(:default_commands) { Pry.config.commands }
- after do
- Pry.config.commands = @oldset
+ let(:command_set) do
+ Pry::CommandSet.new { import Pry::Commands }
end
+ before { Pry.config.commands = command_set }
+ after { Pry.config.commands = default_commands }
+
describe "block commands" do
it 'should show source for an ordinary command' do
- @set.command('foo', :body_of_foo) {}
-
- expect(pry_eval('show-source foo')).to match(/:body_of_foo/)
+ command_set.command('foo', :body_of_foo) {}
+ expect(pry_eval(binding, 'show-source foo')).to match(/:body_of_foo/)
end
it "should output source of commands using special characters" do
- @set.command('!%$', 'I gots the yellow fever') {}
-
- expect(pry_eval('show-source !%$')).to match(/yellow fever/)
+ command_set.command('!%$', 'I gots the yellow fever') {}
+ expect(pry_eval(binding, 'show-source !%$')).to match(/yellow fever/)
end
it 'should show source for a command with spaces in its name' do
- @set.command('foo bar', :body_of_foo_bar) {}
-
- expect(pry_eval('show-source foo bar')).to match(/:body_of_foo_bar/)
+ command_set.command('foo bar', :body_of_foo_bar) {}
+ expect(pry_eval(binding, 'show-source foo bar')).to match(/:body_of_foo_bar/)
end
it 'should show source for a command by listing name' do
- @set.command(/foo(.*)/, :body_of_foo_bar_regex, listing: "bar") { ; }
-
- expect(pry_eval('show-source bar')).to match(/:body_of_foo_bar_regex/)
+ command_set.command(/foo(.*)/, :body_of_foo_bar_regex, listing: "bar") {}
+ expect(pry_eval(binding, 'show-source bar')).to match(/:body_of_foo_bar_regex/)
end
end
describe "create_command commands" do
it 'should show source for a command' do
- @set.create_command "foo", "babble" do
+ command_set.create_command "foo", "babble" do
def process
:body_of_foo
end
end
- expect(pry_eval('show-source foo')).to match(/:body_of_foo/)
+ expect(pry_eval(binding, 'show-source foo')).to match(/:body_of_foo/)
end
it 'should show source for a command defined inside pry' do
@@ -855,7 +849,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength
def process() :body_of_foo end
end
}
- expect(pry_eval('show-source foo')).to match(/:body_of_foo/)
+ expect(pry_eval(binding, 'show-source foo')).to match(/:body_of_foo/)
end
end
@@ -1789,17 +1783,17 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength
after { Pry.config.commands = default_commands }
it "displays help for a specific command" do
- expect(pry_eval('show-source -d ls')).to match(/Usage: ls/)
+ expect(pry_eval(binding, 'show-source -d ls')).to match(/Usage: ls/)
end
it "displays help for a regex command with a \"listing\"" do
command_set.command(/bar(.*)/, 'Test listing', listing: 'foo') {}
- expect(pry_eval('show-source -d foo')).to match(/Test listing/)
+ expect(pry_eval(binding, 'show-source -d foo')).to match(/Test listing/)
end
it "displays help for a command with a spaces in its name" do
command_set.command('command with spaces', 'command with spaces desc') {}
- expect(pry_eval('show-source -d command with spaces')).to match(
+ expect(pry_eval(binding, 'show-source -d command with spaces')).to match(
/command with spaces desc/
)
end