Skip to content

Commit

Permalink
Allows global config overrides & reset
Browse files Browse the repository at this point in the history
Fixes #25
  • Loading branch information
searls committed Aug 21, 2016
1 parent 2de1027 commit c2925fe
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 3 deletions.
9 changes: 9 additions & 0 deletions lib/suture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@ def self.verify(name, options)
Suture::InterpretsResults.new.interpret(test_results)
end
end

def self.config(config = {})
@config ||= DEFAULT_OPTIONS.dup
@config.merge!(config)
end

def self.reset!
@config = nil
end
end
2 changes: 1 addition & 1 deletion lib/suture/builds_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class BuildsPlan

def build(name, options = {})
Value::Plan.new(
DEFAULT_OPTIONS.
Suture.config.
merge(options).
merge(:name => name).
merge(Suture::Util::Env.to_map(UN_ENV_IABLE_OPTIONS))
Expand Down
4 changes: 2 additions & 2 deletions lib/suture/prescribes_test_plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class PrescribesTestPlan
}

def prescribe(name, options = {})
Value::TestPlan.new(DEFAULT_OPTIONS.
merge(DEFAULT_TEST_OPTIONS).
Value::TestPlan.new(DEFAULT_TEST_OPTIONS.
merge(Suture.config).
merge(options).
merge(:name => name).
merge(Suture::Util::Env.to_map(UN_ENV_IABLE_OPTIONS)))
Expand Down
1 change: 1 addition & 0 deletions safe/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def setup
super
clean("db")
ENV.delete_if { |(k,v)| k.start_with?("SUTURE_") }
Suture.reset!
end

private
Expand Down
9 changes: 9 additions & 0 deletions test/suture/builds_plan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Suture
class BuildsPlanTest < Minitest::Test
def teardown
ENV.delete_if { |(k,v)| k.start_with?("SUTURE_") }
Suture.reset!
end

def test_defaults
Expand All @@ -11,6 +12,14 @@ def test_defaults
assert_equal :foo, result.name
end

def test_global_overrides
Suture.config(:database_path => "other.db")

result = BuildsPlan.new.build(:foo)

assert_equal "other.db", result.database_path
end

def test_build_without_env_vars
some_callable = lambda { "hi" }
some_new_callable = lambda { "hi" }
Expand Down
9 changes: 9 additions & 0 deletions test/suture/prescribes_test_plan_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def setup

def teardown
ENV.delete_if { |(k,v)| k.start_with?("SUTURE_") }
Suture.reset!
end

def test_defaults
Expand All @@ -15,6 +16,14 @@ def test_defaults
assert_equal "db/suture.sqlite3", result.database_path
end

def test_global_overrides
Suture.config(:database_path => "other.db")

result = @subject.prescribe(:foo)

assert_equal "other.db", result.database_path
end

def test_options
some_subject = lambda {}

Expand Down
26 changes: 26 additions & 0 deletions test/suture_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,30 @@ def test_verify_did_fail

verify(interprets_results).interpret(test_results)
end

def test_config_default
assert_equal Suture::DEFAULT_OPTIONS, Suture.config
end

def test_config_override
initial = Suture::DEFAULT_OPTIONS

result = Suture.config({:pants => true})

expected = Suture::DEFAULT_OPTIONS.merge(:pants => true)
assert_equal expected, result
assert_equal expected, Suture.config
end

def test_reset!
Suture.config({:trollface => "lol"})

Suture.reset!

assert_equal Suture::DEFAULT_OPTIONS, Suture.config
end

def teardown
Suture.reset!
end
end

0 comments on commit c2925fe

Please sign in to comment.