class RokuBuilder::Tester

Method for running unit tests This is intended to be used with the brstest librbary but should work with other testing libraries

Public Class Methods

commands() click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 11
def self.commands
  {test: {device: true, source: true, stage: true}}
end
dependencies() click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 22
def self.dependencies
  [Loader, Linker]
end
parse_options(parser:, options:) click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 15
def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("-t", "--test", "Test an app") do
    options[:test] = true
  end
end

Public Instance Methods

init() click to toggle source

Initialize starting and ending regular expressions

# File lib/roku_builder/plugins/tester.rb, line 27
def init()
  @end_reg = /\*+\s*End testing\s*\*+/
  @start_reg = /\*+\s*Start testing\s*\*+/
  @test_logger = ::Logger.new(STDOUT)
  @test_logger.formatter = proc {|_severity, _datetime, _progname, msg|
    "%s\n\r" % [msg]
  }
  @in_tests = false
  @logs = []
end
test(options:) click to toggle source

Run tests and report results @param sideload_config [Hash] The config for sideloading the app

# File lib/roku_builder/plugins/tester.rb, line 40
def test(options:)
  loader = Loader.new(config: @config)
  loader.sideload(options: options)
  linker = Linker.new(config: @config)
  linker.deeplink(options: Options.new(options: {deeplink: "RunTests:true"}))

  telnet_config ={
    'Host' => @roku_ip_address,
    'Port' => 8085
  }
  connection = Net::Telnet.new(telnet_config)
  connection.waitfor(@end_reg) do |txt|
    handle_text(txt: txt)
  end
  print_logs
  connection.puts("cont\n")
end

Private Instance Methods

check_for_end(line:) click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 79
def check_for_end(line:)
  if line =~ @end_reg
    @in_tests = false
    breakline = line.gsub(/./, '*')
    @logs.push line
    @logs.push breakline
    @logs.push breakline
  end
end
check_for_start(line:) click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 89
def check_for_start(line:)
  if line =~ @start_reg
    @logs = []
    @in_tests = true
    breakline = line.gsub(/./, '*')
    @logs.push breakline
    @logs.push breakline
    @logs.push line
  end
end
check_for_used_connection(txt:) click to toggle source
# File lib/roku_builder/plugins/tester.rb, line 73
def check_for_used_connection(txt:)
  if txt =~ /connection already in use/
    raise IOError, "Telnet Connection Already in Use"
  end
end
handle_text(txt:) click to toggle source

Handel testing text @param txt [String] current text from telnet @param in_tests [Boolean] currently parsing test text @return [Boolean] currently parsing test text

# File lib/roku_builder/plugins/tester.rb, line 64
def handle_text(txt:)
  check_for_used_connection(txt: txt)
  txt.split("\n").each do |line|
    check_for_end(line: line)
    @logs.push line if @in_tests
    check_for_start(line: line)
  end
end
print_logs() click to toggle source