spec/lita/handlers/task_scheduler_spec.rb in lita-task-scheduler-1.0.0 vs spec/lita/handlers/task_scheduler_spec.rb in lita-task-scheduler-1.1.0

- old
+ new

@@ -1,16 +1,20 @@ require 'spec_helper' describe Lita::Handlers::TaskScheduler, lita_handler: true do let(:robot) { Lita::Robot.new(registry) } + before(:suite) { subject.scheduler.clear } subject { described_class.new(robot) } + # START:routes describe 'routing' do - it { is_expected.to route('Lita schedule "show schedule" in 2 hours') } + it { is_expected.to route('Lita schedule "double 4" in 2 hours') } it { is_expected.to route('Lita show schedule') } + it { is_expected.to route('Lita empty schedule') } end + # END:routes describe 'functionality' do describe ':schedule_report' do context 'tasks are scheduled' @@ -25,10 +29,11 @@ subject.show_schedule(message) send_message 'Lita show schedule' end end + # START: defer_task describe ':defer_task' do it 'defers any single task' do message = { canary_message: Time.now } run_at = Time.now + 5 result = subject.defer_task(message, run_at) @@ -46,11 +51,13 @@ result = subject.defer_task(message, run_at) expect(result).to eq([message] * 6) end end + # END: defer_task + # START:find_tasks_due describe ':find_tasks_due' do context 'two tasks are scheduled for five seconds ago' do before { 2.times { subject.defer_task('past_task', Time.now - 5) } } it 'returns all past due tasks' do @@ -67,32 +74,27 @@ result = subject.find_tasks_due expect(result).to_not include('future_task') end end end + # END:find_tasks_due end - describe 'execute_tasks' do - it 'resends each task' do - tasks = [{}, {}] - - expect(subject).to receive(:resend).exactly(2).times - subject.execute_tasks(tasks) - end - end - + # START:loop_ticks describe 'tick' do before { subject.stub(:find_tasks_due).and_return ['a_task'] } it 'should find tasks due and resend them' do expect(subject).to receive(:find_tasks_due) - expect(subject).to receive(:resend).with('a_task') + expect(subject).to receive(:resend_command).with('a_task') subject.tick end end + # END:loop_ticks + # START:parse_timing describe ':parse_timing' do def time_drift(time, expected_seconds:) delta = (Time.now.utc - time).abs (expected_seconds - delta).abs end @@ -110,6 +112,7 @@ drift = time_drift(response, expected_seconds: expected) expect(drift < 0.1).to be_truthy, "#{input}:\t #{expected}" end end end + # END:parse_timing end