Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
greeneca committed Jul 10, 2017
1 parent d28aed6 commit 4897658
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 9 deletions.
32 changes: 32 additions & 0 deletions test/roku_builder/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,38 @@ def test_config_configure_edit_params
File.delete(target_config) if File.exist?(target_config)
end

def test_config_configure_edit_params_project
target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
options = build_options({
config: target_config,
configure: true,
edit_params: "directory:/test/dir"
})
File.delete(target_config) if File.exist?(target_config)
refute File.exist?(target_config)
config = Config.new(options: options)
config.configure
assert File.exist?(target_config)
assert_equal "/test/dir", config.raw[:projects][config.raw[:projects][:default]][:directory]
File.delete(target_config) if File.exist?(target_config)
end

def test_config_configure_edit_params_stage
target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
options = build_options({
config: target_config,
configure: true,
edit_params: "branch:test"
})
File.delete(target_config) if File.exist?(target_config)
refute File.exist?(target_config)
config = Config.new(options: options)
config.configure
assert File.exist?(target_config)
assert_equal "test", config.raw[:projects][config.raw[:projects][:default]][:stages][:production][:branch]
File.delete(target_config) if File.exist?(target_config)
end

def test_config_configure_edit_params_default
target_config = File.join(test_files_path(ConfigTest), "configure_test.json")
options = build_options({
Expand Down
65 changes: 56 additions & 9 deletions test/roku_builder/test_options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
module RokuBuilder
class OptionsTest < Minitest::Test
def setup
RokuBuilder.class_variable_set(:@@plugins, [])
RokuBuilder.setup_plugins
register_plugins(Core)
Logger.set_testing
end
def teardown
Expand Down Expand Up @@ -36,8 +37,10 @@ def test_options_parse
parser.expect(:banner=, nil, [String])
parser.expect(:parse!, nil)
OptionParser.stub(:new, parser) do
options.stub(:validate_parser, nil) do
options_hash = options.send(:parse)
options.stub(:add_plugin_options, nil) do
options.stub(:validate_parser, nil) do
options_hash = options.send(:parse)
end
end
end
parser.verify
Expand All @@ -50,12 +53,14 @@ def test_options_parse_validate_options_good
parser.expect(:banner=, nil, [String])
parser.expect(:parse!, nil)
OptionParser.stub(:new, parser) do
options.send(:parse)
options.stub(:add_plugin_options, nil) do
options.send(:parse)
end
end
parser.verify
Array.class_eval { remove_method :each_option }
end
def test_options_parse_validate_options_bad
def test_options_parse_validate_options_bad_short
Array.class_eval { alias_method :each_option, :each }
parser = Minitest::Mock.new()
options = Options.allocate
Expand All @@ -64,25 +69,47 @@ def test_options_parse_validate_options_bad

OptionParser.stub(:new, parser) do
assert_raises(ImplementationError) do
options.send(:parse)
options.stub(:add_plugin_options, nil) do
options.send(:parse)
end
end
end
parser.verify
Array.class_eval { remove_method :each_option }
end
def build_stack(good = true)
def test_options_parse_validate_options_bad_long
Array.class_eval { alias_method :each_option, :each }
parser = Minitest::Mock.new()
options = Options.allocate
parser.expect(:banner=, nil, [String])
parser.expect(:instance_variable_get, build_stack(true, false), [:@stack])

OptionParser.stub(:new, parser) do
options.stub(:add_plugin_options, nil) do
assert_raises(ImplementationError) do
options.send(:parse)
end
end
end
parser.verify
Array.class_eval { remove_method :each_option }
end
def build_stack(shortgood = true, longgood = true)
optionsA = Minitest::Mock.new()
optionsB = Minitest::Mock.new()
list = [optionsA, optionsB]
stack = [list]
3.times do
optionsA.expect(:short, [ "a" ])
optionsA.expect(:long, [ "aOption" ])
if good
if shortgood
optionsB.expect(:short, [ "b" ])
optionsB.expect(:long, ["bOption" ])
else
optionsB.expect(:short, [ "a" ])
end
if longgood
optionsB.expect(:long, ["bOption" ])
else
optionsB.expect(:long, [ "aOption" ])
end
end
Expand All @@ -103,6 +130,15 @@ def test_options_validate_no_commands
build_options(options)
end
end
def test_options_validate_source
options = Options.allocate
options.stub(:source_command?, true) do
assert_raises InvalidOptions do
options.send(:initialize, {options: {validate: true}})
options.validate
end
end
end
def test_options_validate_extra_sources_sideload
options = {
validate: true,
Expand All @@ -123,6 +159,17 @@ def test_options_validate_extra_sources_package
build_options(options)
end
end
def test_options_validate_depricated
options = Options.allocate
logger = Minitest::Mock.new()
logger.expect(:warn, nil, ["Depricated"])
Logger.class_variable_set(:@@instance, logger)
options.stub(:depricated_options, {validate: "Depricated"}) do
options.send(:initialize, {options: {validate: true}})
options.validate
end
logger.verify
end
def test_options_exclude_command
options = build_options({
validate:true,
Expand Down

0 comments on commit 4897658

Please sign in to comment.