Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何使用webmock测试存根状态作为响应?_Ruby On Rails_Ruby_Rspec_Webmock - Fatal编程技术网

Ruby on rails 如何使用webmock测试存根状态作为响应?

Ruby on rails 如何使用webmock测试存根状态作为响应?,ruby-on-rails,ruby,rspec,webmock,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:

我正在测试一些服务

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
你想要的是
expect(response).to be_success
而不是
expect(response.status).to be_success