- From: Daniel DeLeo <
>
- To:
- Subject: [chef] Re: Re: Custom LWRP undefined local variable or method `new_resource'
- Date: Wed, 4 Jan 2012 14:05:21 -0800
On Wednesday, January 4, 2012 at 12:35 PM, andi abes wrote:
>
try @new_resource ... it's an instance variable.
>
>
On Wed, Jan 4, 2012 at 12:45 PM,
>
<
>
>
(mailto:
)>
>
wrote:
>
> 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 (http://new_resource.name)}" do
>
> block do
>
> require 'rspec/autorun'
>
>
>
> describe new_resource.name (http://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?
Probably RSpec is changing the execution context. Throw a `puts self.inspect`
in there to see.
--
Dan DeLeo
Archive powered by MHonArc 2.6.16.