【问题标题】:how to stub URI(request.referrer).path to include 'cart'如何存根 URI(request.referrer).path 以包含“购物车”
【发布时间】:2018-01-19 07:58:51
【问题描述】:

我正在编写一个失败的 rspec 测试

 if URI(request.referrer).path.include?('cart')

我希望能够让 request.referrer 包含“购物车”

如果您有任何方法,请告诉我。

我尝试了以下方法,但它们不起作用:

@request.env['HTTP_REFERER']='http://localhost:port/account/cart/id'
post url, params

也试过了:

post url, params, {"HTTP_REFERER" => "http://localhost:port/account/cart/id"}

【问题讨论】:

  • 这些是请求规范还是控制器规范?

标签: rspec http-referer


【解决方案1】:

尝试模拟它:

allow(@request).to receive(:referer).and_return('http://localhost:port/account/cart/id')

【讨论】:

    猜你喜欢
    • 2013-10-26
    • 1970-01-01
    • 2016-01-29
    • 1970-01-01
    • 1970-01-01
    • 2020-10-19
    • 2023-01-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多