Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conform to standard and update CI test versions #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/standup_md.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require_relative 'standup_md/version'
require_relative 'standup_md/file'
require_relative 'standup_md/entry'
require_relative 'standup_md/entry_list'
require_relative 'standup_md/cli'
require_relative 'standup_md/config'
require_relative "standup_md/version"
require_relative "standup_md/file"
require_relative "standup_md/entry"
require_relative "standup_md/entry_list"
require_relative "standup_md/cli"
require_relative "standup_md/config"

##
# The main module for the gem. Provides access to configuration classes.
Expand Down
18 changes: 8 additions & 10 deletions lib/standup_md/cli.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require 'optparse'
require_relative 'cli/helpers'
require "optparse"
require_relative "cli/helpers"

module StandupMD
##
Expand Down Expand Up @@ -76,18 +76,16 @@ def initialize(options = [], load_config: true)
#
# @return [nil]
def load_preferences
if ::File.exist?(@config.preference_file)
::StandupMD.load_config_file(@config.preference_file)
@preference_file_loaded = true
else
echo "Preference file #{@config.preference_file} does not exist."
end
::StandupMD::ConfigFile.new(@config.preference_file)
@preference_file_loaded = true
rescue
echo "Preference file #{@config.preference_file} does not exist."
end

##
# Has the preference file been loaded?
#
# @return boolean
# @return [Boolean]
def preference_file_loaded?
@preference_file_loaded
end
Expand All @@ -111,7 +109,7 @@ def write_file
end

##
# Quick access to Cli.echo.
# Quick access to +Cli.echo+.
#
# @return [nil]
def echo(msg)
Expand Down
14 changes: 7 additions & 7 deletions lib/standup_md/config.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require_relative 'config/cli'
require_relative 'config/file'
require_relative 'config/entry'
require_relative 'config/entry_list'
require_relative "config/cli"
require_relative "config/file"
require_relative "config/entry"
require_relative "config/entry_list"

module StandupMD
##
Expand Down Expand Up @@ -36,9 +36,9 @@ class Config
##
# Builds the links to the configuration classes.
def initialize
@cli = StandupMD::Config::Cli.new
@file = StandupMD::Config::File.new
@entry = StandupMD::Config::Entry.new
@cli = StandupMD::Config::Cli.new
@file = StandupMD::Config::File.new
@entry = StandupMD::Config::Entry.new
@entry_list = StandupMD::Config::EntryList.new
end
end
Expand Down
33 changes: 33 additions & 0 deletions lib/standup_md/config_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true

module StandupMD
class ConfigFile
##
# The name of the instantiated config file.
attr_reader :name

##
# @param [String] file_name
def initialize(name)
@name = ::File.expand_path(name)
raise "File #{@name} does not exist." unless ::File.file?(@name)
@loaded = false
end

##
# Has the config file been loaded?
#
# @return [Boolean]
def loaded?
@loaded
end

##
# Loads the config file.
#
# @return [Boolean] Was the file loaded?
def load
@loaded = load @file
end
end
end
8 changes: 5 additions & 3 deletions lib/standup_md/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,29 @@ module Version
# @return [Integer]
PATCH = 14

module_function

##
# Version as +[MAJOR, MINOR, PATCH]+
#
# @return [Array]
def self.to_a
def to_a
[MAJOR, MINOR, PATCH]
end

##
# Version as +MAJOR.MINOR.PATCH+
#
# @return [String]
def self.to_s
def to_s
to_a.join('.')
end

##
# Version as +{major: MAJOR, minor: MINOR, patch: PATCH}+
#
# @return [Hash]
def self.to_h
def to_h
Hash[%i[major minor patch].zip(to_a)]
end
end
Expand Down
66 changes: 33 additions & 33 deletions test/standup_md/cli_test.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/standup_md'
require_relative "../test_helper"
require_relative "../../lib/standup_md"

##
# The test suite for +Cli+.
Expand All @@ -14,10 +14,10 @@ def setup
StandupMD.config.entry.reset
StandupMD.config.entry_list.reset
StandupMD.config.cli.preference_file = test_config_file_name
StandupMD.instance_variable_set('@config_file_loaded', false)
StandupMD.instance_variable_set(:@config_file_loaded, false)
@previous_month_test_file =
File.join(workdir, Date.today.prev_month.strftime('%Y_%m.md'))
@options = ['--no-edit', '--no-write', '--directory', workdir.to_s]
File.join(workdir, Date.today.prev_month.strftime("%Y_%m.md"))
@options = ["--no-edit", "--no-write", "--directory", workdir.to_s]
end

def teardown
Expand Down Expand Up @@ -83,23 +83,23 @@ def test_verbose
cli(@options)
refute(StandupMD.config.cli.verbose)

cli(['--directory', workdir.to_s, '-v'] + @options)
cli(["--directory", workdir.to_s, "-v"] + @options)
assert(StandupMD.config.cli.verbose)
end

def test_write
cli(@options)
refute(StandupMD.config.cli.write)

cli(['--directory', workdir.to_s, '--write'] + @options)
cli(["--directory", workdir.to_s, "--write"] + @options)
assert(StandupMD.config.cli.write)
end

def test_auto_fill_previous
assert(StandupMD.config.cli.auto_fill_previous)
cli(@options)

cli(['--no-auto-fill-previous'] + @options)
cli(["--no-auto-fill-previous"] + @options)
refute(StandupMD.config.cli.auto_fill_previous)
end

Expand All @@ -109,43 +109,43 @@ def test_write_file
end

