You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For a new custom resource, we tried to use the new syntax as given in the README.md. The cookbook has many "old" style ChefSpec tests and configuration.
As the platform and version is configured globally in the cookbook using RSpec.configure, we did not include the platform method in our spec file. ChefSpec does not complain in this case, but can't find the custom resource (apparently it can find builtin resources, though).
The example below uses the custom resource from the example in README.md.
Command: rspec spec/greet_spec_old_platform.rb
Content of greet_spec_old_platform.rb is:
require'chefspec'# Old style generic platform configuration (usually resides in# spec_helper)RSpec.configuredo |config|
config.platform='ubuntu'enddescribe'mycookbook_greet'dostep_into:mycookbook_greetcontext'with the default greeting'dorecipedomycookbook_greet'test'endit{is_expected.towrite_log('Hello world')}endend
OS: CentOS 7
ChefDK: 3.7.24 (also tried with chefspec gem built from master)
Output:
F
Failures:
1) mycookbook_greet with the default greeting
Failure/Error: mycookbook_greet 'test'
NoMethodError:
undefined method `mycookbook_greet' for cookbook: mycookbook, recipe: _test :Chef::Recipe
# ./spec/greet_spec_old_platform.rb:15:in `block (3 levels) in <top (required)>'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/solo_runner.rb:140:in `instance_exec'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/solo_runner.rb:140:in `block in converge_block'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/solo_runner.rb:119:in `converge'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/solo_runner.rb:138:in `converge_block'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/api/core.rb:135:in `block in recipe'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/api/core.rb:208:in `block in included'
# ./spec/greet_spec_old_platform.rb:18:in `block (3 levels) in <top (required)>'
# /home/baatz/.chefdk/gem/ruby/2.5.0/gems/chefspec-7.3.4/lib/chefspec/api/core.rb:18:in `block in <module:Core>'
Finished in 0.068 seconds (files took 1.32 seconds to load)
1 example, 1 failure
Failed examples:
rspec ./spec/greet_spec_old_platform.rb:18 # mycookbook_greet with the default greeting
Adding platform 'ubuntu' to the describe block fixes the problem.
Expected behavior:
ChefSpec should work in this case or complain that it needs platform.
The text was updated successfully, but these errors were encountered:
Not sure if I should jump around in joy or break random things in my living room since I just spent 2 hours debugging my tests ... should have checked here sooner. @simon-baatz thanks, you just saved what's left of my sanity ;)
Also:
The issue only occured after I deleted the recipes and the tests for them so I had ONLY the custom resource left. Everything worked (that is the tests for the resource too) when the recipes were tested before without defining the platform in the describes block
Interesting wrinkle. Suppose you have this in spec_helper.rb:
RSpec.configure do |config|
config.platform = 'redhat'
config.version = '7.8'
end
and then you use platform: 'ubuntu' as in the greet_spec.rb example:
You'll get:
Fauxhai::Exception::InvalidPlatform:
Could not find platform 'ubuntu/7.8' on the local disk and an HTTP error was encountered when fetching from Github. A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md```
So it would seem that the run from the bare recipe in the spec file gets some information from the RSpec configuration but not enough to avoid using `platform` in the test.
For a new custom resource, we tried to use the new syntax as given in the
README.md
. The cookbook has many "old" style ChefSpec tests and configuration.As the platform and version is configured globally in the cookbook using
RSpec.configure
, we did not include theplatform
method in our spec file. ChefSpec does not complain in this case, but can't find the custom resource (apparently it can find builtin resources, though).The example below uses the custom resource from the example in
README.md
.rspec spec/greet_spec_old_platform.rb
Content of
greet_spec_old_platform.rb
is:Adding
platform 'ubuntu'
to thedescribe
block fixes the problem.ChefSpec should work in this case or complain that it needs
platform
.The text was updated successfully, but these errors were encountered: