Class: HipChatNotifier

Inherits:
Object
  • Object
show all
Defined in:
lib/abt/notifiers/hip_chat_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ HipChatNotifier

Returns a new instance of HipChatNotifier.



5
6
7
8
9
# File 'lib/abt/notifiers/hip_chat_notifier.rb', line 5

def initialize(config)
  @client = HipChat::API.new(config["token"])
  @room_name = config["room_name"]
  @user_name = config["user_name"] || "AbtWorker"
end

Instance Method Details

#send_formatted_message(result) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/abt/notifiers/hip_chat_notifier.rb', line 11

def send_formatted_message(result)
  color = result.passed? ? 'green' : 'red'
  message = "Result: <b>#{result.status}</b> [#{result.pass_percentage}%] <br>
   <strong>#{result.run_count}</strong> tests, <strong>#{result.assertion_count}</strong> assertions"
  if result.error_occurred? || result.failure_occurred?
   message+=", <strong>#{result.failure_count}</strong> failures, <strong>#{result.error_count}</strong>, errors<br/>"
    result.faults.each { |f| message+="<br><pre>#{f.to_s.gsub(/>/,' ').gsub(/</,' ')}</pre><br/>" }
   end
  send_message(message,color)
end

#send_message(message, color = 'yellow') ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/abt/notifiers/hip_chat_notifier.rb', line 22

def send_message(message,color='yellow')
  puts "sending_message #{message}"
  begin
    puts @client.rooms_message(@room_name, @user_name, message, false,color).body
  rescue =>ex
    ex.inspect
  end
end