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