【问题标题】:How to test stubbed status in response using webmock?如何使用 webmock 测试存根状态以响应响应?
【发布时间】:2013-12-26 10:37:07
【问题描述】:

我正在测试一些服务

require 'spec_helper'

feature 'MyAPIService' do
  before do
    stub_request(:get, "http://my_app.com/persisted_session").
      with(headers: {'Accept'=>'*/*', 'User-Agent'=>'Ruby'}).
      to_return(status: 200, body: 's', headers: {})
  end

  it 'checks if session persist' do
    uri = URI('http://my_app.com/persisted_session')

    response = Net::HTTP.get(uri)

    expect(response.status).to be_success
  end
end

我想测试状态和解析的 xml 正文。但是我遇到了错误

  1) MyAPIService checks if session persist
     Failure/Error: expect(response).to be_success
     NoMethodError:
       undefined method `success?' for "s":String

【问题讨论】:

    标签: ruby-on-rails ruby rspec webmock


    【解决方案1】:

    你想要expect(response).to be_success 而不是expect(response.status).to be_success

    【讨论】:

      猜你喜欢
      • 2016-10-03
      • 2016-10-03
      • 2016-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      相关资源
      最近更新 更多