Guest User

Catching NoMethodError and returning value

a guest
Jul 18th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.90 KB | None | 0 0
  1. class DataStructure                                                            
  2.   2                                                                                
  3.   3     def method_missing(method_sym, *arguments, &block)                          
  4.   4     rescue NoMethodError => nME                                                
  5.   5         nME                                                                    
  6.   6     end                                                                        
  7.   7                                                                                
  8.   8 end                                                                            
  9.   9 class SinglyLinkedList < DataStructure                                          
  10.  10                                                                                
  11.  11 end                  
  12.  
  13. require_relative 'dataStructures'                                              
  14.   2 class Test                                                                      
  15.   3     @@test_count = 0                                                            
  16.   4     @@failures = 0                                                              
  17.   5     @@successes = 0                                                            
  18.   6                                                                                
  19.   7     def initialize(actual, expected, class_tested, method_tested)              
  20.   8         actual == expected ? @@successes += 1 : @@failures += 1                
  21.   9         puts "Test #{@@test_count}: Testing #{class_tested}'s #{method_tested} method."
  22.  10         puts "#{actual == expected ? "Success" : "Failure"}: Expected #{expected}, was #{actual}"
  23.  11         @@test_count += 1                                                      
  24.  12     end                                                                        
  25.  13                                                                                
  26.  14     def self.final_summary                                                      
  27.  15         puts "There were #{@@test_count} tests with #{@@successes} successes    
  28. 16         and #{@@failures} failures."                                            
  29.  17     end                                                                        
  30.  18 end                                                                            
  31.  19                                                                                
  32.  20 # Singly Linked List Tests                                                      
  33.  21                                                                                
  34.  22 singlyLinkedList = SinglyLinkedList.new                                        
  35.  23                                                                                
  36.  24 testInsert = Test.new(singlyLinkedList.insert("A"), "", "SinglyLinkedList", "insert")
Advertisement
Add Comment
Please, Sign In to add comment