1

ログ ファイルにエラー メッセージがないかどうかを確認しています。ログ ファイルにエラー メッセージが見つかった場合は、'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
4

1 に答える 1

-1

まず、 http: //pragprog.com/book/hwcuc/the-cucumber-bookを読むか、少なくとも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

これらを.../features / step_definitions / xxx_steps.rbファイルに入れてから、pending実際のコードへの置き換えを開始します。投稿したコードのブロックは使用できません。RSpecテストの作成を開始します。最初のステップは、ログを読み取るメソッドを作成することです。2番目の方法は、ログが空でないかどうかを検出します。最後の仕様は、エラーが発生したことを確認します。

HTH

于 2013-01-30T11:31:28.740 に答える