How to test stubbed status in response using webmock?

1.3k views Asked by At

I am testing some service

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

I want to test status and parsed xml body. But I got an error

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

There are 1 answers

0
Peter Alfvin On

You want expect(response).to be_success instead of expect(response.status).to be_success