2013-01-29 3 views
0

로그 파일에 오류 메시지가 있는지 확인하고 있습니다. 로그 파일에 오류 메시지가있는 경우 'raise'문을 사용하여 창을 인쇄하고 다음 로그 파일을 계속 확인합니다. 오류 메시지가 로그 파일에서 발견되면 Cucumber는 여전히 단계가 통과되었음을 나타냅니다. 단계 실패를 표시하는 방법을 알고 싶습니다. 실행이 끝날 때 인쇄합니다 (예 : 2 시나리오 (1 실패, 1 통과) 4 단계 (1 실패, 3 통과)). 어떤 도움을 주시면 감사하겠습니다!오이에서 단계 실패를 표시하는 방법?

    Scenario: Running rake test 
        Given the system is installed 
        Then I run the rake test 



     logs_all = s.sudo "egrep -i '#{error_message}' #{log_file}" 
     logs_all.each do |hostname, logs| 
      unless logs.empty? 
      puts line, "Unhappy logs on #{hostname}", line, logs 
      happy = false 
      end 

      begin 
      raise "Unhappy logs found! in #{log_file}" unless happy 
      rescue StandardError => error 
      puts error.message 
      end 

     end 

답변

-1

먼저 나는 http://pragprog.com/book/hwcuc/the-cucumber-book 또는 Cuccumber에 전체 부분이 적어도 http://pragprog.com/book/achbd/the-rspec-book를 읽고 추천 할 것입니다.

오이 테스트가 통과해야하며 실패하지 않아야합니다. 하나가 실패하면 다른 하나는 건너 뛸 수 있습니다. 이는 테스트 스위트를 실행할 때 우리가 원하는 것이 아닙니다. 그러나 로그가 비어 있지 않으면 단계에서 오류가 발생하는지 확인할 수 있습니다.

는 시나리오가 될 수있다 :

Feature: Logs 
Scenario: Checking non-empty log files 
    Given there are logged errors 
    When I check if logs are empty 
    Then an error should be raised 

실행 cucumber, 그것은 필요한 단계를 제안합니다 :

You can implement step definitions for undefined steps with these snippets: 

Given /^there are logged errors$/ do 
    pending # express the regexp above with the code you wish you had 
end 

When /^I check if logs are empty$/ do 
    pending # express the regexp above with the code you wish you had 
end 

Then /^an error should be raised$/ do 
    pending # express the regexp above with the code you wish you had 
end 

는 .../기능/step_definitions/xxx_steps.rb 파일에 다음을 넣어, pending을 실제 코드로 바꾸십시오. 게시 한 코드 블록을 사용할 수 없습니다. RSpec 테스트를 시작할 것입니다. 첫 번째 단계는 로그를 읽는 메소드를 작성하는 것입니다. 두 번째 방법은 로그가 비어 있지 않은지 여부를 감지합니다. 마지막 스펙은 오류가 발생했는지 확인합니다.

HTH

관련 문제