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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/hierarchy_string.rb', line 148 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
190 191 192 |
# File 'lib/hierarchy_string.rb', line 190 def test_concatenate_nested_hashes assert_equal 'Hello World', @hierarchy_nested.concatenate end |
#test_concatenate_single_hash ⇒ Object
186 187 188 |
# File 'lib/hierarchy_string.rb', line 186 def test_concatenate_single_hash assert_equal 'Hello', @hierarchy_single.concatenate end |
#test_decorate_nested_hashes ⇒ Object
198 199 200 201 |
# File 'lib/hierarchy_string.rb', line 198 def test_decorate_nested_hashes assert_equal "#{'Hello'.downcase} #{'World'.upcase}", @hierarchy_nested.decorate end |
#test_decorate_single_hash ⇒ Object
194 195 196 |
# File 'lib/hierarchy_string.rb', line 194 def test_decorate_single_hash assert_equal 'Hello'.downcase, @hierarchy_single.decorate end |
#test_initialize_nested_hashes ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/hierarchy_string.rb', line 172 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
164 165 166 167 168 169 170 |
# File 'lib/hierarchy_string.rb', line 164 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
213 214 215 |
# File 'lib/hierarchy_string.rb', line 213 def test_method_missing assert_equal 'Hello', @hierarchy_single.capitalize end |
#test_replace_text_nested_hashes ⇒ Object
208 209 210 211 |
# File 'lib/hierarchy_string.rb', line 208 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
203 204 205 206 |
# File 'lib/hierarchy_string.rb', line 203 def test_replace_text_single_hash @hierarchy_single.replace_text!(&:upcase) assert_equal 'HELLO', @hierarchy_single.concatenate end |
#test_respond_to_missing ⇒ Object
217 218 219 220 |
# File 'lib/hierarchy_string.rb', line 217 def test_respond_to_missing assert @hierarchy_single.respond_to?(:capitalize) refute @hierarchy_single.respond_to?(:non_existent_method) end |