Sorry if this is a dumb question, but I’m not having much luck in finding an
answer.
I’ve been using minitests for a short while now in my recipes, so I have a
basic understanding of how it works. What I’m trying to figure out is how to
test a resource that is not one of the pre-defined ones here:
Specifically what I’m trying to do is something like:
chef_gem(“blah”).must_be_installed
Whats the best/proper way to be able to that? I tried the above, and it of
course didn’t work. I was also trying to see if I could use the pre-defined
package resource and specify the provider, like you might do in a recipe,
without success.
Any chance, someone has any advice for me on this? I've restored to doing a
system call and gem list as a totally hack workaround, given
the multitude of ways it could not work right, but my ruby skillz are not
top notch, and I'm struggling to understand how I might expose the resource
for testing like shown below.
Any advice at all would be greatly appreciated.
Thanks
Sorry if this is a dumb question, but I'm not having much luck in finding
an
answer.
I've been using minitests for a short while now in my recipes, so I have a
basic understanding of how it works. What I'm trying to figure out is how
to
test a resource that is not one of the pre-defined ones here:
Specifically what I'm trying to do is something like:
chef_gem("blah").must_be_installed
Whats the best/proper way to be able to that? I tried the above, and it of
course didn't work. I was also trying to see if I could use the
pre-defined
package resource and specify the provider, like you might do in a recipe,
without success.
Any chance, someone has any advice for me on this? I've restored to doing a
system call and gem list as a totally hack workaround, given the multitude
of ways it could not work right, but my ruby skillz are not top notch, and
I'm struggling to understand how I might expose the resource for testing
like shown below.
Any advice at all would be greatly appreciated.
Thanks
Sorry if this is a dumb question, but I'm not having much luck in finding
an
answer.
I've been using minitests for a short while now in my recipes, so I have a
basic understanding of how it works. What I'm trying to figure out is how
to
test a resource that is not one of the pre-defined ones here:
Specifically what I'm trying to do is something like:
chef_gem("blah").must_be_installed
Whats the best/proper way to be able to that? I tried the above, and it of
course didn't work. I was also trying to see if I could use the
pre-defined
package resource and specify the provider, like you might do in a recipe,
without success.
Any chance, someone has any advice for me on this? I've restored to doing a
system call and gem list as a totally hack workaround, given the multitude
of ways it could not work right, but my ruby skillz are not top notch, and
I'm struggling to understand how I might expose the resource for testing
like shown below.
Any advice at all would be greatly appreciated.
Thanks
Sorry if this is a dumb question, but I'm not having much luck in finding
an
answer.
I've been using minitests for a short while now in my recipes, so I have a
basic understanding of how it works. What I'm trying to figure out is how
to
test a resource that is not one of the pre-defined ones here:
Specifically what I'm trying to do is something like:
chef_gem("blah").must_be_installed
Whats the best/proper way to be able to that? I tried the above, and it of
course didn't work. I was also trying to see if I could use the
pre-defined
package resource and specify the provider, like you might do in a recipe,
without success.
This doesn’t address the minitest question, but it’s a handy way to check for a required gem. It doesn’t narrow the possibilities down to a specific version, but it can be a quick sanity check.
Simply try requiring the gem, wrapped inside a begin/rescue block:
begin
require 'httparty’
rescue LoadError
Chef::Log.warn(“Missing gem ‘httparty’”)
chef_gem ‘httparty’ ## go ahead and install the gem once you’ve found it’s missing.
require ‘httparty’ ## then require it again
end
Any chance, someone has any advice for me on this? I’ve restored to doing a system call and gem list as a totally hack workaround, given the multitude of ways it could not work right, but my ruby skillz are not top notch, and I’m struggling to understand how I might expose the resource for testing like shown below.
Any advice at all would be greatly appreciated.
Thanks
I’ve been using minitests for a short while now in my recipes, so I have a
basic understanding of how it works. What I’m trying to figure out is how to
test a resource that is not one of the pre-defined ones here:
Specifically what I’m trying to do is something like:
chef_gem(“blah”).must_be_installed
Whats the best/proper way to be able to that? I tried the above, and it of
course didn’t work. I was also trying to see if I could use the pre-defined
package resource and specify the provider, like you might do in a recipe,
without success.
require 'minitest/chef' # or require 'minitest-chef' ??
MiniTest::Chef::Resources.register_resource(:foo)
Some really great answers!!
John, Your approach was uber simple and directly addressed the specific use
case I provided, and did the trick.
Bryan, Your answer addressed my wider question of "other resources". I
couldn't get the exact code you gave me working, however it made things
click for me, so I was able to get the following working:
require 'minitest-chef-handler'
MiniTest::Chef::Resources.register_resource(:chef_gem)
describe_recipe 'my_recipe::default' do
it "installs the gem with the proper version" do
chef_gem("foo").must_be_installed.with(:version, "0.1.0")
end
end