RSpec.describe ERDL::URLFetcher do
  let(:browser) { instance_double(Watir::Browser) }
  let(:routes) { instance_double(YouTube::Routes) }

  describe '#initialize' do
    it 'does not raise an error' do
      expect { ERDL::URLFetcher.new({}, browser, routes) }.to_not raise_error
    end
  end

  describe '#url' do
    it 'traverses the route to fetch the url' do
      expect(routes).to receive(:traverse)
      ERDL::URLFetcher.new({}, browser, routes).url
    end
  end

  describe '#teardown' do
    it 'closes the browser' do
      expect(browser).to receive(:quit).at_least(:once)
      ERDL::URLFetcher.new({}, browser, routes).teardown
    end
  end

  describe '#class_from' do
    it 'returns the Class represented by the String' do
      require_relative '../fixtures/pages/fake_youtube/first_page'
      expect { ERDL::URLFetcher.new({}, browser, routes).send(:class_from, 'FakeYouTube::FirstPage') }.to_not raise_error
    end

    it 'raises an error if it can\'t be resolved on Object' do
      expect { ERDL::URLFetcher.new({}, browser, routes).send(:class_from, 'FakeModule::FakeClass') }.to raise_error
    end
  end
end
