|
65 | 65 |
|
66 | 66 | describe "when the file doesn't yet exist" do |
67 | 67 | before do |
| 68 | + @install_to = Dir.tmpdir + '/apache2_modconf.pl' |
| 69 | + |
68 | 70 | @current_resource = @new_resource.dup |
69 | 71 | @provider.current_resource = @current_resource |
70 | 72 | end |
71 | 73 |
|
| 74 | + after { ::File.exist?(@install_to) && FileUtils.rm(@install_to) } |
| 75 | + |
72 | 76 | it "loads the current file state" do |
73 | 77 | @provider.load_current_resource |
74 | 78 | @provider.current_resource.checksum.should be_nil |
|
105 | 109 | end |
106 | 110 |
|
107 | 111 | it "installs the file from the cookbook cache" do |
108 | | - tempfile = nil |
109 | | - begin |
110 | | - tempfile = Tempfile.open('rspec-action-create-test') |
111 | | - install_path = ::File.dirname(tempfile.path) + '/apache2_modconf.pl' |
112 | | - @new_resource.path(install_path) |
113 | | - @provider.should_receive(:set_all_access_controls) |
114 | | - @provider.action_create |
115 | | - actual = IO.read(install_path) |
116 | | - actual.should == @file_content |
117 | | - ensure |
118 | | - tempfile && tempfile.close! |
119 | | - end |
| 112 | + @new_resource.path(@install_to) |
| 113 | + @provider.should_receive(:backup_new_resource) |
| 114 | + @provider.should_receive(:set_all_access_controls) |
| 115 | + @provider.action_create |
| 116 | + actual = IO.read(@install_to) |
| 117 | + actual.should == @file_content |
120 | 118 | end |
121 | 119 |
|
122 | 120 | it "installs the file for create_if_missing" do |
123 | | - install_path = nil |
124 | | - Tempfile.open('rspec-action-create-test') do |tempfile| |
125 | | - install_path = ::File.dirname(tempfile.path) + '/apache2_modconf.pl' |
126 | | - FileUtils.rm(install_path) |
127 | | - end |
128 | | - |
129 | | - ::File.exist?(install_path).should be_false |
130 | | - |
131 | | - @new_resource.path(install_path) |
| 121 | + @new_resource.path(@install_to) |
132 | 122 | @provider.should_receive(:set_all_access_controls) |
| 123 | + @provider.should_receive(:backup_new_resource) |
133 | 124 | @provider.action_create_if_missing |
134 | | - actual = IO.read(install_path) |
| 125 | + actual = IO.read(@install_to) |
135 | 126 | actual.should == @file_content |
136 | 127 | end |
137 | 128 | end |
|
148 | 139 |
|
149 | 140 | it "overwrites it when the create action is called" do |
150 | 141 | @provider.should_receive(:set_all_access_controls) |
| 142 | + @provider.should_receive(:backup_new_resource) |
151 | 143 | @provider.action_create |
152 | 144 | actual = IO.read(@target_file) |
153 | 145 | actual.should == @file_content |
|
173 | 165 | @provider.current_resource = @current_resource |
174 | 166 | end |
175 | 167 |
|
| 168 | + after { @tempfile && @tempfile.unlink} |
| 169 | + |
176 | 170 | it "it checks access control but does not alter content when action is create" do |
177 | 171 | @provider.load_current_resource |
178 | 172 | @provider.should_receive(:set_all_access_controls) |
|
0 commit comments