module HammerCLI::Testing::Messages
Public Instance Methods
all_subcommands(cmd, parent=HammerCLI::AbstractCommand)
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 9 def all_subcommands(cmd, parent=HammerCLI::AbstractCommand) result = [] get_subcommands(cmd).each do |klass| if klass < parent result << klass result += all_subcommands(klass, parent) end end result end
assert_msg_period(cmd, method_name)
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 20 def assert_msg_period(cmd, method_name) if cmd.respond_to?(method_name) && !cmd.send(method_name).nil? assert(cmd.send(method_name).end_with?('.'), "#{cmd}.#{method_name} doesn't end with '.'") end end
check_all_command_messages(main_cmd, parent=HammerCLI::AbstractCommand, except: {})
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 45 def check_all_command_messages(main_cmd, parent=HammerCLI::AbstractCommand, except: {}) all_subcommands(main_cmd, parent).each do |cmd| it "test messages of #{cmd}" do check_command_messages(cmd, except: (except[cmd.to_s] || [])) end end end
check_command_messages(cmd, except: [])
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 36 def check_command_messages(cmd, except: []) cmd.recognised_options.each do |opt| check_option_description(cmd, opt) end refute_msg_period(cmd, :desc) unless except.include?(:desc) assert_msg_period(cmd, :success_message) unless except.include?(:success_message) refute_msg_period(cmd, :failure_message) unless except.include?(:failure_message) end
check_option_description(cmd, opt)
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 32 def check_option_description(cmd, opt) refute opt.description.end_with?('.'), "Description for option #{opt.long_switch} in #{cmd} ends with '.'" end
get_subcommands(cmd)
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 4 def get_subcommands(cmd) return [] unless cmd.respond_to? :recognised_subcommands cmd.recognised_subcommands.map { |c| c.subcommand_class } end
refute_msg_period(cmd, method_name)
click to toggle source
# File lib/hammer_cli/testing/messages.rb, line 26 def refute_msg_period(cmd, method_name) if cmd.respond_to?(method_name) && !cmd.send(method_name).nil? refute(cmd.send(method_name).end_with?('.'), "#{cmd}.#{method_name} ends with '.'") end end