spec/unit/robots_spec.rb in robot-controller-2.0.0 vs spec/unit/robots_spec.rb in robot-controller-2.0.1

- old
+ new

@@ -4,11 +4,11 @@ context 'simple' do subject do RobotController::Parser.load('standard.yml', 'spec/fixtures', 'host1') end - it 'pass1' do + it 'parses correctly' do expect(subject).to eq [ { robot: 'X', queues: ['X_default'], n: 1 }, { robot: 'Y', queues: ['Y_B'], n: 1 }, { robot: 'Z', queues: ['Z_C'], n: 3 } ] @@ -18,33 +18,64 @@ context 'expanded' do subject do RobotController::Parser.load('standard.yml', 'spec/fixtures', 'host2') end - it 'pass2' do + it 'parses correctly' do expect(subject).to eq [ { robot: 'A', queues: ['A_*'], n: 1 }, { robot: 'B', queues: %w(B_X B_Y), n: 1 }, { robot: 'C', queues: %w(C_X C_Y C_Z), n: 5 }, { robot: 'D', queues: ['D_default'], n: 1 } ] end end - context 'parse_instances' do + context 'expanded mismatched host' do + it 'reports error' do + expect do + RobotController::Parser.load('standard.yml', 'spec/fixtures', 'host3') + end.to raise_error(RuntimeError) + end + end + + context 'matcher' do subject do + RobotController::Parser.load('matcher.yml', 'spec/fixtures', 'host3') + end + + it 'parses correctly' do + expect(subject).to eq [ + { robot: 'M', queues: ['M_default'], n: 1 }, + { robot: 'N', queues: ['N_B'], n: 2 }, + { robot: 'O', queues: ['O_C'], n: 3 } + ] + end + end + + context 'file-not-found' do + it 'reports error' do + expect do + RobotController::Parser.load('nofile.yml', 'spec/fixtures', 'host3') + end.to raise_error(RuntimeError) + end + end + + context 'instances_valid?' do + subject do RobotController::Parser end it 'valid inputs' do - expect(subject.parse_instances(0)).to eq 1 - expect(subject.parse_instances(1)).to eq 1 - expect(subject.parse_instances(16)).to eq 16 + expect(subject.instances_valid?(0)).to eq 1 + expect(subject.instances_valid?(1)).to eq 1 + expect(subject.instances_valid?(8)).to eq 8 + expect(subject.instances_valid?(16)).to eq 16 end it 'invalid inputs' do expect do - subject.parse_instances(17) + subject.instances_valid?(17) end.to raise_error RuntimeError end end context 'parse_lanes' do @@ -68,17 +99,17 @@ expect(subject.parse_lanes('A-B')).to eq ['A-B'] expect(subject.parse_lanes('A,B,A')).to eq %w(A B) end end - context 'build_queues' do + context 'queue_names' do subject do RobotController::Parser end it 'valid inputs' do - expect(subject.build_queues('z', '*')).to eq ['z_*'] - expect(subject.build_queues('z', 'default')).to eq ['z_default'] - expect(subject.build_queues('z', 'A,B,C')).to eq %w(z_A z_B z_C) + expect(subject.queue_names('z', '*')).to eq ['z_*'] + expect(subject.queue_names('z', 'default')).to eq ['z_default'] + expect(subject.queue_names('z', 'A,B,C')).to eq %w(z_A z_B z_C) end end end