fauxhai 6.2.0 → 6.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 274df03ed198e04c66a40ef402c457fa134ff12b1743318d0323b738cca5cba7
4
- data.tar.gz: 6421a7904788a9b9acf5bb57a793c0e9890de503aa4868a546ff6a42ce270670
3
+ metadata.gz: f8758e2957229d8875e474fd7b2cb5c382129421fdc91dbc7ff0047194e7075b
4
+ data.tar.gz: 316a128aea7f8603ad71599b9770a0c11f9eb85f5a50bd193cd035945abcbb58
5
5
  SHA512:
6
- metadata.gz: 2aa995c73fd977d2a7256b279508603d12ca6594cdde4fa0c510e62e8142185a51919512e898e27a8c2d4c61f8b7ff80c68645473de8eafff5d2d32a1a39a002
7
- data.tar.gz: 7115dba0806a8d5a6261de4bae80960403a3199c7ae2159bd6cb2ece530d9cad9269516fa028500ff7c9c0d0aab7f39f8e7978893ba7e43ffef1c184932910a3
6
+ metadata.gz: 9b52807f92d14264e5aa1834409c6e364dc10ecfc37b95bab6604e7b88d5ab9834811b02763d54de1e7e7ead7150538462912b0d9f16e55daba63ee3e08aba02
7
+ data.tar.gz: b0935dce4685b22d5fd4cb88b7042d6a5815e4f4d1eb0054893549d35b90512a2d3285d417cea7afc40cf2565cc362dbe3168e0824977762822b836e903b280d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Fauxhai Changelog
2
2
 
3
+ ## v6.3.0 (2018-06-11)
4
+
5
+ New intelligent platform and version matching. This means if you specify the platform centos we'll now automatically match you to the latest version. If you specify the version of 6 we'll automatically match you to 6.9\. This should make it easier to write specs that don't need constant updating as we deprecate dumps of minor versions.
6
+
3
7
  ## v6.2.0 (2018-05-07)
4
8
 
5
9
  ### New Platforms
data/fauxhai.gemspec CHANGED
@@ -24,4 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'chef', '>= 12.0'
25
25
  spec.add_development_dependency 'ohai', '>= 8.5'
26
26
  spec.add_development_dependency 'rake'
27
+ spec.add_development_dependency 'rspec', '~> 3.7'
28
+ spec.add_development_dependency 'rspec-its', '~> 1.2'
27
29
  end
data/lib/fauxhai.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Fauxhai
2
- require 'fauxhai/exception'
3
- require 'fauxhai/fetcher'
4
- require 'fauxhai/mocker'
5
- require 'fauxhai/version'
2
+ autoload :Exception, 'fauxhai/exception'
3
+ autoload :Fetcher, 'fauxhai/fetcher'
4
+ autoload :Mocker, 'fauxhai/mocker'
5
+ autoload :VERSION, 'fauxhai/version'
6
6
 
7
7
  def self.root
8
8
  @@root ||= File.expand_path('../../', __FILE__)
@@ -10,9 +10,6 @@ module Fauxhai
10
10
  # A message about where to find a list of platforms
11
11
  PLATFORM_LIST_MESSAGE = 'A list of available platforms is available at https://github.com/chefspec/fauxhai/blob/master/PLATFORMS.md'.freeze
12
12
 
13
- # @return [Hash] The raw ohai data for the given Mock
14
- attr_reader :data
15
-
16
13
  # Create a new Ohai Mock with fauxhai.
17
14
  #
18
15
  # @param [Hash] options
@@ -28,15 +25,10 @@ module Fauxhai
28
25
  def initialize(options = {}, &override_attributes)
29
26
  @options = { github_fetching: true }.merge(options)
30
27
 
31
- @data = fauxhai_data
32
- yield(@data) if block_given?
33
-
34
- @data
28
+ yield(data) if block_given?
35
29
  end
36
30
 
37
- private
38
-
39
- def fauxhai_data
31
+ def data
40
32
  @fauxhai_data ||= lambda do
41
33
  # If a path option was specified, use it
42
34
  if @options[:path]
@@ -80,6 +72,8 @@ module Fauxhai
80
72
  end.call
