fauxbag 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7b325f82e436f0757f61d48143105994034089d6
4
+ data.tar.gz: b457f11d944350c853852e604f773a8df74f4458
5
+ SHA512:
6
+ metadata.gz: 158a65bde03d3d0d1616b876fb82498e306801a0bd4a02f9e9ff46346a0391503bf49d856176e75e741560c3a485f265751bb7f17f2eac9ec14a3e66345a4607
7
+ data.tar.gz: 60e87a4cac50ae150a579fe3b10cd12842523a765b349f022930764ee86b8f8ec59118645ad18567d5a72c5ab2b8ab779363bbae385c2ee08e09136f37a6d24a
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,117 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ fauxbag (0.1.0)
5
+ chefspec
6
+ multi_json
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ chef (11.10.4)
12
+ chef-zero (~> 1.7, >= 1.7.2)
13
+ diff-lcs (~> 1.2, >= 1.2.4)
14
+ erubis (~> 2.7)
15
+ highline (~> 1.6, >= 1.6.9)
16
+ json (>= 1.4.4, <= 1.8.1)
17
+ mime-types (~> 1.16)
18
+ mixlib-authentication (~> 1.3)
19
+ mixlib-cli (~> 1.4)
20
+ mixlib-config (~> 2.0)
21
+ mixlib-log (~> 1.3)
22
+ mixlib-shellout (~> 1.3)
23
+ net-ssh (~> 2.6)
24
+ net-ssh-multi (~> 1.1)
25
+ ohai (~> 6.0)
26
+ pry (~> 0.9)
27
+ puma (~> 1.6)
28
+ rest-client (>= 1.0.4, < 1.7.0)
29
+ yajl-ruby (~> 1.1)
30
+ chef-zero (1.7.3)
31
+ hashie (~> 2.0)
32
+ json
33
+ mixlib-log (~> 1.3)
34
+ moneta (< 0.7.0)
35
+ rack
36
+ chefspec (3.2.0)
37
+ chef (~> 11.0)
38
+ fauxhai (~> 2.0)
39
+ i18n (>= 0.6.9, < 1.0.0)
40
+ rspec (~> 2.14)
41
+ coderay (1.1.0)
42
+ columnize (0.3.6)
43
+ debugger (1.6.5)
44
+ columnize (>= 0.3.1)
45
+ debugger-linecache (~> 1.2.0)
46
+ debugger-ruby_core_source (~> 1.3.1)
47
+ debugger-linecache (1.2.0)
48
+ debugger-ruby_core_source (1.3.1)
49
+ diff-lcs (1.2.5)
50
+ erubis (2.7.0)
51
+ fauxhai (2.1.0)
52
+ net-ssh
53
+ ohai
54
+ hashie (2.0.5)
55
+ highline (1.6.21)
56
+ i18n (0.6.9)
57
+ ipaddress (0.8.0)
58
+ json (1.8.1)
59
+ method_source (0.8.2)
60
+ mime-types (1.25.1)
61
+ mixlib-authentication (1.3.0)
62
+ mixlib-log
63
+ mixlib-cli (1.4.0)
64
+ mixlib-config (2.1.0)
65
+ mixlib-log (1.6.0)
66
+ mixlib-shellout (1.3.0)
67
+ moneta (0.6.0)
68
+ multi_json (1.9.2)
69
+ net-ssh (2.8.0)
70
+ net-ssh-gateway (1.2.0)
71
+ net-ssh (>= 2.6.5)
72
+ net-ssh-multi (1.2.0)
73
+ net-ssh (>= 2.6.5)
74
+ net-ssh-gateway (>= 1.2.0)
75
+ ohai (6.20.0)
76
+ ipaddress
77
+ mixlib-cli
78
+ mixlib-config
79
+ mixlib-log
80
+ mixlib-shellout
81
+ systemu (~> 2.5.2)
82
+ yajl-ruby
83
+ pry (0.9.12.6)
84
+ coderay (~> 1.0)
85
+ method_source (~> 0.8)
86
+ slop (~> 3.4)
87
+ pry-debugger (0.2.2)
88
+ debugger (~> 1.3)
89
+ pry (~> 0.9.10)
90
+ puma (1.6.3)
91
+ rack (~> 1.2)
92
+ rack (1.5.2)
93
+ rake (10.1.1)
94
+ rest-client (1.6.7)
95
+ mime-types (>= 1.16)
96
+ rspec (2.14.1)
97
+ rspec-core (~> 2.14.0)
98
+ rspec-expectations (~> 2.14.0)
99
+ rspec-mocks (~> 2.14.0)
100
+ rspec-core (2.14.7)
101
+ rspec-expectations (2.14.5)
102
+ diff-lcs (>= 1.1.3, < 2.0)
103
+ rspec-mocks (2.14.5)
104
+ slop (3.4.7)
105
+ systemu (2.5.2)
106
+ yajl-ruby (1.2.0)
107
+
108
+ PLATFORMS
109
+ ruby
110
+
111
+ DEPENDENCIES
112
+ bundler (~> 1.5)
113
+ fauxbag!
114
+ pry
115
+ pry-debugger
116
+ rake
117
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Squaremouth
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # Fauxbag
2
+
3
+ Adds `load_databag_json` support method to use with Data Bags and [ChefSpec](http://code.sethvargo.com/chefspec/)
4
+
5
+ ## Installation and Configuration
6
+
7
+ Add this line to your Gemfile:
8
+ ```ruby
9
+ gem 'fauxbag'
10
+ ```
11
+
12
+ And then execute:
13
+ ```bash
14
+ $ bundle
15
+ ```
16
+
17
+ Include `fauxbag` in your `spec_helper.rb` file.
18
+ ```ruby
19
+ # mycookbook/spec/spec_helper.rb
20
+ require 'fauxbag'
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ The expected location for data bag items is a `data_bags` folder in the `spec` directory:
26
+
27
+ `spec/data_bags/data_bag_name/data_bag_item.json`
28
+
29
+ ### Methods
30
+
31
+ ##### load_databag_item
32
+
33
+ The `load_databag_item` method requires the arguments of the `data_bag_name` folder and the `data_bag_item` without the `.json`:
34
+
35
+ `load_databag_json(data_bag_name, data_bag_item)`
36
+
37
+ ##### load_chefzero_databag
38
+
39
+ The `load_chefzero_databag` method requires the data bag group (such as users) and returns all items as a single hash to be used with Chef-Zero:
40
+
41
+ `load_chefzero_databag(data_bag_name)`
42
+
43
+ ## Example
44
+
45
+ The expected layout of your cookbook and data bag fixtures:
46
+ ```bash
47
+ mycookbook
48
+ .
49
+ ├── README.md
50
+ ├── attributes
51
+ ├── metadata.rb
52
+ ├── recipes
53
+ │   └── default.rb
54
+ └── spec
55
+ ├── data_bags
56
+ │   └── users
57
+ │   └── hansolo.json
58
+ └── default_spec.rb
59
+ ```
60
+
61
+ Using the data_bag fixtures:
62
+ ```ruby
63
+ # mycookbook/spec/default_spec.rb
64
+ require 'spec_helper'
65
+
66
+ describe 'mycookbook::default' do
67
+ it "installs something for all users" do
68
+ # Loads JSON from mycookbook/spec/data_bags/users/hansolo.json
69
+ fauxbag = load_databag_json('users', 'hansolo')
70
+ stub_data_bag_item('users', 'hansolo').and_return(fauxbag)
71
+
72
+ # ... rest of the spec test with expectation
73
+ end
74
+ end
75
+ ```
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( http://github.com/sqm/fauxbag/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/fauxbag.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'fauxbag/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fauxbag"
8
+ spec.version = Fauxbag::VERSION
9
+ spec.authors = ["Squaremouth"]
10
+ spec.email = ["developers@squaremouth.com"]
11
+ spec.summary = %q{ChefSpec plugin for stubbing data bags from JSON.}
12
+ spec.description = %q{ChefSpec plugin for stubbing data bags from JSON.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.required_ruby_version = '>= 1.9'
22
+
23
+ spec.add_dependency 'chefspec'
24
+ spec.add_dependency 'multi_json'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.5"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "pry-debugger"
29
+ spec.add_development_dependency "rake"
30
+ spec.add_development_dependency "rspec"
31
+ end
@@ -0,0 +1,49 @@
1
+ require 'multi_json'
2
+ require 'rspec'
3
+
4
+ module Fauxbag
5
+ # Parse example data bag item JSON file
6
+ #
7
+ # @param [String] Data Bag Directory
8
+ # @param [String] Data Bag Item
9
+ # @return [Hash] Parsed JSON Data Bag Item
10
+ def load_databag_json(databag, item)
11
+ File.open(File.join(data_bag_load_path, databag, "#{item}.json"), "r") do |f|
12
+ MultiJson.load(f)
13
+ end
14
+ end
15
+
16
+ # Parse all data bag JSON files into a single hash
17
+ #
18
+ # @param [String] Data Bag Directory
19
+ # @return [Hash] All data bags in a single Hash
20
+ def load_chefzero_databag(databag)
21
+ databag_hash = Hash.new
22
+ databag_dir = Dir.glob("#{data_bag_load_path}/#{databag}/" + '*.json')
23
+
24
+ databag_dir.each do |item|
25
+ File.open(item, "r") do |f|
26
+ data_bag_item = MultiJson.load(f)
27
+ id = data_bag_item.delete("id")
28
+
29
+ databag_hash[id] = data_bag_item
30
+ end
31
+ end
32
+
33
+ databag_hash
34
+ end
35
+
36
+ private
37
+
38
+ def data_bag_load_path
39
+ File.join(current_example_dir, "data_bags")
40
+ end
41
+
42
+ # Returns a string of the full path to the folder where the current spec file is
43
+ # located based on the example metadata for this test.
44
+ #
45
+ # @return [String] Path to the spec file
46
+ def current_example_dir
47
+ File.dirname(File.expand_path(example.metadata[:file_path]))
48
+ end
49
+ end
@@ -0,0 +1,4 @@
1
+ # Configure RSpec to include Fauxbag Helper Methods
2
+ RSpec.configure do |config|
3
+ config.include(Fauxbag)
4
+ end
@@ -0,0 +1,3 @@
1
+ module Fauxbag
2
+ VERSION = "0.1.0"
3
+ end
data/lib/fauxbag.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'fauxbag/version'
2
+ require 'fauxbag/load_databag_json'
3
+ require 'fauxbag/rspec'
4
+
5
+ module Fauxbag
6
+
7
+ end
@@ -0,0 +1,4 @@
1
+ {
2
+ "id" : "bar",
3
+ "username" : "bar"
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "id" : "foo",
3
+ "username" : "foobar"
4
+ }
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe '.load_databag_json' do
4
+ it 'should return a Hash' do
5
+ data_bag = load_databag_json('test', 'foo')
6
+ expect(data_bag).to be_a Hash
7
+ end
8
+ end
9
+
10
+ describe '.load_chefzero_databag' do
11
+ let(:all_databags_hash) {
12
+ {
13
+ "bar" => {"username"=>"bar"},
14
+ "foo" => {"username"=>"foobar"}
15
+ }
16
+ }
17
+
18
+ it 'returns a Hash' do
19
+ data_bag = load_chefzero_databag('test')
20
+ expect(data_bag).to be_a Hash
21
+ end
22
+
23
+ it 'returns a hash containing all data bag items' do
24
+ data_bag_hash = load_chefzero_databag('test')
25
+ expect(data_bag_hash).to eq all_databags_hash
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'fauxbag'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fauxbag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Squaremouth
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: chefspec
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '>='
19
+ - !ruby/object:Gem::Version
20
+ version: '0'
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ type: :runtime
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ type: :development
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ~>
47
+ - !ruby/object:Gem::Version
48
+ version: '1.5'
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ type: :development
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-debugger
71
+ type: :development
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ type: :development
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - '>='
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ type: :development
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: ChefSpec plugin for stubbing data bags from JSON.
112
+ email:
113
+ - developers@squaremouth.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - Gemfile
119
+ - Gemfile.lock
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - fauxbag.gemspec
124
+ - lib/fauxbag.rb
125
+ - lib/fauxbag/load_databag_json.rb
126
+ - lib/fauxbag/rspec.rb
127
+ - lib/fauxbag/version.rb
128
+ - spec/data_bags/test/bar.json
129
+ - spec/data_bags/test/foo.json
130
+ - spec/load_databag_json_spec.rb
131
+ - spec/spec_helper.rb
132
+ homepage: ''
133
+ licenses:
134
+ - MIT
135
+ metadata: {}
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '1.9'
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ requirements:
147
+ - - '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ requirements: []
151
+ rubyforge_project:
152
+ rubygems_version: 2.1.11
153
+ signing_key:
154
+ specification_version: 4
155
+ summary: ChefSpec plugin for stubbing data bags from JSON.
156
+ test_files:
157
+ - spec/data_bags/test/bar.json
158
+ - spec/data_bags/test/foo.json
159
+ - spec/load_databag_json_spec.rb
160
+ - spec/spec_helper.rb
161
+ has_rdoc: