Class: TestHierarchyString
- Defined in:
- lib/hierarchy_string.rb
Instance Method Summary collapse
- #setup ⇒ Object
- #test_concatenate_nested_hashes ⇒ Object
- #test_concatenate_single_hash ⇒ Object
- #test_decorate_nested_hashes ⇒ Object
- #test_decorate_single_hash ⇒ Object
- #test_initialize_nested_hashes ⇒ Object
- #test_initialize_single_hash ⇒ Object
- #test_method_missing ⇒ Object
- #test_replace_text_nested_hashes ⇒ Object
- #test_replace_text_single_hash ⇒ Object
- #test_respond_to_missing ⇒ Object
Instance Method Details
#setup ⇒ Object
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_hashes ⇒ Object
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_hash ⇒ Object
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_hashes ⇒ Object
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_hash ⇒ Object
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_hashes ⇒ Object
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_hash ⇒ Object
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_missing ⇒ Object
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_hashes ⇒ Object
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_hash ⇒ Object
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_missing ⇒ Object
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 |