chefspec中来自gem的方法中未定义的局部变量

问题描述 投票:0回答:1

我在厨师食谱中加入了定制的宝石。无论我尝试了什么,都会遇到与未定义的局部变量或方法“主机”]类似的错误。

我为此尝试了许多不同的变体。

allow(HostOpsCookbook).to receive(:host).with(:sonic.version).and_return('10.0')

宝石布局 cust_gem \lib \ibus \host sonic.rb host.rb

host.rb

module Ibus
  class Host
   attr_reader :sonic

    def initialize
      extend_type
    end

    def enxtend_type
      @sonic = Ibus::Host::Sonic.new
    end

  end
end

host \ sonic.rb

module Ibus
  class Host
    class Sonic

      def version
         .....
      end
  end
 end
end

厨师食谱 cookbook \libraries host_helper.rb \recipes default.rb

chef \ cookbook \ libraries \ host_helper.rb

module HostOpsCookbook
  def host
    require_ibus_gem #Loads the gem
    @@host ||= Ibus::Host.new
  end
end

Chef::Recipe.send(:include, HostOpsCookbook) if defined?(Chef::Recipe)
Chef::Resource.send(:include, HostOpsCookbook) if defined?(Chef::Resource)
Chef::Provider.send(:include, HostOpsCookbook) if defined?(Chef::Provider)

厨师\菜谱\食谱\ default.rb

sonic_version = host.sonic.version

这是代码,可以调用gem方法。

但是我无法弄清楚如何在规范测试中对以下内容进行存根。

host.sonic.version

我在厨师食谱中加入了定制的宝石。无论我尝试过什么,都会遇到与未定义的局部变量或方法“主机”类似的错误,我已经尝试了许多不同的变化。 allow(...

rspec rubygems chef chefspec
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.