Skip to content

Commit

Permalink
Update Slack::Poster
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Graf committed Jan 31, 2019
1 parent deface8 commit beef6c0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions lib/seal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

require './lib/github_fetcher.rb'
require './lib/message_builder.rb'
require './lib/slack_poster.rb'
require './lib/slack_lib.rb'

# Entry point for the Seal!
class Seal
Expand Down Expand Up @@ -36,7 +36,7 @@ def bark_at(team)
message_builder = MessageBuilder.new(team_params(team), @mode)
message = message_builder.build
channel = ENV["SLACK_CHANNEL"] ? ENV["SLACK_CHANNEL"] : team_config(team)['channel']
slack = SlackPoster.new(ENV['SLACK_WEBHOOK'], channel, message_builder.poster_mood)
slack = SlackLib.new(ENV['SLACK_WEBHOOK'], channel, message_builder.poster_mood)
slack.send_request(message)
end

Expand Down
4 changes: 2 additions & 2 deletions lib/slack_poster.rb → lib/slack_lib.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require 'slack-poster'
require 'slack/poster'

class SlackPoster
class SlackLib

SlackResponseError = Class.new(StandardError)

Expand Down
2 changes: 1 addition & 1 deletion server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require './lib/seal'
require './lib/github_fetcher'
require './lib/message_builder'
require './lib/slack_poster'
require './lib/slack_lib'

class SealApp < Sinatra::Base

Expand Down
4 changes: 2 additions & 2 deletions spec/seal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
expect(MessageBuilder).to receive(:new)
.exactly(number_of_teams).times
.and_return(instance_double(MessageBuilder, build: nil, poster_mood: nil))
expect(SlackPoster).to receive(:new)
expect(SlackLib).to receive(:new)
.exactly(number_of_teams).times
.and_return(instance_double(SlackPoster, send_request: nil))
.and_return(instance_double(SlackLib, send_request: nil))
end

context 'given a team "tigers"' do
Expand Down
28 changes: 14 additions & 14 deletions spec/slack_poster_spec.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require 'spec_helper'
require './lib/slack_poster'
require './lib/slack_lib'

describe 'slack_poster' do
subject(:slack_poster) { SlackPoster.new(webhook_url, team_channel, mood) }
describe 'slack_lib' do
subject(:slack_lib) { SlackLib.new(webhook_url, team_channel, mood) }

let(:webhook_url) { 'https://slack/webhook' }
let(:team_channel) { '#angry-seal-bot-test' }
Expand All @@ -23,7 +23,7 @@
context 'successful response' do
it 'posts to Slack' do
expect(fake_slack_poster).to receive(:send_message).with(message).and_return(fake_slack_response)
expect(slack_poster.send_request(message)).to be nil
expect(slack_lib.send_request(message)).to be nil
end
end

Expand All @@ -36,7 +36,7 @@
end

it 'raises an exception' do
expect { slack_poster.send_request(message) }.to raise_error(SlackPoster::SlackResponseError)
expect { slack_lib.send_request(message) }.to raise_error(SlackLib::SlackResponseError)
end
end
end
Expand All @@ -49,8 +49,8 @@
end

it "posts as Informative Seal" do
slack_poster.send(:mood_hash)
expect(slack_poster.send(:mood_hash)).to eq "Informative Seal"
slack_lib.send(:mood_hash)
expect(slack_lib.send(:mood_hash)).to eq "Informative Seal"
end
end

Expand All @@ -61,12 +61,12 @@
end

it "knows it is Halloween season" do
expect(slack_poster.send(:halloween_season?)).to eq true
expect(slack_lib.send(:halloween_season?)).to eq true
end

it "posts as Halloween Informative Seal" do
slack_poster.send(:mood_hash)
expect(slack_poster.send(:mood_hash)).to eq "Halloween Informative Seal"
slack_lib.send(:mood_hash)
expect(slack_lib.send(:mood_hash)).to eq "Halloween Informative Seal"
end
end

Expand All @@ -77,12 +77,12 @@
end

it "knows it is Festive Season" do
expect(slack_poster.send(:festive_season?)).to eq true
expect(slack_lib.send(:festive_season?)).to eq true
end

it "posts as Festive Season Informative Seal" do
slack_poster.send(:mood_hash)
expect(slack_poster.send(:mood_hash)).to eq "Festive Season Informative Seal"
slack_lib.send(:mood_hash)
expect(slack_lib.send(:mood_hash)).to eq "Festive Season Informative Seal"
end
end
end
Expand All @@ -91,7 +91,7 @@
let(:mood) { 'baadf00d' }

it 'emits a meaningful error' do
expect { slack_poster }.to raise_error(RuntimeError, /Bad mood: baadf00d/)
expect { slack_lib }.to raise_error(RuntimeError, /Bad mood: baadf00d/)
end
end
end

0 comments on commit beef6c0

Please sign in to comment.