Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
serradura committed Jan 1, 2024
1 parent 3a97c91 commit 83f90e2
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/bcdd/result/config/switchers/addons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module Addons
continue: {
default: false,
affects: %w[BCDD::Result BCDD::Result::Context BCDD::Result::Expectations BCDD::Result::Context::Expectations]
},
given: {
default: true,
affects: %w[BCDD::Result BCDD::Result::Context BCDD::Result::Expectations BCDD::Result::Context::Expectations]
}
}.transform_values!(&:freeze).freeze

Expand Down
10 changes: 9 additions & 1 deletion lib/bcdd/result/context/expectations/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ module Continuable
end
end

OPTIONS = { continue: Continuable }.freeze
module Given
private def Given(*values)
value = values.map(&:to_h).reduce({}) { |acc, val| acc.merge(val) }

Success.new(type: :initial_input, value: value, subject: self)
end
end

OPTIONS = { continue: Continuable, given: Given }.freeze

def self.options(config_flags)
::BCDD::Result::Config::Options.addon(map: config_flags, from: OPTIONS)
Expand Down
10 changes: 9 additions & 1 deletion lib/bcdd/result/context/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,15 @@ def Success(type, **value)
end
end

OPTIONS = { continue: Continuable }.freeze
module Given
private def Given(*values)
value = values.map(&:to_h).reduce({}) { |acc, val| acc.merge(val) }

_ResultAs(Success, :initial_input, value)
end
end

OPTIONS = { continue: Continuable, given: Given }.freeze

def self.options(config_flags)
::BCDD::Result::Config::Options.addon(map: config_flags, from: OPTIONS)
Expand Down
8 changes: 7 additions & 1 deletion lib/bcdd/result/expectations/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ module Continuable
end
end

OPTIONS = { continue: Continuable }.freeze
module Given
private def Given(value)
Success.new(type: :initial_input, value: value, subject: self)
end
end

OPTIONS = { continue: Continuable, given: Given }.freeze

def self.options(config_flags)
Config::Options.addon(map: config_flags, from: OPTIONS)
Expand Down
8 changes: 7 additions & 1 deletion lib/bcdd/result/mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ def Success(type, value = nil)
end
end

OPTIONS = { continue: Continuable }.freeze
module Given
private def Given(value)
_ResultAs(Success, :initial_input, value)
end
end

OPTIONS = { continue: Continuable, given: Given }.freeze

def self.options(config_flags)
Config::Options.addon(map: config_flags, from: OPTIONS)
Expand Down
13 changes: 9 additions & 4 deletions test/bcdd/result/config/addon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ class AddonTest < Minitest::Test
continue: {
enabled: false,
affects: [
'BCDD::Result',
'BCDD::Result::Context',
'BCDD::Result::Expectations',
'BCDD::Result::Context::Expectations'
'BCDD::Result', 'BCDD::Result::Context',
'BCDD::Result::Expectations', 'BCDD::Result::Context::Expectations'
]
},
given: {
enabled: true,
affects: [
'BCDD::Result', 'BCDD::Result::Context',
'BCDD::Result::Expectations', 'BCDD::Result::Context::Expectations'
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion test/bcdd/result/config_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Test < Minitest::Test
test '#to_h' do
config_values = BCDD::Result.config.to_h

assert_equal({ continue: false }, config_values[:addon])
assert_equal({ continue: false, given: true }, config_values[:addon])
assert_equal({ expectations: true, transitions: true }, config_values[:feature])
assert_equal({ nil_as_valid_value_checking: false }, config_values[:pattern_matching])
assert_equal({ 'Result' => false, 'Context' => false, 'BCDD::Context' => false }, config_values[:constant_alias])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
class BCDD::Result::TransitionsEnabledWithSubjectSingletonNestedTest < Minitest::Test
include BCDDResultTransitionAssertions

module Giveable
def Given(value)
_ResultAs(BCDD::Result::Success, :initial_input, value)
end
end

module CheckForZeros
extend self, Giveable, BCDD::Result.mixin(config: { addon: { continue: true } })
extend self, BCDD::Result.mixin(config: { addon: { continue: true } })

def call(numbers)
BCDD::Result.transitions(name: 'CheckForZeros') do
Expand All @@ -33,7 +27,7 @@ def detect_zero(numbers, ref)
end

module Division
extend self, Giveable, BCDD::Result.mixin(config: { addon: { continue: true } })
extend self, BCDD::Result.mixin(config: { addon: { continue: true } })

def call(num1, num2)
BCDD::Result.transitions(name: 'Division') do
Expand Down Expand Up @@ -67,7 +61,7 @@ def divide((num1, num2))
end

module SumDivisionsByTwo
extend self, Giveable, BCDD::Result.mixin(config: { addon: { continue: true } })
extend self, BCDD::Result.mixin(config: { addon: { continue: true } })

def call(*numbers)
BCDD::Result.transitions(name: 'SumDivisionsByTwo') do
Expand Down

0 comments on commit 83f90e2

Please sign in to comment.