Class: Cuukie::Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/cuukie/server/server.rb

Instance Method Summary collapse

Instance Method Details

#counts(elements) ⇒ Object



179
180
181
182
183
184
185
# File 'lib/cuukie/server/server.rb', line 179

def counts(elements)
  counts = ['failed', 'skipped', 'undefined', 'pending', 'passed'].map do |status|
    selected = elements.find_all {|element| element[:status] == status }
    selected.any? ? "#{selected.size} #{status}" : nil
  end.compact
  counts.any? ? " (#{counts.join(', ')})" : ''
end

#current_featureObject



136
137
138
# File 'lib/cuukie/server/server.rb', line 136

def current_feature
  settings.features.last
end

#current_scenarioObject



140
141
142
143
144
145
146
147
# File 'lib/cuukie/server/server.rb', line 140

def current_scenario
  # return a "nil scenario" (that includes a "nil step") if we
  # don't have a scenario yet. this is useful to eliminate steps
  # coming from backgrounds (which will be re-sent during the
  # following scenarios anyway)
  return { :steps => [{}] } if current_feature[:scenarios].empty?
  current_feature[:scenarios].last
end

#current_stepObject



149
150
151
# File 'lib/cuukie/server/server.rb', line 149

def current_step
  current_scenario[:steps].last
end

#htmlize(ruby) ⇒ Object



187
188
189
190
# File 'lib/cuukie/server/server.rb', line 187

def htmlize(ruby)
  convertor = Syntax::Convertors::HTML.for_syntax("ruby")
  convertor.convert(ruby, false)
end

#pluralize(count, what) ⇒ Object



175
176
177
# File 'lib/cuukie/server/server.rb', line 175

def pluralize(count, what)
  "#{count} #{what}#{count == 1 ? '' : 's'}"
end

#read_from_requestObject



192
193
194
195
196
197
198
# File 'lib/cuukie/server/server.rb', line 192

def read_from_request
  result = {}
  request.params.each do |k, v|
    result[k.to_sym] = (k =~ /^raw_/) ? v : Rack::Utils.escape_html(v)
  end
  result
end

#statsObject



159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'lib/cuukie/server/server.rb', line 159

def stats
  scenarios = []
  settings.features.each {|feature| scenarios.concat feature[:scenarios] }

  result = {:scenarios => String.new, :steps => String.new}
  result[:scenarios] << pluralize(scenarios.size, "scenario")
  result[:scenarios] << counts(scenarios)
  
  steps = []
  scenarios.each {|scenario| steps.concat scenario[:steps] }
  result[:steps] << pluralize(steps.size, "step")
  step_count = counts steps
  result[:steps] << step_count if step_count
  result
end

#timeObject



153
154
155
156
157
# File 'lib/cuukie/server/server.rb', line 153

def time
  return settings.duration if settings.duration
  return 0 unless settings.start_time
  return Time.now - settings.start_time
end