Git Product home page Git Product logo

Comments (9)

sethvargo avatar sethvargo commented on September 25, 2024

ChefSpec is doing a simple require 'berkshelf' and then rescuing the LoadError

from chef-dk.

tknerr avatar tknerr commented on September 25, 2024

Does that mean that I additionally need to install berkshelf as a Gem, even though it comes with ChefDK pre-bundled already?

from chef-dk.

danielsdeleo avatar danielsdeleo commented on September 25, 2024

Berkshelf is installed as a gem into ChefDK. For example, this works for me (on mac):

$ /opt/chefdk/embedded/bin/gem which berkshelf
/opt/chefdk/embedded/lib/ruby/gems/2.1.0/gems/berkshelf-3.1.3/lib/berkshelf.rb
$ /opt/chefdk/embedded/bin/ruby -e 'require "berkshelf"; p Berkshelf::VERSION'
"3.1.3"

So I'm not sure what's going on. Can you reproduce this error if ChefDK is installed to the default location? Is there any bundler or anything else involved that could be affecting this?

from chef-dk.

tknerr avatar tknerr commented on September 25, 2024

Same for me:

D:\Repos\_github\bills-kitchen\target\build\repo\tmp2>gem which berkshelf
D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/berkshelf-3.1.3/lib/berkshelf.rb

D:\Repos\_github\bills-kitchen\target\build\repo\tmp2>ruby -e 'require "berkshelf"; p Berkshelf::VERSION'
DL is deprecated, please use Fiddle
"3.1.3"

The problem is when adding a chefspec example that requires berkshelf, e.g. with spec/foo_spec.rb:

require 'chefspec'
require 'chefspec/berkshelf'

describe "foo" do
  it "compares numbers" do
    expect(1 == 1).to be true
  end
end

Running rspec will now produce the above mentioned error due to the require 'chefspec/berkshelf'.

from chef-dk.

tknerr avatar tknerr commented on September 25, 2024

Btw: I have also tried adding both chefspec and berkshelf to a Gemfile, but they seem to conflict :-(

Gemfile:

source 'https://rubygems.org'

gem 'berkshelf', '3.1.3'
gem 'chefspec', '4.0.0'

Output:

D:\Repos\_github\bills-kitchen\target\build\repo\tmp>bundle install
DL is deprecated, please use Fiddle
Fetching gem metadata from https://rubygems.org/........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Bundler could not find compatible versions for gem "ffi":
  In Gemfile:
    berkshelf (= 3.1.3) x86-mingw32 depends on
      ffi (~> 1.9) x86-mingw32

    chefspec (= 4.0.0) x86-mingw32 depends on
      ffi (1.5.0)

from chef-dk.

danielsdeleo avatar danielsdeleo commented on September 25, 2024

@tknerr that's probably the root cause of your original issue. Can you try running with ruby -d? That will show all exceptions (including ones that get rescued). You'll see a lot of irrelevant exceptions, but you should get the full message of the Gem::LoadError that happens right before chefspec finally fails.

For example:

$ ruby -e "raise 'foo' rescue nil" 
$ ruby -d -e "raise 'foo' rescue nil"
Exception `LoadError' at /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems.rb:1082 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /Users/ddeleo/.rbenv/versions/2.0.0-p247/lib/ruby/2.0.0/rubygems.rb:1091 - cannot load such file -- rubygems/defaults/ruby
Exception `RuntimeError' at -e:1 - foo

I'll guess that this issue is caused by chef pinning its FFI dependency to an older version. If that is indeed the problem, it will be fixed soon. See: chef/chef#1528

from chef-dk.

tknerr avatar tknerr commented on September 25, 2024

@danielsdeleo guess you are right, should probably be fixed with chef/chef#1528

Here's the output of ruby -d -e 'require "chefspec"; require "chefspec/berkshelf"':

D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55: warning: loading in progress, circular require considered harmful - D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chef-11.14.0.alpha.5-x86-mingw32/lib/chef/resource/windows_package.rb
        from -e:1:in `<main>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:144:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `rescue in require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:135:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec.rb:24:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec.rb:24:in `require_relative'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec/api.rb:1:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec/api.rb:1:in `require_relative'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec/runner.rb:5:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chef-11.14.0.alpha.5-x86-mingw32/lib/chef/resources.rb:72:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chef-11.14.0.alpha.5-x86-mingw32/lib/chef/resource/windows_package.rb:20:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chef-11.14.0.alpha.5-x86-mingw32/lib/chef/provider/package/windows.rb:19:in `<top (required)>'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
Exception `LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- berkshelf
Exception `Gem::LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/specification.rb:2007 - Unable to activate dep_selector-1.0.3, because ffi-1.5.0-x86-mingw32 conflicts with ffi (~> 1.9)
Exception `Gem::LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/specification.rb:2007 - Unable to activate dep_selector-1.0.3, because ffi-1.5.0-x86-mingw32 conflicts with ffi (~> 1.9)
Exception `ChefSpec::Error::GemLoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/gems/2.0.0/gems/chefspec-4.0.0/lib/chefspec/berkshelf.rb:4 - I could not load the 'Berkshelf' gem! You must have the gem installed
on your local system before you can use the berkshelf plugin.
You can install berkshelf by running:

    gem install berkshelf

or add Berkshelf to your Gemfile and

Relevant lines:

Exception `LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55 - cannot load such file -- berkshelf
Exception `Gem::LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/specification.rb:2007 - Unable to activate dep_selector-1.0.3, because ffi-1.5.0-x86-mingw32 conflicts with ffi (~> 1.9)
Exception `Gem::LoadError' at D:/Repos/_github/bills-kitchen/target/build/tools/chefdk/embedded/lib/ruby/2.0.0/rubygems/specification.rb:2007 - Unable to activate dep_selector-1.0.3, because ffi-1.5.0-x86-mingw32 conflicts with ffi (~> 1.9)

from chef-dk.

danielsdeleo avatar danielsdeleo commented on September 25, 2024

Okay, gonna close this as a duplicate in that case. The relevant fix should be released as an updated alpha as soon as we verify things with the new ffi version in our build lab.

from chef-dk.

tknerr avatar tknerr commented on September 25, 2024

@danielsdeleo cool stuff, let me know when a new alpha build is available

from chef-dk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.