lita-onewheel-forecast-io 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,11 +1,14 @@
1
1
  require_relative '../../spec_helper'
2
2
  require 'geocoder'
3
3
 
4
+ def mock_up(filename)
5
+ mock_weather_json = File.open("spec/fixtures/#{filename}.json").read
6
+ allow(RestClient).to receive(:get) { mock_weather_json }
7
+ end
8
+
4
9
  describe Lita::Handlers::OnewheelForecastIo, lita_handler: true do
5
10
 
6
11
  before(:each) do
7
- # mock_geocoder = ::Geocoder::Result::Google.new({'formatted_address' => 'Portland, OR', 'geometry' => { 'location' => { 'lat' => 45.523452, 'lng' => -122.676207 }}})
8
- # allow(::Geocoder).to receive(:search) { [mock_geocoder] } # It expects an array of geocoder objects.
9
12
  Geocoder.configure(:lookup => :test)
10
13
 
11
14
  Geocoder::Lookup::Test.add_stub(
@@ -106,8 +109,7 @@ describe Lita::Handlers::OnewheelForecastIo, lita_handler: true do
106
109
 
107
110
  # Mock up the ForecastAPI call.
108
111
  # Todo: add some other mocks to allow more edgy testing (rain percentages, !rain eightball replies, etc
109
- mock_weather_json = File.open('spec/fixtures/mock_weather.json').read
110
- allow(RestClient).to receive(:get) { mock_weather_json }
112
+ mock_up('mock_weather')
111
113
 
112
114
  registry.configure do |config|
113
115
  config.handlers.onewheel_forecast_io.api_uri = ''
@@ -167,6 +169,7 @@ describe Lita::Handlers::OnewheelForecastIo, lita_handler: true do
167
169
  it { is_expected.to route_command('dailypressure') }
168
170
  it { is_expected.to route_command('dailybarometer') }
169
171
  it { is_expected.to route_command('neareststorm') }
172
+ it { is_expected.to route_command('tomorrow') }
170
173
 
171
174
  # This is where we test for regex overflow, so !weeklyrain doesn't try to get a forecast for Rain, Germany.
172
175
  it { is_expected.not_to route_command('forecastrain') }
@@ -237,13 +240,13 @@ describe Lita::Handlers::OnewheelForecastIo, lita_handler: true do
237
240
  end
238
241
 
239
242
  it '!ansirain no minutes' do
240
- allow(RestClient).to receive(:get) { File.open('spec/fixtures/mock_weather_no_minute.json').read }
243
+ mock_up 'mock_weather_no_minute'
241
244
  send_command 'ansirain'
242
245
  expect(replies.last).to include('|No minute-by-minute data available.|')
243
246
  end
244
247
 
245
248
  it '!ansiintensity no minutes' do
246
- allow(RestClient).to receive(:get) { File.open('spec/fixtures/mock_weather_no_minute.json').read }
249
+ mock_up 'mock_weather_no_minute'
247
250
  send_command 'ansiintensity'
248
251
  expect(replies.last).to include('|No minute-by-minute data available.|')
249
252
  end
@@ -481,12 +484,30 @@ describe Lita::Handlers::OnewheelForecastIo, lita_handler: true do
481
484
  expect(replies.last).to eq('The nearest storm is 158 mi to the S of you.')
482
485
  end
483
486
 
487
+ it '!neareststorm is zero' do
488
+ mock_up 'heavy_rain'
489
+
490
+ send_command 'neareststorm'
491
+ expect(replies.last).to eq('You\'re in it!')
492
+ end
493
+
484
494
  it '!neareststorm with scale' do
485
495
  send_command 'set scale c'
486
496
  send_command 'neareststorm'
487
497
  expect(replies.last).to eq('The nearest storm is 252.8 km to the S of you.')
488
498
  end
489
499
 
500
+ it '!tomorrows' do
501
+ send_command 'tomorrow'
502
+ expect(replies.last).to eq('Tomorrow will be warmer than today.')
503
+ end
504
+
505
+ it '!tomorrows' do
506
+ mock_up 'much_warmer'
507
+ send_command 'tomorrow'
508
+ expect(replies.last).to eq('Tomorrow will be much hotter than today.')
509
+ end
510
+
490
511
  # it 'colors strings' do
491
512
  # cstr = Lita::Handlers::ForecastIo.get_colored_string([{:key => 1}], :key, 'x', {1 => :blue})
492
513
  # expect(cstr).to equal('x')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-onewheel-forecast-io
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kreps
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-15 00:00:00.000000000 Z
11
+ date: 2016-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lita
@@ -195,6 +195,7 @@ files:
195
195
  - spec/fixtures/mock_weather.json
196
196
  - spec/fixtures/mock_weather_no_minute.json
197
197
  - spec/fixtures/mock_weather_with_snow.json
198
+ - spec/fixtures/much_warmer.json
198
199
  - spec/lita/handlers/forecast_io_spec.rb
199
200
  - spec/spec_helper.rb
200
201
  homepage: https://github.com/onewheelskyward/lita-onewheel-forecast-io
@@ -227,5 +228,6 @@ test_files:
227
228
  - spec/fixtures/mock_weather.json
228
229
  - spec/fixtures/mock_weather_no_minute.json
229
230
  - spec/fixtures/mock_weather_with_snow.json
231
+ - spec/fixtures/much_warmer.json
230
232
  - spec/lita/handlers/forecast_io_spec.rb
231
233
  - spec/spec_helper.rb