class TestCli

The test suite for Cli.

Public Instance Methods

setup() click to toggle source

Set working directory, current month's file, and last month's file, which will be created and destroyed for each test.

# File test/standup_md/cli_test.rb, line 12
def setup
  @workdir = File.join(__dir__, 'files')
  @current_test_file =
    File.join(@workdir, Date.today.strftime('%Y_%m.md'))
  @previous_month_test_file =
    File.join(@workdir, Date.today.prev_month.strftime('%Y_%m.md'))
  @options = ['--no-edit', '--no-write', "--directory=#{@workdir}"]
end
should_append?() click to toggle source

True only if --no-append and --previous-entry-tasks are passed.

# File test/standup_md/cli_test.rb, line 161
def should_append?
  c = cli
  refute(c.should_append?)

  c = cli['--no-append']
  refute(c.should_append?)

  c = cli(['--no-append', '--previous-entry-tasks="test one","test two"'])
  refute(c.should_append?)

  c = cli(['--previous-entry-tasks="test one","test two"'])
  assert(c.should_append?)
end
teardown() click to toggle source

Destroy the working directory and its contents.

# File test/standup_md/cli_test.rb, line 23
def teardown
  FileUtils.rm_r(@workdir) if File.directory?(@workdir)
  FileUtils.rm(@current_test_file) if File.file?(@current_test_file)
end
test_PREFERENCE_FILE() click to toggle source

The user's preference file is a string.

# File test/standup_md/cli_test.rb, line 30
def test_PREFERENCE_FILE
  assert_equal(
    File.expand_path(File.join(ENV['HOME'], '.standup_md.yml')),
    StandupMD::Cli::PREFERENCE_FILE
  )
end
test_append_previous?() click to toggle source

True by default. False if flag is passed.

# File test/standup_md/cli_test.rb, line 151
def test_append_previous?
  c = cli
  assert(c.append_previous?)

  c = cli(['--no-append-previous'])
  refute(c.append_previous?)
end
test_edit?() click to toggle source

True by default. False if flag is passed.

# File test/standup_md/cli_test.rb, line 141
def test_edit?
  c = cli
  assert(c.edit?)

  c = cli(['--no-edit'])
  refute(c.edit?)
end
test_editor() click to toggle source

The editor should be set by preferences, or env, or set to 'vim'.

# File test/standup_md/cli_test.rb, line 75
def test_editor
  c = cli
  if ENV['VISUAL']
    assert_equal(ENV['VISUAL'], c.editor)
  elsif ENV['EDITOR']
    assert_equal(ENV['EDITOR'], c.editor)
  else
    assert_equal('vim', c.editor)
  end

  c = cli(['--editor=mate'])
  assert_equal('mate', c.editor)
end
test_initialize() click to toggle source

The initialize method should accept the same parameters as exectute.

# File test/standup_md/cli_test.rb, line 62
def test_initialize
  assert_nothing_raised { StandupMD::Cli.new(@options) }
end
test_json?() click to toggle source

False by default. True if flag is passed.

# File test/standup_md/cli_test.rb, line 101
def test_json?
  c = cli
  refute(c.json?)

  c = cli(['-j'])
  assert(c.json?)
end
test_options() click to toggle source

The options should be an array of options passed from the command line.

# File test/standup_md/cli_test.rb, line 46
def test_options
  c = cli(@options)
  assert_equal(@options, c.options)
end
test_preferences() click to toggle source

The preferences are the settings after options are parsed.

# File test/standup_md/cli_test.rb, line 53
def test_preferences
  c = cli(@options)
  assert_equal(false, c.instance_variable_get('@write'))
  assert_equal(false, c.instance_variable_get('@edit'))
  assert_equal(@workdir, c.preferences['directory'])
end
test_print_all_entries?() click to toggle source

False by default. True if flag is passed.

# File test/standup_md/cli_test.rb, line 111
def test_print_all_entries?
  c = cli
  refute(c.print_all_entries?)

  c = cli(['-a'])
  assert(c.print_all_entries?)
end
test_print_current_entry?() click to toggle source

False by default. True if flag is passed.

# File test/standup_md/cli_test.rb, line 91
def test_print_current_entry?
  c = cli
  refute(c.print_current_entry?)

  c = cli(['-c'])
  assert(c.print_current_entry?)
end
test_self_execute() click to toggle source

The execute method is the entry point for the Cli. It's parameter is an array of command-line flags

# File test/standup_md/cli_test.rb, line 40
def test_self_execute
  assert_nothing_raised { StandupMD::Cli.execute(@options) }
end
test_standup() click to toggle source

Creates the instance of StandupMD.

# File test/standup_md/cli_test.rb, line 68
def test_standup
  c = cli
  assert_instance_of(StandupMD, c.standup)
end
test_verbose?() click to toggle source

False by default. True if flag is passed.

# File test/standup_md/cli_test.rb, line 121
def test_verbose?
  c = cli
  refute(c.verbose?)

  c = cli(['-v'])
  assert(c.verbose?)
end
test_write?() click to toggle source

True by default. False if flag is passed.

# File test/standup_md/cli_test.rb, line 131
def test_write?
  c = cli
  assert(c.write?)

  c = cli(['--no-write'])
  refute(c.write?)
end