diff --git a/lib/rbui.rb b/lib/rbui.rb index e7005576e..63073aeac 100644 --- a/lib/rbui.rb +++ b/lib/rbui.rb @@ -6,8 +6,6 @@ module RBUI extend Phlex::Kit - attr_accessor :namespace - def self.setup yield self create_namespace_module if namespace @@ -35,6 +33,14 @@ def self.create_namespace_module end end end + + def self.namespace + @namespace ||= nil + end + + def self.namespace=(value) + @namespace = value + end end # Require the Base class first diff --git a/test/rbui/setup_test.rb b/test/rbui/setup_test.rb new file mode 100644 index 000000000..8e796121a --- /dev/null +++ b/test/rbui/setup_test.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require "test_helper" + +class RBUI::SetupTest < Minitest::Test + def setup + @original_namespace = RBUI.namespace + end + + def teardown + RBUI.namespace = @original_namespace + Object.send(:remove_const, :UI) if Object.const_defined?(:UI) + end + + def test_default_namespace + RBUI.setup {} + + assert_nil RBUI.namespace + assert_kind_of RBUI::Base, RBUI::Button.new + end + + def test_custom_namespace + RBUI.setup do |config| + config.namespace = "UI" + end + + assert_equal "UI", RBUI.namespace + assert_equal RBUI::Base, UI::Base + assert_kind_of RBUI::Base, UI::Button.new + end +end