Class: Janky::Notifier::Mock

Inherits:
Object
  • Object
show all
Defined in:
lib/janky/notifier/mock.rb

Overview

Mock notifier implementation used in testing environments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMock

Returns a new instance of Mock.



5
6
7
# File 'lib/janky/notifier/mock.rb', line 5

def initialize
  @notifications = []
end

Instance Attribute Details

#notificationsObject (readonly)

Returns the value of attribute notifications.



9
10
11
# File 'lib/janky/notifier/mock.rb', line 9

def notifications
  @notifications
end

Instance Method Details

#completed(build) ⇒ Object



21
22
23
# File 'lib/janky/notifier/mock.rb', line 21

def completed(build)
  notify(:completed, build)
end

#failure?(repo, branch, room_name) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/janky/notifier/mock.rb', line 43

def failure?(repo, branch, room_name)
  room_name ||= Janky::ChatService.default_room_name

  builds = @notifications.select do |state, build|
    state == :completed &&
      build.red? &&
      build.repo_name   == repo &&
      build.branch_name == branch &&
      build.room_name   == room_name
  end

  builds.size == 1
end

#notify(state, build) ⇒ Object



25
26
27
# File 'lib/janky/notifier/mock.rb', line 25

def notify(state, build)
  @notifications << [state, build]
end

#queued(build) ⇒ Object



11
12
# File 'lib/janky/notifier/mock.rb', line 11

def queued(build)
end

#reset!Object



14
15
16
# File 'lib/janky/notifier/mock.rb', line 14

def reset!
  @notifications.clear
end

#started(build) ⇒ Object



18
19
# File 'lib/janky/notifier/mock.rb', line 18

def started(build)
end

#success?(repo, branch, room_name) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/janky/notifier/mock.rb', line 29

def success?(repo, branch, room_name)
  room_name ||= Janky::ChatService.default_room_name

  builds = @notifications.select do |state, build|
    state == :completed &&
      build.green? &&
      build.repo_name   == repo &&
      build.branch_name == branch &&
      build.room_name   == room_name
  end

  builds.size == 1
end