Chefspec question

I’ve only been using chefspec for about a month now and was wondering, Is
this a good idea?

it ‘renders the file with content from
./spec/rendered_templates/template.conf’ do template_conf = File.read(’
./spec/rendered_templates/template.conf’) expect(chef_run).to render_file(’
/etc/template.conf’).with_content(template_conf) end

With a known default rendered template in rendered_templates of course. It
was what I though render_file would expect but I never saw it as an example
anywhere. It works as I expected so I’m using it. Just not seeing it
elsewhere makes me think there’s something I’m missing.

Thanks,


Bill Warner

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you use
partials , etc. I know at least couple of other groups that are using it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com wrote:

I've only been using chefspec for about a month now and was wondering, Is
this a good idea?

it 'renders the file with content from
./spec/rendered_templates/template.conf' do template_conf = File.read('
./spec/rendered_templates/template.conf') expect(chef_run).to render_file(
'/etc/template.conf').with_content(template_conf) end

With a known default rendered template in rendered_templates of course.
It was what I though render_file would expect but I never saw it as an
example anywhere. It works as I expected so I'm using it. Just not seeing
it elsewhere makes me think there's something I'm missing.

Thanks,

--
Bill Warner

Hi Dey,

Cool, I was just looking for some validation. All the examples always seem
to have a small snip it of content or maybe a regex. I wasn't sure if
putting a fully rendered template was going to cause me some unforseen
problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you use
partials , etc. I know at least couple of other groups that are using it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com wrote:

I've only been using chefspec for about a month now and was wondering, Is
this a good idea?

it 'renders the file with content from
./spec/rendered_templates/template.conf' do template_conf = File.read('
./spec/rendered_templates/template.conf') expect(chef_run).to
render_file('/etc/template.conf').with_content(template_conf) end

With a known default rendered template in rendered_templates of course.
It was what I though render_file would expect but I never saw it as an
example anywhere. It works as I expected so I'm using it. Just not seeing
it elsewhere makes me think there's something I'm missing.

Thanks,

--
Bill Warner

--

Bill Warner

diff of rendered template with what? like chef we dont have an existing
file to generate the diff against.
chef core already has pretty neat helper methods for this :slight_smile:

On Wed, Jan 7, 2015 at 9:24 PM, Bill Warner bill.warner@gmail.com wrote:

Hi Dey,

Cool, I was just looking for some validation. All the examples always
seem to have a small snip it of content or maybe a regex. I wasn't sure if
putting a fully rendered template was going to cause me some unforseen
problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you use
partials , etc. I know at least couple of other groups that are using it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com
wrote:

I've only been using chefspec for about a month now and was wondering,
Is this a good idea?

it 'renders the file with content from
./spec/rendered_templates/template.conf' do template_conf = File.read('
./spec/rendered_templates/template.conf') expect(chef_run).to
render_file('/etc/template.conf').with_content(template_conf) end

With a known default rendered template in rendered_templates of course.
It was what I though render_file would expect but I never saw it as an
example anywhere. It works as I expected so I'm using it. Just not seeing
it elsewhere makes me think there's something I'm missing.

Thanks,

--
Bill Warner

--

Bill Warner

As I feel I'm missing something:

Bill is validating its template toward a pre-generated file, so the diff
would be against it.

Actually if the test fail it shows the rendered content and the expected
content, which is hard to compare for long text.

Having the actual_content and expected_content (actual vars in
chefspec), adding a diff of them when its not a regex nor matcher sounds
a good idea to speed up spotting the error.

(I'm unsure of how to call the chef helper method to make the diff that
said)

@Ranjib Did I missed a point somewhere ? I don't understand your 'we
don't have an existing file' message.

Le 2015-01-08 07:14, Ranjib Dey a écrit :

diff of rendered template with what? like chef we dont have an existing file to generate the diff against.
chef core already has pretty neat helper methods for this :slight_smile:

On Wed, Jan 7, 2015 at 9:24 PM, Bill Warner bill.warner@gmail.com wrote:

Hi Dey,

