我想測試這個方法重定向到同一頁面,但與www。如果它不在那裏,則爲前綴。 它執行重定向,但RSpec測試返回「預期響應爲<:重定向>,但是是< 200>」。這是爲什麼?RSpec測試重定向返回200
application_controller.rb
def check_uri
if request.subdomain.present? and request.subdomain.first != "www"
redirect_to request.protocol + "www." + request.host_with_port + request.fullpath if !/^www/.match(request.host)
end
end
application_controller_spec.rb#
describe :check_uri do
it "should redirect to www" do
{ :get => "http://sub.lvh.me:3000/accounts/sign_up" }.
should redirect_to "http://www.sub.lvh.me:3000/accounts/sign_up"
end
end
當我調試,我得到: (
rdb:1) p response
#<ActionController::TestResponse:0x0000010277d988 @writer=#<Proc:[email protected]/Users/mm/.rvm/gems/[email protected]/gems/actionpack-3.0.7/lib/action_dispatch/http/response.rb:43 (lambda)>, @block=nil, @length=0, @header={}, @status=200, @body=[], @cookie=[], @sending_file=false, @blank=false, @cache_control={}, @etag=nil>
你調試的反應如何?什麼是response.body的內容? – e3matheus
你有check_uri作爲application_controller中的'before_filter'嗎? – dexter
是的,check_uri通過before_filter調用。我將調試響應添加到原始文章中。 – 99miles