diff --git a/lib/openhab/dsl/sitemaps/builder.rb b/lib/openhab/dsl/sitemaps/builder.rb index a22b7dd4e9..95752200d8 100644 --- a/lib/openhab/dsl/sitemaps/builder.rb +++ b/lib/openhab/dsl/sitemaps/builder.rb @@ -144,12 +144,14 @@ def initialize(type, if @builder_proxy old_obj = @builder_proxy.__getobj__ @builder_proxy.__setobj__(self) - yield @builder_proxy + begin + yield @builder_proxy + ensure + @builder_proxy.__setobj__(old_obj) + end else instance_eval_with_dummy_items(&block) end - ensure - @builder_proxy&.__setobj__(old_obj) end # Adds one or more new rules for setting the label color diff --git a/spec/openhab/dsl/sitemaps/builder_spec.rb b/spec/openhab/dsl/sitemaps/builder_spec.rb index 8fa206b712..3d43592ede 100644 --- a/spec/openhab/dsl/sitemaps/builder_spec.rb +++ b/spec/openhab/dsl/sitemaps/builder_spec.rb @@ -35,6 +35,10 @@ expect(b.__getobj__).to be_a(OpenHAB::DSL::Sitemaps::SitemapBuilder) expect(self).not_to respond_to(:text) b.text item: "Switch1" + expect(self).to be example + expect(b.__getobj__).to be_a(OpenHAB::DSL::Sitemaps::SitemapBuilder) + expect(self).not_to respond_to(:text) + expect { b.text }.not_to raise_error # Call a second time to ensure that builder proxy got reset correctly end end end