Class: SlackMessage::RSpec::PostTo
- Inherits:
-
Object
- Object
- SlackMessage::RSpec::PostTo
- Defined in:
- lib/slack_message/rspec.rb
Instance Method Summary collapse
- #enforce_expectations ⇒ Object
- #failure_expression ⇒ Object
- #failure_message ⇒ Object
- #failure_message_when_negated ⇒ Object
-
#initialize ⇒ PostTo
constructor
A new instance of PostTo.
- #record_call(deets) ⇒ Object
- #with_channel(channel) ⇒ Object
- #with_content_matching(content) ⇒ Object
- #with_icon(icon) ⇒ Object
- #with_icon_matching(icon) ⇒ Object
- #with_profile(profile) ⇒ Object
Constructor Details
#initialize ⇒ PostTo
Returns a new instance of PostTo.
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/slack_message/rspec.rb', line 194 def initialize @captured_calls = [] @content = nil @channel = nil @profile = nil @icon = nil @icon_matching = nil SlackMessage::RSpec.register_expectation_listener(self) end |
Instance Method Details
#enforce_expectations ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/slack_message/rspec.rb', line 231 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 ⇒ Object
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/slack_message/rspec.rb', line 251 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 ⇒ Object
243 244 245 |
# File 'lib/slack_message/rspec.rb', line 243 def "expected block to #{failure_expression}" end |
#failure_message_when_negated ⇒ Object
247 248 249 |
# File 'lib/slack_message/rspec.rb', line 247 def "expected block not to #{failure_expression}" end |
#record_call(deets) ⇒ Object
205 206 207 |
# File 'lib/slack_message/rspec.rb', line 205 def record_call(deets) @captured_calls.push(deets) end |
#with_channel(channel) ⇒ Object
209 210 211 |
# File 'lib/slack_message/rspec.rb', line 209 def with_channel(channel) @channel = channel end |
#with_content_matching(content) ⇒ Object
222 223 224 225 |
# File 'lib/slack_message/rspec.rb', line 222 def with_content_matching(content) raise ArgumentError unless content.is_a? Regexp @content = content end |
#with_icon(icon) ⇒ Object
213 214 215 |
# File 'lib/slack_message/rspec.rb', line 213 def with_icon(icon) @icon = icon end |
#with_icon_matching(icon) ⇒ Object
217 218 219 220 |
# File 'lib/slack_message/rspec.rb', line 217 def with_icon_matching(icon) raise ArgumentError unless icon.is_a? Regexp @icon_matching = icon end |
#with_profile(profile) ⇒ Object
227 228 229 |
# File 'lib/slack_message/rspec.rb', line 227 def with_profile(profile) @profile = profile end |