summaryrefslogtreecommitdiff
path: root/test/csv/helper.rb
blob: 1f9cf969799fc26383a7f48a99bce943184023e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
require "tempfile"
require "test/unit"

require "csv"

require_relative "../lib/with_different_ofs"

module Helper
  def with_chunk_size(chunk_size)
    chunk_size_keep = ENV["CSV_PARSER_SCANNER_TEST_CHUNK_SIZE"]
    begin
      ENV["CSV_PARSER_SCANNER_TEST_CHUNK_SIZE"] = chunk_size
      yield
    ensure
      ENV["CSV_PARSER_SCANNER_TEST_CHUNK_SIZE"] = chunk_size_keep
    end
  end

  def with_verbose(verbose)
    original = $VERBOSE
    begin
      $VERBOSE = verbose
      yield
    ensure
      $VERBOSE = original
    end
  end

  def with_default_internal(encoding)
    original = Encoding.default_internal
    begin
      with_verbose(false) do
        Encoding.default_internal = encoding
      end
      yield
    ensure
      with_verbose(false) do
        Encoding.default_internal = original
      end
    end
  end
end