【问题标题】:Airborne GET from test environment来自测试环境的机载 GET
【发布时间】:2016-11-01 15:56:27
【问题描述】:

使用 Airborne,我如何使用 GET 从测试环境中返回值?

例如,我有以下测试:

it 'should foo the bar' do
  product = FactoryGirl.create(:product)
  get "/v1/products"
  pp product
  pp body
  expect_status 200
end

product 的输出为:

#<Product:0x007f9dfe601078
 id: 847,
 ref: "038-71-8140174268593",
 name: "Adipisci Sqryujdcoefpthnzbvagwlxikm",
 description:
  "Lorem ipsum...",
 created_at: Tue, 01 Nov 2016 15:48:25 UTC +00:00,
 updated_at: Tue, 01 Nov 2016 15:48:25 UTC +00:00>

但是body的输出是:

"{\"data\":[]}"

我有使用rails s -e test 运行测试环境的rails 服务器

如果我在开发环境中运行 rails 服务器,body 会毫无问题地返回来自开发环境的所有产品。

【问题讨论】:

    标签: ruby-on-rails rspec rest-client rails-api airborne


    【解决方案1】:

    我使用RSpec.describe ProductResource, type: :resource do 而不是RSpec.describe 'Products', type: :request do 运行测试。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-07
      • 1970-01-01
      • 2019-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多