Module: HammerCLI::Testing::Messages
- Defined in:
- lib/hammer_cli/testing/messages.rb
Instance Method Summary collapse
- #all_subcommands(cmd, parent = HammerCLI::AbstractCommand) ⇒ Object
- #assert_msg_period(cmd, method_name) ⇒ Object
- #check_all_command_messages(main_cmd, parent = HammerCLI::AbstractCommand, except: {}) ⇒ Object
- #check_command_messages(cmd, except: []) ⇒ Object
- #check_option_description(cmd, opt) ⇒ Object
- #get_subcommands(cmd) ⇒ Object
- #refute_msg_period(cmd, method_name) ⇒ Object
Instance Method Details
#all_subcommands(cmd, parent = HammerCLI::AbstractCommand) ⇒ Object
9 10 11 12 13 14 15 16 17 18 |
# 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) ⇒ Object
20 21 22 23 24 |
# 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: {}) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/hammer_cli/testing/messages.rb', line 45 def (main_cmd, parent=HammerCLI::AbstractCommand, except: {}) all_subcommands(main_cmd, parent).each do |cmd| it "test messages of #{cmd}" do (cmd, except: (except[cmd.to_s] || [])) end end end |
#check_command_messages(cmd, except: []) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/hammer_cli/testing/messages.rb', line 36 def (cmd, except: []) cmd..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) ⇒ Object
32 33 34 |
# 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) ⇒ Object
4 5 6 7 |
# 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) ⇒ Object
26 27 28 29 30 |
# 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 |