user3464189
user3464189

Reputation: 193

Executing chef test from a rakefile

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:in `require': cannot load such file -- chefspec (LoadError)
        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 `<top (required)>'
        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:in `block 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:in `load_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:in `run'
        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:in `invoke'
        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:in `load'
        from C:/Ruby22/bin/rspec:23:

in <main>'

Upvotes: 0

Views: 1003

Answers (1)

user5067463
user5067463

Reputation:

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

Upvotes: 0

Related Questions