如何使用webmock测试存根状态?

时间:2013-12-09 10:45:43

标签: ruby-on-rails ruby rspec webmock

我正在测试一些服务

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

1 个答案:

答案 0 :(得分:0)

您希望expect(response).to be_success代替expect(response.status).to be_success