rspec不接受自定义http标头

时间:2012-12-23 20:41:58

标签: ruby-on-rails ruby rspec

我的规格是这样的:

describe SomeController do

    before(:each) do
        @request.env["HTTP_ACCEPT"] = 'application/vnd.apple.mpegurl'
    end

    describe 'GET #index' do
        it "returns response" do
            get 'index', format: :m3u8
            puts response.code # prints 406
            response.should be_success # fails
        end
    end
end

控制器:

class SomeController < AuthenticatedController
  def index
    Mime::Type.register "application/vnd.apple.mpegurl", :m3u8
    # do some stuff
    respond_to do |format|
        format.m3u8 { render :m3u8 => @some_variable.html_safe }
    end
end

我错过了什么让它回复状态200?现在,返回的状态是406.谢谢。

1 个答案:

答案 0 :(得分:1)

放弃@

before(:each) do
  request.env["HTTP_ACCEPT"] = 'application/vnd.apple.mpegurl'
end