edi 0.1.2
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 +7 -0
- data/.gitignore +23 -0
- data/.rspec +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/Guardfile +47 -0
- data/LICENSE.txt +22 -0
- data/README.md +129 -0
- data/Rakefile +11 -0
- data/bin/edi +12 -0
- data/edi.gemspec +40 -0
- data/features/fact_service.feature +7 -0
- data/features/giphy_service.feature +43 -0
- data/features/i_heart_quotes_service.feature +21 -0
- data/features/step_definitions/fact_service_steps.rb +7 -0
- data/features/step_definitions/giphy_steps.rb +3 -0
- data/features/step_definitions/server_steps.rb +3 -0
- data/features/step_definitions/tweet_that_steps.rb +19 -0
- data/features/step_definitions/weather_steps.rb +3 -0
- data/features/support/env.rb +37 -0
- data/features/support/hooks.rb +1 -0
- data/features/support/vcr_cassettes/Fact_Service/EDI_responds_with_a_random_fact.yml +53 -0
- data/features/support/vcr_cassettes/Fact_Service/Jarvis_responds_with_a_random_fact.yml +52 -0
- data/features/support/vcr_cassettes/Giphy_Service/Bacon.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Cat_GIF_-_Cat_Wording.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Cat_GIF_-_Kitty_Wording.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Cat_GIF_-_Kitty_Wording_-_Case_Insensitive.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Plain_old_GIF.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Sloth.yml +58 -0
- data/features/support/vcr_cassettes/Giphy_Service/Trippy.yml +58 -0
- data/features/support/vcr_cassettes/I_Heart_Quotes/A_Random_Quote.yml +44 -0
- data/features/support/vcr_cassettes/I_Heart_Quotes/A_Simpsons_Quote.yml +44 -0
- data/features/support/vcr_cassettes/I_Heart_Quotes/A_Star_Wars_Quote.yml +44 -0
- data/features/support/vcr_cassettes/Tweet_that/Post_the_last_message_to_twitter.yml +211 -0
- data/features/support/vcr_cassettes/Weather_Service/Use_a_specified_location.yml +86 -0
- data/features/support/vcr_cassettes/Weather_Service/Use_default_location.yml +86 -0
- data/features/tweet_that_service.feature +14 -0
- data/features/weather_service.feature +21 -0
- data/lib/edi.rb +53 -0
- data/lib/edi/api/response.rb +22 -0
- data/lib/edi/application.rb +39 -0
- data/lib/edi/cli.rb +61 -0
- data/lib/edi/configuration.rb +26 -0
- data/lib/edi/core_ext.rb +1 -0
- data/lib/edi/core_ext/symbol.rb +7 -0
- data/lib/edi/exceptions.rb +8 -0
- data/lib/edi/http_utilities.rb +40 -0
- data/lib/edi/interpreter.rb +32 -0
- data/lib/edi/refinements.rb +1 -0
- data/lib/edi/refinements/zip_refinement.rb +11 -0
- data/lib/edi/scheduler.rb +21 -0
- data/lib/edi/server.rb +45 -0
- data/lib/edi/service.rb +89 -0
- data/lib/edi/services.rb +9 -0
- data/lib/edi/services/dice.rb +25 -0
- data/lib/edi/services/eightball.rb +38 -0
- data/lib/edi/services/fact.rb +7 -0
- data/lib/edi/services/giphy.rb +38 -0
- data/lib/edi/services/i_heart_quotes.rb +29 -0
- data/lib/edi/services/img_flip.rb +69 -0
- data/lib/edi/services/img_flip_memes/afraid_to_ask.rb +17 -0
- data/lib/edi/services/img_flip_memes/and_its_gone.rb +17 -0
- data/lib/edi/services/img_flip_memes/base_meme.rb +57 -0
- data/lib/edi/services/img_flip_memes/everywhere.rb +15 -0
- data/lib/edi/services/img_flip_memes/gonna_have_a_bad_time.rb +17 -0
- data/lib/edi/services/img_flip_memes/most_interesting_man.rb +13 -0
- data/lib/edi/services/img_flip_memes/not_sure_if.rb +13 -0
- data/lib/edi/services/img_flip_memes/one_does_not_simply.rb +17 -0
- data/lib/edi/services/img_flip_memes/overly_attached_girlfriend.rb +13 -0
- data/lib/edi/services/img_flip_memes/picard.rb +13 -0
- data/lib/edi/services/img_flip_memes/success_kid.rb +13 -0
- data/lib/edi/services/img_flip_memes/sudden_clarity.rb +13 -0
- data/lib/edi/services/img_flip_memes/what_if_i_told_you.rb +17 -0
- data/lib/edi/services/img_flip_memes/willy_wonka.rb +13 -0
- data/lib/edi/services/img_flip_memes/y_u_no.rb +17 -0
- data/lib/edi/services/null_service.rb +5 -0
- data/lib/edi/services/tweet_that.rb +68 -0
- data/lib/edi/services/weather.rb +42 -0
- data/lib/edi/slack.rb +1 -0
- data/lib/edi/slack/message.rb +17 -0
- data/lib/edi/test_support/cucumber.rb +1 -0
- data/lib/edi/test_support/test_support.rb +27 -0
- data/lib/edi/utilities/array_responder.rb +16 -0
- data/lib/edi/version.rb +3 -0
- data/spec/edi/edi_spec.rb +29 -0
- data/spec/edi/interpreter_spec.rb +61 -0
- data/spec/edi/server_spec.rb +20 -0
- data/spec/edi/service_spec.rb +112 -0
- data/spec/services/dice_spec.rb +22 -0
- data/spec/services/eightball_spec.rb +9 -0
- data/spec/services/fact_spec.rb +7 -0
- data/spec/services/giphy_spec.rb +46 -0
- data/spec/services/i_heart_quotes_spec.rb +50 -0
- data/spec/services/img_flip_spec.rb +89 -0
- data/spec/services/null_service_spec.rb +3 -0
- data/spec/services/tweet_that_spec.rb +18 -0
- data/spec/services/weather_spec.rb +17 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/fixtures/vcr_cassettes/fact.yml +57 -0
- data/spec/support/fixtures/vcr_cassettes/giphy.yml +513 -0
- data/spec/support/fixtures/vcr_cassettes/i_heart_quotes.yml +222 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_afraid_to_ask.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_and_its_gone.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_everywhere.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_gonna_have_a_bad_time.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_most_interesting_man.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_not_sure_if.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_one_does_not_simply.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_overly_attached_girlfriend.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_picard.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_success_kid.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_sudden_clarity.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_what_if_I_told_you.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_willy_wonka.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/img_flip_y_u_no.yml +54 -0
- data/spec/support/fixtures/vcr_cassettes/tweet_that.yml +189 -0
- data/spec/support/fixtures/vcr_cassettes/weather.yml +346 -0
- data/spec/support/shared_contexts/server.rb +9 -0
- data/spec/support/shared_contexts/service.rb +10 -0
- data/templates/project/Gemfile +7 -0
- data/templates/project/bot/server.rb +6 -0
- data/templates/project/bot/services/.gitkeep +0 -0
- data/templates/project/config.ru +2 -0
- data/templates/project/config/.gitkeep +0 -0
- data/templates/project/config/environment.rb +12 -0
- data/templates/project/config/initializers/.gitkeep +0 -0
- data/templates/services/%name%.rb.tt +5 -0
- metadata +514 -0
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe EDI::Server do
|
4
|
+
let(:parsed_response) { JSON.parse(last_response.body) }
|
5
|
+
let(:message) { parsed_response["text"] }
|
6
|
+
describe "get /" do
|
7
|
+
before { get "/" }
|
8
|
+
it { expect(last_response).to be_ok }
|
9
|
+
it { expect(message).to eq "Hello, I'm EDI" }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "unfit environment" do
|
13
|
+
let(:slack_message) { slack_outgoing_message(text: "EDI, success kid blah blah blah") }
|
14
|
+
before { service.environment :blah }
|
15
|
+
before { service.phrases "success kid" }
|
16
|
+
before { EDI.register_services :test_service }
|
17
|
+
before { post "/edi", slack_message }
|
18
|
+
it { expect(message).to eq "I'm really sorry, but that service needs to be configured" }
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe EDI::Service do
|
4
|
+
let(:message) { double("Slack::Message") }
|
5
|
+
describe "Validate Environment Variables are Present" do
|
6
|
+
before { service.environment :service_token }
|
7
|
+
subject { service.new message }
|
8
|
+
context "Required Environment not set up" do
|
9
|
+
it { expect { subject.validate_environment }.to raise_exception(EDI::UnfitEnvironmentException) }
|
10
|
+
end
|
11
|
+
|
12
|
+
context "Environment Correctly Set Up" do
|
13
|
+
before { stub_env("SERVICE_TOKEN" => "token") }
|
14
|
+
it { expect { subject.validate_environment }.to_not raise_exception }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "tries lowercase environment variable if uppercase isn't present" do
|
18
|
+
before { service.environment :service_token }
|
19
|
+
before { stub_env("SERVICE_TOKEN" => nil, "service_token" => "token")}
|
20
|
+
subject { service.new message }
|
21
|
+
it { expect { subject.validate_environment }.to_not raise_exception }
|
22
|
+
end
|
23
|
+
|
24
|
+
context "Multiple Required Variables, Some not present" do
|
25
|
+
before { service.environment :service_token, :service_secret }
|
26
|
+
before { stub_env("SERVICE_TOKEN" => "token", "SERVICE_SECRET" => nil, "service_secret" => nil) }
|
27
|
+
it { expect { subject.validate_environment }.to raise_exception(EDI::UnfitEnvironmentException) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "Expose Pattern For the Service to be Interpreted" do
|
32
|
+
before { service.interpreter_pattern /are you up/i }
|
33
|
+
it { expect(service.pattern).to eq /are you up/i }
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "Allow the Developer to make a list of phrases to be concatenated into the interpreter pattern" do
|
37
|
+
context "Accepts a single phrase" do
|
38
|
+
before { service.phrases "success kid" }
|
39
|
+
it { expect(service.pattern ).to eq /success kid/i }
|
40
|
+
end
|
41
|
+
|
42
|
+
context "Multiple Phrases" do
|
43
|
+
before { service.phrases "success kid", "hello world" }
|
44
|
+
it { expect(service.pattern).to eq /success kid|hello world/i }
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "Environment Accessor" do
|
50
|
+
context "Uppercase" do
|
51
|
+
before { service.environment :service_token }
|
52
|
+
before { stub_env("SERVICE_TOKEN" => "token") }
|
53
|
+
subject { service.new message }
|
54
|
+
it { expect(subject.service_token).to eq "token"}
|
55
|
+
end
|
56
|
+
context "Lowercase" do
|
57
|
+
before { service.environment :service_token }
|
58
|
+
before { stub_env("SERVICE_TOKEN" => nil, "service_token" => "token") }
|
59
|
+
subject { service.new message }
|
60
|
+
it { expect(subject.service_token).to eq "token"}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe "invoke_with" do
|
65
|
+
describe "defaults to run" do
|
66
|
+
before do
|
67
|
+
class TestService < EDI::Service
|
68
|
+
def run
|
69
|
+
"Hello World"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
it { expect(service.new(message).invoke).to eq "Hello World" }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe "Can be overridden with #invoke_with" do
|
77
|
+
before do
|
78
|
+
class OtherTestService < EDI::Service
|
79
|
+
invoke_with :call_me_maybe
|
80
|
+
def call_me_maybe
|
81
|
+
"This is crazy"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
it { expect(other_service.new(message).invoke).to eq "This is crazy" }
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
describe "before_invoke" do
|
91
|
+
before { class TestService < EDI::Service
|
92
|
+
before_invoke :puts_hello
|
93
|
+
def puts_hello
|
94
|
+
puts "Hello"
|
95
|
+
end
|
96
|
+
end }
|
97
|
+
|
98
|
+
it { expect { service.new(message).invoke }.to output("Hello\n").to_stdout }
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "after_invoke" do
|
102
|
+
before { class TestService < EDI::Service
|
103
|
+
after_invoke :puts_hello
|
104
|
+
def puts_hello
|
105
|
+
puts "Hello"
|
106
|
+
end
|
107
|
+
end }
|
108
|
+
|
109
|
+
it { expect { service.new(message).invoke }.to output("Hello\n").to_stdout }
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Dice do
|
4
|
+
context "d6" do
|
5
|
+
let(:message) { Slack::Message.new slack_outgoing_message(text: "EDI, roll 1d6") }
|
6
|
+
subject { described_class.new(message) }
|
7
|
+
before { allow(subject).to receive(:roll) { 5 }}
|
8
|
+
it { expect(subject.invoke).to eq "You got a 5" }
|
9
|
+
end
|
10
|
+
context "2d6" do
|
11
|
+
let(:message) { Slack::Message.new slack_outgoing_message(text: "EDI, roll 2d6") }
|
12
|
+
subject { described_class.new(message) }
|
13
|
+
before { allow(subject).to receive(:roll).and_return(1, 6) }
|
14
|
+
it { expect(subject.invoke).to eq "You got a 7" }
|
15
|
+
end
|
16
|
+
context "5d20" do
|
17
|
+
let(:message) { Slack::Message.new slack_outgoing_message(text: "EDI, roll 5d20") }
|
18
|
+
subject { described_class.new(message) }
|
19
|
+
before { allow(subject).to receive(:roll).and_return(1, 12, 20, 3, 4) }
|
20
|
+
it { expect(subject.invoke).to eq "You got a 40" }
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Eightball do
|
4
|
+
|
5
|
+
let(:message) { Slack::Message.new slack_outgoing_message(text: "EDI, will I ship this gem today?")}
|
6
|
+
subject { described_class.new(message) }
|
7
|
+
before { allow_any_instance_of(Array).to receive(:sample) { "Outlook not so good" } }
|
8
|
+
specify { expect(subject.invoke).to eq "Outlook not so good" }
|
9
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Fact, vcr: { cassette_name: 'fact' } do
|
4
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, fact")) }
|
5
|
+
subject { described_class.new message }
|
6
|
+
it { expect(subject.invoke).to eq "182 is the carat of the Star of Bombay cabochon-cut star sapphire originating from Sri Lanka." }
|
7
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Giphy, vcr: { cassette_name: 'giphy', :record => :new_episodes} do
|
4
|
+
before { stub_env("GIPHY_API_VERSION" => "v1", "GIPHY_API_KEY" => "key") }
|
5
|
+
describe "Any old GIF" do
|
6
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a gif please")) }
|
7
|
+
subject { described_class.new message }
|
8
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/10BhvFXneBD6X6/giphy.gif" }
|
9
|
+
it { expect(subject.send(:additional_params)).to eq "" } # No tags
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "Cat GIF" do
|
13
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a cat gif please")) }
|
14
|
+
subject { described_class.new message }
|
15
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/4u8WdgQEMVaj6/giphy.gif" }
|
16
|
+
it { expect(subject.send(:additional_params)).to eq "&tag=cat" }
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "Kitty GIF" do
|
20
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a Kitty gif please")) }
|
21
|
+
subject { described_class.new message }
|
22
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/4u8WdgQEMVaj6/giphy.gif" }
|
23
|
+
it { expect(subject.send(:additional_params)).to eq "&tag=cat" }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "Sloth GIF" do
|
27
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a sloth gif please")) }
|
28
|
+
subject { described_class.new message }
|
29
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/FsjDdnIRcroIM/giphy.gif" }
|
30
|
+
it { expect(subject.send(:additional_params)).to eq "&tag=sloth" }
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "Bacon GIF" do
|
34
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a bacon gif please")) }
|
35
|
+
subject { described_class.new message }
|
36
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/La4sAOzY9H8L6/giphy.gif" }
|
37
|
+
it { expect(subject.send(:additional_params)).to eq "&tag=bacon" }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "Trippy GIF" do
|
41
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a trippy gif please")) }
|
42
|
+
subject { described_class.new message }
|
43
|
+
it { expect(subject.invoke).to eq "http://s3.amazonaws.com/giphymedia/media/muAhZqHWt0bv2/giphy.gif" }
|
44
|
+
it { expect(subject.send(:additional_params)).to eq "&tag=trippy" }
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe IHeartQuotes, vcr: { cassette_name: 'i_heart_quotes', :record => :new_episodes} do
|
4
|
+
describe "A random quote" do
|
5
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a quote please")) }
|
6
|
+
subject { described_class.new message }
|
7
|
+
it { expect(subject.invoke).to eq "Prosperity makes friends, adversity tries them.\n\t\t-- Publilius Syrus" }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Simpsons Quotes" do
|
11
|
+
let(:simpsons_response) { "Homer:\tI don't want you to see me sitting on my worthless butt.\n\nBart:\tWe've seen it, Dad.\n\n\t\t Homer at the Bat" }
|
12
|
+
context "Homer" do
|
13
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a homer quote please")) }
|
14
|
+
subject { described_class.new message }
|
15
|
+
it { expect(subject.invoke).to eq simpsons_response }
|
16
|
+
end
|
17
|
+
context "Simpsons" do
|
18
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a simpsons quote please")) }
|
19
|
+
subject { described_class.new message }
|
20
|
+
it { expect(subject.invoke).to eq simpsons_response }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "Star Wars" do
|
25
|
+
let(:star_wars_response) { "Han Solo:\n\tAfraid I was gonna leave without giving you a\n\tgoodbye kiss?\nPrincess Leia:\n\tI'd just as soon kiss a Wookiee!\nHan Solo:\n\tI can arrange that! You could use a good kiss!" }
|
26
|
+
context "Star Wars" do
|
27
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a star wars quote please")) }
|
28
|
+
subject { described_class.new message }
|
29
|
+
it { expect(subject.invoke).to eq star_wars_response }
|
30
|
+
end
|
31
|
+
|
32
|
+
context "Luke" do
|
33
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a luke quote please")) }
|
34
|
+
subject { described_class.new message }
|
35
|
+
it { expect(subject.invoke).to eq star_wars_response }
|
36
|
+
end
|
37
|
+
|
38
|
+
context "Leia" do
|
39
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a leia quote please")) }
|
40
|
+
subject { described_class.new message }
|
41
|
+
it { expect(subject.invoke).to eq star_wars_response }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "Vader" do
|
45
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, a darth vader quote please")) }
|
46
|
+
subject { described_class.new message }
|
47
|
+
it { expect(subject.invoke).to eq star_wars_response }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe ImgFlip do
|
4
|
+
# before { stub_env("IMGFLIP_USER" => "imgflip_user", "IMGFLIP_PASSWORD" => "imgflip_password") }
|
5
|
+
describe "Success Kid", vcr: { cassette_name: 'img_flip_success_kid', :record => :new_episodes} do
|
6
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, success kid hello, world")) }
|
7
|
+
subject { described_class.new message }
|
8
|
+
let(:meme_link) { "http://i.imgflip.com/hz9zo.jpg" }
|
9
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
10
|
+
end
|
11
|
+
describe "Afraid to Ask Andy", vcr: { cassette_name: 'img_flip_afraid_to_ask', :record => :new_episodes} do
|
12
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, I'm not sure how to mock third party apis, and at this point, I'm afraid to ask")) }
|
13
|
+
subject { described_class.new message }
|
14
|
+
let(:meme_link) { "http://i.imgflip.com/hza6u.jpg" }
|
15
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
16
|
+
end
|
17
|
+
describe "And It's Gone", vcr: { cassette_name: 'img_flip_and_its_gone', :record => :new_episodes} do
|
18
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, you have some services here, and it's gone")) }
|
19
|
+
subject { described_class.new message }
|
20
|
+
let(:meme_link) { "http://i.imgflip.com/hzqv7.jpg" }
|
21
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
22
|
+
end
|
23
|
+
describe "Everywhere", vcr: { cassette_name: 'img_flip_everywhere', :record => :new_episodes} do
|
24
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, tests, tests everywhere")) }
|
25
|
+
subject { described_class.new message }
|
26
|
+
let(:meme_link) { "http://i.imgflip.com/hzr5m.jpg" }
|
27
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
28
|
+
end
|
29
|
+
describe "Everywhere", vcr: { cassette_name: 'img_flip_gonna_have_a_bad_time', :record => :new_episodes} do
|
30
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, if you mock when you should use a real object, you're gonna have a bad time")) }
|
31
|
+
subject { described_class.new message }
|
32
|
+
let(:meme_link) { "http://i.imgflip.com/hzrd1.jpg" }
|
33
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
34
|
+
end
|
35
|
+
describe "Most Interesting Man", vcr: { cassette_name: 'img_flip_most_interesting_man', :record => :new_episodes} do
|
36
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, I don't always ci my code, but when I do, I do it on Travis")) }
|
37
|
+
subject { described_class.new message }
|
38
|
+
let(:meme_link) { "http://i.imgflip.com/hzrnq.jpg" }
|
39
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
40
|
+
end
|
41
|
+
describe "Not Sure If", vcr: { cassette_name: 'img_flip_not_sure_if', :record => :new_episodes} do
|
42
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, Not sure if this test is going to pass, or if it's gonna break the build")) }
|
43
|
+
subject { described_class.new message }
|
44
|
+
let(:meme_link) { "http://i.imgflip.com/hzrz0.jpg" }
|
45
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
46
|
+
end
|
47
|
+
describe "One Does Not Simply", vcr: { cassette_name: 'img_flip_one_does_not_simply', :record => :new_episodes} do
|
48
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, one does not simply write rspecs")) }
|
49
|
+
subject { described_class.new message }
|
50
|
+
let(:meme_link) { "http://i.imgflip.com/hzs4e.jpg" }
|
51
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
52
|
+
end
|
53
|
+
describe "Overly Attached Girlfriend", vcr: { cassette_name: 'img_flip_overly_attached_girlfriend', :record => :new_episodes} do
|
54
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, overly attached girlfriend I looked at your slack channel, who is this jarvis you keep talking to?")) }
|
55
|
+
subject { described_class.new message }
|
56
|
+
let(:meme_link) { "http://i.imgflip.com/hzsbu.jpg" }
|
57
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
58
|
+
end
|
59
|
+
describe "Picard", vcr: { cassette_name: 'img_flip_picard', :record => :new_episodes} do
|
60
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, picard why the fuck, did you make so many memes?")) }
|
61
|
+
subject { described_class.new message }
|
62
|
+
let(:meme_link) { "http://i.imgflip.com/hzsgd.jpg" }
|
63
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
64
|
+
end
|
65
|
+
describe "Sudden Clarity", vcr: { cassette_name: 'img_flip_sudden_clarity', :record => :new_episodes} do
|
66
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, sudden clarity can't think of, anything clever right now")) }
|
67
|
+
subject { described_class.new message }
|
68
|
+
let(:meme_link) { "http://i.imgflip.com/hzspk.jpg" }
|
69
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
70
|
+
end
|
71
|
+
describe "What if I Told You", vcr: { cassette_name: 'img_flip_what_if_I_told_you', :record => :new_episodes} do
|
72
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI, what if I told you EDI is the best bot ever?")) }
|
73
|
+
subject { described_class.new message }
|
74
|
+
let(:meme_link) { "http://i.imgflip.com/hzsv9.jpg" }
|
75
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
76
|
+
end
|
77
|
+
describe "Willy Wonka", vcr: { cassette_name: 'img_flip_willy_wonka', :record => :new_episodes} do
|
78
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI willy wonka hello, world")) }
|
79
|
+
subject { described_class.new message }
|
80
|
+
let(:meme_link) { "http://i.imgflip.com/hzt18.jpg" }
|
81
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
82
|
+
end
|
83
|
+
describe "Y U No", vcr: { cassette_name: 'img_flip_y_u_no', :record => :new_episodes} do
|
84
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(user_name: "DVG", text: "EDI y u no sql")) }
|
85
|
+
subject { described_class.new message }
|
86
|
+
let(:meme_link) { "http://i.imgflip.com/hzt5g.jpg" }
|
87
|
+
it { expect(subject.invoke).to eq "Here you go, DVG\n\n#{meme_link}" }
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe TweetThat, vcr: { cassette_name: 'tweet_that', :record => :new_episodes} do
|
4
|
+
describe "Tweet last message" do
|
5
|
+
before do
|
6
|
+
stub_env "SLACK_TOKEN" => "slack_token",
|
7
|
+
"TWITTER_ACCESS_TOKEN" => "twitter_access_token",
|
8
|
+
"TWITTER_CONSUMER_KEY" => "twitter_consumer_key",
|
9
|
+
"TWITTER_CONSUMER_SECRET" => "twitter_consumer_secret",
|
10
|
+
"TWITTER_HANDLE" => "twitter_handle",
|
11
|
+
"TWITTER_TOKEN_SECRET" => "twitter_token_secret"
|
12
|
+
|
13
|
+
end
|
14
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, tweet that", channel_id: "C0000001", user_name: "DVG")) }
|
15
|
+
subject { described_class.new message }
|
16
|
+
it { expect(subject.invoke).to eq "Here you are, DVG, https://twitter.com/twitter_handle/status/569329768350380032" }
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Weather, vcr: { cassette_name: 'weather', :record => :new_episodes} do
|
4
|
+
describe "Providing a ZIP" do
|
5
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, what's the weather in 90210")) }
|
6
|
+
subject { described_class.new message }
|
7
|
+
it { expect(subject.invoke).to eq "Sky is clear. The temperature is currently 60" }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "Default Location" do
|
11
|
+
before {stub_env('DEFAULT_LOCATION' => "43123")}
|
12
|
+
let(:message) { Slack::Message.new(slack_outgoing_message(text: "EDI, what's the weather")) }
|
13
|
+
subject { described_class.new message }
|
14
|
+
it { expect(subject.invoke).to eq "Light rain. The temperature is currently 35" }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
ENV['RACK_ENV'] = 'test'
|
2
|
+
require 'rspec'
|
3
|
+
require 'rack/test'
|
4
|
+
require 'json'
|
5
|
+
require 'edi'
|
6
|
+
require 'byebug'
|
7
|
+
require 'vcr'
|
8
|
+
require_relative './support/shared_contexts/service'
|
9
|
+
require_relative './support/shared_contexts/server'
|
10
|
+
require 'edi/test_support/test_support'
|
11
|
+
|
12
|
+
include Rack::Test::Methods
|
13
|
+
include EDI::TestSupport
|
14
|
+
|
15
|
+
def app
|
16
|
+
EDI::Server
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.expose_dsl_globally = false
|
21
|
+
config.around(:each) do |example|
|
22
|
+
class TestService < EDI::Service
|
23
|
+
def run
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
class OtherTestService < EDI::Service
|
28
|
+
def run
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
class TestServer < EDI::Server
|
33
|
+
end
|
34
|
+
|
35
|
+
example.run
|
36
|
+
|
37
|
+
EDI.clear_services
|
38
|
+
|
39
|
+
Object.send :remove_const, :TestServer
|
40
|
+
Object.send :remove_const, :TestService
|
41
|
+
Object.send :remove_const, :OtherTestService
|
42
|
+
end
|
43
|
+
config.include ServerContext
|
44
|
+
config.include ServiceContext
|
45
|
+
end
|
46
|
+
|
47
|
+
VCR.configure do |config|
|
48
|
+
config.cassette_library_dir = "spec/support/fixtures/vcr_cassettes"
|
49
|
+
config.configure_rspec_metadata!
|
50
|
+
config.hook_into :webmock
|
51
|
+
end
|