Cool, I was just looking for some validation. All the examples always seem to have a small snip it of content or maybe a regex. I wasn't sure if putting a fully rendered template was going to cause me some unforseen problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you use partials , etc. I know at least couple of other groups that are using it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com wrote:

I've only been using chefspec for about a month now and was wondering, Is this a good idea?

it 'renders the file with content from ./spec/rendered_templates/template.conf' do

template_conf = File.read('./spec/rendered_templates/template.conf')

expect(chef_run).to render_file('/etc/template.conf').with_content(template_conf)

end

With a known default rendered template in rendered_templates of course. It was what I though render_file would expect but I never saw it as an example anywhere. It works as I expected so I'm using it. Just not seeing it elsewhere makes me think there's something I'm missing.

Thanks, --

--
Bill Warner

--

--
Bill Warner

yes Tensaibai, that's exactly what I was saying. I'll look a little deeper
and maybe there's a way I can do it with what I have.

Maybe save the chefspec rendered file to a var and diff it to my
pre-rendered template var.

-Bill
On Jan 8, 2015 2:11 AM, "Tensibai" tensibai@iabis.net wrote:

As I feel I'm missing something:

Bill is validating its template toward a pre-generated file, so the diff
would be against it.

Actually if the test fail it shows the rendered content and the expected
content, which is hard to compare for long text.

Having the actual_content and expected_content (actual vars in chefspec),
adding a diff of them when its not a regex nor matcher sounds a good idea
to speed up spotting the error.

(I'm unsure of how to call the chef helper method to make the diff that
said)

@Ranjib Did I missed a point somewhere ? I don't understand your 'we don't
have an existing file' message.

Le 2015-01-08 07:14, Ranjib Dey a écrit :

diff of rendered template with what? like chef we dont have an existing
file to generate the diff against.
chef core already has pretty neat helper methods for this :slight_smile:

On Wed, Jan 7, 2015 at 9:24 PM, Bill Warner bill.warner@gmail.com wrote:

Hi Dey,

Cool, I was just looking for some validation. All the examples always
seem to have a small snip it of content or maybe a regex. I wasn't sure if
putting a fully rendered template was going to cause me some unforseen
problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you
use partials , etc. I know at least couple of other groups that are using
it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com
wrote:

I've only been using chefspec for about a month now and was wondering,
Is this a good idea?

     it 'renders the file with content from

./spec/rendered_templates/template.conf' do template_conf = File.read(
'./spec/rendered_templates/template.conf') expect(chef_run).to
render_file('/etc/template.conf').with_content(template_conf) end

With a known default rendered template in rendered_templates of
course. It was what I though render_file would expect but I never saw it
as an example anywhere. It works as I expected so I'm using it. Just not
seeing it elsewhere makes me think there's something I'm missing.

Thanks,

--
Bill Warner

--

Bill Warner

Looking at chef source code here

I think there's something doable copying the udiff method to a new one
(udiff_datas ?) to work on actual datas instead of file path.

it sounds to me this helper method has no real interest in chef itself
but could be great in ChefSpec...

Le 2015-01-08 17:45, Bill Warner a écrit :

yes Tensaibai, that's exactly what I was saying. I'll look a little deeper and maybe there's a way I can do it with what I have.

Maybe save the chefspec rendered file to a var and diff it to my pre-rendered template var.

-Bill
On Jan 8, 2015 2:11 AM, "Tensibai" tensibai@iabis.net wrote:

As I feel I'm missing something:

Bill is validating its template toward a pre-generated file, so the diff would be against it.

Actually if the test fail it shows the rendered content and the expected content, which is hard to compare for long text.

Having the actual_content and expected_content (actual vars in chefspec), adding a diff of them when its not a regex nor matcher sounds a good idea to speed up spotting the error.

