diff --git a/.rubocop.yml b/.rubocop.yml index c5728e1..5814c60 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -63,6 +63,7 @@ RSpec/ContextWording: Prefixes: - when - with + - without - for RSpec/DescribeClass: diff --git a/mrblib/rf/container.rb b/mrblib/rf/container.rb index 1208549..2a0944d 100644 --- a/mrblib/rf/container.rb +++ b/mrblib/rf/container.rb @@ -28,8 +28,8 @@ def hash? end %i[gsub gsub! match match? sub sub! tr tr!].each do |sym| - define_method(sym) do |*args| - _.__send__(sym, *args) if string? + define_method(sym) do |*args, &block| + _.__send__(sym, *args, &block) if string? end end diff --git a/spec/method_spec.rb b/spec/method_spec.rb index d35b18b..0dc2589 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -30,13 +30,25 @@ end describe '#match' do - let(:input) { 'foo' } - let(:output) { 'foo' } + context 'without block' do + let(:input) { 'foo' } + let(:output) { 'foo' } - before { run_rf("'match(/foo/)'", input) } + before { run_rf("'match(/foo/)'", input) } - it { expect(last_command_started).to be_successfully_executed } - it { expect(last_command_started).to have_output output_string_eq output } + it { expect(last_command_started).to be_successfully_executed } + it { expect(last_command_started).to have_output output_string_eq output } + end + + context 'with block' do + let(:input) { 'foo' } + let(:output) { 'bar' } + + before { run_rf(%('match(/foo/) { "bar" }'), input) } + + it { expect(last_command_started).to be_successfully_executed } + it { expect(last_command_started).to have_output output_string_eq output } + end end describe '#match?' do