:
コントローラ仕様レール機能テスト (ActionController::TestCase::Behavior
)用のRSpecのラッパーです。
ので、Special Instance Variables section下、ActionController::TestCase::Behavior
用で、コードのドキュメントを見て、私たちは最後のHTTPの応答を表す、「ActionDispatch::TestResponse
目的である、ActionController::TestCase
が自動的a @response
instance variable(readable as just response
in the test)を提供することを見ることができます応答"。だから、コントローラー仕様で明示的な要求をせずにアクセスできるresponse
がある理由を説明しているようですが、なぜそれがステータス200
ですか?
まあ、ActionDispatch::TestResponse
はActionDispatch::Response
(when initialized provides 200
as the default status)を継承しています。あなたもあなたのレールコンソールでこれを試すことができます:それは確かに地雷をしたとして
> ActionDispatch::TestResponse.new
=> #<ActionDispatch::TestResponse:0x007fc449789b68
@blank=false,
@cache_control={},
@charset=nil,
@committed=false,
@content_type=nil,
@cv=
#<MonitorMixin::ConditionVariable:0x007fc449789848
@cond=#<Thread::ConditionVariable:0x007fc449789820>,
@monitor=#<ActionDispatch::TestResponse:0x007fc449789b68 ...>>,
@etag=nil,
@header={"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff"},
@mon_count=0,
@mon_mutex=#<Thread::Mutex:0x007fc449789a50>,
@mon_owner=nil,
@sending=false,
@sending_file=false,
@sent=false,
@status=200, # <<< Here's your default status.
@stream=#<ActionDispatch::Response::Buffer:0x007fc449789938 @buf=[], @closed=false, @response=#<ActionDispatch::TestResponse:0x007fc449789b68 ...>>>
だから、私は、RSpecのコントローラの仕様でresponse
オブジェクトのご理解を支援し、この深いダイビングを願っています。
偉大な答えポール。それはまさに私が探していたものです!ありがとう – vinibol12