Why use a ruby block in your action? The action code already executes in the converge phase. You could try to use ruby's ' eval' method directly to call into rspec On Jan 4, 2012, at 5:16 PM, Bryan Baugher <
">
> wrote: Yes, you are right. 'puts self.inspect' gives '#<Class:0x2b2aba647728>' inside the describe block, where as outside 'put self.inspect' gives a large blob of chef info.
I am still pretty new to ruby, is there a way to pass new_resource into this block?
On Wed, Jan 4, 2012 at 4:05 PM, Daniel DeLeo <
">
> wrote:
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
-- -Bryan
|