Skip to content

Commit

Permalink
Allow passing block to match method
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Jul 5, 2023
1 parent 036abf9 commit 361dc49
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ RSpec/ContextWording:
Prefixes:
- when
- with
- without
- for

RSpec/DescribeClass:
Expand Down
4 changes: 2 additions & 2 deletions mrblib/rf/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 17 additions & 5 deletions spec/method_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 361dc49

Please sign in to comment.