-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathslack_post_spec.rb
54 lines (45 loc) · 1.58 KB
/
slack_post_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'spec_helper'
describe Slacked do
let(:message) { 'Gothan is calling!' }
before(:each) {
ENV[Slacked::SLACK_WEBHOOK_URL_KEY] = 'slack.mywebhook.com'
}
context 'post' do
it 'returns false when message is blank' do
expect(Slacked.post('')).to be_falsey
end
it 'returns false when message is nil' do
expect(Slacked.post(nil)).to be_falsey
end
it 'uses the env variable SLACK_DEFAULT_MESSAGE if no message is passed' do
expect_any_instance_of(Slack::Notifier).to receive(:ping).with(message, Slacked::SLACK_DEFAULT_CONFIG).and_return(true)
ENV[Slacked::SLACK_DEFAULT_MESSAGE_KEY] = message
expect(Slacked.post).to be_truthy
end
it 'merges with the default config when config is passed' do
config = {
icon_emoji: ':ghost:',
webhook_url: 'WEBHOOK_URL'
}
expect_any_instance_of(Slack::Notifier).to receive(:ping).with(message, config).and_return(true)
expect(Slacked.post(message, config)).to be_truthy
end
end
context 'calls ping method of Slack Notifier' do
before(:each) {
expect_any_instance_of(Slack::Notifier).to receive(:ping).with(message, Slacked::SLACK_DEFAULT_CONFIG).and_return(true)
}
context 'async' do
it 'post method is called async' do
thread = Slacked.post_async(message)
expect(thread.value).to be_truthy
expect(thread.class).to eql(Thread)
end
end
context 'sync' do
it 'the ping method of Slack::Notifier is called' do
expect(Slacked.post(message)).to be_truthy
end
end
end
end