|
| 1 | +require 'json' |
1 | 2 | require 'webmock/rspec' |
2 | 3 |
|
3 | 4 | require_relative './plugin_stub.rb' |
4 | 5 | require_relative '../bin/check-trello-incidents.rb' |
5 | 6 |
|
6 | 7 | describe CheckTrelloIncidents do |
7 | | - it 'should run' do |
8 | | - stub_request( |
| 8 | + before(:each) do |
| 9 | + @api = stub_request( |
9 | 10 | :get, |
10 | 11 | 'https://api.trello.com//1/lists/abcde/cards/?key=12345&token=12345' |
11 | | - ).to_return(body: '[]', status: 200) |
| 12 | + ) |
| 13 | + |
| 14 | + @check = CheckTrelloIncidents.new |
| 15 | + @check.config[:api_key] = '12345' |
| 16 | + @check.config[:api_token] = '12345' |
| 17 | + @check.config[:list] = 'abcde' |
| 18 | + |
| 19 | + allow(@check).to receive(:output) |
| 20 | + end |
| 21 | + |
| 22 | + it 'should run' do |
| 23 | + @api.to_return(body: '[]', status: 200) |
| 24 | + |
| 25 | + expect { @check.run }.to raise_error do |error| |
| 26 | + expect(error).to be_a SystemExit |
| 27 | + expect(error.status).to eq 0 |
| 28 | + end |
| 29 | + expect(@check).to have_received(:output).with('No new incidents') |
| 30 | + expect(@api).to have_been_requested |
| 31 | + end |
12 | 32 |
|
13 | | - check = CheckTrelloIncidents.new |
14 | | - check.config[:api_key] = '12345' |
15 | | - check.config[:api_token] = '12345' |
16 | | - check.config[:list] = 'abcde' |
| 33 | + it 'should be critical if trello cards' do |
| 34 | + cards = [{ id: '1a2b3c', name: 'foo' }, { id: '1x2y3z', name: 'bar' }] |
| 35 | + @api.to_return(body: JSON.generate(cards), status: 200) |
17 | 36 |
|
18 | | - expect(check).to receive(:output).with('No new incidents') |
19 | | - expect(-> { check.run }).to raise_error SystemExit |
| 37 | + expect { @check.run }.to raise_error do |error| |
| 38 | + expect(error).to be_a SystemExit |
| 39 | + expect(error.status).to eq 2 |
| 40 | + end |
| 41 | + expect(@check).to have_received(:output).with('foo; bar') |
| 42 | + expect(@api).to have_been_requested |
20 | 43 | end |
21 | 44 | end |
0 commit comments