Skip to content

Commit ca016cc

Browse files
committed
add method to save generated rspec
1 parent 449adff commit ca016cc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ There is no one single workflow that works, but this is what we use. In your spe
4545
it { dump_catalog }
4646
```
4747

48-
This will dump the full current catalog as rspec-code. Here is an example:
48+
This will dump the full current catalog as rspec-code to standard output. Here is an example:
4949

5050
```
5151
it {
@@ -76,6 +76,13 @@ it {
7676
}
7777
```
7878

79+
Alternatively, instead of dumping to standard output, use the following to save the generated rspec:
80+
81+
```
82+
it { rspec_catalog('generated_rspec_catalog.rb') }
83+
```
84+
85+
7986
Now copy and paste the parts that you want to check in your manifest into your rspec-code and voila.
8087
## Development
8188

lib/puppet-catalog_rspec/rspec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
11
def dump_catalog
22
catalogue.to_rspec
33
end
4+
5+
def rspec_catalog(output = undef)
6+
o_stdout = $stdout
7+
if output
8+
$stdout = File.open(output, 'w+')
9+
else
10+
$stdout = StringIO.new
11+
end
12+
catalogue.to_rspec
13+
yield
14+
$stdout.string
15+
ensure
16+
$stdout = o_stdout
17+
end

0 commit comments

Comments
 (0)