class SlackMessage::RSpec::PostTo
Public Class Methods
new()
click to toggle source
# File lib/slack_message/rspec.rb, line 192 def initialize @captured_calls = [] @content = nil @channel = nil @profile = nil @icon = nil @icon_matching = nil SlackMessage::RSpec.register_expectation_listener(self) end
Public Instance Methods
enforce_expectations()
click to toggle source
# File lib/slack_message/rspec.rb, line 229 def enforce_expectations SlackMessage::RSpec.unregister_expectation_listener(self) @captured_calls .select { |call| !@channel || call[:channel] == @channel } .select { |call| !@profile || [call[:profile][:handle], call[:username]].include?(@profile) } .select { |call| !@content || call.fetch(:blocks).to_s =~ @content } .select { |call| !@icon || call.fetch(:icon_emoji, call.fetch(:icon_url, '')) == @icon } .select { |call| !@icon_matching || call.fetch(:icon_emoji, call.fetch(:icon_url, '')) =~ @icon_matching } .any? end
failure_expression()
click to toggle source
# File lib/slack_message/rspec.rb, line 249 def failure_expression concat = [] if @channel concat << "post a slack message to '#{@channel}'" elsif @profile concat << "post a slack message as '#{@profile}'" elsif @icon concat << "post a slack message with icon '#{@icon}'" elsif @icon_matching concat << "post a slack message with icon matching '#{@icon_matching.inspect}'" else concat << "post a slack message" end if @content concat << "with content matching #{@content.inspect}" end concat.join " " end
failure_message()
click to toggle source
# File lib/slack_message/rspec.rb, line 241 def failure_message "expected block to #{failure_expression}" end
failure_message_when_negated()
click to toggle source
# File lib/slack_message/rspec.rb, line 245 def failure_message_when_negated "expected block not to #{failure_expression}" end
record_call(deets)
click to toggle source
# File lib/slack_message/rspec.rb, line 203 def record_call(deets) @captured_calls.push(deets) end
with_channel(channel)
click to toggle source
# File lib/slack_message/rspec.rb, line 207 def with_channel(channel) @channel = channel end
with_content_matching(content)
click to toggle source
# File lib/slack_message/rspec.rb, line 220 def with_content_matching(content) raise ArgumentError unless content.is_a? Regexp @content = content end
with_icon(icon)
click to toggle source
# File lib/slack_message/rspec.rb, line 211 def with_icon(icon) @icon = icon end
with_icon_matching(icon)
click to toggle source
# File lib/slack_message/rspec.rb, line 215 def with_icon_matching(icon) raise ArgumentError unless icon.is_a? Regexp @icon_matching = icon end
with_profile(profile)
click to toggle source
# File lib/slack_message/rspec.rb, line 225 def with_profile(profile) @profile = profile end