def test_current
cli(['--directory', workdir.to_s])
cli(["--directory", workdir.to_s])
assert_equal(["<!-- ADD TODAY'S WORK HERE -->"], StandupMD.config.entry.current)

cli(['--current', 'test', '--directory', workdir.to_s])
cli(["--current", "test", "--directory", workdir.to_s])
assert_equal(%w[test], StandupMD.config.entry.current)
end

def test_previous
cli(['--directory', workdir.to_s])
cli(["--directory", workdir.to_s])
assert_equal([], StandupMD.config.entry.previous)

cli(['--previous', 'test', '--directory', workdir.to_s])
cli(["--previous", "test", "--directory", workdir.to_s])
assert_equal(%w[test], StandupMD.config.entry.previous)
end

def test_impediments
cli(['--directory', workdir.to_s])
assert_equal(['None'], StandupMD.config.entry.impediments)
cli(["--directory", workdir.to_s])
assert_equal(["None"], StandupMD.config.entry.impediments)

cli(['--impediments', 'test', '--directory', workdir.to_s])
cli(["--impediments", "test", "--directory", workdir.to_s])
assert_equal(%w[test], StandupMD.config.entry.impediments)
end

def test_notes
cli(['--directory', workdir.to_s])
cli(["--directory", workdir.to_s])
assert_equal([], StandupMD.config.entry.notes)

cli(['--notes', 'test', '--directory', workdir.to_s])
cli(["--notes", "test", "--directory", workdir.to_s])
assert_equal(%w[test], StandupMD.config.entry.notes)
end

def test_sub_header_order
cli(['--directory', workdir.to_s])
cli(["--directory", workdir.to_s])
assert_equal(%w[previous current impediments notes], StandupMD.config.file.sub_header_order)

cli(
['--sub-header-order', 'current,previous,notes,impediments', '--directory', workdir.to_s],
["--sub-header-order", "current,previous,notes,impediments", "--directory", workdir.to_s],
load_config: false
)
assert_equal(
Expand All @@ -155,37 +155,37 @@ def test_sub_header_order
end

def test_file_name_format
cli(['--directory', workdir.to_s], load_config: false)
assert_equal('%Y_%m.md', StandupMD.config.file.name_format)
cli(["--directory", workdir.to_s], load_config: false)
assert_equal("%Y_%m.md", StandupMD.config.file.name_format)

cli(['--file-name-format', '%y_%m.md', '--directory', workdir.to_s])
assert_equal('%y_%m.md', StandupMD.config.file.name_format)
cli(["--file-name-format", "%y_%m.md", "--directory", workdir.to_s])
assert_equal("%y_%m.md", StandupMD.config.file.name_format)
end

def test_editor
ENV['VISUAL'] = 'vim'
cli(['--directory', workdir.to_s])
assert_equal('vim', StandupMD.config.cli.editor)
ENV["VISUAL"] = "vim"
cli(["--directory", workdir.to_s])
assert_equal("vim", StandupMD.config.cli.editor)

cli(['--editor', 'mate', '--directory', workdir.to_s])
assert_equal('mate', StandupMD.config.cli.editor)
cli(["--editor", "mate", "--directory", workdir.to_s])
assert_equal("mate", StandupMD.config.cli.editor)
end

def test_print
enable_stdout_redirection

cli(['--directory', workdir.to_s])
cli(["--directory", workdir.to_s])
refute(StandupMD.config.cli.print)

cli(['--print', '--directory', workdir.to_s])
cli(["--print", "--directory", workdir.to_s])
assert(StandupMD.config.cli.print)
assert_equal(Date.today, StandupMD.config.cli.date)

cli(
[
'--print',
'--directory', workdir.to_s,
'--print', Date.today.prev_day.strftime(StandupMD.config.file.header_date_format).to_s
"--print",
"--directory", workdir.to_s,
"--print", Date.today.prev_day.strftime(StandupMD.config.file.header_date_format).to_s
]
)
assert(StandupMD.config.cli.print)
Expand Down
22 changes: 11 additions & 11 deletions test/standup_md_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

require_relative 'test_helper'
require_relative '../lib/standup_md'
require_relative "test_helper"
require_relative "../lib/standup_md"

class TestStandupMD < TestHelper
def setup
StandupMD.instance_variable_set('@config_file_loaded', false)
StandupMD.instance_variable_set(:@config_file_loaded, false)
end

def test_config
Expand Down Expand Up @@ -39,23 +39,23 @@ def test_version
def test_configure
assert_nothing_raised do
StandupMD.configure do |s|
s.file.directory = workdir
s.cli.editor = 'mate'
s.entry.impediments = ['Nothing']
s.file.directory = workdir
s.cli.editor = "mate"
s.entry.impediments = ["Nothing"]
end
end
assert_equal(workdir, StandupMD.config.file.directory)
assert_equal('mate', StandupMD.config.cli.editor)
assert_equal(['Nothing'], StandupMD.config.entry.impediments)
assert_equal("mate", StandupMD.config.cli.editor)
assert_equal(["Nothing"], StandupMD.config.entry.impediments)
end

def test_load_config_file
create_config_file(test_config_file_name)
refute(StandupMD.config_file_loaded?)
assert_nothing_raised { StandupMD.load_config_file(test_config_file_name) }
assert(StandupMD.config_file_loaded?)
assert_equal(['NONE'], StandupMD.config.entry.impediments)
assert_equal('Current', StandupMD.config.file.current_header)
assert_equal('mate', StandupMD.config.cli.editor)
assert_equal(["NONE"], StandupMD.config.entry.impediments)
assert_equal("Current", StandupMD.config.file.current_header)
assert_equal("mate", StandupMD.config.cli.editor)
end
end
Loading