|
4 | 4 | require 'rspec-puppet' |
5 | 5 | describe 'ensure_resource' do |
6 | 6 | describe 'when a type or title is not specified' do |
7 | | - it do |
8 | | - should run.with_params().and_raise_error(ArgumentError) |
9 | | - should run.with_params(['type']).and_raise_error(ArgumentError) |
10 | | - end |
| 7 | + it { should run.with_params().and_raise_error(ArgumentError) } |
| 8 | + it { should run.with_params(['type']).and_raise_error(ArgumentError) } |
11 | 9 | end |
| 10 | + |
12 | 11 | describe 'when compared against a resource with no attributes' do |
13 | 12 | let :pre_condition do |
14 | 13 | 'user { "dan": }' |
15 | 14 | end |
16 | | - it do |
17 | | - should run.with_params('user', 'dan', {}) |
| 15 | + it "should contain the the ensured resources" do |
| 16 | + subject.should run.with_params('user', 'dan', {}) |
18 | 17 | compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' |
19 | 18 | end |
20 | 19 | end |
|
23 | 22 | let :pre_condition do |
24 | 23 | 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' |
25 | 24 | end |
26 | | - it do |
27 | | - # these first three should not fail |
28 | | - should run.with_params('User', 'dan', {}) |
29 | | - should run.with_params('User', 'dan', '') |
30 | | - should run.with_params('User', 'dan', {'ensure' => 'present'}) |
31 | | - should run.with_params('User', 'dan', |
32 | | - {'ensure' => 'present', 'managehome' => false} |
33 | | - ) |
34 | | - # test that this fails |
35 | | - should run.with_params('User', 'dan', |
36 | | - {'ensure' => 'absent', 'managehome' => false} |
37 | | - ).and_raise_error(Puppet::Error) |
| 25 | + # these first three should not fail |
| 26 | + it { should run.with_params('User', 'dan', {}) } |
| 27 | + it { should run.with_params('User', 'dan', '') } |
| 28 | + it { should run.with_params('User', 'dan', {'ensure' => 'present'}) } |
| 29 | + it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) } |
| 30 | + # test that this fails |
| 31 | + it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) } |
| 32 | + end |
| 33 | + |
| 34 | + describe 'when an array of new resources are passed in' do |
| 35 | + it "should contain the ensured resources" do |
| 36 | + subject.should run.with_params('User', ['dan', 'alex'], {}) |
| 37 | + compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' |
| 38 | + compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' |
| 39 | + end |
| 40 | + end |
| 41 | + |
| 42 | + describe 'when an array of existing resources is compared against existing resources' do |
| 43 | + let :pre_condition do |
| 44 | + 'user { "dan": ensure => present; "alex": ensure => present }' |
| 45 | + end |
| 46 | + it "should return the existing resources" do |
| 47 | + subject.should run.with_params('User', ['dan', 'alex'], {}) |
| 48 | + compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' |
| 49 | + compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' |
| 50 | + end |
| 51 | + end |
| 52 | + |
| 53 | + describe 'when compared against existing resources with attributes' do |
| 54 | + let :pre_condition do |
| 55 | + 'user { "dan": ensure => present; "alex": ensure => present }' |
38 | 56 | end |
| 57 | + # These should not fail |
| 58 | + it { should run.with_params('User', ['dan', 'alex'], {}) } |
| 59 | + it { should run.with_params('User', ['dan', 'alex'], '') } |
| 60 | + it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) } |
| 61 | + # This should fail |
| 62 | + it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) } |
39 | 63 | end |
40 | 64 | end |
0 commit comments