class Optimist::ParserEduateTest

Public Instance Methods

setup() click to toggle source
# File test/optimist/parser_educate_test.rb, line 6
def setup
end
test_argument_to_stringio() click to toggle source
# File test/optimist/parser_educate_test.rb, line 15
def test_argument_to_stringio
  assert_educates(/Options:/)
end
test_help_has_default_banner() click to toggle source

convert these into multiple tests pulled out of optimist_test for now

# File test/optimist/parser_educate_test.rb, line 41
def test_help_has_default_banner
  @p = Parser.new
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /options/i
  assert_equal 2, help.length # options, then -h

  @p = Parser.new
  @p.version "my version"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /my version/i
  assert_equal 4, help.length # version, options, -h, -v

  @p = Parser.new
  @p.banner "my own banner"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /my own banner/i
  assert_equal 2, help.length # banner, -h

  @p = Parser.new
  @p.text "my own text banner"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /my own text banner/i
  assert_equal 2, help.length # banner, -h
end
test_help_has_grammatical_default_text() click to toggle source
# File test/optimist/parser_educate_test.rb, line 151
def test_help_has_grammatical_default_text
  parser.opt :arg1, 'description with period.', :default => 'hello'
  parser.opt :arg2, 'description without period', :default => 'world'
  sio = StringIO.new 'w'
  parser.educate sio

  help = sio.string.split "\n"
  assert help[1] =~ /Default/
  assert help[2] =~ /default/
end
test_help_has_optional_synopsis() click to toggle source
# File test/optimist/parser_educate_test.rb, line 89
def test_help_has_optional_synopsis
  @p = Parser.new
  @p.synopsis "About this program"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /About this program/i
  assert_equal 4, help.length # line break, options, then -h
end
test_help_has_optional_usage() click to toggle source
# File test/optimist/parser_educate_test.rb, line 78
def test_help_has_optional_usage
  @p = Parser.new
  @p.usage "OPTIONS FILES"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /OPTIONS FILES/i
  assert_equal 4, help.length # line break, options, then -h
end
test_help_has_specific_order_for_usage_and_synopsis() click to toggle source
# File test/optimist/parser_educate_test.rb, line 100
def test_help_has_specific_order_for_usage_and_synopsis
  @p = Parser.new
  @p.usage "OPTIONS FILES"
  @p.synopsis "About this program"
  sio = StringIO.new "w"
  @p.parse []
  @p.educate sio
  help = sio.string.split "\n"
  assert help[0] =~ /OPTIONS FILES/i
  assert help[1] =~ /About this program/i
  assert_equal 5, help.length # line break, options, then -h
end
test_help_includes_option_types() click to toggle source
# File test/optimist/parser_educate_test.rb, line 124
def test_help_includes_option_types
  parser.opt :arg1, 'arg', :type => :int
  parser.opt :arg2, 'arg', :type => :ints
  parser.opt :arg3, 'arg', :type => :string
  parser.opt :arg4, 'arg', :type => :strings
  parser.opt :arg5, 'arg', :type => :float
  parser.opt :arg6, 'arg', :type => :floats
  parser.opt :arg7, 'arg', :type => :io
  parser.opt :arg8, 'arg', :type => :ios
  parser.opt :arg9, 'arg', :type => :date
  parser.opt :arg10, 'arg', :type => :dates
  sio = StringIO.new "w"
  parser.educate sio

  help = sio.string.split "\n"
  assert help[1] =~ /<i>/
  assert help[2] =~ /<i\+>/
  assert help[3] =~ /<s>/
  assert help[4] =~ /<s\+>/
  assert help[5] =~ /<f>/
  assert help[6] =~ /<f\+>/
  assert help[7] =~ /<filename\/uri>/
  assert help[8] =~ /<filename\/uri\+>/
  assert help[9] =~ /<date>/
  assert help[10] =~ /<date\+>/
end
test_help_preserves_positions() click to toggle source
# File test/optimist/parser_educate_test.rb, line 113
def test_help_preserves_positions
  parser.opt :zzz, "zzz"
  parser.opt :aaa, "aaa"
  sio = StringIO.new "w"
  parser.educate sio

  help = sio.string.split "\n"
  assert help[1] =~ /zzz/
  assert help[2] =~ /aaa/
end
test_no_arguments_to_stdout() click to toggle source
# File test/optimist/parser_educate_test.rb, line 9
def test_no_arguments_to_stdout
  assert_stdout(/Options:/) do
    parser.educate
  end
end
test_no_headers() click to toggle source
# File test/optimist/parser_educate_test.rb, line 19
def test_no_headers
  assert_educates(/^Options:/)
end
test_usage() click to toggle source
# File test/optimist/parser_educate_test.rb, line 23
def test_usage
  parser.usage("usage string")
  assert_educates(/^Usage: \w* usage string\n\nOptions:/)
end
test_usage_synopsis_version() click to toggle source
# File test/optimist/parser_educate_test.rb, line 28
def test_usage_synopsis_version
end