File: file_like_test.rb

package info (click to toggle)
ruby-multi-xml 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 472 kB
  • sloc: ruby: 2,822; sh: 4; makefile: 2
file content (181 lines) | stat: -rw-r--r-- 5,035 bytes parent folder | download
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
require "test_helper"

# Tests for FileLikeOriginalFilenameTest
class FileLikeOriginalFilenameTest < Minitest::Test
  cover "MultiXml*"

  def test_original_filename_returns_custom_value_when_set
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.original_filename = "custom.txt"

    assert_equal "custom.txt", io.original_filename
  end

  def test_original_filename_returns_default_when_not_set
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    assert_equal "untitled", io.original_filename
    assert_equal MultiXml::FileLike::DEFAULT_FILENAME, io.original_filename
  end

  def test_original_filename_returns_default_when_set_to_nil
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.original_filename = nil

    assert_equal "untitled", io.original_filename
  end

  def test_original_filename_uses_instance_variable_not_method_call
    # The mutant would cause infinite recursion
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.original_filename = "test.xml"

    # Should not cause stack overflow
    assert_equal "test.xml", io.original_filename
  end

  def test_original_filename_returns_set_value_not_always_default
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.original_filename = "my_file.pdf"

    refute_equal MultiXml::FileLike::DEFAULT_FILENAME, io.original_filename
    assert_equal "my_file.pdf", io.original_filename
  end

  def test_original_filename_with_falsy_but_present_value
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    # Not setting original_filename leaves @original_filename as nil

    refute_nil io.original_filename
    assert_equal "untitled", io.original_filename
  end

  def test_original_filename_does_not_raise
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    assert_equal "untitled", io.original_filename
  end

  def test_original_filename_returns_actual_value_not_nil
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    refute_nil io.original_filename
  end

  def test_original_filename_prefers_instance_variable_over_default
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.original_filename = "specific.doc"

    assert_equal "specific.doc", io.original_filename
    refute_equal "untitled", io.original_filename
  end

  def test_original_filename_body_is_needed
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    result = io.original_filename

    refute_nil result
    assert_kind_of String, result
  end
end

# Tests for FileLikeContentTypeTest
class FileLikeContentTypeTest < Minitest::Test
  cover "MultiXml*"

  def test_content_type_returns_custom_value_when_set
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.content_type = "text/plain"

    assert_equal "text/plain", io.content_type
  end

  def test_content_type_returns_default_when_not_set
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    assert_equal "application/octet-stream", io.content_type
    assert_equal MultiXml::FileLike::DEFAULT_CONTENT_TYPE, io.content_type
  end

  def test_content_type_returns_default_when_set_to_nil
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.content_type = nil

    assert_equal "application/octet-stream", io.content_type
  end

  def test_content_type_uses_instance_variable_not_method_call
    # The mutant would cause infinite recursion
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.content_type = "image/png"

    # Should not cause stack overflow
    assert_equal "image/png", io.content_type
  end

  def test_content_type_returns_set_value_not_always_default
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.content_type = "application/pdf"

    refute_equal MultiXml::FileLike::DEFAULT_CONTENT_TYPE, io.content_type
    assert_equal "application/pdf", io.content_type
  end

  def test_content_type_with_falsy_but_present_value
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    # Not setting content_type leaves @content_type as nil

    refute_nil io.content_type
    assert_equal "application/octet-stream", io.content_type
  end

  def test_content_type_does_not_raise
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    assert_equal "application/octet-stream", io.content_type
  end

  def test_content_type_returns_actual_value_not_nil
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    refute_nil io.content_type
  end

  def test_content_type_prefers_instance_variable_over_default
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)
    io.content_type = "text/html"

    assert_equal "text/html", io.content_type
    refute_equal "application/octet-stream", io.content_type
  end

  def test_content_type_body_is_needed
    io = StringIO.new("test")
    io.extend(MultiXml::FileLike)

    result = io.content_type

    refute_nil result
    assert_kind_of String, result
  end
end