Nokogiri::HTML should receive the body, not the response object (#5297)

This commit is contained in:
rhymes 2019-12-31 14:46:49 +01:00 committed by Ben Halpern
parent 49545ae41f
commit 5cf1134d5e
2 changed files with 3 additions and 5 deletions

View file

@ -10,8 +10,8 @@ class MediumArticleRetrievalService
end
def call
html = HTTParty.get(url)
page = Nokogiri::HTML(html)
response = HTTParty.get(url)
page = Nokogiri::HTML(response.body)
title = page.at("meta[name='title']")["content"]
reading_time = page.at("meta[name='twitter:data1']")["value"]

View file

@ -13,13 +13,11 @@ RSpec.describe MediumArticleRetrievalService, type: :service, vcr: {} do
}
end
context "when valid medium url" do
context "when the medium url is valid" do
let(:medium_url) { "https://medium.com/@edisonywh/my-ruby-journey-hooking-things-up-91d757e1c59c" }
it "returns a valid response" do
VCR.use_cassette("medium") do
html = HTTParty.get(medium_url)
stub_request(:get, medium_url).to_return(body: html.body, status: 200)
expect(described_class.call(medium_url)).to include(expected_response)
end
end