slack_messaging 2.2.0 → 3.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/Guardfile +3 -1
- data/LICENSE.md +11 -0
- data/README.md +21 -11
- data/Rakefile +2 -0
- data/bin/slack-messaging +16 -12
- data/lib/slack_messaging.rb +6 -2
- data/lib/slack_messaging/config.rb +20 -17
- data/lib/slack_messaging/default_paths.rb +9 -7
- data/lib/slack_messaging/notify_slack.rb +2 -0
- data/lib/slack_messaging/random_message.rb +3 -1
- data/lib/slack_messaging/send.rb +24 -0
- data/lib/slack_messaging/setup.rb +72 -66
- data/lib/slack_messaging/version.rb +3 -1
- data/spec/slack_messaging/config_spec.rb +9 -7
- data/spec/slack_messaging/notify_slack_spec.rb +16 -16
- data/spec/slack_messaging/random_message_spec.rb +2 -0
- data/spec/slack_messaging/setup_spec.rb +43 -35
- data/spec/spec_helper.rb +3 -1
- metadata +24 -14
- data/Gemfile.lock +0 -106
- data/LICENSE +0 -22
- data/lib/slack_messaging/highline_cli.rb +0 -33
- data/lib/slack_messaging/slack.rb +0 -22
- data/spec/slack_messaging/highline_cli_spec.rb +0 -49
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5c4c7aef44ea0d755210046e0f211673f25e69fca20f702304b3943c11ae3903
|
4
|
+
data.tar.gz: 27ba520ee53f03706b1b64dae70d768825990c2bad7680901b912f74e4a956ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fc66d9bda665075b85519d8d5bf7d0ef8b87fb81c882e73a1e8d24d4fd816e64f3204ba08606991b3246b4e9f568689ed1be1585b55d6362015e550ef7c4395
|
7
|
+
data.tar.gz: 34ec445b8de695759dd74382e18dab2be6ad74eed7d341e0b4ee67941231d97f469a17da68b83226c3aa229e8a1c57b52e6ac293d69d01ec70e3d8b70906ed96
|
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
|
2
4
|
watch(%r{^spec/.+_spec\.rb$})
|
3
5
|
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
4
6
|
watch('spec/spec_helper.rb') { 'spec' }
|
data/LICENSE.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Copyright (c) 2014 Emma Sax. All rights reserved.
|
2
|
+
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
4
|
+
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
|
6
|
+
|
7
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
8
|
+
|
9
|
+
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
+
|
11
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Slack Messaging [![
|
1
|
+
# Slack Messaging [![Main](https://github.com/emmahsax/slack_messaging/actions/workflows/main.yml/badge.svg)](https://github.com/emmahsax/slack_messaging/actions/workflows/main.yml)
|
2
2
|
|
3
3
|
This is a simple project designed to post messages to a given Slack channel as a bot.
|
4
4
|
|
@@ -22,7 +22,7 @@ Or install it yourself as:
|
|
22
22
|
gem install slack_messaging
|
23
23
|
```
|
24
24
|
|
25
|
-
|
25
|
+
## Usage
|
26
26
|
|
27
27
|
This project requires a config file that should look like this:
|
28
28
|
|
@@ -53,7 +53,7 @@ mv ~/.slack_messaging.yml /PATH/TO/FILE/config.yml
|
|
53
53
|
And then you can pass in that specific file location like this:
|
54
54
|
|
55
55
|
```bash
|
56
|
-
slack-messaging --config="/PATH/TO/FILE/config.yml"
|
56
|
+
slack-messaging --config="/PATH/TO/FILE/config.yml" send
|
57
57
|
```
|
58
58
|
|
59
59
|
Once the config file is set up, the project is ready to go!
|
@@ -61,7 +61,7 @@ Once the config file is set up, the project is ready to go!
|
|
61
61
|
To print a friendly message to Slack, run:
|
62
62
|
|
63
63
|
```bash
|
64
|
-
slack-messaging
|
64
|
+
slack-messaging send
|
65
65
|
```
|
66
66
|
|
67
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/).
|
@@ -69,13 +69,13 @@ Here, no specific message is being given to print to Slack, so slack_messaging w
|
|
69
69
|
However, what if you wanted to print something specific? Well, you can! Just run:
|
70
70
|
|
71
71
|
```bash
|
72
|
-
slack-messaging
|
72
|
+
slack-messaging send 'MESSAGE 1'
|
73
73
|
```
|
74
74
|
|
75
75
|
You can even print multiple messages at once:
|
76
76
|
|
77
77
|
```bash
|
78
|
-
slack-messaging
|
78
|
+
slack-messaging send 'MESSAGE 1' 'MESSAGE 2' 'MESSAGE 3' ... 'MESSAGE N'
|
79
79
|
```
|
80
80
|
|
81
81
|
The output of slack_messaging will look something like this:
|
@@ -84,19 +84,29 @@ The output of slack_messaging will look something like this:
|
|
84
84
|
|
85
85
|
I hope you enjoy printing fun and specialized messages to Slack!
|
86
86
|
|
87
|
-
|
87
|
+
## Tests
|
88
88
|
|
89
|
-
To run the tests, run `bundle exec rspec` from the command
|
89
|
+
To run the tests, run `bundle exec rspec` from the command-line. GitHub Actions will also run the tests upon every commit to make sure they're up to date and that everything is working correctly. Locally, you can also run `bundle exec guard` to automatically run tests as you develop!
|
90
90
|
|
91
|
-
|
91
|
+
---
|
92
|
+
|
93
|
+
### Contributing
|
92
94
|
|
93
95
|
To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/slack_messaging/issues/new).
|
94
96
|
|
95
|
-
|
97
|
+
### Security Policy
|
98
|
+
|
99
|
+
To report any security vulnerabilities, please view this repository's [Security Policy](https://github.com/emmahsax/slack_messaging/security/policy).
|
100
|
+
|
101
|
+
### Licensing
|
102
|
+
|
103
|
+
For information on licensing, please see [LICENSE.md](https://github.com/emmahsax/slack_messaging/blob/main/LICENSE.md).
|
104
|
+
|
105
|
+
### Code of Conduct
|
96
106
|
|
97
107
|
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
98
108
|
|
99
|
-
|
109
|
+
### Releasing
|
100
110
|
|
101
111
|
To make a new release of this gem:
|
102
112
|
|
data/Rakefile
CHANGED
data/bin/slack-messaging
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# frozen_string_literal: true
|
4
|
+
|
2
5
|
require 'rubygems'
|
3
6
|
require 'gli'
|
4
7
|
require_relative '../lib/slack_messaging'
|
@@ -10,29 +13,30 @@ version SlackMessaging::VERSION
|
|
10
13
|
|
11
14
|
wrap_help_text :verbatim
|
12
15
|
|
13
|
-
flag [:config], :
|
16
|
+
flag [:config], desc: 'Slack Messaging config file path', default_value: SlackMessaging::DefaultPaths.config
|
14
17
|
|
15
|
-
program_long_desc "
|
18
|
+
program_long_desc "
|
16
19
|
DOCUMENTATION
|
17
20
|
For documentation and help in setting up your configuration files,
|
18
21
|
see Slack Messaging's GitHub repo: https://github.com/emmahsax/slack_messaging
|
19
|
-
"
|
22
|
+
"
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
true
|
26
|
-
end
|
24
|
+
pre do |global, _command, _options, _args|
|
25
|
+
SlackMessaging::Config.load(global[:config])
|
26
|
+
true
|
27
|
+
end
|
27
28
|
|
28
|
-
|
29
|
-
|
29
|
+
desc 'Prints a variety of messages to Slack'
|
30
|
+
command 'send' do |c|
|
31
|
+
c.action do |_global_options, options, args|
|
32
|
+
SlackMessaging::Send.execute(args, options)
|
30
33
|
end
|
31
34
|
end
|
32
35
|
|
33
36
|
desc 'Sets up a Slack Messaging config file at ~/.slack_messaging.yml'
|
37
|
+
skips_pre
|
34
38
|
command 'setup' do |c|
|
35
|
-
c.action do
|
39
|
+
c.action do
|
36
40
|
SlackMessaging::Setup.execute
|
37
41
|
end
|
38
42
|
end
|
data/lib/slack_messaging.rb
CHANGED
@@ -1,10 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'yaml'
|
2
4
|
require 'hashie'
|
3
5
|
require 'httparty'
|
4
|
-
require '
|
6
|
+
require 'highline_wrapper'
|
5
7
|
require 'json'
|
6
8
|
|
7
|
-
|
9
|
+
files = "#{File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'slack_messaging'))}/**/*.rb"
|
10
|
+
|
11
|
+
Dir[files].each do |file|
|
8
12
|
require_relative file
|
9
13
|
end
|
10
14
|
|
@@ -1,27 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackMessaging
|
2
4
|
class Config
|
3
|
-
|
4
|
-
|
5
|
-
|
5
|
+
class << self
|
6
|
+
def method_missing(method, args = false)
|
7
|
+
config_data.send(method, args)
|
8
|
+
end
|
6
9
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def load(path)
|
11
|
+
load_config(path)
|
12
|
+
config
|
13
|
+
end
|
11
14
|
|
12
|
-
|
15
|
+
private def config
|
16
|
+
config_data.to_hash
|
17
|
+
end
|
13
18
|
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
private def config_data
|
20
|
+
@config_data ||= Hashie::Mash.new
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
23
|
+
private def load_config(file)
|
24
|
+
raise StandardError, "Missing configuration file: #{file}" unless File.exist?(file)
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
26
|
+
YAML.load_file(file).each { |key, value| config_data.assign_property(key, value) }
|
27
|
+
end
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
@@ -1,13 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackMessaging
|
2
4
|
class DefaultPaths
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
private
|
5
|
+
class << self
|
6
|
+
def config
|
7
|
+
File.join(home, '.slack_messaging.yml')
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
private def home
|
11
|
+
ENV['HOME'] || '.'
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,10 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackMessaging
|
2
4
|
class RandomMessage
|
3
5
|
def self.acquire_random_quote
|
4
6
|
random_quote = HTTParty.get('http://api.quotable.io/random', headers: { 'Content-Type': 'application/json' }).body
|
5
7
|
quote_content = JSON.parse(random_quote)['content']
|
6
8
|
quote_author = JSON.parse(random_quote)['author']
|
7
|
-
|
9
|
+
"\"#{quote_content}\"\n—#{quote_author}"
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SlackMessaging
|
4
|
+
class Send
|
5
|
+
class << self
|
6
|
+
attr_accessor :options
|
7
|
+
|
8
|
+
def execute(args, _options = nil)
|
9
|
+
if args.empty?
|
10
|
+
message = SlackMessaging::RandomMessage.acquire_random_quote
|
11
|
+
print_message(message)
|
12
|
+
else
|
13
|
+
args.each do |arg_message|
|
14
|
+
print_message(arg_message)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private def print_message(message)
|
20
|
+
SlackMessaging::NotifySlack.new(message).perform
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -1,81 +1,87 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module SlackMessaging
|
2
4
|
class Setup
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
class << self
|
6
|
+
# rubocop:disable Style/ConditionalAssignment
|
7
|
+
def execute
|
8
|
+
if config_file_exists?
|
9
|
+
answer = highline.ask_yes_no(
|
10
|
+
"It looks like the #{default_config} file already exists. Do you wish to replace it? (y/n)",
|
11
|
+
{ required: true }
|
12
|
+
)
|
13
|
+
else
|
14
|
+
answer = true
|
10
15
|
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
16
|
|
39
|
-
|
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
|
17
|
+
create_or_update_config_file(ask_config_questions) if answer
|
51
18
|
end
|
19
|
+
# rubocop:enable Style/ConditionalAssignment
|
52
20
|
|
53
|
-
|
54
|
-
|
55
|
-
|
21
|
+
private def create_or_update_config_file(answers)
|
22
|
+
contents = generate_config_file(answers)
|
23
|
+
puts "Creating or updating your #{default_config} file..."
|
24
|
+
File.open(default_config, 'w') { |file| file.puts contents }
|
25
|
+
puts 'Done!'
|
26
|
+
end
|
56
27
|
|
57
|
-
|
58
|
-
|
59
|
-
|
28
|
+
private def generate_config_file(answers)
|
29
|
+
file_contents = ''.dup
|
30
|
+
file_contents << "slack:\n"
|
31
|
+
file_contents << " channel: #{answers[:channel].tr('#', '').strip}\n"
|
32
|
+
file_contents << " username: #{answers[:username].strip}\n"
|
33
|
+
file_contents << " webhook_url: #{answers[:webhook_url].strip}\n"
|
34
|
+
file_contents << " icon_emoji: '#{answers[:icon_emoji].strip}'"
|
35
|
+
file_contents
|
36
|
+
end
|
60
37
|
|
61
|
-
|
62
|
-
|
63
|
-
|
38
|
+
private def config_file_exists?
|
39
|
+
File.exist?(default_config)
|
40
|
+
end
|
64
41
|
|
65
|
-
|
66
|
-
|
42
|
+
# rubocop:disable Metrics/MethodLength
|
43
|
+
private def ask_config_questions
|
44
|
+
answers = {}
|
45
|
+
|
46
|
+
answers[:webhook_url] = ask_question(
|
47
|
+
"What is your Slack webhook URL? If you don't have one yet, please navigate" \
|
48
|
+
' to https://api.slack.com/messaging/webhooks to create one, and then come back' \
|
49
|
+
' here and paste it in the Terminal.',
|
50
|
+
nil,
|
51
|
+
required: true
|
52
|
+
)
|
53
|
+
|
54
|
+
answers[:channel] = ask_question(
|
55
|
+
'What slack channel do you wish to post to? (default is "#general")',
|
56
|
+
'#general'
|
57
|
+
)
|
58
|
+
|
59
|
+
answers[:username] = ask_question(
|
60
|
+
"What slack username do you wish to post as? (default is \"Let's Get Quoty\")",
|
61
|
+
"Let's Get Quoty"
|
62
|
+
)
|
63
|
+
|
64
|
+
answers[:icon_emoji] = ask_question(
|
65
|
+
'What emoji would you like to post with (include the colons at the beginning and end' \
|
66
|
+
' of the emoji name)? (default is ":mailbox_with_mail:")',
|
67
|
+
':mailbox_with_mail:'
|
68
|
+
)
|
69
|
+
|
70
|
+
answers
|
71
|
+
end
|
72
|
+
# rubocop:enable Metrics/MethodLength
|
67
73
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
74
|
+
private def ask_question(prompt, default, required: false)
|
75
|
+
highline.ask(prompt, { default: default, required: required })
|
76
|
+
end
|
72
77
|
|
73
|
-
|
74
|
-
|
75
|
-
|
78
|
+
private def highline
|
79
|
+
@highline ||= HighlineWrapper.new
|
80
|
+
end
|
76
81
|
|
77
|
-
|
78
|
-
|
82
|
+
private def default_config
|
83
|
+
SlackMessaging::DefaultPaths.config
|
84
|
+
end
|
79
85
|
end
|
80
86
|
end
|
81
87
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'slack_messaging'
|
3
5
|
|
@@ -23,13 +25,13 @@ describe SlackMessaging::Config do
|
|
23
25
|
|
24
26
|
let(:config_file) do
|
25
27
|
{
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
33
35
|
}
|
34
36
|
}
|
35
37
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'slack_messaging'
|
3
5
|
|
@@ -10,12 +12,12 @@ describe SlackMessaging::NotifySlack do
|
|
10
12
|
|
11
13
|
let(:config_file) do
|
12
14
|
{
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
slack: {
|
16
|
+
slack_option: true,
|
17
|
+
username: username,
|
18
|
+
icon_emoji: emoji,
|
19
|
+
channel: channel,
|
20
|
+
webhook_url: webhook
|
19
21
|
}
|
20
22
|
}
|
21
23
|
end
|
@@ -26,20 +28,18 @@ describe SlackMessaging::NotifySlack do
|
|
26
28
|
SlackMessaging::Config.load(Faker::Lorem.word)
|
27
29
|
end
|
28
30
|
|
29
|
-
subject { SlackMessaging::NotifySlack }
|
31
|
+
subject { SlackMessaging::NotifySlack.new(sentence) }
|
30
32
|
|
31
33
|
it 'should call HTTParty' do
|
32
34
|
expect(HTTParty).to receive(:post)
|
33
|
-
|
34
|
-
message.perform
|
35
|
+
subject.perform
|
35
36
|
end
|
36
37
|
|
37
|
-
|
38
|
-
|
39
|
-
expect(
|
40
|
-
expect(
|
41
|
-
expect(
|
42
|
-
expect(
|
43
|
-
expect(message.icon_emoji).to eq(emoji)
|
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
44
|
end
|
45
45
|
end
|
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
require 'slack_messaging'
|
3
5
|
|
4
6
|
describe SlackMessaging::Setup do
|
5
|
-
let(:
|
6
|
-
let(:highline_cli) { double(:highline_cli, ask: response, ask_yes_no: true) }
|
7
|
+
let(:highline_wrapper) { double(:highline_wrapper, ask: Faker::Lorem.word, ask_yes_no: true) }
|
7
8
|
let(:answers) do
|
8
9
|
{
|
9
10
|
channel: Faker::Lorem.word,
|
@@ -14,20 +15,21 @@ describe SlackMessaging::Setup do
|
|
14
15
|
end
|
15
16
|
|
16
17
|
before do
|
17
|
-
allow(
|
18
|
+
allow(HighlineWrapper).to receive(:new).and_return(highline_wrapper)
|
18
19
|
allow(subject).to receive(:puts)
|
19
20
|
end
|
20
21
|
|
21
22
|
after do
|
22
|
-
SlackMessaging::Setup.instance_variable_set(
|
23
|
+
SlackMessaging::Setup.instance_variable_set('@highline', nil)
|
23
24
|
end
|
24
25
|
|
25
26
|
subject { SlackMessaging::Setup }
|
26
27
|
|
27
28
|
describe '#self.execute' do
|
28
29
|
it 'should ask a question if the config file exists' do
|
30
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
29
31
|
allow(File).to receive(:exists?).and_return(true)
|
30
|
-
expect(
|
32
|
+
expect(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
31
33
|
allow(subject).to receive(:create_or_update_config_file).and_return(true)
|
32
34
|
allow(subject).to receive(:ask_config_questions).and_return(true)
|
33
35
|
subject.execute
|
@@ -35,18 +37,19 @@ describe SlackMessaging::Setup do
|
|
35
37
|
|
36
38
|
it 'should call to create or update the config file' do
|
37
39
|
allow(File).to receive(:exists?).and_return(true)
|
38
|
-
allow(
|
40
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(true)
|
39
41
|
expect(subject).to receive(:create_or_update_config_file).and_return(true)
|
40
42
|
expect(subject).to receive(:ask_config_questions).and_return(true)
|
41
43
|
subject.execute
|
42
44
|
end
|
43
45
|
|
44
|
-
it 'should
|
46
|
+
it 'should skip if the user opts not to continue' do
|
47
|
+
allow(subject).to receive(:config_file_exists?).and_return(true)
|
45
48
|
allow(File).to receive(:exists?).and_return(true)
|
46
|
-
allow(
|
49
|
+
allow(highline_wrapper).to receive(:ask_yes_no).and_return(false)
|
47
50
|
expect(subject).not_to receive(:create_or_update_config_file)
|
48
51
|
expect(subject).not_to receive(:ask_config_questions)
|
49
|
-
|
52
|
+
subject.execute
|
50
53
|
end
|
51
54
|
end
|
52
55
|
|
@@ -72,61 +75,66 @@ describe SlackMessaging::Setup do
|
|
72
75
|
|
73
76
|
describe '#self.config_file_exists?' do
|
74
77
|
it 'should return true if the file exists' do
|
75
|
-
allow(File).to receive(:
|
78
|
+
allow(File).to receive(:exist?).and_return(true)
|
76
79
|
expect(subject.send(:config_file_exists?)).to eq(true)
|
77
80
|
end
|
78
81
|
|
79
82
|
it 'should return false if the file does not exist' do
|
80
|
-
allow(File).to receive(:
|
83
|
+
allow(File).to receive(:exist?).and_return(false)
|
81
84
|
expect(subject.send(:config_file_exists?)).to eq(false)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
85
88
|
describe '#self.ask_question' do
|
86
89
|
it 'should use highline to ask a question' do
|
87
|
-
expect(
|
88
|
-
subject.send(:ask_question, Faker::Lorem.sentence)
|
90
|
+
expect(highline_wrapper).to receive(:ask).and_return('')
|
91
|
+
subject.send(:ask_question, Faker::Lorem.sentence, nil)
|
89
92
|
end
|
90
93
|
|
91
94
|
it 'should return nil if the highline client gets an empty string' do
|
92
|
-
allow(
|
93
|
-
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be_nil
|
95
|
+
allow(highline_wrapper).to receive(:ask).and_return(nil)
|
96
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence, nil)).to be_nil
|
94
97
|
end
|
95
98
|
|
96
99
|
it 'should return the answer if it is given' do
|
97
100
|
answer = Faker::Lorem.sentence
|
98
|
-
allow(
|
99
|
-
expect(subject.send(:ask_question, Faker::Lorem.sentence)).to be(answer)
|
101
|
+
allow(highline_wrapper).to receive(:ask).and_return(answer)
|
102
|
+
expect(subject.send(:ask_question, Faker::Lorem.sentence, :default)).to be(answer)
|
100
103
|
end
|
101
104
|
end
|
102
105
|
|
103
106
|
describe '#self.ask_config_questions' do
|
104
107
|
it 'should call to ask at least four questions' do
|
105
|
-
expect(subject).to receive(:ask_question).at_least(4).times
|
108
|
+
expect(subject).to receive(:ask_question).at_least(4).times.and_return(Faker::Lorem.word)
|
106
109
|
subject.send(:ask_config_questions)
|
107
110
|
end
|
108
111
|
|
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
112
|
it 'should return the defaults if nothing is given' do
|
115
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
|
+
}
|
116
120
|
allow(subject).to receive(:ask_question).with(
|
117
|
-
"
|
118
|
-
|
119
|
-
|
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
|
120
124
|
).and_return(slack_url)
|
121
|
-
allow(subject).to receive(:ask_question).
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
)
|
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)
|
130
138
|
end
|
131
139
|
end
|
132
140
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'faker'
|
2
4
|
require 'pry'
|
3
5
|
|
@@ -34,7 +36,7 @@ RSpec.configure do |config|
|
|
34
36
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
35
37
|
end
|
36
38
|
|
37
|
-
config.filter_run :
|
39
|
+
config.filter_run focus: true
|
38
40
|
config.run_all_when_everything_filtered = true
|
39
41
|
|
40
42
|
# rspec-mocks config goes here. You can use an alternate test double
|
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:
|
4
|
+
version: 3.1.3
|
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-
|
11
|
+
date: 2021-06-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -53,19 +53,19 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '4.1'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: highline_wrapper
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.1'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '1.1'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: httparty
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
194
|
version: '3.9'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: rubocop
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '1.10'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '1.10'
|
195
209
|
description: Sending Personalized Slack Messages to a Slack channel of your choice.
|
196
210
|
email:
|
197
211
|
executables:
|
@@ -200,9 +214,8 @@ extensions: []
|
|
200
214
|
extra_rdoc_files: []
|
201
215
|
files:
|
202
216
|
- Gemfile
|
203
|
-
- Gemfile.lock
|
204
217
|
- Guardfile
|
205
|
-
- LICENSE
|
218
|
+
- LICENSE.md
|
206
219
|
- QuoteExample.png
|
207
220
|
- README.md
|
208
221
|
- Rakefile
|
@@ -210,21 +223,19 @@ files:
|
|
210
223
|
- lib/slack_messaging.rb
|
211
224
|
- lib/slack_messaging/config.rb
|
212
225
|
- lib/slack_messaging/default_paths.rb
|
213
|
-
- lib/slack_messaging/highline_cli.rb
|
214
226
|
- lib/slack_messaging/notify_slack.rb
|
215
227
|
- lib/slack_messaging/random_message.rb
|
228
|
+
- lib/slack_messaging/send.rb
|
216
229
|
- lib/slack_messaging/setup.rb
|
217
|
-
- lib/slack_messaging/slack.rb
|
218
230
|
- lib/slack_messaging/version.rb
|
219
231
|
- spec/slack_messaging/config_spec.rb
|
220
|
-
- spec/slack_messaging/highline_cli_spec.rb
|
221
232
|
- spec/slack_messaging/notify_slack_spec.rb
|
222
233
|
- spec/slack_messaging/random_message_spec.rb
|
223
234
|
- spec/slack_messaging/setup_spec.rb
|
224
235
|
- spec/spec_helper.rb
|
225
236
|
homepage: https://github.com/emmahsax/slack_messaging
|
226
237
|
licenses:
|
227
|
-
-
|
238
|
+
- BSD-3-Clause
|
228
239
|
metadata: {}
|
229
240
|
post_install_message:
|
230
241
|
rdoc_options: []
|
@@ -234,21 +245,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
245
|
requirements:
|
235
246
|
- - ">="
|
236
247
|
- !ruby/object:Gem::Version
|
237
|
-
version: '
|
248
|
+
version: '2.4'
|
238
249
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
239
250
|
requirements:
|
240
251
|
- - ">="
|
241
252
|
- !ruby/object:Gem::Version
|
242
253
|
version: '0'
|
243
254
|
requirements: []
|
244
|
-
rubygems_version: 3.2.
|
255
|
+
rubygems_version: 3.2.15
|
245
256
|
signing_key:
|
246
257
|
specification_version: 4
|
247
258
|
summary: Personalized Slack Messages
|
248
259
|
test_files:
|
249
260
|
- spec/spec_helper.rb
|
250
261
|
- spec/slack_messaging/config_spec.rb
|
251
|
-
- spec/slack_messaging/highline_cli_spec.rb
|
252
262
|
- spec/slack_messaging/notify_slack_spec.rb
|
253
263
|
- spec/slack_messaging/random_message_spec.rb
|
254
264
|
- spec/slack_messaging/setup_spec.rb
|
data/Gemfile.lock
DELETED
@@ -1,106 +0,0 @@
|
|
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/LICENSE
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
Copyright (c) 2014 Emma Sax
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -1,33 +0,0 @@
|
|
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
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module SlackMessaging
|
2
|
-
class Slack
|
3
|
-
attr_accessor :options
|
4
|
-
|
5
|
-
def self.execute(args, options = nil)
|
6
|
-
if args.empty?
|
7
|
-
message = SlackMessaging::RandomMessage.acquire_random_quote
|
8
|
-
print_message(message)
|
9
|
-
else
|
10
|
-
args.each do |message|
|
11
|
-
print_message(message)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
|
18
|
-
def self.print_message(message)
|
19
|
-
SlackMessaging::NotifySlack.new(message).perform
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,49 +0,0 @@
|
|
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
|