minitest-chef-handler 0.4.0 → 0.5.0

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.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 0.5.0 / 05-02-2012
2
+
3
+ * 1 new feature:
4
+
5
+ * Load tests and specs automatically according to the seen recipes.
6
+
1
7
  === 0.4.0 / 04-20-2012
2
8
 
3
9
  * 2 new features:
@@ -11,9 +11,6 @@ module MiniTest
11
11
  module Chef
12
12
  class Handler < ::Chef::Handler
13
13
  def initialize(options = {})
14
- path = options.delete(:path) || './test/test_*.rb'
15
- Dir.glob(path).each {|test_suite| require test_suite}
16
-
17
14
  @options = options
18
15
  end
19
16
 
@@ -21,6 +18,7 @@ module MiniTest
21
18
  # do not run tests if chef failed
22
19
  return if failed?
23
20
 
21
+ require_test_suites
24
22
  runner = Runner.new(run_status)
25
23
 
26
24
  if custom_runner?
@@ -32,6 +30,56 @@ module MiniTest
32
30
 
33
31
  private
34
32
 
33
+ #
34
+ # Load the test suites.
35
+ # If the option "path" is specified we use it to load the tests from it.
36
+ # The option can be a string or an array of paths.
37
+ # Otherwise we load the tests according to the recipes seen.
38
+ #
39
+ def require_test_suites
40
+ paths = @options.delete(:path) || seen_recipes_paths
41
+ Array(paths).each do |path|
42
+ Dir.glob(path).each {|test_suite| require test_suite}
43
+ end
44
+ end
45
+
46
+ #
47
+ # Collect test paths based in the recipes ran.
48
+ # It loads the tests based in the name of the cookbook and the name of the recipe.
49
+ # The tests must be under the cookbooks directory.
50
+ #
51
+ # Examples:
52
+ #
53
+ # If the seen recipes includes the recipe "foo" we try to load tests from:
54
+ #
55
+ # cookbooks/foo/tests/default_test.rb
56
+ # cookbooks/foo/tests/default/*_test.rb
57
+ #
58
+ # cookbooks/foo/specs/default_spec.rb
59
+ # cookbooks/foo/specs/default/*_spec.rb
60
+ #
61
+ # If the seen recipes includes the recipe "foo::install" we try to load tests from:
62
+ #
63
+ # cookbooks/foo/tests/install_test.rb
64
+ # cookbooks/foo/tests/install/*_test.rb
65
+ #
66
+ # cookbooks/foo/specs/install_spec.rb
67
+ # cookbooks/foo/specs/install/*_spec.rb
68
+ #
69
+ def seen_recipes_paths
70
+ run_status.node.run_state[:seen_recipes].keys.map do |recipe_name|
71
+ cookbook_name, recipe_short_name = ::Chef::Recipe.parse_recipe_name(recipe_name)
72
+ base_path = ::Chef::Config[:cookbook_path]
73
+
74
+ file_test_pattern = "%s/%s/tests/%s_test.rb" % [base_path, cookbook_name, recipe_short_name]
75
+ dir_test_pattern = "%s/%s/tests/%s/*_test.rb" % [base_path, cookbook_name, recipe_short_name]
76
+ file_spec_pattern = "%s/%s/specs/%s_spec.rb" % [base_path, cookbook_name, recipe_short_name]
77
+ dir_spec_pattern = "%s/%s/specs/%s/*_spec.rb" % [base_path, cookbook_name, recipe_short_name]
78
+
79
+ [file_test_pattern, dir_test_pattern, file_spec_pattern, dir_spec_pattern]
80
+ end.flatten
81
+ end
82
+
35
83
  def miniunit_options
36
84
  options = []
37
85
  options << ['-n', @options[:filter]] if @options[:filter]
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
11
11
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
12
12
  gem.name = "minitest-chef-handler"
13
13
  gem.require_paths = ["lib"]
14
- gem.version = '0.4.0'
14
+ gem.version = '0.5.0'
15
15
 
16
16
  gem.add_dependency('chef')
17
17
  gem.add_development_dependency('rake')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-chef-handler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-20 00:00:00.000000000 Z
12
+ date: 2012-05-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
16
- requirement: &2164305860 !ruby/object:Gem::Requirement
16
+ requirement: &70284019403120 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2164305860
24
+ version_requirements: *70284019403120
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &2164304620 !ruby/object:Gem::Requirement
27
+ requirement: &70284019401500 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2164304620
35
+ version_requirements: *70284019401500
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2164303800 !ruby/object:Gem::Requirement
38
+ requirement: &70284019400800 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2164303800
46
+ version_requirements: *70284019400800
47
47
  description: Run Minitest suites as Chef report handlers
48
48
  email:
49
49
  - david.calavera@gmail.com
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: -4192483900398886253
109
+ hash: -3992918998714058940
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,10 +115,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: -4192483900398886253
118
+ hash: -3992918998714058940
119
119
  requirements: []
120
120
  rubyforge_project:
121
- rubygems_version: 1.8.10
121
+ rubygems_version: 1.8.11
122
122
  signing_key:
123
123
  specification_version: 3
124
124
  summary: Run Minitest suites as Chef report handlers