0

I have some chef unit tests that I can run via the command : chef exec rspec

However, I am trying to run these from TeamCity and I am using a rakefile. When I try to execute the rakefile the require 'chefspec' line in the test file causes an error "cannot load such file -- chefspec (LoadError)"

I know chefspec is installed. I am new to Ruby, chefspec, rspec. I know there is mention of a gemspec file and I have tried to create one in the directory where I can run the command chef exec rspec to execute the test. However, when I try to run bundle install I get the error Could not locate Gemfile or .bundle/ directory. Is there a default location of a gemfile when you install ruby? I am pretty lost at this point.

C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire': cannot load such file -- chefspec (LoadErr or) from C:/Ruby22/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from D:/../spec/octopus_tentacle_spec.rb:1:in' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:inblock in load_ spec_files' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in each' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:inload_spec_file s' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in setup' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:inrun' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in run' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:ininvoke' from C:/Ruby22/lib/ruby/gems/2.2.0/gems/rspec-core-3.3.2/exe/rspec:4:in <top (required)>' from C:/Ruby22/bin/rspec:23:inload' from C:/Ruby22/bin/rspec:23:in <main>'

user3464189
  • 183
  • 1
  • 1
  • 11

1 Answers1

0

The gemspec files are normally used when you are creating a Ruby gem, and contains the metadata about the Gem you are creating.

when you use bundle install it requires a Gemfile in the directory. The Gemfile works as a manifest file for the gems required for the project in the directory. It is possible that chef exec is looking for this file and will only work with gems specified here.

Try creating a Gemfile with the content

source 'https://rubygems.org'

gem 'rspec'
gem 'chefspec'

you should list other gems you are using in the file. and then run bundle install

  • Thanks for the reply, Hassan. I have created a file named `chefspec.gemfile` and used the content you mentioned. However when I run `bundle install` from the location of the file I still get the error `Could not locate Gemfile or .bundle/ directory` – user3464189 Aug 27 '15 at 15:34
  • The file name is important here I believe, by default it must be `Gemfile`. if you prefer to keep it as `chefspec.gemfile` then you will need to pass the location of the file when you run `bundle install` On unix based OS you an provide an environment variable to bundle by running `BUNDLE_GEMFILE=path/to/gemfile bundle install`. Not sure if its the same on windows. Also note you will always have to define `BUNDLE_GEMFILE` for commands the gemfile is needed. –  Aug 27 '15 at 17:59