Skip to content

Commit

Permalink
Change Config inheritance to preserve order
Browse files Browse the repository at this point in the history
  • Loading branch information
mbj committed Nov 22, 2020
1 parent 05eae35 commit 5f24cb8
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/mutant/cli/command/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def zombie?

def initialize(attributes)
super(attributes)
@config = Config::DEFAULT
@config = Config.env
end

def execute
Expand All @@ -49,7 +49,7 @@ def execute
end

def expand(file_config)
@config = Config.env.merge(file_config).merge(@config)
@config = @config.merge(file_config)
end

def soft_fail(result)
Expand Down
4 changes: 2 additions & 2 deletions lib/mutant/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ class Config
def merge(other)
other.with(
fail_fast: fail_fast || other.fail_fast,
includes: includes + other.includes,
includes: other.includes + includes,
jobs: other.jobs || jobs,
integration: other.integration || integration,
mutation_timeout: other.mutation_timeout || mutation_timeout,
matcher: matcher.merge(other.matcher),
requires: requires + other.requires,
requires: other.requires + requires,
zombie: zombie || other.zombie
)
end
Expand Down
32 changes: 25 additions & 7 deletions spec/unit/mutant/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -382,15 +382,14 @@ def self.make
let(:env_result) { instance_double(Mutant::Result::Env, success?: true) }
let(:expected_events) { [license_validation_event] }
let(:expected_exit) { true }
let(:file_config) { Mutant::Config::DEFAULT }
let(:file_config_result) { MPrelude::Either::Right.new(file_config) }
let(:license_result) { MPrelude::Either::Right.new(subscription) }
let(:runner_result) { MPrelude::Either::Right.new(env_result) }

let(:file_config) do
Mutant::Config::DEFAULT.with(
includes: %w[lib],
requires: %w[foo]
includes: %w[include-file],
requires: %w[require-file]
)
end

Expand Down Expand Up @@ -557,15 +556,34 @@ def self.make
end

context 'with --include option' do
let(:arguments) { super() + %w[--include lob --include lub] }
let(:bootstrap_config) { super().with(includes: %w[lib lob lub]) }
let(:arguments) do
super() + %w[
--include include-cli-a
--include include-cli-b
]
end

let(:bootstrap_config) do
super().with(
includes: %w[
include-file
include-cli-a
include-cli-b
]
)
end

include_examples 'CLI run'
end

context 'with --require option' do
let(:arguments) { super() + %w[--require bar] }
let(:bootstrap_config) { super().with(requires: %w[foo bar]) }
let(:arguments) { super() + %w[--require require-cli] }

let(:bootstrap_config) do
super().with(
requires: %w[require-file require-cli]
)
end

include_examples 'CLI run'
end
Expand Down
2 changes: 1 addition & 1 deletion spec/unit/mutant/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def expect_value(value)
let(:original_value) { %w[bar] }

it 'adds other and orignial' do
expect_value(original_value + other_value)
expect_value(other_value + original_value)
end
end

Expand Down

0 comments on commit 5f24cb8

Please sign in to comment.