Class: TestHierarchyString

Inherits:
Minitest::Test
  • Object
show all
Defined in:
lib/hierarchy_string.rb

Instance Method Summary collapse

Instance Method Details

#setupObject



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/hierarchy_string.rb', line 162

def setup
  text_sym = :text
  style_sym = :color

  @single_hash = { text_sym => 'Hello', style_sym => :downcase }
  @nested_hashes = [
    { text_sym => 'Hello', style_sym => :downcase },
    [
      { text_sym => ' ', style_sym => nil },
      { text_sym => 'World', style_sym => :upcase }
    ]
  ]
  @hierarchy_single = HierarchyString.new(@single_hash)
  @hierarchy_nested = HierarchyString.new(@nested_hashes)
end

#test_concatenate_nested_hashesObject



204
205
206
# File 'lib/hierarchy_string.rb', line 204

def test_concatenate_nested_hashes
  assert_equal 'Hello World', @hierarchy_nested.concatenate
end

#test_concatenate_single_hashObject



200
201
202
# File 'lib/hierarchy_string.rb', line 200

def test_concatenate_single_hash
  assert_equal 'Hello', @hierarchy_single.concatenate
end

#test_decorate_nested_hashesObject



212
213
214
215
# File 'lib/hierarchy_string.rb', line 212

def test_decorate_nested_hashes
  assert_equal "#{'Hello'.downcase} #{'World'.upcase}",
               @hierarchy_nested.decorate
end

#test_decorate_single_hashObject



208
209
210
# File 'lib/hierarchy_string.rb', line 208

def test_decorate_single_hash
  assert_equal 'Hello'.downcase, @hierarchy_single.decorate
end

#test_initialize_nested_hashesObject



186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/hierarchy_string.rb', line 186

def test_initialize_nested_hashes
  text_sym = :text
  style_sym = :color

  expected = [
    [{ text_sym => 'Hello', style_sym => :downcase }],
    [
      [{ text_sym => ' ', style_sym => nil }],
      [{ text_sym => 'World', style_sym => :upcase }]
    ]
  ]
  assert_equal expected, @hierarchy_nested.substrings
end

#test_initialize_single_hashObject



178
179
180
181
182
183
184
# File 'lib/hierarchy_string.rb', line 178

def test_initialize_single_hash
  text_sym = :text
  style_sym = :color

  assert_equal [{ text_sym => 'Hello', style_sym => :downcase }],
               @hierarchy_single.substrings
end

#test_method_missingObject



227
228
229
# File 'lib/hierarchy_string.rb', line 227

def test_method_missing
  assert_equal 'Hello', @hierarchy_single.capitalize
end

#test_replace_text_nested_hashesObject



222
223
224
225
# File 'lib/hierarchy_string.rb', line 222

def test_replace_text_nested_hashes
  @hierarchy_nested.replace_text!(&:upcase)
  assert_equal 'HELLO WORLD', @hierarchy_nested.concatenate
end

#test_replace_text_single_hashObject



217
218
219
220
# File 'lib/hierarchy_string.rb', line 217

def test_replace_text_single_hash
  @hierarchy_single.replace_text!(&:upcase)
  assert_equal 'HELLO', @hierarchy_single.concatenate
end

#test_respond_to_missingObject



231
232
233
234
# File 'lib/hierarchy_string.rb', line 231

def test_respond_to_missing
  assert @hierarchy_single.respond_to?(:capitalize)
  refute @hierarchy_single.respond_to?(:non_existent_method)
end