Class: Blade::Runner::Tab

Inherits:
Model
  • Object
show all
Defined in:
lib/blade/interface/runner/tab.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

all, create, find, models, size

Class Attribute Details

.content_windowObject (readonly)

Returns the value of attribute content_window.



7
8
9
# File 'lib/blade/interface/runner/tab.rb', line 7

def content_window
  @content_window
end

.state_windowObject (readonly)

Returns the value of attribute state_window.



7
8
9
# File 'lib/blade/interface/runner/tab.rb', line 7

def state_window
  @state_window
end

.windowObject (readonly)

Returns the value of attribute window.



7
8
9
# File 'lib/blade/interface/runner/tab.rb', line 7

def window
  @window
end

Class Method Details

.activeObject



35
36
37
# File 'lib/blade/interface/runner/tab.rb', line 35

def active
  all.detect(&:active?)
end

.drawObject



21
22
23
24
25
# File 'lib/blade/interface/runner/tab.rb', line 21

def draw
  window.clear
  window.noutrefresh
  all.each(&:draw)
end

.install(options = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/blade/interface/runner/tab.rb', line 9

def install(options = {})
  top = options[:top]
  @window = create_window(top: top, height: 3)

  top = @window.begy + @window.maxy + 1
  @state_window = create_window(top: top, height: 1)

  top = @state_window.begy + @state_window.maxy + 1
  @content_window = create_window(top: top)
  @content_window.scrollok(true)
end

.remove(id) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/blade/interface/runner/tab.rb', line 27

def remove(id)
  tab = find(id)
  tab.deactivate
  tab.window.close
  super
  draw
end

.staleObject



39
40
41
42
# File 'lib/blade/interface/runner/tab.rb', line 39

def stale
  threshold = Time.now - 2
  all.select { |t| t.last_ping_at && t.last_ping_at < threshold }
end

Instance Method Details

#activateObject



140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/blade/interface/runner/tab.rb', line 140

def activate
  return if active?

  if tab = tabs.active
    tab.deactivate
  end

  self.active = true
  draw

  tabs.state_window.addstr(session.to_s)
  tabs.state_window.noutrefresh
end

#activate_nextObject



167
168
169
170
171
172
173
174
175
# File 'lib/blade/interface/runner/tab.rb', line 167

def activate_next
  all = tabs.all

  if all.last == self
    all.first.activate
  elsif tab = all[index + 1]
    tab.activate
  end
end

#activate_previousObject



177
178
179
180
181
182
183
184
185
# File 'lib/blade/interface/runner/tab.rb', line 177

def activate_previous
  all = tabs.all

  if all.first == self
    all.last.activate
  elsif tab = all[index - 1]
    tab.activate
  end
end

#active?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/blade/interface/runner/tab.rb', line 136

def active?
  active
end

#colorObject



187
188
189
190
191
192
193
194
# File 'lib/blade/interface/runner/tab.rb', line 187

def color
  case state
  when "running"  then colors.yellow
  when "finished" then colors.green
  when /fail/     then colors.red
  else                 colors.white
  end
end

#deactivateObject



154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/blade/interface/runner/tab.rb', line 154

def deactivate
  return unless active?

  self.active = false
  draw

  tabs.state_window.clear
  tabs.state_window.noutrefresh

  tabs.content_window.clear
  tabs.content_window.noutrefresh
end

#dotObject



116
117
118
# File 'lib/blade/interface/runner/tab.rb', line 116

def dot
  state == "pending" ? "" : ""
end

#drawObject



69
70
71
72
73
# File 'lib/blade/interface/runner/tab.rb', line 69

def draw
  window.clear
  active? ? draw_active : draw_inactive
  window.noutrefresh
end

#draw_activeObject



75
76
77
78
79
80
81
82
83
84
# File 'lib/blade/interface/runner/tab.rb', line 75

def draw_active
  window.addstr "╔═══╗"
  window.addstr ""
  window.attron(color)
  window.addstr(dot)
  window.attroff(color)
  window.addstr("")
  window.addstr "╝   ╚"
  draw_test_results
end

#draw_inactiveObject



86
87
88
89
90
91
92
# File 'lib/blade/interface/runner/tab.rb', line 86

def draw_inactive
  window.addstr "\n"
  window.attron(color)
  window.addstr("  #{dot}\n")
  window.attroff(color)
  window.addstr "═════"
end

#draw_test_resultsObject



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/blade/interface/runner/tab.rb', line 94

def draw_test_results
  tabs.content_window.clear
  failures = []

  session.test_results.results.each do |result|
    tabs.content_window.addstr(status_dot(result))
    failures << result if result[:status] == "fail"
  end

  failures.each do |result|
    tabs.content_window.addstr("\n\n")
    tabs.content_window.attron(Curses::A_BOLD)
    tabs.content_window.attron(colors.red)
    tabs.content_window.addstr("#{status_dot(result)} #{result[:name]}\n")
    tabs.content_window.attroff(colors.red)
    tabs.content_window.attroff(Curses::A_BOLD)
    tabs.content_window.addstr(result[:message])
  end

  tabs.content_window.noutrefresh
end

#heightObject



49
50
51
# File 'lib/blade/interface/runner/tab.rb', line 49

def height
  3
end

#indexObject



124
125
126
# File 'lib/blade/interface/runner/tab.rb', line 124

def index
  tabs.all.index(self)
end

#leftObject



61
62
63
# File 'lib/blade/interface/runner/tab.rb', line 61

def left
  tabs.window.begx + index * width
end

#sessionObject



128
129
130
# File 'lib/blade/interface/runner/tab.rb', line 128

def session
  Blade::Session.find(id)
end

#stateObject



132
133
134
# File 'lib/blade/interface/runner/tab.rb', line 132

def state
  session.test_results.state
end

#status_dot(result) ⇒ Object



120
121
122
# File 'lib/blade/interface/runner/tab.rb', line 120

def status_dot(result)
  Blade::TestResults::STATUS_DOTS[result[:status]]
end

#tabsObject



45
46
47
# File 'lib/blade/interface/runner/tab.rb', line 45

def tabs
  self.class
end

#topObject



57
58
59
# File 'lib/blade/interface/runner/tab.rb', line 57

def top
  tabs.window.begy
end

#widthObject



53
54
55
# File 'lib/blade/interface/runner/tab.rb', line 53

def width
  5
end

#windowObject



65
66
67
# File 'lib/blade/interface/runner/tab.rb', line 65

def window
  @window ||= create_window(height: height, width: width, top: top, left: left)
end