chef-umami 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 016bd54f66198e533440c6eff8d3cc9d9a02a4dc
4
- data.tar.gz: 1df201ee4d54ebfb32e4741ef08607562884af78
3
+ metadata.gz: 332bd1c06e4c1ef37879026cb156036d17c0ab9f
4
+ data.tar.gz: 0af958230fbe4ba6ee6ad8bc548a4cd724b6b23f
5
5
  SHA512:
6
- metadata.gz: 4e405c663e1d1a0a7281540651555a715e57703de31fbec5097054bd8ea50806ea821d22868feaa6ebcdb0e953e8df8b1ac87ab14bc74c8a297893a09441998d
7
- data.tar.gz: ea9b841efacd7aeff6b373e5c0757382e2a990cb225eb1e19115b571ecbbbc16889c27ebcb58435315e4f0321df0366fb470151699e525fb164e503fcdbd4aa5
6
+ metadata.gz: 9bb516181d9d2fc958e79827fe1cf9fc60c8b122aacaa03404239d6b4bd2e97a1f6cd3a22f9f7cc175297ae815d0428a42bcdd56b2636b3014c8155b43860fa1
7
+ data.tar.gz: 38ef2f48e5172497dd44c76dbab69fe437dc6dc54db8420e16fed2ca1b497ae1aa14157371d38533d90549f03d7499d81a9482db1e1f8efd93b474fcac798eba
data/CHANGELOG.md CHANGED
@@ -1,4 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.0.4]
4
+ - Fixes a bug where two methods have the same name. Thanks @HarryYC.
5
+ - Adds `spec_helper.rb` for unit tests, cutting down on boilerplate in each unit test.
6
+ - Includes test coverage report.
7
+
8
+ ## [0.0.3]
9
+ - I have no recollection.
10
+
11
+ ## [0.0.2]
12
+ - My dog ate my homework.
13
+
3
14
  ## [0.0.1] - 2017-08-07
4
15
  - Initial release.
data/README.md CHANGED
@@ -3,6 +3,10 @@
3
3
  A tool that attempts to write unit and integration tests for Chef cookbooks and
4
4
  policies, making it easier to do the right thing and test code.
5
5
 
