diff options
author | Kyrylo Silin <silin@kyrylo.org> | 2019-04-06 16:02:13 +0300 |
---|---|---|
committer | Kyrylo Silin <silin@kyrylo.org> | 2019-04-08 00:49:39 +0300 |
commit | d2938064e6e6a5b6a0983c6ae32965cf9e27bdb1 (patch) | |
tree | 0164f4ac08ff01366e97d70b1ec1cb5e6ace1cf3 /spec | |
parent | 26f665eaf294f1c96db336749cca362562ef88a6 (diff) | |
download | pry-d2938064e6e6a5b6a0983c6ae32965cf9e27bdb1.tar.gz |
Test BlockCommand
Diffstat (limited to 'spec')
-rw-r--r-- | spec/block_command_spec.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/spec/block_command_spec.rb b/spec/block_command_spec.rb new file mode 100644 index 00000000..1a57e96a --- /dev/null +++ b/spec/block_command_spec.rb @@ -0,0 +1,63 @@ +RSpec.describe Pry::BlockCommand do + subject { Class.new(described_class).new } + + describe "#call" do + context "when #process accepts no arguments" do + let(:block) do + def process; end + method(:process) + end + + before { subject.class.block = block } + + it "calls the block despite passed arguments" do + expect { subject.call(1, 2) }.not_to raise_error + end + end + + context "when #process accepts some arguments" do + let(:block) do + def process(arg, other); end + method(:process) + end + + before { subject.class.block = block } + + it "calls the block even if there's not enough arguments" do + expect { subject.call(1) }.not_to raise_error + end + + it "calls the block even if there are more arguments than needed" do + expect { subject.call(1, 2, 3) }.not_to raise_error + end + end + + context "when passed a variable-length array" do + let(:block) do + def process(*args); end + method(:process) + end + + before { subject.class.block = block } + + it "calls the block without arguments" do + expect { subject.call }.not_to raise_error + end + + it "calls the block with some arguments" do + expect { subject.call(1, 2, 3) }.not_to raise_error + end + end + end + + describe "#help" do + before do + subject.class.description = 'desc' + subject.class.command_options(listing: 'listing') + end + + it "returns help output" do + expect(subject.help).to eq('listing desc') + end + end +end |