slack_messaging 3.2.3 → 3.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +39 -38
- data/Guardfile +2 -2
- data/README.md +31 -7
- data/bin/slack-messaging +5 -1
- data/lib/slack_messaging/config.rb +2 -2
- data/lib/slack_messaging/default_paths.rb +1 -1
- data/lib/slack_messaging/notify_discord.rb +24 -0
- data/lib/slack_messaging/notify_slack.rb +6 -6
- data/lib/slack_messaging/send.rb +18 -5
- data/lib/slack_messaging/setup.rb +80 -17
- data/lib/slack_messaging/version.rb +1 -1
- data/lib/slack_messaging.rb +1 -1
- data/message_discord.png +0 -0
- data/message_slack.png +0 -0
- metadata +7 -15
- data/QuoteExample.png +0 -0
- data/spec/slack_messaging/config_spec.rb +0 -57
- data/spec/slack_messaging/notify_slack_spec.rb +0 -45
- data/spec/slack_messaging/random_message_spec.rb +0 -47
- data/spec/slack_messaging/setup_spec.rb +0 -140
- data/spec/spec_helper.rb +0 -50
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f64abe8c431be41a49398d8ae7a8972968d9fc0c4ce18d814bd650d498d918be
|
|
4
|
+
data.tar.gz: dcafa39cde670c4dd5b0c089e0440e7c82de81d70415fb6d814b81a4211b61e4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: edff54c98cb3ff17bdb0aa42f0530f9a3560e999db259d1f7ef7ae2f998d0561978366aec5215be1061d7434c6afd5dd631f9161dff684b0ca3670fca2f2b6c3
|
|
7
|
+
data.tar.gz: cbc96620ccdc82142722873992e579f31e2d5f409a4620757959c662118e0fe673e5672f3e950af0e3a35f379ee968008eb8cc6bac097111392f1bf503d3967f
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
slack_messaging (3.
|
|
4
|
+
slack_messaging (3.3.0)
|
|
5
5
|
gli (~> 2.10)
|
|
6
6
|
hashie (>= 4.1, <= 5)
|
|
7
7
|
highline_wrapper (~> 1.1)
|
|
@@ -13,13 +13,13 @@ GEM
|
|
|
13
13
|
specs:
|
|
14
14
|
ast (2.4.2)
|
|
15
15
|
coderay (1.1.3)
|
|
16
|
-
concurrent-ruby (1.1.
|
|
17
|
-
diff-lcs (1.
|
|
18
|
-
faker (2.
|
|
19
|
-
i18n (>= 1.
|
|
20
|
-
ffi (1.15.
|
|
21
|
-
formatador (
|
|
22
|
-
gli (2.
|
|
16
|
+
concurrent-ruby (1.1.10)
|
|
17
|
+
diff-lcs (1.5.0)
|
|
18
|
+
faker (2.22.0)
|
|
19
|
+
i18n (>= 1.8.11, < 2)
|
|
20
|
+
ffi (1.15.5)
|
|
21
|
+
formatador (1.1.0)
|
|
22
|
+
gli (2.21.0)
|
|
23
23
|
guard (2.18.0)
|
|
24
24
|
formatador (>= 0.2.4)
|
|
25
25
|
listen (>= 2.7, < 4.0)
|
|
@@ -41,65 +41,66 @@ GEM
|
|
|
41
41
|
httparty (0.20.0)
|
|
42
42
|
mime-types (~> 3.0)
|
|
43
43
|
multi_xml (>= 0.5.2)
|
|
44
|
-
i18n (1.
|
|
44
|
+
i18n (1.12.0)
|
|
45
45
|
concurrent-ruby (~> 1.0)
|
|
46
|
-
json (2.6.
|
|
47
|
-
listen (3.7.
|
|
46
|
+
json (2.6.2)
|
|
47
|
+
listen (3.7.1)
|
|
48
48
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
49
49
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
50
50
|
lumberjack (1.2.8)
|
|
51
51
|
method_source (1.0.0)
|
|
52
52
|
mime-types (3.4.1)
|
|
53
53
|
mime-types-data (~> 3.2015)
|
|
54
|
-
mime-types-data (3.
|
|
54
|
+
mime-types-data (3.2022.0105)
|
|
55
55
|
multi_xml (0.6.0)
|
|
56
56
|
nenv (0.3.0)
|
|
57
57
|
notiffany (0.1.3)
|
|
58
58
|
nenv (~> 0.1)
|
|
59
59
|
shellany (~> 0.0)
|
|
60
|
-
parallel (1.
|
|
61
|
-
parser (3.
|
|
60
|
+
parallel (1.22.1)
|
|
61
|
+
parser (3.1.2.1)
|
|
62
62
|
ast (~> 2.4.1)
|
|
63
63
|
pry (0.14.1)
|
|
64
64
|
coderay (~> 1.1)
|
|
65
65
|
method_source (~> 1.0)
|
|
66
|
-
rainbow (3.
|
|
67
|
-
rb-fsevent (0.11.
|
|
66
|
+
rainbow (3.1.1)
|
|
67
|
+
rb-fsevent (0.11.1)
|
|
68
68
|
rb-inotify (0.10.1)
|
|
69
69
|
ffi (~> 1.0)
|
|
70
|
-
regexp_parser (2.
|
|
70
|
+
regexp_parser (2.5.0)
|
|
71
71
|
rexml (3.2.5)
|
|
72
|
-
rspec (3.
|
|
73
|
-
rspec-core (~> 3.
|
|
74
|
-
rspec-expectations (~> 3.
|
|
75
|
-
rspec-mocks (~> 3.
|
|
76
|
-
rspec-core (3.
|
|
77
|
-
rspec-support (~> 3.
|
|
78
|
-
rspec-expectations (3.
|
|
72
|
+
rspec (3.11.0)
|
|
73
|
+
rspec-core (~> 3.11.0)
|
|
74
|
+
rspec-expectations (~> 3.11.0)
|
|
75
|
+
rspec-mocks (~> 3.11.0)
|
|
76
|
+
rspec-core (3.11.0)
|
|
77
|
+
rspec-support (~> 3.11.0)
|
|
78
|
+
rspec-expectations (3.11.0)
|
|
79
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
80
|
-
rspec-support (~> 3.
|
|
81
|
-
rspec-mocks (3.
|
|
80
|
+
rspec-support (~> 3.11.0)
|
|
81
|
+
rspec-mocks (3.11.1)
|
|
82
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
|
83
|
-
rspec-support (~> 3.
|
|
84
|
-
rspec-support (3.
|
|
85
|
-
rubocop (1.
|
|
83
|
+
rspec-support (~> 3.11.0)
|
|
84
|
+
rspec-support (3.11.0)
|
|
85
|
+
rubocop (1.35.1)
|
|
86
|
+
json (~> 2.3)
|
|
86
87
|
parallel (~> 1.10)
|
|
87
|
-
parser (>= 3.
|
|
88
|
+
parser (>= 3.1.2.1)
|
|
88
89
|
rainbow (>= 2.2.2, < 4.0)
|
|
89
90
|
regexp_parser (>= 1.8, < 3.0)
|
|
90
|
-
rexml
|
|
91
|
-
rubocop-ast (>= 1.
|
|
91
|
+
rexml (>= 3.2.5, < 4.0)
|
|
92
|
+
rubocop-ast (>= 1.20.1, < 2.0)
|
|
92
93
|
ruby-progressbar (~> 1.7)
|
|
93
94
|
unicode-display_width (>= 1.4.0, < 3.0)
|
|
94
|
-
rubocop-ast (1.
|
|
95
|
-
parser (>= 3.
|
|
95
|
+
rubocop-ast (1.21.0)
|
|
96
|
+
parser (>= 3.1.1.0)
|
|
96
97
|
ruby-progressbar (1.11.0)
|
|
97
98
|
shellany (0.0.1)
|
|
98
|
-
thor (1.1
|
|
99
|
-
unicode-display_width (2.
|
|
99
|
+
thor (1.2.1)
|
|
100
|
+
unicode-display_width (2.2.0)
|
|
100
101
|
|
|
101
102
|
PLATFORMS
|
|
102
|
-
|
|
103
|
+
arm64-darwin-21
|
|
103
104
|
|
|
104
105
|
DEPENDENCIES
|
|
105
106
|
bundler (~> 2.2)
|
|
@@ -111,4 +112,4 @@ DEPENDENCIES
|
|
|
111
112
|
slack_messaging!
|
|
112
113
|
|
|
113
114
|
BUNDLED WITH
|
|
114
|
-
2.
|
|
115
|
+
2.3.20
|
data/Guardfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
|
|
4
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
|
5
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
4
6
|
watch(%r{^spec/.+_spec\.rb$})
|
|
5
|
-
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
|
6
|
-
watch('spec/spec_helper.rb') { 'spec' }
|
|
7
7
|
end
|
data/README.md
CHANGED
|
@@ -22,11 +22,15 @@ Or install it yourself as:
|
|
|
22
22
|
gem install slack_messaging
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
##
|
|
25
|
+
## Setup
|
|
26
26
|
|
|
27
27
|
This project requires a config file that should look like this:
|
|
28
28
|
|
|
29
29
|
```yml
|
|
30
|
+
discord:
|
|
31
|
+
avatar_url: <PUBLIC URL OF AN IMAGE>
|
|
32
|
+
username: <AWESOME USER NAME>
|
|
33
|
+
webhook_url: <DISCORD WEBHOOK URL>
|
|
30
34
|
slack:
|
|
31
35
|
channel: <AWESOME CHANNEL NAME>
|
|
32
36
|
username: <AWESOME USER NAME>
|
|
@@ -34,13 +38,13 @@ slack:
|
|
|
34
38
|
icon_emoji: ':<SOME EMOJI>:'
|
|
35
39
|
```
|
|
36
40
|
|
|
37
|
-
To generate this file at `~/.slack_messaging.yml`, please run this command:
|
|
41
|
+
A config file can have both Discord and Slack settings, or just one or the other. To easily generate this file at `~/.slack_messaging.yml`, please run this command once for each setting type:
|
|
38
42
|
|
|
39
43
|
```bash
|
|
40
44
|
slack-messaging setup
|
|
41
45
|
```
|
|
42
46
|
|
|
43
|
-
To obtain
|
|
47
|
+
To obtain a Slack webhook URL, follow [these instructions](https://slack.com/help/articles/115005265063-Incoming-webhooks-for-Slack). To obtain a Discord webhook URL, follow [these instructions](https://support.discord.com/hc/en-us/articles/228383668-Intro-to-Webhooks).
|
|
44
48
|
|
|
45
49
|
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
50
|
|
|
@@ -50,13 +54,13 @@ slack-messaging setup
|
|
|
50
54
|
mv ~/.slack_messaging.yml /PATH/TO/FILE/config.yml
|
|
51
55
|
```
|
|
52
56
|
|
|
53
|
-
And then you can pass in that specific file location
|
|
57
|
+
And then you can pass in that specific file location using the global `-c`/`--config` flag:
|
|
54
58
|
|
|
55
59
|
```bash
|
|
56
60
|
slack-messaging --config="/PATH/TO/FILE/config.yml" send
|
|
57
61
|
```
|
|
58
62
|
|
|
59
|
-
|
|
63
|
+
## Usage
|
|
60
64
|
|
|
61
65
|
To print a friendly message to Slack, run:
|
|
62
66
|
|
|
@@ -78,9 +82,29 @@ You can even print multiple messages at once:
|
|
|
78
82
|
slack-messaging send 'MESSAGE 1' 'MESSAGE 2' 'MESSAGE 3' ... 'MESSAGE N'
|
|
79
83
|
```
|
|
80
84
|
|
|
81
|
-
|
|
85
|
+
> When using special characters in your custom messages, use single quotes instead of double quotes
|
|
86
|
+
|
|
87
|
+
If your config file contains both Slack and Discord settings, then running a basic `send` command (either passing in a message or not), will notify both Slack and Discord. To specify which service to send a message to, you can pass in a `-s`/`--service` flag:
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
slack-messaging send --service slack
|
|
91
|
+
# OR
|
|
92
|
+
slack-messaging send --service discord
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
To specify a service _and_ send a customized message, you can pass both at once:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
slack-messaging send -s slack 'MESSAGE 1'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The output of a Slack message will look something like this:
|
|
102
|
+
|
|
103
|
+
<img src="https://github.com/emmahsax/slack_messaging/blob/main/message_slack.png" width="500">
|
|
104
|
+
|
|
105
|
+
The output of a Discord message will look something like this:
|
|
82
106
|
|
|
83
|
-
<img src="https://github.com/emmahsax/slack_messaging/blob/main/
|
|
107
|
+
<img src="https://github.com/emmahsax/slack_messaging/blob/main/message_discord.png" width="500">
|
|
84
108
|
|
|
85
109
|
I hope you enjoy printing fun and specialized messages to Slack!
|
|
86
110
|
|
data/bin/slack-messaging
CHANGED
|
@@ -13,7 +13,7 @@ version SlackMessaging::VERSION
|
|
|
13
13
|
|
|
14
14
|
wrap_help_text :verbatim
|
|
15
15
|
|
|
16
|
-
flag [
|
|
16
|
+
flag %i[c config], desc: 'Slack Messaging config file path', default_value: SlackMessaging::DefaultPaths.config
|
|
17
17
|
|
|
18
18
|
program_long_desc "
|
|
19
19
|
DOCUMENTATION
|
|
@@ -28,6 +28,10 @@ end
|
|
|
28
28
|
|
|
29
29
|
desc 'Prints a variety of messages to Slack'
|
|
30
30
|
command 'send' do |c|
|
|
31
|
+
c.desc "The service ('slack' or 'discord') that you wish to notify - if none is given, Slack Messaging will " \
|
|
32
|
+
'notify each service present in the config file'
|
|
33
|
+
c.flag %i[s service]
|
|
34
|
+
|
|
31
35
|
c.action do |_global_options, options, args|
|
|
32
36
|
SlackMessaging::Send.execute(args, options)
|
|
33
37
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module SlackMessaging
|
|
4
|
+
class NotifyDiscord
|
|
5
|
+
attr_accessor :avatar_url, :text, :username, :webhook_url
|
|
6
|
+
|
|
7
|
+
def initialize(text)
|
|
8
|
+
self.avatar_url = SlackMessaging::Config.discord[:avatar_url] || 'https://i.imgur.com/9ZTbiSF.jpg'
|
|
9
|
+
self.text = text
|
|
10
|
+
self.username = SlackMessaging::Config.discord[:username] || 'Slack Messaging'
|
|
11
|
+
self.webhook_url = SlackMessaging::Config.discord[:webhook_url]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def perform
|
|
15
|
+
options = {
|
|
16
|
+
avatar_url: avatar_url,
|
|
17
|
+
content: text,
|
|
18
|
+
username: username
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
`curl -s -H "Content-Type: application/json" -d '#{options.to_json.gsub("'", "'\\\\''")}' '#{webhook_url}'`
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -2,22 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
module SlackMessaging
|
|
4
4
|
class NotifySlack
|
|
5
|
-
attr_accessor :
|
|
5
|
+
attr_accessor :channel, :icon_emoji, :text, :username, :webhook_url
|
|
6
6
|
|
|
7
7
|
def initialize(text)
|
|
8
|
+
self.channel = SlackMessaging::Config.slack[:channel] || 'general'
|
|
9
|
+
self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ':robot_face:'
|
|
8
10
|
self.text = text
|
|
9
|
-
self.
|
|
11
|
+
self.username = SlackMessaging::Config.slack[:username] || 'Slack Messaging'
|
|
10
12
|
self.webhook_url = SlackMessaging::Config.slack[:webhook_url]
|
|
11
|
-
self.username = SlackMessaging::Config.slack[:username] || 'MessageMe'
|
|
12
|
-
self.icon_emoji = SlackMessaging::Config.slack[:icon_emoji] || ':mailbox_with_mail'
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def perform
|
|
16
16
|
options = {
|
|
17
17
|
channel: channel,
|
|
18
|
-
username: username,
|
|
19
18
|
icon_emoji: icon_emoji,
|
|
20
|
-
text: text
|
|
19
|
+
text: text,
|
|
20
|
+
username: username
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
HTTParty.post(webhook_url, body: options.to_json)
|
data/lib/slack_messaging/send.rb
CHANGED
|
@@ -5,19 +5,32 @@ module SlackMessaging
|
|
|
5
5
|
class << self
|
|
6
6
|
attr_accessor :options
|
|
7
7
|
|
|
8
|
-
def execute(args,
|
|
8
|
+
def execute(args, options)
|
|
9
9
|
if args.empty?
|
|
10
10
|
message = SlackMessaging::RandomMessage.acquire_random_quote
|
|
11
|
-
|
|
11
|
+
distribute_notification(message, options[:service])
|
|
12
12
|
else
|
|
13
13
|
args.each do |arg_message|
|
|
14
|
-
|
|
14
|
+
distribute_notification(arg_message, options[:service])
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
private def
|
|
20
|
-
|
|
19
|
+
private def distribute_notification(message, service)
|
|
20
|
+
if service
|
|
21
|
+
print_message(message, service)
|
|
22
|
+
else
|
|
23
|
+
SlackMessaging::Config.full_config.each { |s, _| print_message(message, s) }
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private def print_message(message, service)
|
|
28
|
+
case service
|
|
29
|
+
when 'discord'
|
|
30
|
+
SlackMessaging::NotifyDiscord.new(message).perform
|
|
31
|
+
when 'slack'
|
|
32
|
+
SlackMessaging::NotifySlack.new(message).perform
|
|
33
|
+
end
|
|
21
34
|
end
|
|
22
35
|
end
|
|
23
36
|
end
|
|
@@ -1,38 +1,76 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
# rubocop:disable Metrics/ClassLength
|
|
3
4
|
module SlackMessaging
|
|
4
5
|
class Setup
|
|
5
6
|
class << self
|
|
7
|
+
# rubocop:disable Metrics/MethodLength
|
|
6
8
|
# rubocop:disable Style/ConditionalAssignment
|
|
7
9
|
def execute
|
|
8
10
|
if config_file_exists?
|
|
9
11
|
answer = highline.ask_yes_no(
|
|
10
|
-
"It looks like the #{default_config} file already exists. Do you wish to
|
|
12
|
+
"It looks like the #{default_config} file already exists. Do you wish to edit it? (y/n)",
|
|
11
13
|
{ required: true }
|
|
12
14
|
)
|
|
13
15
|
else
|
|
14
16
|
answer = true
|
|
15
17
|
end
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
exit unless answer
|
|
20
|
+
|
|
21
|
+
type = highline.ask_multiple_choice(
|
|
22
|
+
'Which type of config do you wish to create/update?',
|
|
23
|
+
%w[Discord Slack],
|
|
24
|
+
required: true
|
|
25
|
+
)[:value]
|
|
26
|
+
|
|
27
|
+
case type
|
|
28
|
+
when 'Discord'
|
|
29
|
+
file_contents = generate_discord_config_file(ask_discord_config_questions)
|
|
30
|
+
when 'Slack'
|
|
31
|
+
file_contents = generate_slack_config_file(ask_slack_config_questions)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
create_or_update_config_file(file_contents)
|
|
18
35
|
end
|
|
36
|
+
# rubocop:enable Metrics/MethodLength
|
|
19
37
|
# rubocop:enable Style/ConditionalAssignment
|
|
20
38
|
|
|
21
|
-
private def create_or_update_config_file(
|
|
22
|
-
contents = generate_config_file(answers)
|
|
39
|
+
private def create_or_update_config_file(contents)
|
|
23
40
|
puts "Creating or updating your #{default_config} file..."
|
|
24
41
|
File.open(default_config, 'w') { |file| file.puts contents }
|
|
25
42
|
puts 'Done!'
|
|
26
43
|
end
|
|
27
44
|
|
|
28
|
-
private def
|
|
45
|
+
private def generate_discord_config_file(answers)
|
|
46
|
+
file_contents = ''.dup
|
|
47
|
+
file_contents << "discord:\n"
|
|
48
|
+
file_contents << " avatar_url: #{answers[:avatar_url].strip}\n"
|
|
49
|
+
file_contents << " username: #{answers[:username].strip}\n"
|
|
50
|
+
file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
|
|
51
|
+
contents_regex = /(discord:\n\s+avatar_url: \S+\n\s+username: [ \S]+\n\s+webhook_url: \S+\n)/
|
|
52
|
+
compare_configs(contents_regex, file_contents)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private def generate_slack_config_file(answers)
|
|
29
56
|
file_contents = ''.dup
|
|
30
57
|
file_contents << "slack:\n"
|
|
31
58
|
file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n"
|
|
59
|
+
file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'\n"
|
|
32
60
|
file_contents << " username: #{answers[:username].strip}\n"
|
|
33
61
|
file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
|
|
34
|
-
|
|
35
|
-
file_contents
|
|
62
|
+
contents_regex = /(slack:\n\s+channel: \S+\n\s+icon_emoji: \S+\n\s+username: [ \S]+\n\s+webhook_url: \S+\n)/
|
|
63
|
+
compare_configs(contents_regex, file_contents)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
private def compare_configs(contents_regex, file_contents)
|
|
67
|
+
if config_file_exists? && contents_regex.match(File.read(default_config))
|
|
68
|
+
File.read(default_config).gsub(contents_regex, file_contents)
|
|
69
|
+
elsif config_file_exists?
|
|
70
|
+
File.read(default_config) << file_contents
|
|
71
|
+
else
|
|
72
|
+
file_contents
|
|
73
|
+
end
|
|
36
74
|
end
|
|
37
75
|
|
|
38
76
|
private def config_file_exists?
|
|
@@ -40,31 +78,55 @@ module SlackMessaging
|
|
|
40
78
|
end
|
|
41
79
|
|
|
42
80
|
# rubocop:disable Metrics/MethodLength
|
|
43
|
-
private def
|
|
81
|
+
private def ask_discord_config_questions
|
|
82
|
+
answers = {}
|
|
83
|
+
|
|
84
|
+
answers[:webhook_url] = ask_question(
|
|
85
|
+
"What is your Discord webhook URL? If you don't have one yet, please navigate " \
|
|
86
|
+
'to https://discord.com/channels/@me to create one for your server, and then come back ' \
|
|
87
|
+
'here and paste it in the Terminal.',
|
|
88
|
+
nil,
|
|
89
|
+
required: true
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
answers[:username] = ask_question(
|
|
93
|
+
'What Discord username do you wish to post as? (default is "Slack Messaging")',
|
|
94
|
+
'Slack Messaging'
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
answers[:avatar_url] = ask_question(
|
|
98
|
+
'What avatar URL would you like to post with? (default is "https://i.imgur.com/9ZTbiSF.jpg")',
|
|
99
|
+
'https://i.imgur.com/9ZTbiSF.jpg'
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
answers
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private def ask_slack_config_questions
|
|
44
106
|
answers = {}
|
|
45
107
|
|
|
46
108
|
answers[:webhook_url] = ask_question(
|
|
47
|
-
"What is your Slack webhook URL? If you don't have one yet, please navigate" \
|
|
48
|
-
'
|
|
49
|
-
'
|
|
109
|
+
"What is your Slack webhook URL? If you don't have one yet, please navigate " \
|
|
110
|
+
'to https://api.slack.com/messaging/webhooks to create one, and then come back ' \
|
|
111
|
+
'here and paste it in the Terminal.',
|
|
50
112
|
nil,
|
|
51
113
|
required: true
|
|
52
114
|
)
|
|
53
115
|
|
|
54
116
|
answers[:channel] = ask_question(
|
|
55
|
-
'What
|
|
117
|
+
'What Slack channel do you wish to post to? (default is "#general")',
|
|
56
118
|
'#general'
|
|
57
119
|
)
|
|
58
120
|
|
|
59
121
|
answers[:username] = ask_question(
|
|
60
|
-
|
|
61
|
-
|
|
122
|
+
'What Slack username do you wish to post as? (default is "Slack Messaging")',
|
|
123
|
+
'Slack Messaging'
|
|
62
124
|
)
|
|
63
125
|
|
|
64
126
|
answers[:icon_emoji] = ask_question(
|
|
65
|
-
'What emoji would you like to post with (include the colons at the beginning and end' \
|
|
66
|
-
'
|
|
67
|
-
':
|
|
127
|
+
'What emoji would you like to post with (include the colons at the beginning and end ' \
|
|
128
|
+
'of the emoji name)? (default is ":robot_face:")',
|
|
129
|
+
':robot_face:'
|
|
68
130
|
)
|
|
69
131
|
|
|
70
132
|
answers
|
|
@@ -85,3 +147,4 @@ module SlackMessaging
|
|
|
85
147
|
end
|
|
86
148
|
end
|
|
87
149
|
end
|
|
150
|
+
# rubocop:enable Metrics/ClassLength
|
data/lib/slack_messaging.rb
CHANGED
data/message_discord.png
ADDED
|
Binary file
|
data/message_slack.png
ADDED
|
Binary file
|
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: 3.
|
|
4
|
+
version: 3.3.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:
|
|
11
|
+
date: 2022-08-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: gli
|
|
@@ -182,23 +182,20 @@ files:
|
|
|
182
182
|
- Gemfile.lock
|
|
183
183
|
- Guardfile
|
|
184
184
|
- LICENSE.md
|
|
185
|
-
- QuoteExample.png
|
|
186
185
|
- README.md
|
|
187
186
|
- Rakefile
|
|
188
187
|
- bin/slack-messaging
|
|
189
188
|
- lib/slack_messaging.rb
|
|
190
189
|
- lib/slack_messaging/config.rb
|
|
191
190
|
- lib/slack_messaging/default_paths.rb
|
|
191
|
+
- lib/slack_messaging/notify_discord.rb
|
|
192
192
|
- lib/slack_messaging/notify_slack.rb
|
|
193
193
|
- lib/slack_messaging/random_message.rb
|
|
194
194
|
- lib/slack_messaging/send.rb
|
|
195
195
|
- lib/slack_messaging/setup.rb
|
|
196
196
|
- lib/slack_messaging/version.rb
|
|
197
|
-
-
|
|
198
|
-
-
|
|
199
|
-
- spec/slack_messaging/random_message_spec.rb
|
|
200
|
-
- spec/slack_messaging/setup_spec.rb
|
|
201
|
-
- spec/spec_helper.rb
|
|
197
|
+
- message_discord.png
|
|
198
|
+
- message_slack.png
|
|
202
199
|
homepage: https://github.com/emmahsax/slack_messaging
|
|
203
200
|
licenses:
|
|
204
201
|
- BSD-3-Clause
|
|
@@ -219,13 +216,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
219
216
|
- !ruby/object:Gem::Version
|
|
220
217
|
version: '0'
|
|
221
218
|
requirements: []
|
|
222
|
-
rubygems_version: 3.
|
|
219
|
+
rubygems_version: 3.3.17
|
|
223
220
|
signing_key:
|
|
224
221
|
specification_version: 4
|
|
225
222
|
summary: Personalized quotes and messages sent straight to Slack
|
|
226
|
-
test_files:
|
|
227
|
-
- spec/spec_helper.rb
|
|
228
|
-
- spec/slack_messaging/config_spec.rb
|
|
229
|
-
- spec/slack_messaging/notify_slack_spec.rb
|
|
230
|
-
- spec/slack_messaging/random_message_spec.rb
|
|
231
|
-
- spec/slack_messaging/setup_spec.rb
|
|
223
|
+
test_files: []
|
data/QuoteExample.png
DELETED
|
Binary file
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'slack_messaging'
|
|
5
|
-
|
|
6
|
-
describe SlackMessaging::Config do
|
|
7
|
-
subject { SlackMessaging::Config }
|
|
8
|
-
|
|
9
|
-
context 'config key methods' do
|
|
10
|
-
it 'should return nil when not set' do
|
|
11
|
-
expect(subject.doesnt_exist).to eql(nil)
|
|
12
|
-
expect(subject.doesnt_exist?).to eql(false)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it 'should return the config value when set' do
|
|
16
|
-
config_value = Faker::Lorem.word
|
|
17
|
-
subject.new_value = config_value
|
|
18
|
-
expect(subject.new_value).to eql(config_value)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
context 'after loading a config file' do
|
|
23
|
-
let(:domain) { Faker::Internet.domain_name }
|
|
24
|
-
let(:sentence) { Faker::Lorem.sentence }
|
|
25
|
-
|
|
26
|
-
let(:config_file) do
|
|
27
|
-
{
|
|
28
|
-
domain: domain,
|
|
29
|
-
slack: {
|
|
30
|
-
slack_option: true,
|
|
31
|
-
username: Faker::Name.name,
|
|
32
|
-
icon_url: Faker::Internet.url,
|
|
33
|
-
channel: Faker::Lorem.word,
|
|
34
|
-
webhook: Faker::Internet.url
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
before do
|
|
40
|
-
allow(YAML).to receive(:load_file).and_return(config_file)
|
|
41
|
-
allow(File).to receive(:exist?).and_return(true)
|
|
42
|
-
subject.load(Faker::Lorem.word)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
it 'calling a method corresponding to a key in the file should return the value' do
|
|
46
|
-
expect(subject.domain).to eql(domain)
|
|
47
|
-
expect(subject.slack).to be_kind_of(Hash)
|
|
48
|
-
expect(subject.slack[:slack_option]).to eql(true)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it 'overwriting values should work' do
|
|
52
|
-
expect(subject.slack).to be_kind_of(Hash)
|
|
53
|
-
subject.slack = sentence
|
|
54
|
-
expect(subject.slack).to eql(sentence)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'slack_messaging'
|
|
5
|
-
|
|
6
|
-
describe SlackMessaging::NotifySlack do
|
|
7
|
-
let(:sentence) { Faker::Lorem.sentence }
|
|
8
|
-
let(:channel) { Faker::Lorem.word }
|
|
9
|
-
let(:username) { Faker::Name.name }
|
|
10
|
-
let(:webhook) { Faker::Internet.url }
|
|
11
|
-
let(:emoji) { Faker::Internet.url }
|
|
12
|
-
|
|
13
|
-
let(:config_file) do
|
|
14
|
-
{
|
|
15
|
-
slack: {
|
|
16
|
-
slack_option: true,
|
|
17
|
-
username: username,
|
|
18
|
-
icon_emoji: emoji,
|
|
19
|
-
channel: channel,
|
|
20
|
-
webhook_url: webhook
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
before :each do
|
|
26
|
-
allow(YAML).to receive(:load_file).and_return(config_file)
|
|
27
|
-
allow(File).to receive(:exist?).and_return(true)
|
|
28
|
-
SlackMessaging::Config.load(Faker::Lorem.word)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
subject { SlackMessaging::NotifySlack.new(sentence) }
|
|
32
|
-
|
|
33
|
-
it 'should call HTTParty' do
|
|
34
|
-
expect(HTTParty).to receive(:post)
|
|
35
|
-
subject.perform
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should define certain values' do
|
|
39
|
-
expect(subject.text).to eq(sentence)
|
|
40
|
-
expect(subject.channel).to eq(channel)
|
|
41
|
-
expect(subject.username).to eq(username)
|
|
42
|
-
expect(subject.webhook_url).to eq(webhook)
|
|
43
|
-
expect(subject.icon_emoji).to eq(emoji)
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'slack_messaging'
|
|
5
|
-
|
|
6
|
-
describe SlackMessaging::RandomMessage do
|
|
7
|
-
let(:quote_object) { double(:quote_object, body: quote_json) }
|
|
8
|
-
|
|
9
|
-
let(:quote_json) do
|
|
10
|
-
"{\"_id\":\"4MRaRRKq4Tcg\",
|
|
11
|
-
\"tags\":[\"famous-quotes\"],
|
|
12
|
-
\"content\":\"There are two ways of spreading light: to be the candle or the mirror that reflects it.\",
|
|
13
|
-
\"author\":\"Edith Wharton\",\"length\":87
|
|
14
|
-
}"
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
before do
|
|
18
|
-
allow(HTTParty).to receive(:get).and_return(quote_object)
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
subject { SlackMessaging::RandomMessage }
|
|
22
|
-
|
|
23
|
-
it 'should get a string message' do
|
|
24
|
-
message = subject.acquire_random_quote
|
|
25
|
-
expect(message).to be_instance_of(String)
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
it 'should get a message that includes a newline' do
|
|
29
|
-
message = subject.acquire_random_quote
|
|
30
|
-
expect(message.include?("\n")).to eq(true)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'should get a message that includes a —' do
|
|
34
|
-
message = subject.acquire_random_quote
|
|
35
|
-
expect(message.include?('—')).to eq(true)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should use HTTParty to ping an API' do
|
|
39
|
-
expect(HTTParty).to receive(:get)
|
|
40
|
-
subject.acquire_random_quote
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'should have the JSON parse the response content twice' do
|
|
44
|
-
expect(JSON).to receive(:parse).at_least(2).times.and_return(JSON.parse(quote_json))
|
|
45
|
-
subject.acquire_random_quote
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'spec_helper'
|
|
4
|
-
require 'slack_messaging'
|
|
5
|
-
|
|
6
|
-
describe SlackMessaging::Setup do
|
|
7
|
-
let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
|
|
8
|
-
let(:answers) do
|
|
9
|
-
{
|
|
10
|
-
channel: Faker::Lorem.word,
|
|
11
|
-
username: Faker::Lorem.word,
|
|
12
|
-
webhook_url: Faker::Internet.url,
|
|
13
|
-
icon_emoji: ":#{Faker::Lorem.word}:"
|
|
14
|
-
}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
before do
|
|
18
|
-
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
|
19
|
-
allow(subject).to receive(:puts)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
after do
|
|
23
|
-
SlackMessaging::Setup.instance_variable_set('@highline', nil)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
subject { SlackMessaging::Setup }
|
|
27
|
-
|
|
28
|
-
describe '#self.execute' do
|
|
29
|
-
it 'should ask a question if the config file exists' do
|
|
30
|
-
allow(subject).to receive(:config_file_exists?).and_return(true)
|
|
31
|
-
allow(File).to receive(:exists?).and_return(true)
|
|
32
|
-
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
|
33
|
-
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
|
34
|
-
allow(subject).to receive(:ask_config_questions).and_return(true)
|
|
35
|
-
subject.execute
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'should call to create or update the config file' do
|
|
39
|
-
allow(File).to receive(:exists?).and_return(true)
|
|
40
|
-
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
|
41
|
-
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
|
42
|
-
expect(subject).to receive(:ask_config_questions).and_return(true)
|
|
43
|
-
subject.execute
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'should skip if the user opts not to continue' do
|
|
47
|
-
allow(subject).to receive(:config_file_exists?).and_return(true)
|
|
48
|
-
allow(File).to receive(:exists?).and_return(true)
|
|
49
|
-
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
|
50
|
-
expect(subject).not_to receive(:create_or_update_config_file)
|
|
51
|
-
expect(subject).not_to receive(:ask_config_questions)
|
|
52
|
-
subject.execute
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
describe '#self.create_or_update_config_file' do
|
|
57
|
-
it 'should generate the file based on the answers to the questions' do
|
|
58
|
-
expect(subject).to receive(:generate_config_file)
|
|
59
|
-
allow(File).to receive(:open).and_return(nil)
|
|
60
|
-
subject.send(:create_or_update_config_file, answers)
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it 'should open the file for writing' do
|
|
64
|
-
allow(subject).to receive(:generate_config_file)
|
|
65
|
-
expect(File).to receive(:open).and_return(nil)
|
|
66
|
-
subject.send(:create_or_update_config_file, answers)
|
|
67
|
-
end
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
describe '#self.generate_config_file' do
|
|
71
|
-
it 'returns a string' do
|
|
72
|
-
expect(subject.send(:generate_config_file, answers)).to be_a(String)
|
|
73
|
-
end
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
describe '#self.config_file_exists?' do
|
|
77
|
-
it 'should return true if the file exists' do
|
|
78
|
-
allow(File).to receive(:exist?).and_return(true)
|
|
79
|
-
expect(subject.send(:config_file_exists?)).to eq(true)
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it 'should return false if the file does not exist' do
|
|
83
|
-
allow(File).to receive(:exist?).and_return(false)
|
|
84
|
-
expect(subject.send(:config_file_exists?)).to eq(false)
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
describe '#self.ask_question' do
|
|
89
|
-
it 'should use highline to ask a question' do
|
|
90
|
-
expect(highline_wrapper).to receive(:ask).and_return('')
|
|
91
|
-
subject.send(:ask_question, Faker::Lorem.sentence, nil)
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
it 'should return nil if the highline client gets an empty string' do
|
|
95
|
-
allow(highline_wrapper).to receive(:ask).and_return(nil)
|
|
96
|
-
expect(subject.send(:ask_question, Faker::Lorem.sentence, nil)).to be_nil
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
it 'should return the answer if it is given' do
|
|
100
|
-
answer = Faker::Lorem.sentence
|
|
101
|
-
allow(highline_wrapper).to receive(:ask).and_return(answer)
|
|
102
|
-
expect(subject.send(:ask_question, Faker::Lorem.sentence, :default)).to be(answer)
|
|
103
|
-
end
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
describe '#self.ask_config_questions' do
|
|
107
|
-
it 'should call to ask at least four questions' do
|
|
108
|
-
expect(subject).to receive(:ask_question).at_least(4).times.and_return(Faker::Lorem.word)
|
|
109
|
-
subject.send(:ask_config_questions)
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it 'should return the defaults if nothing is given' do
|
|
113
|
-
slack_url = Faker::Internet.url
|
|
114
|
-
defaults = {
|
|
115
|
-
channel: 'general',
|
|
116
|
-
username: "Let's Get Quoty",
|
|
117
|
-
webhook_url: slack_url,
|
|
118
|
-
icon_emoji: ':mailbox_with_mail:'
|
|
119
|
-
}
|
|
120
|
-
allow(subject).to receive(:ask_question).with(
|
|
121
|
-
"What is your Slack webhook URL? If you don't have one yet, please navigate to https://api.slack.com/messaging/webhooks to create one, and then come back here and paste it in the Terminal.",
|
|
122
|
-
nil,
|
|
123
|
-
required: true
|
|
124
|
-
).and_return(slack_url)
|
|
125
|
-
allow(subject).to receive(:ask_question).with(
|
|
126
|
-
'What slack channel do you wish to post to? (default is "#general")',
|
|
127
|
-
'#general'
|
|
128
|
-
).and_return('general')
|
|
129
|
-
allow(subject).to receive(:ask_question).with(
|
|
130
|
-
"What slack username do you wish to post as? (default is \"Let's Get Quoty\")",
|
|
131
|
-
"Let's Get Quoty"
|
|
132
|
-
).and_return("Let's Get Quoty")
|
|
133
|
-
allow(subject).to receive(:ask_question).with(
|
|
134
|
-
'What emoji would you like to post with (include the colons at the beginning and end of the emoji name)? (default is ":mailbox_with_mail:")',
|
|
135
|
-
':mailbox_with_mail:'
|
|
136
|
-
).and_return(':mailbox_with_mail:')
|
|
137
|
-
expect(subject.send(:ask_config_questions)).to eq(defaults)
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
end
|
data/spec/spec_helper.rb
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require 'faker'
|
|
4
|
-
require 'pry'
|
|
5
|
-
|
|
6
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
7
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
8
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
|
9
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
|
10
|
-
# files.
|
|
11
|
-
#
|
|
12
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
|
13
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
|
14
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
|
15
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
|
16
|
-
# a separate helper file that requires the additional dependencies and performs
|
|
17
|
-
# the additional setup, and require it from the spec files that actually need
|
|
18
|
-
# it.
|
|
19
|
-
#
|
|
20
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
|
21
|
-
# users commonly want.
|
|
22
|
-
#
|
|
23
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
24
|
-
RSpec.configure do |config|
|
|
25
|
-
# rspec-expectations config goes here. You can use an alternate
|
|
26
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
|
27
|
-
# assertions if you prefer.
|
|
28
|
-
config.expect_with :rspec do |expectations|
|
|
29
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
|
30
|
-
# and `failure_message` of custom matchers include text for helper methods
|
|
31
|
-
# defined using `chain`, e.g.:
|
|
32
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
|
33
|
-
# # => "be bigger than 2 and smaller than 4"
|
|
34
|
-
# ...rather than:
|
|
35
|
-
# # => "be bigger than 2"
|
|
36
|
-
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
config.filter_run focus: true
|
|
40
|
-
config.run_all_when_everything_filtered = true
|
|
41
|
-
|
|
42
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
|
43
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
|
44
|
-
config.mock_with :rspec do |mocks|
|
|
45
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
|
46
|
-
# a real object. This is generally recommended, and will default to
|
|
47
|
-
# `true` in RSpec 4.
|
|
48
|
-
mocks.verify_partial_doubles = true
|
|
49
|
-
end
|
|
50
|
-
end
|