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

fix: bug: file names included in files when using -i option with multiple files #203

Merged
merged 1 commit into from
Jun 10, 2024
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 mrblib/rf/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self.run(...)
# or when the recursive (-r) option is specified along with a directory.
def with_filename?
return true if config.with_filename
return false unless filter == Filter::Text
return false if filter != Filter::Text || in_place

files.size > 1 || (recursive? && File.directory?(files.first))
end
Expand Down
20 changes: 20 additions & 0 deletions spec/global_options/in_place_option_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,24 @@
it { expect(file_content).to eq "bar\n" }
end
end

context 'when multiple files are given' do
before do
write_file('test1', 'abc')
write_file('test2', 'bac')
end

let(:args) do
%(-i 'gsub(/a/, "A")' test1 test2)
end
let(:expect_output) { '' }

it_behaves_like 'a successful exec' do
let(:test1) { read_file('test1') }
let(:test2) { read_file('test2') }

it { expect(test1).to eq "Abc\n" }
it { expect(test2).to eq "bAc\n" }
end
end
end