lib/chusaku.rb in chusaku-0.3.1 vs lib/chusaku.rb in chusaku-0.3.2

- old
+ new

@@ -96,10 +96,14 @@ def write_to_file(path:, parsed_file:) content = parsed_file[:groups].map { |pf| pf[:body] }.join return unless parsed_file[:content] != content unless @flags.include?(:dry) - File.open(path, 'r+') do |file| + # When running the test suite, we want to make sure we're not + # overwriting any files. `r` mode ensures that. + mode = File.instance_methods.include?(:test_write) ? 'r' : 'w' + + File.open(path, mode) do |file| if file.respond_to?(:test_write) file.test_write(content, path) else file.write(content) end