Skip to content

Commit

Permalink
Silence encoding warnings in specs
Browse files Browse the repository at this point in the history
Setting `Encoding.default_external` prints a warning when running specs:

   warning: setting Encoding.default_external

Wrapping this with a `silence_warnings` block, silences the warnings.
  • Loading branch information
p8 committed Aug 9, 2023
1 parent 5fb6206 commit 2ef9fd7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions spec/actions/inject_into_file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ def file
encoding_original = Encoding.default_external

begin
Encoding.default_external = Encoding.find("UTF-8")
silence_warnings do
Encoding.default_external = Encoding.find("UTF-8")
end
invoke! "doc/README.zh", "\n中文", after: "__start__"
expect(File.read(File.join(destination_root, "doc/README.zh"))).to eq("__start__\n中文\n说明\n__end__\n")
ensure
Encoding.default_external = encoding_original
silence_warnings do
Encoding.default_external = encoding_original
end
end
end
end
Expand Down

0 comments on commit 2ef9fd7

Please sign in to comment.