slack_messaging 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +106 -0
- data/README.md +26 -12
- data/bin/slack-messaging +13 -5
- data/lib/slack_messaging/highline_cli.rb +33 -0
- data/lib/slack_messaging/setup.rb +81 -0
- data/lib/slack_messaging/version.rb +1 -1
- data/spec/slack_messaging/config_spec.rb +13 -11
- data/spec/slack_messaging/highline_cli_spec.rb +49 -0
- data/spec/slack_messaging/notify_slack_spec.rb +4 -2
- data/spec/slack_messaging/random_message_spec.rb +7 -5
- data/spec/slack_messaging/setup_spec.rb +132 -0
- metadata +9 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd3e90f703693ae103c78862c1c506cc48dcab4f04065d4aee1b6e60a9cab9da
|
4
|
+
data.tar.gz: 9cf11baa6f0d033e3c944a7a6d30255eb4ed94233a3a54cfa277c59566bdd91b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc3b3d202c84093c07a6d0aae39f05dad04aa16a7b28fb66a57b4399e4f1bccdff049909d92fba9a56431a4171422d589a3b616c56b7ee72dad2aca0d48e5560
|
7
|
+
data.tar.gz: cab8ff992b73a96e41f4f8cb996df80b644ec304a58292d728f54ba5b3965695d4421c5f1df6819aad530981be893a1bfe8fb2c51cf2338142440787f3eff390
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
slack_messaging (2.2.0)
|
5
|
+
activesupport (~> 6.0)
|
6
|
+
gli (~> 2.10)
|
7
|
+
hashie (~> 4.1)
|
8
|
+
highline (~> 2.0)
|
9
|
+
httparty (~> 0.18)
|
10
|
+
json (~> 2.5)
|
11
|
+
rack (~> 2.2)
|
12
|
+
|
13
|
+
GEM
|
14
|
+
remote: https://rubygems.org/
|
15
|
+
specs:
|
16
|
+
activesupport (6.1.2.1)
|
17
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
i18n (>= 1.6, < 2)
|
19
|
+
minitest (>= 5.1)
|
20
|
+
tzinfo (~> 2.0)
|
21
|
+
zeitwerk (~> 2.3)
|
22
|
+
coderay (1.1.3)
|
23
|
+
concurrent-ruby (1.1.8)
|
24
|
+
diff-lcs (1.4.4)
|
25
|
+
faker (2.15.1)
|
26
|
+
i18n (>= 1.6, < 2)
|
27
|
+
ffi (1.14.2)
|
28
|
+
formatador (0.2.5)
|
29
|
+
gli (2.19.2)
|
30
|
+
guard (2.16.2)
|
31
|
+
formatador (>= 0.2.4)
|
32
|
+
listen (>= 2.7, < 4.0)
|
33
|
+
lumberjack (>= 1.0.12, < 2.0)
|
34
|
+
nenv (~> 0.1)
|
35
|
+
notiffany (~> 0.0)
|
36
|
+
pry (>= 0.9.12)
|
37
|
+
shellany (~> 0.0)
|
38
|
+
thor (>= 0.18.1)
|
39
|
+
guard-compat (1.2.1)
|
40
|
+
guard-rspec (4.7.3)
|
41
|
+
guard (~> 2.1)
|
42
|
+
guard-compat (~> 1.1)
|
43
|
+
rspec (>= 2.99.0, < 4.0)
|
44
|
+
hashie (4.1.0)
|
45
|
+
highline (2.0.3)
|
46
|
+
httparty (0.18.1)
|
47
|
+
mime-types (~> 3.0)
|
48
|
+
multi_xml (>= 0.5.2)
|
49
|
+
i18n (1.8.8)
|
50
|
+
concurrent-ruby (~> 1.0)
|
51
|
+
json (2.5.1)
|
52
|
+
listen (3.4.1)
|
53
|
+
rb-fsevent (~> 0.10, >= 0.10.3)
|
54
|
+
rb-inotify (~> 0.9, >= 0.9.10)
|
55
|
+
lumberjack (1.2.8)
|
56
|
+
method_source (1.0.0)
|
57
|
+
mime-types (3.3.1)
|
58
|
+
mime-types-data (~> 3.2015)
|
59
|
+
mime-types-data (3.2020.1104)
|
60
|
+
minitest (5.14.3)
|
61
|
+
multi_xml (0.6.0)
|
62
|
+
nenv (0.3.0)
|
63
|
+
notiffany (0.1.3)
|
64
|
+
nenv (~> 0.1)
|
65
|
+
shellany (~> 0.0)
|
66
|
+
pry (0.14.0)
|
67
|
+
coderay (~> 1.1)
|
68
|
+
method_source (~> 1.0)
|
69
|
+
rack (2.2.3)
|
70
|
+
rake (13.0.3)
|
71
|
+
rb-fsevent (0.10.4)
|
72
|
+
rb-inotify (0.10.1)
|
73
|
+
ffi (~> 1.0)
|
74
|
+
rspec (3.10.0)
|
75
|
+
rspec-core (~> 3.10.0)
|
76
|
+
rspec-expectations (~> 3.10.0)
|
77
|
+
rspec-mocks (~> 3.10.0)
|
78
|
+
rspec-core (3.10.1)
|
79
|
+
rspec-support (~> 3.10.0)
|
80
|
+
rspec-expectations (3.10.1)
|
81
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
82
|
+
rspec-support (~> 3.10.0)
|
83
|
+
rspec-mocks (3.10.2)
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
85
|
+
rspec-support (~> 3.10.0)
|
86
|
+
rspec-support (3.10.2)
|
87
|
+
shellany (0.0.1)
|
88
|
+
thor (1.1.0)
|
89
|
+
tzinfo (2.0.4)
|
90
|
+
concurrent-ruby (~> 1.0)
|
91
|
+
zeitwerk (2.4.2)
|
92
|
+
|
93
|
+
PLATFORMS
|
94
|
+
x86_64-darwin-19
|
95
|
+
|
96
|
+
DEPENDENCIES
|
97
|
+
bundler (~> 2.2)
|
98
|
+
faker (~> 2.15)
|
99
|
+
guard-rspec (~> 4.3)
|
100
|
+
pry (~> 0.13)
|
101
|
+
rake (~> 13.0)
|
102
|
+
rspec (~> 3.9)
|
103
|
+
slack_messaging!
|
104
|
+
|
105
|
+
BUNDLED WITH
|
106
|
+
2.2.9
|
data/README.md
CHANGED
@@ -26,42 +26,56 @@ gem install slack_messaging
|
|
26
26
|
|
27
27
|
This project requires a config file that should look like this:
|
28
28
|
|
29
|
-
```
|
29
|
+
```yml
|
30
30
|
slack:
|
31
31
|
channel: <AWESOME CHANNEL NAME>
|
32
32
|
username: <AWESOME USER NAME>
|
33
33
|
webhook_url: <SLACK WEBHOOK URL>
|
34
|
-
icon_emoji:
|
34
|
+
icon_emoji: ':<SOME EMOJI>:'
|
35
35
|
```
|
36
36
|
|
37
|
-
|
37
|
+
To generate this file at `~/.slack_messaging.yml`, please run this command:
|
38
38
|
|
39
|
+
```bash
|
40
|
+
slack-messaging setup
|
39
41
|
```
|
40
|
-
|
42
|
+
|
43
|
+
To obtain the webhook URL, go to [this link](https://api.slack.com/messaging/webhooks).
|
44
|
+
|
45
|
+
If you'd like to create the config file at a different directory, I recommend using the `setup` command, and then manually moving the file to your desired location:
|
46
|
+
|
47
|
+
```bash
|
48
|
+
slack-messaging setup
|
49
|
+
# Walk through the prompts to create the file
|
50
|
+
mv ~/.slack_messaging.yml /PATH/TO/FILE/config.yml
|
41
51
|
```
|
42
52
|
|
43
|
-
|
53
|
+
And then you can pass in that specific file location like this:
|
44
54
|
|
45
|
-
|
55
|
+
```bash
|
56
|
+
slack-messaging --config="/PATH/TO/FILE/config.yml" slack
|
57
|
+
```
|
58
|
+
|
59
|
+
Once the config file is set up, the project is ready to go!
|
46
60
|
|
47
61
|
To print a friendly message to Slack, run:
|
48
62
|
|
49
|
-
```
|
63
|
+
```bash
|
50
64
|
slack-messaging slack
|
51
65
|
```
|
52
66
|
|
53
|
-
|
67
|
+
Here, no specific message is being given to print to Slack, so slack_messaging will choose a random quote. The random quotes are selected using the [Quotable API](http://api.quotable.io/).
|
54
68
|
|
55
69
|
However, what if you wanted to print something specific? Well, you can! Just run:
|
56
70
|
|
57
|
-
```
|
58
|
-
slack-messaging slack
|
71
|
+
```bash
|
72
|
+
slack-messaging slack 'MESSAGE 1'
|
59
73
|
```
|
60
74
|
|
61
75
|
You can even print multiple messages at once:
|
62
76
|
|
63
|
-
```
|
64
|
-
slack-messaging slack
|
77
|
+
```bash
|
78
|
+
slack-messaging slack 'MESSAGE 1' 'MESSAGE 2' 'MESSAGE 3' ... 'MESSAGE N'
|
65
79
|
```
|
66
80
|
|
67
81
|
The output of slack_messaging will look something like this:
|
data/bin/slack-messaging
CHANGED
@@ -10,23 +10,31 @@ version SlackMessaging::VERSION
|
|
10
10
|
|
11
11
|
wrap_help_text :verbatim
|
12
12
|
|
13
|
-
flag [:config], :desc => '
|
13
|
+
flag [:config], :desc => 'Slack Messaging config file path', :default_value => SlackMessaging::DefaultPaths.config
|
14
14
|
|
15
15
|
program_long_desc """
|
16
16
|
DOCUMENTATION
|
17
|
+
For documentation and help in setting up your configuration files,
|
18
|
+
see Slack Messaging's GitHub repo: https://github.com/emmahsax/slack_messaging
|
17
19
|
"""
|
18
20
|
|
19
21
|
desc 'Prints a variety of messages to Slack'
|
20
22
|
command 'slack' do |c|
|
23
|
+
pre do |global, command, options, args|
|
24
|
+
SlackMessaging::Config.load(global[:config])
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
21
28
|
c.action do |global_options, options, args|
|
22
29
|
SlackMessaging::Slack.execute(args, options)
|
23
30
|
end
|
24
31
|
end
|
25
32
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
33
|
+
desc 'Sets up a Slack Messaging config file at ~/.slack_messaging.yml'
|
34
|
+
command 'setup' do |c|
|
35
|
+
c.action do ||
|
36
|
+
SlackMessaging::Setup.execute
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
32
40
|
exit run(ARGV)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module SlackMessaging
|
2
|
+
class HighlineCli
|
3
|
+
def ask(prompt)
|
4
|
+
highline_client.ask(prompt) do |conf|
|
5
|
+
conf.readline = true
|
6
|
+
end.to_s
|
7
|
+
end
|
8
|
+
|
9
|
+
def ask_yes_no(prompt)
|
10
|
+
answer = highline_client.ask(prompt) do |conf|
|
11
|
+
conf.readline = true
|
12
|
+
end.to_s
|
13
|
+
|
14
|
+
answer.empty? ? true : !!(answer =~ /^y/i)
|
15
|
+
end
|
16
|
+
|
17
|
+
def ask_options(prompt, choices)
|
18
|
+
choices_as_string_options = ''
|
19
|
+
choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
|
20
|
+
compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
|
21
|
+
|
22
|
+
index = highline_client.ask(compiled_prompt) do |conf|
|
23
|
+
conf.readline = true
|
24
|
+
end.to_i - 1
|
25
|
+
|
26
|
+
choices[index]
|
27
|
+
end
|
28
|
+
|
29
|
+
private def highline_client
|
30
|
+
@highline_client ||= HighLine.new
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
module SlackMessaging
|
2
|
+
class Setup
|
3
|
+
def self.execute
|
4
|
+
if config_file_exists?
|
5
|
+
answer = highline.ask_yes_no("It looks like the #{default_config} file already exists. Do you wish to replace it? (y/n)")
|
6
|
+
|
7
|
+
unless answer
|
8
|
+
puts "\nExiting because you selected to not replace the #{default_config} file..."
|
9
|
+
exit
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
create_or_update_config_file(ask_config_questions)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.create_or_update_config_file(answers)
|
19
|
+
contents = generate_config_file(answers)
|
20
|
+
puts "\nCreating or updating your #{default_config} file..."
|
21
|
+
File.open(default_config, 'w') { |file| file.puts contents }
|
22
|
+
puts "\nDone!"
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.generate_config_file(answers)
|
26
|
+
file_contents = ''
|
27
|
+
file_contents << "slack:\n"
|
28
|
+
file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n"
|
29
|
+
file_contents << " username: #{answers[:username].strip}\n"
|
30
|
+
file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
|
31
|
+
file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'"
|
32
|
+
file_contents
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.config_file_exists?
|
36
|
+
File.exists?(default_config)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.ask_config_questions
|
40
|
+
answers = {}
|
41
|
+
|
42
|
+
answers[:webhook_url] = ask_question(
|
43
|
+
"\nWhat is your Slack webhook URL? If you don't have one yet, please navigate" \
|
44
|
+
" to https://api.slack.com/messaging/webhooks to create one, and then come back" \
|
45
|
+
" here and paste it in the Terminal."
|
46
|
+
)
|
47
|
+
|
48
|
+
unless answers[:webhook_url]
|
49
|
+
puts "\nExiting because Slack webhoook is required..."
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
|
53
|
+
answers[:channel] = ask_question(
|
54
|
+
"\nWhat slack channel do you wish to post to? (default is \"#general\")"
|
55
|
+
) || 'general'
|
56
|
+
|
57
|
+
answers[:username] = ask_question(
|
58
|
+
"\nWhat slack username do you wish to post as? (default is \"Let's Get Quoty\")"
|
59
|
+
) || "Let's Get Quoty"
|
60
|
+
|
61
|
+
answers[:icon_emoji] = ask_question(
|
62
|
+
"\nWhat emoji would you like to post with (include the colons at the beginning and end of the emoji name)? (default is \":mailbox_with_mail:\")"
|
63
|
+
) || ":mailbox_with_mail:"
|
64
|
+
|
65
|
+
answers
|
66
|
+
end
|
67
|
+
|
68
|
+
def self.ask_question(prompt)
|
69
|
+
answer = highline.ask(prompt)
|
70
|
+
answer.empty? ? nil : answer
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.highline
|
74
|
+
@highline ||= SlackMessaging::HighlineCli.new
|
75
|
+
end
|
76
|
+
|
77
|
+
def self.default_config
|
78
|
+
SlackMessaging::DefaultPaths.config
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
@@ -2,16 +2,18 @@ require 'spec_helper'
|
|
2
2
|
require 'slack_messaging'
|
3
3
|
|
4
4
|
describe SlackMessaging::Config do
|
5
|
+
subject { SlackMessaging::Config }
|
6
|
+
|
5
7
|
context 'config key methods' do
|
6
8
|
it 'should return nil when not set' do
|
7
|
-
expect(
|
8
|
-
expect(
|
9
|
+
expect(subject.doesnt_exist).to eql(nil)
|
10
|
+
expect(subject.doesnt_exist?).to eql(false)
|
9
11
|
end
|
10
12
|
|
11
13
|
it 'should return the config value when set' do
|
12
14
|
config_value = Faker::Lorem.word
|
13
|
-
|
14
|
-
expect(
|
15
|
+
subject.new_value = config_value
|
16
|
+
expect(subject.new_value).to eql(config_value)
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -35,19 +37,19 @@ describe SlackMessaging::Config do
|
|
35
37
|
before do
|
36
38
|
allow(YAML).to receive(:load_file).and_return(config_file)
|
37
39
|
allow(File).to receive(:exist?).and_return(true)
|
38
|
-
|
40
|
+
subject.load(Faker::Lorem.word)
|
39
41
|
end
|
40
42
|
|
41
43
|
it 'calling a method corresponding to a key in the file should return the value' do
|
42
|
-
expect(
|
43
|
-
expect(
|
44
|
-
expect(
|
44
|
+
expect(subject.domain).to eql(domain)
|
45
|
+
expect(subject.slack).to be_kind_of(Hash)
|
46
|
+
expect(subject.slack[:slack_option]).to eql(true)
|
45
47
|
end
|
46
48
|
|
47
49
|
it 'overwriting values should work' do
|
48
|
-
expect(
|
49
|
-
|
50
|
-
expect(
|
50
|
+
expect(subject.slack).to be_kind_of(Hash)
|
51
|
+
subject.slack = sentence
|
52
|
+
expect(subject.slack).to eql(sentence)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'slack_messaging'
|
3
|
+
|
4
|
+
describe SlackMessaging::HighlineCli do
|
5
|
+
let(:response) { double(:response, readline: true, to_i: 3) }
|
6
|
+
let(:highline_client) { double(:highline_cli, ask: response) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(HighLine).to receive(:new).and_return(highline_client)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#ask' do
|
13
|
+
it 'should ask the highline client ask'do
|
14
|
+
expect(highline_client).to receive(:ask)
|
15
|
+
subject.ask(Faker::Lorem.sentence)
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should return a string' do
|
19
|
+
expect(subject.ask(Faker::Lorem.sentence)).to be_a(String)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#ask_yes_no' do
|
24
|
+
it 'should ask the highline client ask'do
|
25
|
+
expect(highline_client).to receive(:ask)
|
26
|
+
subject.ask_yes_no(Faker::Lorem.sentence)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should return a boolean' do
|
30
|
+
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_falsey
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should return true if we say yes' do
|
34
|
+
allow(response).to receive(:to_s).and_return('y')
|
35
|
+
expect(subject.ask_yes_no(Faker::Lorem.sentence)).to be_truthy
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#ask_options' do
|
40
|
+
it 'should ask the highline client ask'do
|
41
|
+
expect(highline_client).to receive(:ask)
|
42
|
+
subject.ask_options(Faker::Lorem.sentence, ['one', 'two', 'three'])
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return a string from the options' do
|
46
|
+
expect(subject.ask_options(Faker::Lorem.sentence, ['one', 'two', 'three'])).to be_a(String)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -26,14 +26,16 @@ describe SlackMessaging::NotifySlack do
|
|
26
26
|
SlackMessaging::Config.load(Faker::Lorem.word)
|
27
27
|
end
|
28
28
|
|
29
|
+
subject { SlackMessaging::NotifySlack }
|
30
|
+
|
29
31
|
it 'should call HTTParty' do
|
30
32
|
expect(HTTParty).to receive(:post)
|
31
|
-
message =
|
33
|
+
message = subject.new(sentence)
|
32
34
|
message.perform
|
33
35
|
end
|
34
36
|
|
35
37
|
it 'should define certain values' do
|
36
|
-
message =
|
38
|
+
message = subject.new(sentence)
|
37
39
|
expect(message.text).to eq(sentence)
|
38
40
|
expect(message.channel).to eq(channel)
|
39
41
|
expect(message.username).to eq(username)
|
@@ -16,28 +16,30 @@ describe SlackMessaging::RandomMessage do
|
|
16
16
|
allow(HTTParty).to receive(:get).and_return(quote_object)
|
17
17
|
end
|
18
18
|
|
19
|
+
subject { SlackMessaging::RandomMessage }
|
20
|
+
|
19
21
|
it 'should get a string message' do
|
20
|
-
message =
|
22
|
+
message = subject.acquire_random_quote
|
21
23
|
expect(message).to be_instance_of(String)
|
22
24
|
end
|
23
25
|
|
24
26
|
it 'should get a message that includes a newline' do
|
25
|
-
message =
|
27
|
+
message = subject.acquire_random_quote
|
26
28
|
expect(message.include?("\n")).to eq(true)
|
27
29
|
end
|
28
30
|
|
29
31
|
it 'should get a message that includes a —' do
|
30
|
-
message =
|
32
|
+
message = subject.acquire_random_quote
|
31
33
|
expect(message.include?('—')).to eq(true)
|
32
34
|
end
|
33
35
|
|
34
36
|
it 'should use HTTParty to ping an API' do
|
35
37
|
expect(HTTParty).to receive(:get)
|
36
|
-
|
38
|
+
subject.acquire_random_quote
|
37
39
|
end
|
38
40
|
|
39
41
|
it 'should have the JSON parse the response content twice' do
|
40
42
|
expect(JSON).to receive(:parse).at_least(2).times.and_return(JSON.parse(quote_json))
|
41
|
-
|
43
|
+
subject.acquire_random_quote
|
42
44
|
end
|
43
45
|
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'slack_messaging'
|
3
|
+
|
4
|
+
describe SlackMessaging::Setup do
|
5
|
+
let(:response) { double(:response, readline: true, to_s: Faker::Lorem.sentence) }
|
6
|
+
let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
|
7
|
+
let(:answers) do
|
8
|
+
{
|
9
|
+
channel: Faker::Lorem.word,
|
10
|
+
username: Faker::Lorem.word,
|
11
|
+
webhook_url: Faker::Internet.url,
|
12
|
+
icon_emoji: ":#{Faker::Lorem.word}:"
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
allow(SlackMessaging::HighlineCli).to receive(:new).and_return(highline_cli)
|
18
|
+
allow(subject).to receive(:puts)
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
SlackMessaging::Setup.instance_variable_set("@highline", nil)
|
23
|
+
end
|
24
|
+
|
25
|
+
subject { SlackMessaging::Setup }
|
26
|
+
|
27
|
+
describe '#self.execute' do
|
28
|
+
it 'should ask a question if the config file exists' do
|
29
|
+
allow(File).to receive(:exists?).and_return(true)
|
30
|
+
expect(highline_cli).to receive(:ask_yes_no).and_return(true)
|
31
|
+
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
32
|
+
allow(subject).to receive(:ask_config_questions).and_return(true)
|
33
|
+
subject.execute
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should call to create or update the config file' do
|
37
|
+
allow(File).to receive(:exists?).and_return(true)
|
38
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(true)
|
39
|
+
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
40
|
+
expect(subject).to receive(:ask_config_questions).and_return(true)
|
41
|
+
subject.execute
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should exit if the user opts not to continue' do
|
45
|
+
allow(File).to receive(:exists?).and_return(true)
|
46
|
+
allow(highline_cli).to receive(:ask_yes_no).and_return(false)
|
47
|
+
expect(subject).not_to receive(:create_or_update_config_file)
|
48
|
+
expect(subject).not_to receive(:ask_config_questions)
|
49
|
+
expect{ subject.execute }.to raise_error(SystemExit)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#self.create_or_update_config_file' do
|
54
|
+
it 'should generate the file based on the answers to the questions' do
|
55
|
+
expect(subject).to receive(:generate_config_file)
|
56
|
+
allow(File).to receive(:open).and_return(nil)
|
57
|
+
subject.send(:create_or_update_config_file, answers)
|
58
|
+
end
|
59
|
+
|
60
|
+
it 'should open the file for writing' do
|
61
|
+
allow(subject).to receive(:generate_config_file)
|
62
|
+
expect(File).to receive(:open).and_return(nil)
|
63
|
+
subject.send(:create_or_update_config_file, answers)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#self.generate_config_file' do
|
68
|
+
it 'returns a string' do
|
69
|
+
expect(subject.send(:generate_config_file, answers)).to be_a(String)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '#self.config_file_exists?' do
|
74
|
+
it 'should return true if the file exists' do
|
75
|
+
allow(File).to receive(:exists?).and_return(true)
|
76
|
+
expect(subject.send(:config_file_exists?)).to eq(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should return false if the file does not exist' do
|
80
|
+
allow(File).to receive(:exists?).and_return(false)
|
81
|
+
expect(subject.send(:config_file_exists?)).to eq(false)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#self.ask_question' do
|
86
|
+
it 'should use highline to ask a question' do
|
87
|
+
expect(highline_cli).to receive(:ask).and_return('')
|
88
|
+
subject.send(:ask_question, Faker::Lorem.sentence)
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should return nil if the highline client gets an empty string' do
|
92
|
+
allow(highline_cli).to receive(:ask).and_return('')
|
93
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be_nil
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should return the answer if it is given' do
|
97
|
+
answer = Faker::Lorem.sentence
|
98
|
+
allow(highline_cli).to receive(:ask).and_return(answer)
|
99
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe '#self.ask_config_questions' do
|
104
|
+
it 'should call to ask at least four questions' do
|
105
|
+
expect(subject).to receive(:ask_question).at_least(4).times
|
106
|
+
subject.send(:ask_config_questions)
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should exit if the slack URL is not given' do
|
110
|
+
allow(subject).to receive(:ask_question).and_return(nil)
|
111
|
+
expect{ subject.send(:ask_config_questions) }.to raise_error(SystemExit)
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should return the defaults if nothing is given' do
|
115
|
+
slack_url = Faker::Internet.url
|
116
|
+
allow(subject).to receive(:ask_question).with(
|
117
|
+
"\nWhat is your Slack webhook URL? If you don't have one yet, please navigate" \
|
118
|
+
" to https://api.slack.com/messaging/webhooks to create one, and then come back" \
|
119
|
+
" here and paste it in the Terminal."
|
120
|
+
).and_return(slack_url)
|
121
|
+
allow(subject).to receive(:ask_question).and_return(nil)
|
122
|
+
expect(subject.send(:ask_config_questions)).to eq(
|
123
|
+
{
|
124
|
+
channel: 'general',
|
125
|
+
username: "Let's Get Quoty",
|
126
|
+
webhook_url: slack_url,
|
127
|
+
icon_emoji: ":mailbox_with_mail:"
|
128
|
+
}
|
129
|
+
)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: slack_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emma Sax
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -200,6 +200,7 @@ extensions: []
|
|
200
200
|
extra_rdoc_files: []
|
201
201
|
files:
|
202
202
|
- Gemfile
|
203
|
+
- Gemfile.lock
|
203
204
|
- Guardfile
|
204
205
|
- LICENSE
|
205
206
|
- QuoteExample.png
|
@@ -209,13 +210,17 @@ files:
|
|
209
210
|
- lib/slack_messaging.rb
|
210
211
|
- lib/slack_messaging/config.rb
|
211
212
|
- lib/slack_messaging/default_paths.rb
|
213
|
+
- lib/slack_messaging/highline_cli.rb
|
212
214
|
- lib/slack_messaging/notify_slack.rb
|
213
215
|
- lib/slack_messaging/random_message.rb
|
216
|
+
- lib/slack_messaging/setup.rb
|
214
217
|
- lib/slack_messaging/slack.rb
|
215
218
|
- lib/slack_messaging/version.rb
|
216
219
|
- spec/slack_messaging/config_spec.rb
|
220
|
+
- spec/slack_messaging/highline_cli_spec.rb
|
217
221
|
- spec/slack_messaging/notify_slack_spec.rb
|
218
222
|
- spec/slack_messaging/random_message_spec.rb
|
223
|
+
- spec/slack_messaging/setup_spec.rb
|
219
224
|
- spec/spec_helper.rb
|
220
225
|
homepage: https://github.com/emmahsax/slack_messaging
|
221
226
|
licenses:
|
@@ -243,5 +248,7 @@ summary: Personalized Slack Messages
|
|
243
248
|
test_files:
|
244
249
|
- spec/spec_helper.rb
|
245
250
|
- spec/slack_messaging/config_spec.rb
|
251
|
+
- spec/slack_messaging/highline_cli_spec.rb
|
246
252
|
- spec/slack_messaging/notify_slack_spec.rb
|
247
253
|
- spec/slack_messaging/random_message_spec.rb
|
254
|
+
- spec/slack_messaging/setup_spec.rb
|