81
73
  end
82
74
 
75
+ private
76
+
83
77
  # As major releases of Ohai ship it's difficult and sometimes impossible
84
78
  # to regenerate all fauxhai data. This allows us to deprecate old releases
85
79
  # and eventually remove them while giving end users ample warning.
@@ -93,7 +87,7 @@ module Fauxhai
93
87
 
94
88
  def platform
95
89
  @options[:platform] ||= begin
96
- STDERR.puts "WARNING: you must specify a 'platform' and 'version' to your ChefSpec Runner and/or Fauxhai constructor, in the future omitting these will become a hard error. #{PLATFORM_LIST_MESSAGE}"
90
+ STDERR.puts "WARNING: you must specify a 'platform' and optionally a 'version' for your ChefSpec Runner and/or Fauxhai constructor, in the future omitting the platform will become a hard error. #{PLATFORM_LIST_MESSAGE}"
97
91
  'chefspec'
98
92
  end
99
93
  end
@@ -103,11 +97,47 @@ module Fauxhai
103
97
  end
104
98
 
105
99
  def version
106
- @options[:version] ||= chefspec_version || raise(Fauxhai::Exception::InvalidVersion.new("Platform version not specified. #{PLATFORM_LIST_MESSAGE}"))
107
- end
100
+ @version ||= begin
101
+ if File.exist?("#{platform_path}/#{@options[:version]}.json")
102
+ # Whole version, use it as-is.
103
+ @options[:version]
104
+ else
105
+ # Check if it's a prefix of an existing version.
106
+ versions = Dir["#{platform_path}/*.json"].map {|path| File.basename(path, '.json') }
107
+ unless @options[:version].to_s == ''
108
+ # If the provided version is nil or '', that means take anything,
109
+ # otherwise run the prefix match with an extra \D to avoid the
110
+ # case where "7.1" matches "7.10.0".
111
+ prefix_re = /^#{Regexp.escape(@options[:version])}\D/
112
+ versions.select! {|ver| ver =~ prefix_re }
113
+ end
108
114
 
109
- def chefspec_version
110
- platform == 'chefspec' ? '0.6.1' : nil
115
+ if versions.empty?
116
+ # No versions available, either an unknown platform or nothing matched
117
+ # the prefix check. Pass through the option as given so we can try
118
+ # github fetching.
119
+ @options[:version]
120
+ else
121
+ # Take the highest version available, trying to use rules that should
122
+ # probably mostly work on all OSes. Famous last words. The idea of
123
+ # the regex is to split on any punctuation (the common case) and
124
+ # also any single letter with digit on either side (2012r2). This
125
+ # leaves any long runs of letters intact (4.2-RELEASE). Then convert
126
+ # any run of digits to an integer to get version-ish comparison.
127
+ # This is basically a more flexible version of Gem::Version.
128
+ versions.max_by do |ver|
129
+ ver.split(/[^a-z0-9]|(?<=\d)[a-z](?=\d)/i).map do |part|
130
+ if part =~ /^\d+$/
131
+ part.to_i
132
+ else
133
+ part
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end
139
+ end
111
140
  end
141
+
112
142
  end
113
143
  end
@@ -1,3 +1,3 @@
1
1
  module Fauxhai
2
- VERSION = '6.2.0'.freeze
2
+ VERSION = '6.3.0'.freeze
3
3
  end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe Fauxhai::Mocker do
