3

我使用 Grape api,我需要使用自定义标头编写测试

我的代码:

  it "should accept message" do
    post "/api/v1/my/route", post_data, secret: "ASDFGHJKL"
    last_response.status.should == 201
  end

但是路线根本没有标题,我也尝试过headers['secret'] = "ASDFGHJKL" ,也request.env['secret'] 没有任何效果。

如何将 rspec 中的标头传递给葡萄路线?

4

2 回答 2

4

你试过了header 'secret', 'ASDFGHJKL'吗?

更多关于机架测试文档

于 2014-06-19T12:01:20.753 回答
0

尝试使用@request变量,例如@request.env['secret'] = 'ASDF..'. 希望这可以帮助。

另外,看看这个 - Sending custom headers through RSpec

于 2014-06-18T10:16:07.327 回答