2010-08-11 2 views
0
class UbacParser 
    def initialize(str) 
     @str= str 
     @valid= true 
     base_parse 
    end 

    private 
    def base_parse 
     @protocol_code = Integer(@str[0..2]) rescue nil 
     begin 
     @data = @str[@str.index('<')[email protected]('>')-1] 
     str_mod = @str[@str.index('>##')+1..-1] 

     arr_mod=str_mod[2..-3].split(',') 
     @hash_mod=Hash.new 
     arr_mod.each_index { |i| @hash_mod[arr_mod[i].split('=')[0]]=arr_mod[i].split('=')[1] } 
     rescue 
      puts "error in data_parse" 
      @valid=false 
     end 
    end 

    public 
    def valid? 

     return @valid; 
    end 

    def [](key) 
     unless @valid: return 
     end 
     @hash_mod[key.upcase] 
    end 

end 

이 Ruby 클래스 코드에 대해 rspec 유효성 검사기/테스트 케이스를 작성하려면 어떻게해야합니까?rspec을 사용하여 루비 코드의 유효성을 검사하는 방법은 무엇입니까?

답변

0

도와주세요 난 당신이 rspec website에서 모양과 먼저 스펙을 작성하여 처음부터 다시 시작하는 것이 좋습니다. 좋은 학습 활동이 될 것이며 테스트 가능한 코드를 작성할 수 있습니다.

관련 문제