小编use*_*132的帖子

如何在rspec测试中设置HTTP_USER_AGENT

可能重复:
是否可以在rails集成测试或规范中指定用户代理?

我正在使用rspec在我的rails应用程序中测试请求.我需要能够在请求之前设置用户代理.

这不起作用:

  describe "GET /articles feed for feedburner" do
it "displays article feed if useragent is feedburner" do
  # Run the generator again with the --webrat flag if you want to use webrat methods/matchers
  @articles=[]
  5.times do
    @articles << Factory(:article, :status=>1, :created_at=>3.days.ago)
  end
  request.env['HTTP_USER_AGENT'] = 'feedburner'
  get "/news.xml" 
  response.should be_success
  response.content_type.should eq("application/xml")
  response.should include("item[title='#{@articles.first.title}']")
end
Run Code Online (Sandbox Code Playgroud)

结束

如何正确指定用户代理?

rspec ruby-on-rails

13
推荐指数
1
解决办法
7056
查看次数

标签 统计

rspec ×1

ruby-on-rails ×1