Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing block to match method #54

Merged
merged 1 commit into from
Jul 5, 2023
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
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