require_relative './test_helper' class TestEnvironment < Minitest::Test def setup @parent = Environment.new(nil, { language: 'ruby' }) @child = Environment.new(@parent, { test_framework: 'minitest' }) end def test_initialize assert_instance_of Environment, @parent assert_instance_of Environment, @child end def test_parent assert_nil @parent.parent assert_instance_of Environment, @child.parent assert_equal @parent, @child.parent end def test_defaults assert_instance_of Hash, @parent.defaults assert_instance_of Hash, @child.defaults end def test_define assert_equal 'vim', @child.define(:editor, 'vim') assert_equal 'vim', @child.defaults[:editor] end def test_defined? assert @child.defined?(:test_framework) assert @child.defined?(:language) refute @child.defined?(:version_control) end def test_lookup assert_equal 'minitest', @child.lookup(:test_framework) assert_equal 'ruby', @child.lookup(:language) assert_raises(RuntimeError) { @child.lookup(:version_control) } end def test_set assert_equal 'rspec', @child.set(:test_framework, 'rspec') assert_equal 'rspec', @child.lookup(:test_framework) assert_equal 'lisp', @child.set(:language, 'lisp') assert_equal 'lisp', @child.lookup(:language) assert_raises(RuntimeError) { @child.set(:version_control, 'git') } end end