2

HipChat / Campfire メッセージを API に送信する Rails 3 バックグラウンド ジョブ (delayed_job) があり、Cucumber 機能で応答を確認したいと考えています。VCR が記録した最後の HTTP 応答を取得する方法はありますか?

特徴はこんな感じ

    @vcr
    Scenario: Send hipchat message when task created
      Given an hipchat_sample integration exists with app: app "teamway"
      When I create an "ActionMailer::Error" task to "Teamway"
      And all jobs are worked off # invoke Delayed::Worker.new.work_off
      Then a hipchat message should be sent "ActionMailer::Error"

私のステップ定義では、応答本文を確認したいと思います:

    Then /^a hipchat message should be sent "(.*?)"$/ do |arg1|
      # Like this:
      # VCR::Response.body.should == arg1
    end

VCR はすでに要求と応答を記録していますが、それらを取得する方法がわかりません。Pickle の手順で送信された電子メールをキャッチするのと似たようなことを考えています。これを行う方法を知っている人はいますか?

Rails 3.2.8、cucumber-rails 1.3、および vcr 2.2.4 (webmock 付き) を使用しています。

よろしくトルステン

4

1 に答える 1

1

を使用VCR.current_cassetteして現在のカセットを取得し、それ[VCR::HTTPInteraction][1]を調べて探しているオブジェクトを取得できますが、少し複雑になります。VCR カセットは、新しく記録された HTTP 対話を、使用可能なものとは別に保存します。テストが記録されているときと再生されているときの両方で適切に動作するようにするには、いくつかの複雑な条件が必要になります。

代わりに、after_http_requestフックを使用することをお勧めします。

module HipmunkHelpers
  extend self
  attr_accessor :last_http_response
end

Before { HipmunkHelpers.last_http_response = nil }

VCR.configure do |c|
  c.after_http_request(lambda { |req| URI(req.uri).host == 'hipmunk.com' }) do |request, response|
    HipmunkHelpers.last_http_response = response
  end
end

次に、キュウリのステップで、にアクセスできますHipmunkHelpers.last_http_response

after_http_requestフックの詳細については、レリッシュのドキュメントをご覧ください。

于 2012-09-07T15:08:22.387 に答える