Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package yast2-ruby-bindings for 
openSUSE:Factory checked in at 2022-01-21 01:25:05
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/yast2-ruby-bindings (Old)
 and      /work/SRC/openSUSE:Factory/.yast2-ruby-bindings.new.1938 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "yast2-ruby-bindings"

Fri Jan 21 01:25:05 2022 rev:115 rq:947351 version:4.4.7

Changes:
--------
--- /work/SRC/openSUSE:Factory/yast2-ruby-bindings/yast2-ruby-bindings.changes  
2021-12-03 20:35:17.512246500 +0100
+++ 
/work/SRC/openSUSE:Factory/.yast2-ruby-bindings.new.1938/yast2-ruby-bindings.changes
        2022-01-21 01:25:15.118656373 +0100
@@ -1,0 +2,6 @@
+Mon Jan 17 14:03:14 UTC 2022 - Ladislav Slez??k <[email protected]>
+
+- Added yast/rspec/helpers.rb (related to bsc#1194784)
+- 4.4.7
+
+-------------------------------------------------------------------

Old:
----
  yast2-ruby-bindings-4.4.6.tar.bz2

New:
----
  yast2-ruby-bindings-4.4.7.tar.bz2

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ yast2-ruby-bindings.spec ++++++
--- /var/tmp/diff_new_pack.4hV2ub/_old  2022-01-21 01:25:15.582653193 +0100
+++ /var/tmp/diff_new_pack.4hV2ub/_new  2022-01-21 01:25:15.586653165 +0100
@@ -1,7 +1,7 @@
 #
 # spec file for package yast2-ruby-bindings
 #
-# Copyright (c) 2021 SUSE LLC
+# Copyright (c) 2022 SUSE LLC
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -17,7 +17,7 @@
 
 
 Name:           yast2-ruby-bindings
-Version:        4.4.6
+Version:        4.4.7
 Release:        0
 URL:            https://github.com/yast/yast-ruby-bindings
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build

++++++ yast2-ruby-bindings-4.4.6.tar.bz2 -> yast2-ruby-bindings-4.4.7.tar.bz2 
++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ruby-bindings-4.4.6/package/yast2-ruby-bindings.changes 
new/yast2-ruby-bindings-4.4.7/package/yast2-ruby-bindings.changes
--- old/yast2-ruby-bindings-4.4.6/package/yast2-ruby-bindings.changes   
2021-11-29 21:30:04.000000000 +0100
+++ new/yast2-ruby-bindings-4.4.7/package/yast2-ruby-bindings.changes   
2022-01-19 08:37:19.000000000 +0100
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Mon Jan 17 14:03:14 UTC 2022 - Ladislav Slez??k <[email protected]>
+
+- Added yast/rspec/helpers.rb (related to bsc#1194784)
+- 4.4.7
+
+-------------------------------------------------------------------
 Mon Nov 29 20:21:23 UTC 2021 - Josef Reidinger <[email protected]>
 
 - Avoid timing issue in integration tests ( bsc#1193192 )
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ruby-bindings-4.4.6/package/yast2-ruby-bindings.spec 
new/yast2-ruby-bindings-4.4.7/package/yast2-ruby-bindings.spec
--- old/yast2-ruby-bindings-4.4.6/package/yast2-ruby-bindings.spec      
2021-11-29 21:30:04.000000000 +0100
+++ new/yast2-ruby-bindings-4.4.7/package/yast2-ruby-bindings.spec      
2022-01-19 08:37:19.000000000 +0100
@@ -17,7 +17,7 @@
 
 
 Name:           yast2-ruby-bindings
-Version:        4.4.6
+Version:        4.4.7
 Release:        0
 URL:            https://github.com/yast/yast-ruby-bindings
 BuildRoot:      %{_tmppath}/%{name}-%{version}-build
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ruby-bindings-4.4.6/src/ruby/yast/rspec/helpers.rb 
new/yast2-ruby-bindings-4.4.7/src/ruby/yast/rspec/helpers.rb
--- old/yast2-ruby-bindings-4.4.6/src/ruby/yast/rspec/helpers.rb        
1970-01-01 01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-4.4.7/src/ruby/yast/rspec/helpers.rb        
2022-01-19 08:37:19.000000000 +0100
@@ -0,0 +1,90 @@
+require "yast"
+
+module Yast
+  module RSpec
+    module Helpers
+      # Helper for defining YaST modules which might not be present in
+      # the system when running the tests.
+      #
+      # When the requested module is present in the system then it is imported
+      # as usually. If it is missing a substitute definition is created.
+      #
+      # In the substitute definition it is enough to define only the methods
+      # used in the tests, you do not need to mirror the complete API.
+      #
+      # @note This needs to be called *after* starting code coverage with
+      #   `SimpleCov.start` so the coverage of the imported modules is 
correctly
+      #   counted.
+      #
+      # @note You can force using the defined stubs although the modules are
+      #   present in the system, this might be useful to actually test the 
stubs.
+      #   Just define the YAST_FORCE_MODULE_STUBS environment variable.
+      #
+      # @example Mock empty `Language` module
+      # Yast::RSpec::Helpers.define_yast_module("Language")
+      #
+      # @example Mock the `Language` module with the `language` method
+      # Yast::RSpec::Helpers.define_yast_module("Language", methods: 
[:language])
+      #
+      # @example Mock the `Language` module with `language` returning a 
default value
+      # Yast::RSpec::Helpers.define_yast_module("Language") do
+      #   def language
+      #     "en_US"
+      #   end
+      # end
+      #
+      # @param name [String] name of the YaST module
+      # @param methods [Array<Symbol>] optional list of defined methods,
+      #   the defined methods accept any parameters
+      # @param force [Boolean] force creating the fake implementation even when
+      #   the module is present in the system, can be also set by the
+      #   YAST_FORCE_MODULE_STUBS environment variable. This might be useful
+      #   if the module constructor touches the system and it would need a lot
+      #   of mocking. But use it carefully, this defeats the purpose of the 
RSpec
+      #   verifying doubles!
+      # @param block [Block] optional method definitions, they should provide
+      #   the same API as the original module, this can be combined with the
+      #   `methods` parameter. The block is evaluated in the context of the
+      #   defined modules so you can also use the helpers like `attr_reader`
+      #   or define constants.
+      def self.define_yast_module(name, methods: [:fake_method], force: false, 
&block)
+        # sanity check, make sure the code coverage is already running if it 
is enabled
+        if ENV["COVERAGE"] && (!defined?(SimpleCov) || !SimpleCov.running)
+          abort "\nERROR: The `define_yast_module` method needs to be called 
*after* " \
+            "enabling the code coverage tracking with `SimpleCov.start`!\n" \
+            "  Called from: #{caller(1).first}\n\n"
+        end
+
+        # force using the full stubs, useful for testing locally when the 
modules are installed
+        if ENV["YAST_FORCE_MODULE_STUBS"] || force
+          define_missing_yast_module(name, methods, &block)
+        else
+          # try loading the module, it might be present in the system (running 
locally
+          # or in GitHub Actions), mock it only when missing (e.g. in OBS 
build)
+          Yast.import(name)
+          puts "Found module Yast::#{name}"
+        end
+      rescue NameError
+        define_missing_yast_module(name, methods, &block)
+      end
+
+      # create a fake YaST module implementation
+      #
+      # @param name [String] name
+      # @param methods [Array<Symbol>] list of defined methods
+      # @param block [Block] optional method definitions
+      private_class_method def self.define_missing_yast_module(name, methods, 
&block)
+        warn "Mocking module Yast::#{name}"
+
+        # create a fake implementation of the module
+        new_class = Class.new do
+          # the defined method takes any number of parameters, a block is 
allowed as well
+          methods.each { |m| define_singleton_method(m) {|*_a, **_k, &_b|} }
+          instance_eval(&block) if block_given?
+        end
+
+        Yast.const_set(name.to_sym, new_class)
+      end
+    end
+  end
+end
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/yast2-ruby-bindings-4.4.6/src/ruby/yast/rspec.rb 
new/yast2-ruby-bindings-4.4.7/src/ruby/yast/rspec.rb
--- old/yast2-ruby-bindings-4.4.6/src/ruby/yast/rspec.rb        2021-11-29 
21:30:04.000000000 +0100
+++ new/yast2-ruby-bindings-4.4.7/src/ruby/yast/rspec.rb        2022-01-19 
08:37:19.000000000 +0100
@@ -1,6 +1,7 @@
+require "yast/rspec/helpers"
+require "yast/rspec/matchers"
 require "yast/rspec/scr"
 require "yast/rspec/shortcuts"
-require "yast/rspec/matchers"
 
 RSpec.configure do |c|
   c.include Yast::RSpec::Shortcuts
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/yast2-ruby-bindings-4.4.6/tests/rspec_helpers_spec.rb 
new/yast2-ruby-bindings-4.4.7/tests/rspec_helpers_spec.rb
--- old/yast2-ruby-bindings-4.4.6/tests/rspec_helpers_spec.rb   1970-01-01 
01:00:00.000000000 +0100
+++ new/yast2-ruby-bindings-4.4.7/tests/rspec_helpers_spec.rb   2022-01-19 
08:37:19.000000000 +0100
@@ -0,0 +1,74 @@
+#!/usr/bin/env rspec
+
+require_relative "test_helper"
+
+require "yast/rspec/helpers"
+
+describe Yast::RSpec::Helpers do
+  describe ".define_yast_module" do
+    context "the requested module is present" do
+      after do
+        # unload the testing YaST module
+        Yast.send(:remove_const, :ExampleTestModule) if 
defined?(Yast::ExampleTestModule)
+      end
+
+      it "imports the module" do
+        # make sure the module was not accidentally loaded before
+        Yast.send(:remove_const, :ExampleTestModule) if 
defined?(Yast::ExampleTestModule)
+
+        # load the tests/test_module/modules/ExampleTestModule.ycp module
+        expect { Yast::RSpec::Helpers.define_yast_module("ExampleTestModule") 
}.to \
+          change { defined?(Yast::ExampleTestModule) }.from(nil).to("constant")
+
+        # check that the testing module is really loaded
+        expect(Yast::ExampleTestModule.respond_to?(:arch_short)).to be true
+      end
+
+      it "does not evaluate the passed block" do
+        # load the tests/test_module/modules/ExampleTestModule.ycp module
+        expect { |b| 
Yast::RSpec::Helpers.define_yast_module("ExampleTestModule", &b) }.to_not \
+          yield_control
+      end
+
+      it "creates the fake implementation when forced" do
+        Yast::RSpec::Helpers.define_yast_module("ExampleTestModule", methods: 
[:foo], force: true)
+        expect(Yast::ExampleTestModule.respond_to?(:foo)).to be true
+      end
+    end
+
+    context "the module is missing" do
+      after do
+        # cleanup the defined testing YaST module
+        Yast.send(:remove_const, :VerySpecialNotExistingModule) if 
defined?(Yast::VerySpecialNotExistingModule)
+      end
+
+      it "defines an empty fake module" do
+        expect { 
Yast::RSpec::Helpers.define_yast_module("VerySpecialNotExistingModule") }.to \
+          change { defined?(Yast::VerySpecialNotExistingModule) 
}.from(nil).to("constant")
+      end
+
+      it "evaluates the passed block" do
+        expect { |b| 
Yast::RSpec::Helpers.define_yast_module("VerySpecialNotExistingModule", &b) 
}.to \
+          yield_control
+      end
+
+      it "defines the requested module methods" do
+        
Yast::RSpec::Helpers.define_yast_module("VerySpecialNotExistingModule", 
methods: [:foo])
+
+        expect(Yast::VerySpecialNotExistingModule.respond_to?(:foo)).to be true
+        # by default accepts any parameters
+        expect(Yast::VerySpecialNotExistingModule.method(:foo).arity).to eq(-1)
+      end
+
+      it "defines the methods passed in the block" do
+        
Yast::RSpec::Helpers.define_yast_module("VerySpecialNotExistingModule") do
+          def foo(_bar, _baz); end
+        end
+
+        expect(Yast::VerySpecialNotExistingModule.respond_to?(:foo)).to be true
+        # accepts two parameters
+        expect(Yast::VerySpecialNotExistingModule.method(:foo).arity).to eq(2)
+      end
+    end
+  end
+end

Reply via email to