diff --git a/lib/roku_builder.rb b/lib/roku_builder.rb index 990b5cd..f558968 100644 --- a/lib/roku_builder.rb +++ b/lib/roku_builder.rb @@ -51,13 +51,12 @@ def self.run end def self.plugins - @@plugins ||= {} + @@plugins ||= [] end - def self.register_plugin(klass:, name:) - @@plugins ||= {} - raise ImplementationError, "Duplicate plugin names" if @@plugins[name] - @@plugins[name] = klass + def self.register_plugin(plugin) + @@plugins ||= [] + @@plugins << plugin end def self.setup_plugins @@ -73,13 +72,13 @@ def self.load_plugins end def self.process_plugins - @@plugins ||= {} - unless @@plugins.count == @@plugins.values.uniq.count - raise ImplementationError, "Duplicate plugin classes" + @@plugins ||= [] + unless @@plugins.count == @@plugins.uniq.count + raise ImplementationError, "Duplicate plugins" end - @@plugins.each_value do |klass| - klass.dependencies.each do |name| - raise ImplementationError, "Missing dependency: #{name}" unless @@plugins[name] + @@plugins.each do |plugin| + plugin.dependencies.each do |dependency| + raise ImplementationError, "Missing dependency: #{dependency}" unless @@plugins.include?(dependency) end end end diff --git a/lib/roku_builder/config_parser.rb b/lib/roku_builder/config_parser.rb index 9df5f88..ee01f9e 100644 --- a/lib/roku_builder/config_parser.rb +++ b/lib/roku_builder/config_parser.rb @@ -32,13 +32,11 @@ def parse_config setup_sideload_config setup_package_config setup_monitor_configs - setup_navigate_configs setup_manifest_config setup_deeplink_configs setup_text_configs setup_test_configs setup_screencapture_configs - setup_screen_config setup_profiler_configs setup_genkey_configs end @@ -264,35 +262,12 @@ def setup_monitor_configs end end - def setup_navigate_configs - @parsed[:init_params][:navigator] = {mappings: generate_maggings} - if @options[:navigate] - @parsed[:navigate_config] = { - commands: @options[:navigate].split(/, */).map{|c| c.to_sym} - } - end - end - - def generate_maggings - mappings = {} - if @config[:input_mapping] - @config[:input_mapping].each_pair {|key, value| - unless "".to_sym == key - key = key.to_s.sub(/\\e/, "\e").to_sym - mappings[key] = value - end - } - end - mappings - end - def setup_manifest_config @parsed[:manifest_config] = { root_dir: get_root_dir } end - def setup_deeplink_configs @parsed[:deeplink_config] = {options: @options[:deeplink]} if @options[:app_id] @@ -312,11 +287,6 @@ def setup_screencapture_configs out_file: @parsed[:out][:file] } end - def setup_screen_config - if @options[:screen] - @parsed[:screen_config] = {type: @options[:screen].to_sym} - end - end def setup_profiler_configs if @options[:profile] @parsed[:profiler_config] = {command: @options[:profile].to_sym} diff --git a/lib/roku_builder/options.rb b/lib/roku_builder/options.rb index 0880ec2..6aa02e4 100644 --- a/lib/roku_builder/options.rb +++ b/lib/roku_builder/options.rb @@ -38,7 +38,7 @@ def has_source? private def setup_plugin_commands - RokuBuilder.plugins.each_value do |plugin| + RokuBuilder.plugins.each do |plugin| plugin.commands.each do |command, attributes| commands << command [:device, :source, :exclude].each do |type| @@ -132,8 +132,8 @@ def build_parser(options:) end def add_plugin_options(parser:, options:) - RokuBuilder.plugins.each_value do |plugin| - plugin.parse_options(options_parser: parser, options: options) + RokuBuilder.plugins.each do |plugin| + plugin.parse_options(parser: parser, options: options) end end diff --git a/lib/roku_builder/plugins/navigator.rb b/lib/roku_builder/plugins/navigator.rb index 9899377..f427c8c 100644 --- a/lib/roku_builder/plugins/navigator.rb +++ b/lib/roku_builder/plugins/navigator.rb @@ -4,9 +4,40 @@ module RokuBuilder # Navigation methods class Navigator < Util + extend Plugin + + def self.commands + { + nav: {device: true}, + navigate: {device: true}, + type: {device: true}, + screen: {device: true}, + screens: {} + } + end + + def self.parse_options(options_parser:, options:) + options_parser.seperator("Navigator Commands:") + options_parser.on("-N", "--nav CMD", "Send the given command to the roku") do |n| + options[:nav] = n + end + options_parser.on("--navigate", "Run interactive navigator") do + options[:navigate] = true + end + options_parser.on("-y", "--type TEXT", "Type the given text on the roku device") do |t| + options[:type] = t + end + options_parser.on("--screen SCREEN", "Show a screen") do |s| + options[:screen] = s + end + + options_parser.on("--screens", "Show possible screens") do + options[:screens] = true + end + end # Setup navigation commands - def init(mappings: nil) + def init() @commands = { home: "Home", rew: "Rev", ff: "Fwd", play: "Play", select: "Select", left: "Left", @@ -33,67 +64,33 @@ def init(mappings: nil) @runable = [ :secret, :channels ] - mappings_init(mappings: mappings) + mappings_init end - # Init Mappings - def mappings_init(mappings: nil) - @mappings = { - "\e[1~": [ "home", "Home" ], - "<": [ "rew", "<" ], - ">": [ "ff", ">" ], - "=": [ "play", "=" ], - "\r": [ "select", "Enter" ], - "\e[D": [ "left", "Left Arrow" ], - "\e[C": [ "right", "Right Arrow" ], - "\e[B": [ "down", "Down Arrow" ], - "\e[A": [ "up", "Up Arrow" ], - "\t": [ "back", "Tab" ], - #"": [ "replay", "" ], - "*": [ "info", "*" ], - "\u007f": [ "backspace", "Backspace" ], - "?": [ "search", "?" ], - "\e\r": [ "enter", "Alt + Enter" ], - "\e[5~": [ "volumeup", "Page Up" ], - "\e[6~": [ "volumedown", "Page Down" ], - "\e[4~": [ "mute", "End" ], - #"": [ "channeldown", "" ], - #"": [ "channelup", "" ], - #"": [ "tuner", "" ], - #"": [ "hdmi1", "" ], - #"": [ "hdmi2", "" ], - #"": [ "hdmi3", "" ], - #"": [ "hdmi4", "" ], - #"": [ "avi", "" ] - } - @mappings.merge!(mappings) if mappings - end # Send a navigation command to the roku device # @param command [Symbol] The smbol of the command to send # @return [Boolean] Success - def nav(commands:) + def nav(options:) + commands = options[:nav].split(/, */).map{|c| c.to_sym} commands.each do |command| - if @commands.has_key?(command) - conn = multipart_connection(port: 8060) - - path = "/keypress/#{@commands[command]}" - @logger.debug("Send Command: "+path) - response = conn.post path - return false unless response.success? - else - return false + unless @commands.has_key?(command) + raise ExecutionError, "Unknown Navigation Command" end + conn = multipart_connection(port: 8060) + path = "/keypress/#{@commands[command]}" + @logger.debug("Send Command: "+path) + response = conn.post path + raise ExecutionError, "Navigation Failed" unless response.success? end - return true end # Type text on the roku device # @param text [String] The text to type on the device # @return [Boolean] Success - def type(text:) + def type(options:) conn = multipart_connection(port: 8060) - text.split(//).each do |c| + options[:type].split(//).each do |c| path = "/keypress/LIT_#{CGI::escape(c)}" @logger.debug("Send Letter: "+path) response = conn.post path @@ -102,7 +99,7 @@ def type(text:) return true end - def interactive + def navigate(options:) running = true @logger.info("Key Mappings:") @mappings.each_value {|key| @@ -115,64 +112,83 @@ def interactive if char == "\u0003" running = false else - Thread.new(char) {|character| - if @mappings[character.to_sym] != nil - nav(commands:[@mappings[character.to_sym][0].to_sym]) - elsif character.inspect.force_encoding("UTF-8").ascii_only? - type(text: character) - end - } + Thread.new(char) {|char| handle_navigate_input(char)} end end end + # Show the commands for one of the roku secret screens # @param type [Symbol] The type of screen to show # @return [Boolean] Screen found - def screen(type:) - if @screens.has_key?(type) - if @runable.include?(type) - nav(commands: @screens[type]) - else - @logger.unknown("Cannot run command automatically") - end - display, count, string = [], [], "" - @screens[type].each do |command| - if display.count > 0 and display[-1] == command - count[-1] = count[-1] + 1 - else - display.push(command) - count.push(1) - end - end - display.each_index do |i| - if count[i] > 1 - string = string + @commands[display[i]]+" x "+count[i].to_s+", " - else - string = string + @commands[display[i]]+", " - end - end - if @runable.include?(type) - @logger.info(string.strip) - else - @logger.unknown(string.strip) - end + def screen(options:) + type = options[:screen].to_sym + unless @screens.has_key?(type) + raise ExecutionError, "Unknown Screen" + end + if @runable.include?(type) + nav(options: {nav: @screens[type].join(", ")}) else - return false + @logger.unknown("Cannot run command automatically") end - true + display_screen_command(type) end # Show avaiable roku secret screens - def screens + def screens(options:) @screens.keys.each {|screen| @logger.unknown(screen)} end + private + + def mappings_init() + @mappings = { + "\e[1~": [ "home", "Home" ], + "<": [ "rew", "<" ], + ">": [ "ff", ">" ], + "=": [ "play", "=" ], + "\r": [ "select", "Enter" ], + "\e[D": [ "left", "Left Arrow" ], + "\e[C": [ "right", "Right Arrow" ], + "\e[B": [ "down", "Down Arrow" ], + "\e[A": [ "up", "Up Arrow" ], + "\t": [ "back", "Tab" ], + #"": [ "replay", "" ], + "*": [ "info", "*" ], + "\u007f": [ "backspace", "Backspace" ], + "?": [ "search", "?" ], + "\e\r": [ "enter", "Alt + Enter" ], + "\e[5~": [ "volumeup", "Page Up" ], + "\e[6~": [ "volumedown", "Page Down" ], + "\e[4~": [ "mute", "End" ], + #"": [ "channeldown", "" ], + #"": [ "channelup", "" ], + #"": [ "tuner", "" ], + #"": [ "hdmi1", "" ], + #"": [ "hdmi2", "" ], + #"": [ "hdmi3", "" ], + #"": [ "hdmi4", "" ], + #"": [ "avi", "" ] + } + @mappings.merge!(generate_maggings) if @config.input_mapping + end + + def generate_maggings + mappings = {} + if @config[:input_mapping] + @config[:input_mapping].each_pair {|key, value| + unless "".to_sym == key + key = key.to_s.sub(/\\e/, "\e").to_sym + mappings[key] = value + end + } + end + mappings + end + def read_char STDIN.echo = false STDIN.raw! - - input = STDIN.getc.chr if input == "\e" then input << STDIN.read_nonblock(3) rescue nil @@ -183,5 +199,38 @@ def read_char STDIN.echo = true STDIN.cooked! end + + def handle_navigate_input(char) + if @mappings[char.to_sym] != nil + nav(options: {nav: @mappings[char.to_sym][0]}) + elsif char.inspect.force_encoding("UTF-8").ascii_only? + type(options: {type: char}) + end + end + + def display_screen_command(type) + display, count, string = [], [], "" + @screens[type].each do |command| + if display.count > 0 and display[-1] == command + count[-1] = count[-1] + 1 + else + display.push(command) + count.push(1) + end + end + display.each_index do |i| + if count[i] > 1 + string = string + @commands[display[i]]+" x "+count[i].to_s+", " + else + string = string + @commands[display[i]]+", " + end + end + if @runable.include?(type) + @logger.info(string.strip) + else + @logger.unknown(string.strip) + end + end end + RokuBuilder.register_plugin(Navigator) end diff --git a/lib/roku_builder/plugins/scripter.rb b/lib/roku_builder/plugins/scripter.rb index b1b0597..c28b2a9 100644 --- a/lib/roku_builder/plugins/scripter.rb +++ b/lib/roku_builder/plugins/scripter.rb @@ -22,7 +22,7 @@ def initialize(config:) @config = config end - def print(config:, options:) + def print(options:) attributes = [ :title, :build_version, :app_version, :root_dir, :app_name ] @@ -31,13 +31,13 @@ def print(config:, options:) raise ExecutionError, "Unknown attribute: #{options[:print]}" end - manifest = Manifest.new(config: config) + manifest = Manifest.new(config: @config) case options[:print] when :root_dir - printf "%s", config.project[:directory] + printf "%s", @config.project[:directory] when :app_name - printf "%s", config.project[:app_name] + printf "%s", @config.project[:app_name] when :title printf "%s", manifest.title when :build_version @@ -50,5 +50,5 @@ def print(config:, options:) end end - RokuBuilder.register_plugin(klass: Scripter, name: "scripter") + RokuBuilder.register_plugin(Scripter) end diff --git a/test/roku_builder/plugins/test_navigator.rb b/test/roku_builder/plugins/test_navigator.rb index a3224f5..0904673 100644 --- a/test/roku_builder/plugins/test_navigator.rb +++ b/test/roku_builder/plugins/test_navigator.rb @@ -3,10 +3,13 @@ require_relative "../test_helper.rb" module RokuBuilder - class NavigatorTest # skip tests for now < Minitest::Test + class NavigatorTest < Minitest::Test def setup Logger.set_testing - @config = build_config_object(NavigatorTest) + RokuBuilder.setup_plugins + unless RokuBuilder.plugins.include?(Navigator) + RokuBuilder.register_plugin(Navigator) + end @requests = [] end def teardown @@ -39,7 +42,7 @@ def test_navigator_nav_fail def test_navigator_type path = "keypress/LIT_" - navigator_test(path: path, input: "Type", type: :text) + navigator_test(path: path, input: "Type", type: :type) end def navigator_test(path:, input:, type:, success: true) @@ -47,7 +50,7 @@ def navigator_test(path:, input:, type:, success: true) if type == :nav @requests.push(stub_request(:post, "http://192.168.0.100:8060#{path}"). to_return(status: 200, body: "", headers: {})) - elsif type == :text + elsif type == :type input.split(//).each do |c| path = "/keypress/LIT_#{CGI::escape(c)}" @requests.push(stub_request(:post, "http://192.168.0.100:8060#{path}"). @@ -55,53 +58,86 @@ def navigator_test(path:, input:, type:, success: true) end end end if - - navigator = Navigator.new(config: @config) - result = nil - if type == :nav - result = navigator.nav(commands: [input]) - elsif type == :text - result = navigator.type(text: input) + options = {} + options[type] = input.to_s + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + if success + navigator.send(type, options: options) + else + assert_raises ExecutionError do + navigator.send(type, options: options) + end end - - assert_equal success, result end - def test_navigator_screen + def test_navigator_screen_secret logger = Minitest::Mock.new Logger.class_variable_set(:@@instance, logger) - navigator = Navigator.new(config: @config) + options = {screen: "secret"} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + + stub_request(:post, "http://192.168.0.100:8060/keypress/Home"). + to_return(status: 200, body: "", headers: {}) + stub_request(:post, "http://192.168.0.100:8060/keypress/Fwd"). + to_return(status: 200, body: "", headers: {}) + stub_request(:post, "http://192.168.0.100:8060/keypress/Rev"). + to_return(status: 200, body: "", headers: {}) logger.expect(:info, nil, ["Home x 5, Fwd x 3, Rev x 2,"]) + 5.times do + logger.expect(:debug, nil, ["Send Command: /keypress/Home"]) + end + 3.times do + logger.expect(:debug, nil, ["Send Command: /keypress/Fwd"]) + end + 2.times do + logger.expect(:debug, nil, ["Send Command: /keypress/Rev"]) + end + + navigator.screen(options: options) + + logger.verify + Logger.set_testing + end + def test_navigator_screen_reboot + logger = Minitest::Mock.new + Logger.class_variable_set(:@@instance, logger) + options = {screen: "reboot"} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + logger.expect(:unknown, nil, ["Cannot run command automatically"]) logger.expect(:unknown, nil, ["Home x 5, Up, Rev x 2, Fwd x 2,"]) - navigator.stub(:nav, nil) do - navigator.screen(type: :secret) - navigator.screen(type: :reboot) - end + navigator.screen(options: options) logger.verify Logger.set_testing end def test_navigator_screen_fail - navigator = Navigator.new(config: @config) - - assert !navigator.screen(type: :bad) - + options = {screen: "bad"} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + assert_raises ExecutionError do + navigator.screen(options: options) + end end def test_navigator_screens logger = Minitest::Mock.new Logger.class_variable_set(:@@instance, logger) - navigator = Navigator.new(config: @config) + options = {screens: true} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) navigator.instance_variable_get("@screens").each_key do |key| logger.expect(:unknown, nil, [key]) end - navigator.screens + navigator.screens(options: options) logger.verify Logger.set_testing @@ -114,12 +150,14 @@ def test_navigator_read_char getc.expect(:call, chr) chr.expect(:chr, "a") + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) - navigator = Navigator.new(config: @config) + navigator = Navigator.new(config: config) STDIN.stub(:echo=, nil) do STDIN.stub(:raw!, nil) do STDIN.stub(:getc, getc) do - assert_equal "a", navigator.read_char + assert_equal "a", navigator.send(:read_char) end end end @@ -137,13 +175,15 @@ def test_navigator_read_char_multichar read_nonblock.expect(:call, "a", [3]) read_nonblock.expect(:call, "b", [2]) + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) - navigator = Navigator.new(config: @config) + navigator = Navigator.new(config: config) STDIN.stub(:echo=, nil) do STDIN.stub(:raw!, nil) do STDIN.stub(:getc, getc) do STDIN.stub(:read_nonblock, read_nonblock) do - assert_equal "\eab", navigator.read_char + assert_equal "\eab", navigator.send(:read_char) end end end @@ -153,14 +193,15 @@ def test_navigator_read_char_multichar end def test_navigator_interactive - navigator = Navigator.new(config: @config) + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) navigator.stub(:read_char, "\u0003") do - navigator.interactive + navigator.navigate(options: options) end end def test_navigator_interactive_nav - read_char = lambda { @i ||= 0 char = nil @@ -173,43 +214,33 @@ def test_navigator_interactive_nav @i += 1 char } - nav = lambda { |args| - assert_equal :rev, args[:commands][0] + assert_equal :rew, args[:commands][0] } - - navigator = Navigator.new(config: @config) + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) navigator.stub(:read_char, read_char) do navigator.stub(:nav, nav) do - navigator.interactive + navigator.navigate(options: options) end end end - def test_navigator_interactive_text - - read_char = lambda { - @i ||= 0 - char = nil - case(@i) - when 0 - char = "a" - when 1 - char = "\u0003" - end - @i += 1 - char - } - - type = lambda { |args| - assert_equal "a", args[:text] - } - - navigator = Navigator.new(config: @config) - navigator.stub(:read_char, read_char) do - navigator.stub(:type, type) do - navigator.interactive - end - end + def test_navigator_hendle_interactive_text + stub_request(:post, "http://192.168.0.100:8060/keypress/LIT_a"). + to_return(status: 200, body: "", headers: {}) + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + navigator.send(:handle_navigate_input, "a") + end + def test_navigator_hendle_interactive_command + stub_request(:post, "http://192.168.0.100:8060/keypress/Play"). + to_return(status: 200, body: "", headers: {}) + options = {navigate: true} + config, options = build_config_options_objects(NavigatorTest, options, false) + navigator = Navigator.new(config: config) + navigator.send(:handle_navigate_input, "=") end end end diff --git a/test/roku_builder/plugins/test_scripter.rb b/test/roku_builder/plugins/test_scripter.rb index 190b0c1..f1811de 100644 --- a/test/roku_builder/plugins/test_scripter.rb +++ b/test/roku_builder/plugins/test_scripter.rb @@ -7,13 +7,16 @@ class ScripterTest < Minitest::Test def setup options = {print: "field", working: true} RokuBuilder.setup_plugins + unless RokuBuilder.plugins.include?(Scripter) + RokuBuilder.register_plugin(Scripter) + end @config, @options = build_config_options_objects(ScripterTest, options, false) end def test_scripter_print_bad_attr scripter = Scripter.new(config: @config) assert_raises ExecutionError do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end end @@ -29,7 +32,7 @@ def test_scripter_print_config_root_dir } scripter = Scripter.new(config: @config) scripter.stub(:printf, fake_print) do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end assert_equal 1, call_count end @@ -45,7 +48,7 @@ def test_scripter_print_config_app_name } scripter = Scripter.new(config: @config) scripter.stub(:printf, fake_print) do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end assert_equal 1, call_count end @@ -62,7 +65,7 @@ def test_scripter_print_manifest_title } scripter = Scripter.new(config: @config) scripter.stub(:printf, fake_print) do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end assert_equal 1, call_count end @@ -79,7 +82,7 @@ def test_scripter_print_manifest_build_version } scripter = Scripter.new(config: @config) scripter.stub(:printf, fake_print) do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end assert_equal 1, call_count end @@ -97,7 +100,7 @@ def test_scripter_print_manifest_app_version } scripter = Scripter.new(config: @config) scripter.stub(:printf, fake_print) do - scripter.print(config: @config, options: @options) + scripter.print(options: @options) end assert_equal 1, call_count end diff --git a/test/roku_builder/test_helper.rb b/test/roku_builder/test_helper.rb index ee2382d..22d5980 100644 --- a/test/roku_builder/test_helper.rb +++ b/test/roku_builder/test_helper.rb @@ -36,7 +36,7 @@ def test_files_path(klass) end def build_options(options = {validate: true}, empty_plugins = true) - RokuBuilder.class_variable_set(:@@plugins, {}) if empty_plugins + RokuBuilder.class_variable_set(:@@plugins, []) if empty_plugins options = RokuBuilder::Options.new(options: options) options.validate options diff --git a/test/roku_builder/test_options_plugins.rb b/test/roku_builder/test_options_plugins.rb index 8418e75..1457044 100644 --- a/test/roku_builder/test_options_plugins.rb +++ b/test/roku_builder/test_options_plugins.rb @@ -8,7 +8,7 @@ def test_options_plugins_parse RokuBuilder.class_variable_set(:@@plugins, nil) parser = Minitest::Mock.new() options_hash = {} - RokuBuilder.register_plugin(klass: OptionsTestPlugin, name: "test") + RokuBuilder.register_plugin( OptionsTestPlugin) options = Options.allocate parser.expect(:parse!, nil) options.stub(:build_parser, parser) do @@ -22,7 +22,7 @@ def test_options_plugins_parse end def test_options_plugins_commands RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin) options = Options.allocate options.send(:setup_plugin_commands) assert_includes options.send(:commands), :test @@ -30,7 +30,7 @@ def test_options_plugins_commands end def test_options_plugins_commands_source RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin) options = Options.allocate options.send(:setup_plugin_commands) assert_includes options.send(:source_commands), :test @@ -38,7 +38,7 @@ def test_options_plugins_commands_source end def test_options_plugins_commands_device RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin) options = Options.allocate options.send(:setup_plugin_commands) assert_includes options.send(:device_commands), :test @@ -46,7 +46,7 @@ def test_options_plugins_commands_device end def test_options_plugins_commands_exclude RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin) options = Options.allocate options.send(:setup_plugin_commands) assert_includes options.send(:exclude_commands), :test @@ -54,7 +54,7 @@ def test_options_plugins_commands_exclude end def test_options_plugins_commands_basic RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin2, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin2) options = Options.allocate options.send(:setup_plugin_commands) assert_includes options.send(:commands), :test @@ -62,7 +62,7 @@ def test_options_plugins_commands_basic end def test_options_plugins_commands_source RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin2, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin2) options = Options.allocate options.send(:setup_plugin_commands) refute_includes options.send(:source_commands), :test @@ -70,7 +70,7 @@ def test_options_plugins_commands_source end def test_options_plugins_commands_device RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin2, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin2) options = Options.allocate options.send(:setup_plugin_commands) refute_includes options.send(:device_commands), :test @@ -78,7 +78,7 @@ def test_options_plugins_commands_device end def test_options_plugins_commands_exclude RokuBuilder.class_variable_set(:@@plugins, nil) - RokuBuilder.register_plugin(klass: OptionsTestPlugin2, name: "test") + RokuBuilder.register_plugin(OptionsTestPlugin2) options = Options.allocate options.send(:setup_plugin_commands) refute_includes options.send(:exclude_commands), :test @@ -87,7 +87,7 @@ def test_options_plugins_commands_exclude end class OptionsTestPlugin extend Plugin - def self.parse_options(options_parser:, options:) + def self.parse_options(parser:, options:) options[:run] = true end def self.commands @@ -96,7 +96,7 @@ def self.commands end class OptionsTestPlugin2 extend Plugin - def self.parse_options(options_parser:, options:) + def self.parse_options(parser:, options:) options[:run] = true end def self.commands diff --git a/test/roku_builder/test_roku_builder.rb b/test/roku_builder/test_roku_builder.rb index 9896c6c..3efa22e 100644 --- a/test/roku_builder/test_roku_builder.rb +++ b/test/roku_builder/test_roku_builder.rb @@ -5,7 +5,7 @@ module RokuBuilder class RokuBuilderTest < Minitest::Test def setup - RokuBuilder.class_variable_set(:@@plugins, {}) + RokuBuilder.class_variable_set(:@@plugins, []) @ping = Minitest::Mock.new @options = build_options({validate: true, device_given: false, working: true}) @options.define_singleton_method(:device_commands){ @@ -26,7 +26,7 @@ def setup end def teardown @ping.verify - RokuBuilder.class_variable_set(:@@plugins, {}) + RokuBuilder.class_variable_set(:@@plugins, []) end def test_roku_builder_check_devices_good @@ -104,46 +104,34 @@ def test_roku_builder_options_parse_complex end def test_roku_builder_plugins_empty RokuBuilder.process_plugins - assert_equal Hash, RokuBuilder.plugins.class + assert_equal Array, RokuBuilder.plugins.class assert_equal 0, RokuBuilder.plugins.count end def test_roku_builder_plugins_empty_no_setup - assert_equal Hash, RokuBuilder.plugins.class + assert_equal Array, RokuBuilder.plugins.class assert_equal 0, RokuBuilder.plugins.count end def test_roku_builder_plugins_registered - RokuBuilder.register_plugin(klass: TestPlugin, name: "test") + RokuBuilder.register_plugin(TestPlugin) RokuBuilder.process_plugins - assert_equal Hash, RokuBuilder.plugins.class + assert_equal Array, RokuBuilder.plugins.class assert_equal 1, RokuBuilder.plugins.count - assert_equal TestPlugin, RokuBuilder.plugins["test"] + assert_equal TestPlugin, RokuBuilder.plugins[0] end def test_roku_builder_plugins_duplicate_classes - RokuBuilder.register_plugin(klass: TestPlugin, name: "test") - RokuBuilder.register_plugin(klass: TestPlugin, name: "test2") + RokuBuilder.register_plugin(TestPlugin) + RokuBuilder.register_plugin(TestPlugin) assert_raises ImplementationError do RokuBuilder.process_plugins end end - def test_roku_builder_plugins_duplicate_names - RokuBuilder.register_plugin(klass: TestPlugin, name: "test") - assert_raises ImplementationError do - RokuBuilder.register_plugin(klass: TestPlugin2, name: "test") - end - end - def test_roku_builder_plugins_duplicate_names - RokuBuilder.register_plugin(klass: TestPlugin, name: "test") - assert_raises ImplementationError do - RokuBuilder.register_plugin(klass: TestPlugin2, name: "test") - end - end def test_roku_builder_plugins_dependencies - RokuBuilder.register_plugin(klass: TestPlugin, name: "test") - RokuBuilder.register_plugin(klass: TestPlugin3, name: "test3") + RokuBuilder.register_plugin(TestPlugin) + RokuBuilder.register_plugin(TestPlugin3) RokuBuilder.process_plugins end def test_roku_builder_plugins_dependencies - RokuBuilder.register_plugin(klass: TestPlugin3, name: "test3") + RokuBuilder.register_plugin(TestPlugin3) assert_raises ImplementationError do RokuBuilder.process_plugins end