Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/rubyshell/chainer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def settings
end

def method_missing(method_name, *args, &block)
if method_name.start_with?(/[^A-Za-z0-9]/)
if method_name.to_s.match?(/\A[^A-Za-z0-9]/)
handle_chain(method_name, args.first)
else
super
Expand Down
2 changes: 1 addition & 1 deletion lib/rubyshell/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def parsed_args
private

def method_missing(method_name, *args, &block)
if method_name.start_with?(/[^A-Za-z0-9]/)
if method_name.to_s.match?(/\A[^A-Za-z0-9]/)
RubyShell::Chainer.new(self).send(method_name, *args, block)
else
super
Expand Down
22 changes: 22 additions & 0 deletions spec/chainer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@
end

describe "Validating Chains" do
context "when chaining several commands with symbolic pipe operators" do
def subject_call
sh do
(printf!("hello") | cat! | cat!).exec
end
end

it "executes every command in the pipeline" do
expect(subject_call).to eq("hello")
end
end

context "when an unknown ordinary method is called on a command" do
def subject_call
RubyShell::Command.new("printf", "hello").unknown_chain_method
end

it "raises for the requested method instead of operator detection" do
expect { subject_call }.to raise_error(NoMethodError, /unknown_chain_method/)
end
end

context "when counting files in current folder" do
def subject_call
sh do
Expand Down
Loading