Sha256: 11faea1583145df83bdd4999bf5eb37737206cb27484a76cd8fb70b8691325dd

Contents?: true

Size: 1.73 KB

Versions: 2

Compression:

Stored size: 1.73 KB

Contents

require_relative '../../spec_helper'

def mock_fixture(fixture)
  mock_xml = File.open("spec/fixtures/#{fixture}.xml").read
  allow(RestClient).to receive(:get) { mock_xml }
end

describe Lita::Handlers::OnewheelWolframAlpha, :lita_handler => true do

  before(:each) do
    # mock_geocoder = ::Geocoder::Result::Google.new({'formatted_address' => 'Portland, OR', 'geometry' => { 'location' => { 'lat' => 45.523452, 'lng' => -122.676207 }}})
    # allow(::Geocoder).to receive(:search) { [mock_geocoder] }  # It expects an array of geocoder objects.

    registry.configure do |config|
      config.handlers.onewheel_wolfram_alpha.api_uri = 'http://api.wolframalpha.com/v2/query?input=[query]&appid=[appid]'
      config.handlers.onewheel_wolfram_alpha.app_id = 'app-id-here'
    end
  end

  it { is_expected.to route_command('alpha') }

  it 'will work' do
    mock_fixture('pi')
    send_command 'alpha pi'
    expect(replies.last).to eq('3.141592653589793238462643383279502884197169399375105820974...')
  end

  it 'will fail gracefully' do
    mock_fixture('boopadoop')
    send_command 'alpha boopadoop'
    expect(replies.last).to eq('Wolfram couldn\'t parse boopadoop.')
  end

  it 'will print plot for mathy things' do
    mock_fixture('x^2')
    send_command 'alpha x^2'
    expect(replies.last).to eq('http://www2.wolframalpha.com/Calculate/MSP/MSP8620hdi8ba18h005cd0000268f85ce36b8h331?MSPStoreType=image/gif&s=15')
  end

  it 'will error missing config' do
    registry.configure do |config|
      config.handlers.onewheel_wolfram_alpha.api_uri = 'http://api.wolframalpha.com/v2/query?input=[query]&appid=[appid]'
      config.handlers.onewheel_wolfram_alpha.app_id = nil
    end
    send_command 'alpha pi'
    expect(replies.last).to eq(nil)
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lita-onewheel-wolfram-alpha-0.1.1 spec/lita/handlers/onewheel_wolfram_alpha_spec.rb
lita-onewheel-wolfram-alpha-0.1.0 spec/lita/handlers/onewheel_wolfram_alpha_spec.rb