Class: HipchatNotifier

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

Instance Method Summary collapse

Constructor Details

#initialize(notifier_details) ⇒ HipchatNotifier

Returns a new instance of HipchatNotifier.



4
5
6
7
8
# File 'lib/abt/notifiers/hipchat_notifier.rb', line 4

def initialize(notifier_details)
  @client = HipChat::API.new(notifier_details["hipchat_api_key"])
  @room_name = notifier_details["room_name"]
  @title= notifier_details["title"]
end

Instance Method Details

#send_formatted_message(result) ⇒ Object



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

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



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

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