I created a custom resource that tries to mimic ruby_block’s block. This
resource was for Rspec and I wanted to follow the typical style of writing
rspec with the format,
rspec “myApp” do
it “should …” do
…
end
end
So I have written my resource as follows,
//
def initialize(*args)
super
@action = :describe
end
def it(s, &it)
if s
should(s)
end
if block_given? and it
@it = it
else
@it
end
end
actions :describe
attribute :name, :kind_of => String, :name_attribute => true
attribute :should, :kind_of => String, :default => “RSpec Test”
\
And my provider as,
//
action :describe do
run_context.include_recipe “rspec”
ruby_block “Rspec:#{new_resource.name}” do
block do
require ‘rspec/autorun’
describe new_resource.name do
it new_resource.should do
new_resource.it.call
end
end
end
end
new_resource.updated_by_last_action(true)
end
\
Chef is telling me that new_resource is undefined in my provider at,
‘it new_resource.should do’
Any thoughts?
Stacktrace:
Generated at Wed Jan 04 11:46:02 -0600 2012
NameError: ruby_block[Rspec:Tomcat]
(/var/cache/chef/cookbooks/rspec/providers/default.rb line 5) had an error:
NameError: undefined local variable or method new_resource' for #<Class:0x2b5af4c31610> /var/cache/chef/cookbooks/rspec/providers/default.rb:10:in
class_from_file’
/usr/lib64/ruby/gems/1.8/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:154:in
module_eval' /usr/lib64/ruby/gems/1.8/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:154:in
subclass’
/usr/lib64/ruby/gems/1.8/gems/rspec-core-2.7.1/lib/rspec/core/example_group.rb:141:in
describe' /usr/lib64/ruby/gems/1.8/gems/rspec-core-2.7.1/lib/rspec/core/dsl.rb:5:in
describe’
/var/cache/chef/cookbooks/rspec/providers/default.rb:9:in class_from_file' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/provider/ruby_block.rb:28:in
call’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/provider/ruby_block.rb:28:in
action_create' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource.rb:440:in
send’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/resource.rb:440:in
run_action' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:45:in
run_action’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/runner.rb:81:in
converge' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/runner.rb:81:in
each’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/runner.rb:81:in
converge' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection.rb:94:in
execute_each_resource’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/resource_collection/stepable_iterator.rb:116:in
call' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:116:in
call_iterator_block’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/resource_collection/stepable_iterator.rb:85:in
step' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection/stepable_iterator.rb:104:in
iterate’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/resource_collection/stepable_iterator.rb:55:in
each_with_index' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/resource_collection.rb:92:in
execute_each_resource’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/runner.rb:76:in
converge' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/client.rb:312:in
converge’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/client.rb:160:in
run' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application/client.rb:239:in
run_application’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/application/client.rb:229:in
loop' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/../lib/chef/application/client.rb:229:in
run_application’
/usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/…/lib/chef/application.rb:67:in
run' /usr/lib64/ruby/gems/1.8/gems/chef-0.10.8/bin/chef-client:26 /usr/bin/chef-client:19:in
load’
/usr/bin/chef-client:19