4
+ describe "#data" do
5
+ let(:options) { {} }
6
+ subject { described_class.new({github_fetching: false}.merge(options)).data }
7
+
8
+ context 'with a platform and version' do
9
+ let(:options) { {platform: 'chefspec', version: '0.6.1'} }
10
+ its(['hostname']) { is_expected.to eq 'chefspec' }
11
+ end
12
+
13
+ context 'with a Windows platform and version' do
14
+ let(:options) { {platform: 'windows', version: '10'} }
15
+ its(['hostname']) { is_expected.to eq 'Fauxhai' }
16
+ end
17
+ end
18
+
19
+ describe '#version' do
20
+ let(:options) { {} }
21
+ subject { described_class.new({github_fetching: false}.merge(options)).send(:version) }
22
+
23
+ context 'with a platform and version' do
24
+ let(:options) { {platform: 'chefspec', version: '0.6.1'} }
25
+ it { is_expected.to eq '0.6.1' }
26
+ end
27
+
28
+ context 'with a platform and no version' do
29
+ let(:options) { {platform: 'chefspec'} }
30
+ it { is_expected.to eq '0.6.1' }
31
+ end
32
+
33
+ context 'with a platform and a blank version' do
34
+ let(:options) { {platform: 'chefspec', version: ''} }
35
+ it { is_expected.to eq '0.6.1' }
36
+ end
37
+
38
+ context 'with a platform and a partial version' do
39
+ let(:options) { {platform: 'chefspec', version: '0.6'} }
40
+ it { is_expected.to eq '0.6.1' }
41
+ end
42
+
43
+ context 'with a platform and a non-matching partial version' do
44
+ let(:options) { {platform: 'chefspec', version: '0.7'} }
45
+ it { is_expected.to eq '0.7' }
46
+ end
47
+
48
+ context 'with a Windows platform and no version' do
49
+ let(:options) { {platform: 'windows'} }
50
+ it { is_expected.to eq '2016' }
51
+ end
52
+
53
+ context 'with a Windows platform and a partial version' do
54
+ let(:options) { {platform: 'windows', version: '2008'} }
55
+ it { is_expected.to eq '2008R2' }
56
+ end
57
+
58
+ context 'with a Windows platform and an exact partial version' do
59
+ let(:options) { {platform: 'windows', version: '2012'} }
60
+ it { is_expected.to eq '2012' }
61
+ end
62
+
63
+ context 'with a CentOS platform and a partial version' do
64
+ let(:options) { {platform: 'centos', version: '6'} }
65
+ it { is_expected.to eq '6.9' }
66
+ end
67
+
68
+ context 'with a platform and an invalid version' do
69
+ let(:options) { {platform: 'chefspec', version: '99'} }
70
+ it { is_expected.to eq '99' }
71
+ end
72
+
73
+ context 'with an invalid platform and an invalid version' do
74
+ let(:options) { {platform: 'notthere', version: '99'} }
75
+ it { is_expected.to eq '99' }
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ require 'rspec'
2
+ require 'rspec/its'
3
+ require 'fauxhai'
4
+
5
+ RSpec.configure do |config|
6
+ # Basic configuraiton
7
+ config.run_all_when_everything_filtered = true
8
+ config.filter_run(:focus)
9
+ config.add_formatter('documentation')
10
+
11
+ # Run specs in random order to surface order dependencies. If you find an
12
+ # order dependency and want to debug it, you can fix the order by providing
13
+ # the seed, which is printed after each run.
14
+ # --seed 1234
15
+ config.order = 'random'
16
+ config.seed = ENV['SEED'].to_i if ENV['SEED']
17
+
18
+ # Enable full backtrace if $DEBUG is set.
19
+ config.full_backtrace = true if ENV['DEBUG']
20
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fauxhai
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.2.0
4
+ version: 6.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seth Vargo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-07 00:00:00.000000000 Z
11
+ date: 2018-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -66,6 +66,34 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.7'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.7'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-its
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
69
97
  description: Easily mock out ohai data
70
98
  email:
71
99
  - sethvargo@gmail.com
@@ -194,6 +222,8 @@ files:
194
222
  - lib/fauxhai/runner/default.rb
195
223
  - lib/fauxhai/runner/windows.rb
196
224
  - lib/fauxhai/version.rb
225
+ - spec/mocker_spec.rb
226
+ - spec/spec_helper.rb
197
227
  - tmp/.gitkeep
198
228
  homepage: https://github.com/chefspec/fauxhai
199
229
  licenses:
@@ -220,4 +250,6 @@ signing_key:
220
250
  specification_version: 4
221
251
  summary: Fauxhai provides an easy way to mock out your ohai data for testing with
222
252
  chefspec!
223
- test_files: []
253
+ test_files:
254
+ - spec/mocker_spec.rb
255
+ - spec/spec_helper.rb