Sha256: 1e61ab4c2eb142eb88074ccdb247236ccae2e6923f373dda29efca1545e0f5cf

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 KB

Contents

require 'spec_helper'

describe Lita::Handlers::WebTitle, lita_handler: true do
  before :each do
    registry.config.handlers.web_title.tap do |config|
      config.ignore_patterns = ["example.com","github.com"]
    end
  end

  let(:robot) { Lita::Robot.new(registry) }
  subject(:handler) { described_class.new(robot) }

  describe 'routing' do
    it { is_expected.to route('I like http://github.com/').to(:parse_uri_request) }
  end

  describe 'messages' do
    it 'returns the title for a mentioned URL' do
      send_command('I search on http://google.com/ a lot.')
      expect(replies.last).to match(/Google/)
    end

    it 'returns the title for only the first mentioned URL' do
      send_command('I search on http://google.com/ and http://yahoo.com/ a lot.')
      expect(replies.last).to match(/Google/)
      expect(replies.last).to_not match(/yahoo/i)
    end

    it 'returns nothing for URLs that are not HTML' do
      send_command('This is the logo https://www.google.com/images/srpr/logo11w.png')
      expect(replies.last).to be_nil
    end

    it 'ignores example.com links' do
      send_command('I hate http://www.example.com/')
      expect(replies.last).to be_nil
    end

   end

  describe '.parse_uri' do
    it 'returns the title' do
      expect(handler.parse_uri('https://google.com/'))
        .to match(/Google/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lita-web-title-1.0.6 spec/lita/handlers/web_title_spec.rb