(I'm unsure of how to call the chef helper method to make the diff that said)

@Ranjib Did I missed a point somewhere ? I don't understand your 'we don't have an existing file' message.

Le 2015-01-08 07:14, Ranjib Dey a écrit :
diff of rendered template with what? like chef we dont have an existing file to generate the diff against.
chef core already has pretty neat helper methods for this :slight_smile:

On Wed, Jan 7, 2015 at 9:24 PM, Bill Warner bill.warner@gmail.com wrote:

Hi Dey,

Cool, I was just looking for some validation. All the examples always seem to have a small snip it of content or maybe a regex. I wasn't sure if putting a fully rendered template was going to cause me some unforseen problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you use partials , etc. I know at least couple of other groups that are using it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com wrote:

I've only been using chefspec for about a month now and was wondering, Is this a good idea?

it 'renders the file with content from ./spec/rendered_templates/template.conf' do

template_conf = File.read('./spec/rendered_templates/template.conf')

expect(chef_run).to render_file('/etc/template.conf').with_content(template_conf)

end

With a known default rendered template in rendered_templates of course. It was what I though render_file would expect but I never saw it as an example anywhere. It works as I expected so I'm using it. Just not seeing it elsewhere makes me think there's something I'm missing.

Thanks, --

--
Bill Warner

--

--
Bill Warner

i was just looking at that as well. when I call render_file does it output
to a temp file or is it stored only in memory?

I could write it to a temp file then Chef:Util:Diff it if there's an
error. This seems to be making my test code more complicated then the
actual code though just for output on failure.
On Jan 8, 2015 10:11 AM, "Tensibai" tensibai@iabis.net wrote:

Looking at chef source code here
https://github.com/opscode/chef/blob/master/lib/chef/util/diff.rb

I think there's something doable copying the udiff method to a new one
(udiff_datas ?) to work on actual datas instead of file path.

it sounds to me this helper method has no real interest in chef itself but
could be great in ChefSpec...

Le 2015-01-08 17:45, Bill Warner a écrit :

yes Tensaibai, that's exactly what I was saying. I'll look a little
deeper and maybe there's a way I can do it with what I have.

Maybe save the chefspec rendered file to a var and diff it to my
pre-rendered template var.

-Bill
On Jan 8, 2015 2:11 AM, "Tensibai" tensibai@iabis.net wrote:

As I feel I'm missing something:

Bill is validating its template toward a pre-generated file, so the diff
would be against it.

Actually if the test fail it shows the rendered content and the expected
content, which is hard to compare for long text.

Having the actual_content and expected_content (actual vars in chefspec),
adding a diff of them when its not a regex nor matcher sounds a good idea
to speed up spotting the error.

(I'm unsure of how to call the chef helper method to make the diff that
said)

@Ranjib Did I missed a point somewhere ? I don't understand your 'we
don't have an existing file' message.

Le 2015-01-08 07:14, Ranjib Dey a écrit :

diff of rendered template with what? like chef we dont have an existing
file to generate the diff against.
chef core already has pretty neat helper methods for this :slight_smile:

On Wed, Jan 7, 2015 at 9:24 PM, Bill Warner bill.warner@gmail.com
wrote:

Hi Dey,

Cool, I was just looking for some validation. All the examples always
seem to have a small snip it of content or maybe a regex. I wasn't sure if
putting a fully rendered template was going to cause me some unforseen
problems latter.

Would be nice if the failed test could output a diff :slight_smile:

-Bill

On Wed, Jan 7, 2015 at 9:31 PM, Ranjib Dey dey.ranjib@gmail.com wrote:

hi bill,
I use it a lot to test our cookbooks. its particularly helpful if you
use partials , etc. I know at least couple of other groups that are using
it.

Note: i co-maintain chefspec with seth, so i am biased :0-)

ranjib

On Wed, Jan 7, 2015 at 7:57 PM, Bill Warner bill.warner@gmail.com
wrote:

I've only been using chefspec for about a month now and was wondering,
Is this a good idea?

     it 'renders the file with content from

./spec/rendered_templates/template.conf' do template_conf = File
.read('./spec/rendered_templates/template.conf') expect(chef_run).to
render_file('/etc/template.conf').with_content(template_conf) end

With a known default rendered template in rendered_templates of
course. It was what I though render_file would expect but I never saw it
as an example anywhere. It works as I expected so I'm using it. Just not
seeing it elsewhere makes me think there's something I'm missing.

Thanks,

--
Bill Warner

--

Bill Warner