title: rails validating url with URI.parse throwing unexpected results
body: <p>I'm following this <a href="https://stackoverflow.com/questions/7167895/rails-whats-a-good-way-to-validate-links-urls">solution</a> to validate a url in a service class in a rails app. The test returns false, but in the console no error is raised when I parse the given url with Ruby's URI class. I <em>don't</em> think there are any typos in my code - any suggestions where I'm going wrong?</p>
  
  <pre><code>class UrlService
    attr_accessor :uri
  
    def initialize(uri)
      @uri = uri
    end
  
    def valid?
      begin
        uri = URI.parse(uri)
        !uri.host.nil? &amp;&amp; uri.kind_of?(URI::HTTP)
      rescue URI::InvalidURIError
        false
      end
    end
  
  end
  </code></pre>
  
  <p>test</p>
  
  <pre><code>require "rails_helper"
  
  RSpec.describe UrlService do
    subject {described_class.new(url)}
  
    describe "#valid?" do
      context "success" do
        let(:url) { "https://www.google.com/" }
  
        it "returns true" do
          expect(subject.valid?).to be_truthy
        end
      end
    end
  
  end
  </code></pre>