6
+ Let's see it in action!
7
+
8
+ [![asciicast](https://asciinema.org/a/138816.png)](https://asciinema.org/a/138816)
9
+
6
10
  ## How does it Work?
7
11
 
8
12
  `umami` loads up one or more cookbooks in a `chef-zero` instance, executes the
@@ -19,8 +23,7 @@ write by matching the current directory to resources derived from that cookbook.
19
23
 
20
24
  ### Integration Tests
21
25
 
22
- Using either Serverspec or Inspec (coming soon), `umami` writes integration
23
- tests for all the resources it has found.
26
+ `umami` writes Inspec-type integration tests for all the resources it has found.
24
27
 
25
28
  ### Spec Files
26
29
 
@@ -35,7 +38,7 @@ and I have the following recipes:
35
38
  │   └── stocks.rb
36
39
  ```
37
40
 
38
- `umami` will write tests as follows:
41
+ `umami` will write tests as follows (assuming the recipes are defined in the run list):
39
42
 
40
43
  ```
41
44
  ├── spec/
@@ -97,8 +100,8 @@ test file, like so:
97
100
 
98
101
  It's preferred to use `kitchen verify` to execute all integration tests.
99
102
  Teach `kitchen` to run `umami`'s tests by updating `.kitchen.yml`. Specify
100
- the appropriate `verifier` (`inspec` should mostly support Serverspec tests)
101
- and, if needed, direct `kitchen` where the tests are located:
103
+ the appropriate `verifier` (`inspec`) and, if needed, direct `kitchen` where
104
+ the tests are located:
102
105
 
103
106
  ```
104
107
  verifier:
@@ -132,12 +135,16 @@ without worrying about what the resulting indentation will be.
132
135
 
133
136
  `umami` depends on ChefDK to do the bulk of the work resolving cookbooks and
134
137
  their dependencies. Further, `umami` assumes you're using Policyfile to manage
135
- your nodes' run list.
138
+ the run list.
136
139
 
137
140
  ## Caveats
138
141
 
139
142
  `umami` is still in early and rapid development. Expect to see lots of activity.
140
143
 
144
+ `umami` **always overwrites the contents of `spec/umami` on each run.** This may
145
+ change in the future. Until then, you may want to move the generated tests
146
+ into a different subdirectory (i.e. `test/`).
147
+
141
148
  `umami` is not aware of any context. For example, if a recipe includes another
142
149
  recipe based on some condition (i.e. operating system), `umami` won't know about
143
150
  it and therefore won't write a relevant test. `umami` knows about the resources
@@ -147,7 +154,7 @@ anything, you want to use.
147
154
 
148
155
  `umami`'s goal is to help get you started writing and using tests in your
149
156
  development cycle. It tries its best to provide a useful set of tests that you
150
- can build on.
157
+ can build on. **Do NOT depend solely on `umami` to provide test coverage!**
151
158
 
152
159
  ## Inspiration and Thanks
153
160
 
@@ -35,12 +35,12 @@ module Umami
35
35
  "inspec"
36
36
  end
37
37
 
38
- def test_file(cookbook = '', recipe = '')
38
+ def test_file_path(cookbook = '', recipe = '')
39
39
  "#{test_root}/#{cookbook}_#{recipe}_spec.rb"
40
40
  end
41
41
 
42
42
  def preamble(cookbook = '', recipe = '')
43
- "# #{test_file(cookbook, recipe)} - Originally written by Umami!"
43
+ "# #{test_file_path(cookbook, recipe)} - Originally written by Umami!"
44
44
  end
45
45
 
46
46
  # Call on the apprpriate method from the Umami::Helper::InSpec
@@ -73,7 +73,7 @@ module Umami
73
73
  resources.each do |resource|
74
74
  content << write_test(resource)
75
75
  end
76
- test_file_name = test_file(cookbook, recipe)
76
+ test_file_name = test_file_path(cookbook, recipe)
77
77
  test_file_content = content.join("\n") + "\n"
78
78
  write_file(test_file_name, test_file_content)
79
79
  test_files_written << test_file_name
@@ -39,16 +39,26 @@ module Umami
39
39
  "#{test_root}/#{recipe}_spec.rb"
40
40
  end
41
41
 
42
+ def spec_helper_path
43
+ File.join(test_root, '..', 'spec_helper.rb')
44
+ end
45
+
42
46
  def preamble(cookbook = '', recipe = '')
43
47
  "# #{test_file(recipe)} - Originally written by Umami!\n" \
44
48
  "\n" \
45
- "require '#{framework}'\n" \
46
- "require '#{framework}/policyfile'\n" \
49
+ "require_relative '../spec_helper'\n" \
47
50
  "\n" \
48
51
  "describe '#{cookbook}::#{recipe}' do\n" \
49
52
  "let(:chef_run) { ChefSpec::ServerRunner.new(platform: '#{os[:platform]}', version: '#{os[:version]}').converge(described_recipe) }"
50
53
  end
51
54
 
55
+ def write_spec_helper
56
+ content = ["require '#{framework}'"]
57
+ content << "require '#{framework}/policyfile'"
58
+ content << "at_exit { ChefSpec::Coverage.report! }\n"
59
+ write_file(spec_helper_path, content.join("\n"))
60
+ end
61
+
52
62
  def write_test(resource = nil)
53
63
  state_attrs = [] # Attribute hash to be used with #with()
54
64
  resource.state.each do |attr, value|
@@ -93,6 +103,8 @@ module Umami
93
103
  end
94
104
 
95
105
  enforce_styling(test_root)
106
+ write_spec_helper
107
+ test_files_written << spec_helper_path
96
108
 
97
109
  unless test_files_written.empty?
98
110
  puts "Wrote the following unit test files:"
@@ -13,5 +13,5 @@
13
13
  # limitations under the License.
14
14
 
15
15
  module Umami
16
- VERSION = '0.0.3'
16
+ VERSION = '0.0.4'
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-umami
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Frantz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-21 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef