Skip to content

Commit

Permalink
Issue 21: only handle .a and not longer trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
planetefrench committed Aug 23, 2020
1 parent 04be796 commit ba58661
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 21 deletions.
2 changes: 1 addition & 1 deletion README.rst
Expand Up @@ -26,7 +26,7 @@ Get yourself a Wolfram Alpha app id here: https://developer.wolframalpha.com/por

Usage
-----
:alpha pi: returns "3.14......"
:a pi: returns "3.14......"

License
-------
Expand Down
2 changes: 1 addition & 1 deletion lib/lita/handlers/onewheel_wolfram_alpha.rb
Expand Up @@ -7,7 +7,7 @@ class OnewheelWolframAlpha < Handler
config :app_id
config :api_uri

route(/^a\s*(.*)/i, :handle_wolfram_query, command: true)
route(/^a\s+(.*)/i, :handle_wolfram_query, command: true)

def handle_wolfram_query(response)
unless config.app_id and config.api_uri
Expand Down
31 changes: 12 additions & 19 deletions spec/lita/handlers/onewheel_wolfram_alpha_spec.rb
Expand Up @@ -17,18 +17,21 @@ def mock_fixture(fixture)
end
end

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

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

it 'shouldnt route other words' do
mock_fixture('pi')
send_command 'animate pi'
expect(replies.last).to eq(nil)
end

it 'will fail gracefully' do
mock_fixture('boopadoop')
send_command 'alpha boopadoop'
send_command 'a boopadoop'
expect(replies.last).to satisfy { |v|
['Nope, no boopadoop to see here.',
'What\'s that, now?',
Expand All @@ -38,7 +41,7 @@ def mock_fixture(fixture)

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

Expand All @@ -47,31 +50,21 @@ def mock_fixture(fixture)
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'
send_command 'a pi'
expect(replies.last).to eq(nil)
end

it 'will single-line a multi-line plaintext' do
mock_fixture('multiline-plaintext')
send_command 'alpha light years'
send_command 'a light years'
expect(replies.last).to eq('1 ly | 0.3066 pc (parsecs) | 63241 au (astronomical units) | 9.461&#xD7;10^12 km (kilometers) | 9.461&#xD7;10^15 meters | 5.879 trillion miles')
end

it 'will add desired text to the end' do
mock_fixture('x^2')
send_command 'alpha x^2 <as a service>'
send_command 'a x^2 <as a service>'
expect(replies.last).to eq('http://www2.wolframalpha.com/Calculate/MSP/MSP8620hdi8ba18h005cd0000268f85ce36b8h331?MSPStoreType=image/gif&s=15 as a service')
end

it 'will add .0 to a fraction' do
mock_fixture('oneovertwo')
send_command 'alpha 1/2'
expect(replies.last).to eq('0.5')
end

it 'will quote' do
mock_fixture('quote')
send_command 'quote amzn'
expect(replies.last).to eq('x')
end
end

0 comments on commit ba58661

Please sign in to comment.