yuyi 0.0.3

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.
@@ -0,0 +1,215 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yuyi::Roll do
4
+ before do
5
+ allow(Yuyi::Menu).to receive :add_roll
6
+ allow(Yuyi::Menu).to receive :find_roll
7
+ allow(Yuyi::Menu).to receive :add_pre_install
8
+ allow(Yuyi::Menu).to receive :add_post_install
9
+ allow(Yuyi::Menu).to receive(:options).and_return({ :foo => 'menu option' })
10
+ allow(Yuyi::Menu).to receive(:on_the_menu?).and_return false
11
+
12
+ class TestRoll < Yuyi::Roll
13
+ pre_install { :pre_install }
14
+ install { :install }
15
+ post_install { :post_install }
16
+ uninstall { :uninstall }
17
+ upgrade { :upgrade }
18
+ installed? { :installed? }
19
+ dependencies :foo
20
+ options({
21
+ :foo => {
22
+ :description => 'Foo.',
23
+ :example => 'foo example',
24
+ :default => 'foo default',
25
+ :required => true
26
+ },
27
+ :bar => {
28
+ :description => 'Bar.',
29
+ :example => 'bar example',
30
+ :default => 'bar default'
31
+ }
32
+ })
33
+ end
34
+ end
35
+
36
+ after do
37
+ allow(Yuyi::Menu).to receive(:add_roll).and_call_original
38
+ allow(Yuyi::Menu).to receive(:find_roll).and_call_original
39
+ allow(Yuyi::Menu).to receive(:add_pre_install).and_call_original
40
+ allow(Yuyi::Menu).to receive(:add_post_install).and_call_original
41
+ allow(Yuyi::Menu).to receive(:options).and_call_original
42
+ allow(Yuyi::Menu).to receive(:on_the_menu?).and_call_original
43
+ end
44
+
45
+ context 'when inherited' do
46
+ it 'should add the roll to the menu' do
47
+ allow(Yuyi::Menu).to receive :add_roll
48
+
49
+ class TestInheritRoll < Yuyi::Roll
50
+ install {}
51
+ uninstall {}
52
+ upgrade {}
53
+ installed? {}
54
+ end
55
+
56
+ expect(Yuyi::Menu).to have_received(:add_roll).with :roll_spec, TestInheritRoll
57
+ end
58
+
59
+ # DSL Methods
60
+ #
61
+
62
+ it 'should add dependencies' do
63
+ expect(Yuyi::Menu).to have_received(:find_roll).with :foo
64
+ end
65
+
66
+ it 'should create a title' do
67
+ expect(TestRoll.title).to eq 'Test Roll'
68
+ end
69
+
70
+ it 'should create a file name' do
71
+ expect(TestRoll.file_name).to eq :roll_spec
72
+ end
73
+
74
+ it 'should respond to .pre_install' do
75
+ expect(Yuyi::Menu).to have_received(:add_pre_install)
76
+ end
77
+
78
+ it 'should respond to .install' do
79
+ expect(TestRoll.install).to be_a Proc
80
+ end
81
+
82
+ it 'should respond to .post_install' do
83
+ expect(Yuyi::Menu).to have_received(:add_post_install)
84
+ end
85
+
86
+ it 'should respond to .uninstall' do
87
+ expect(TestRoll.uninstall).to be_a Proc
88
+ end
89
+
90
+ it 'should respond to .upgrade' do
91
+ expect(TestRoll.upgrade).to be_a Proc
92
+ end
93
+
94
+ it 'should respond to .installed?' do
95
+ expect(TestRoll.installed?).to be_a Proc
96
+ end
97
+
98
+ it 'should return .dependencies' do
99
+ expect(TestRoll.dependencies).to eq([:foo])
100
+ end
101
+
102
+ it 'should return .options' do
103
+ expect(TestRoll.options[:foo][:default]).to eq 'foo default'
104
+ end
105
+ end
106
+
107
+ context 'when initialized' do
108
+ before do
109
+ @test_roll = TestRoll.new
110
+ end
111
+
112
+ it 'should return the title' do
113
+ expect(@test_roll.title).to eq 'Test Roll'
114
+ end
115
+
116
+ it 'should return the file_name' do
117
+ expect(@test_roll.file_name).to eq :roll_spec
118
+ end
119
+
120
+ it 'should add dependencies' do
121
+ expect(@test_roll.dependencies).to eq([:foo])
122
+ end
123
+
124
+ it 'should return the install results' do
125
+ expect(@test_roll.send(:install)).to eq :install
126
+ end
127
+
128
+ it 'should return the uninstall results' do
129
+ expect(@test_roll.send(:uninstall)).to eq :uninstall
130
+ end
131
+
132
+ it 'should return the upgrade results' do
133
+ expect(@test_roll.send(:upgrade)).to eq :upgrade
134
+ end
135
+
136
+ it 'should return the installed? boolean' do
137
+ expect(@test_roll.send(:installed?)).to eq true
138
+ end
139
+
140
+ it 'should return options' do
141
+ expect(@test_roll.options).to eq({
142
+ :foo => 'menu option',
143
+ :bar => 'bar default'
144
+ })
145
+
146
+ expect(@test_roll.option_defs).to eq({
147
+ :foo => {
148
+ :description => 'Foo.',
149
+ :example => 'foo example',
150
+ :default => 'foo default',
151
+ :required => true
152
+ },
153
+ :bar => {
154
+ :description => 'Bar.',
155
+ :example => 'bar example',
156
+ :default => 'bar default'
157
+ }
158
+ })
159
+ end
160
+ end
161
+
162
+ context '#order' do
163
+ before do
164
+ @roll = TestRoll.new
165
+ allow(@roll).to receive(:install)
166
+ allow(@roll).to receive(:uninstall)
167
+ allow(@roll).to receive(:upgrade)
168
+ end
169
+
170
+ context 'when not installed' do
171
+ before do
172
+ allow(@roll).to receive(:installed?).and_return false
173
+ @roll.send :order
174
+ end
175
+
176
+ it 'should call install' do
177
+ expect(@roll).to have_received :install
178
+ expect(@roll).to_not have_received :uninstall
179
+ expect(@roll).to_not have_received :upgrade
180
+ end
181
+ end
182
+
183
+ context 'when installed' do
184
+ before do
185
+ allow(@roll).to receive(:installed?).and_return true
186
+ end
187
+
188
+ context 'when uninstall option is set' do
189
+ before do
190
+ allow(Yuyi::Menu).to receive(:options).and_return({ :uninstall => true })
191
+ @roll.send :order
192
+ end
193
+
194
+ it 'should call uninstall' do
195
+ expect(@roll).to_not have_received :install
196
+ expect(@roll).to have_received :uninstall
197
+ expect(@roll).to_not have_received :upgrade
198
+ end
199
+ end
200
+
201
+ context 'when uninstall option is not set & upgrade is true' do
202
+ before do
203
+ allow(@roll).to receive(:upgrade?).and_return true
204
+ @roll.send :order
205
+ end
206
+
207
+ it 'should call upgrade' do
208
+ expect(@roll).to_not have_received :install
209
+ expect(@roll).to_not have_received :uninstall
210
+ expect(@roll).to have_received :upgrade
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,55 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yuyi::Source do
4
+ shared_examples 'a source' do
5
+ before do
6
+ @path = File.expand_path(File.join(File.dirname(__FILE__), "../../fixtures/#{source}"))
7
+ @source = Yuyi::Source.new @name, @path
8
+ end
9
+
10
+ it 'should set the root tmp dir' do
11
+ expect(Yuyi::Source.var(:root_tmp_dir)).to_not be_nil
12
+ end
13
+
14
+ it 'should set the instance vars' do
15
+ expect(@source.var(:name)).to eq @name
16
+ expect(@source.var(:path)).to eq @path
17
+ expect(@source.var(:tmp_dir)).to include Yuyi::Source.var(:root_tmp_dir)
18
+ expect(@source.var(:tmp_dir)).to include @name.to_s
19
+ end
20
+
21
+ it 'should put roll files in the tmp dir' do
22
+ paths = @source.var(:available_rolls).values
23
+
24
+ expect(paths.size).to eq 2
25
+
26
+ paths.each do |path|
27
+ expect(File.exists?(File.join(Yuyi::Source.var(:root_tmp_dir), "#{path}.rb"))).to be true
28
+ end
29
+ end
30
+
31
+ it 'should set the available rolls' do
32
+ expect(@source.var(:available_rolls).keys).to include :foo_roll
33
+ end
34
+ end
35
+
36
+ context 'with a compressed file' do
37
+ let(:source){ 'roll_zip.zip' }
38
+
39
+ before do
40
+ @name = :compressed_source
41
+ end
42
+
43
+ it_behaves_like 'a source'
44
+ end
45
+
46
+ context 'with a directory' do
47
+ let(:source){ 'roll_dir' }
48
+
49
+ before do
50
+ @name = :directory_source
51
+ end
52
+
53
+ it_behaves_like 'a source'
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ require 'spec_helper'
2
+
3
+ describe Yuyi do
4
+ end
@@ -0,0 +1,54 @@
1
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
2
+ $: << File.expand_path('../../lib', __FILE__)
3
+ $: << File.expand_path('../../rolls', __FILE__)
4
+ $: << File.expand_path('../fixtures', __FILE__)
5
+
6
+ require 'yuyi'
7
+
8
+ RSpec.configure do |config|
9
+ config.alias_example_to :the
10
+
11
+ config.run_all_when_everything_filtered = true
12
+ config.filter_run :focus
13
+
14
+ config.expect_with :rspec do |c|
15
+ c.syntax = :expect
16
+ end
17
+
18
+ config.order = 'random'
19
+
20
+ config.before do
21
+ allow(Yuyi).to receive(:say)
22
+ end
23
+ end
24
+
25
+ # Allow true/false to respond to Boolean class
26
+ module Boolean; end
27
+ class TrueClass; include Boolean; end
28
+ class FalseClass; include Boolean; end
29
+
30
+ class Object
31
+ def var var, value = nil
32
+ if self.instance_of? Class
33
+ class_var var, value
34
+ else
35
+ instance_var var, value
36
+ end
37
+ end
38
+
39
+ def class_var var, value = nil
40
+ if value
41
+ self.send(:class_variable_set, :"@@#{var}", value)
42
+ else
43
+ self.send(:class_variable_get, :"@@#{var}")
44
+ end
45
+ end
46
+
47
+ def instance_var var, value = nil
48
+ if value
49
+ self.send(:instance_variable_set, :"@#{var}", value)
50
+ else
51
+ self.send(:instance_variable_get, :"@#{var}")
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yuyi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Ryan Brewster
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: new
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
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: guard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: terminal-notifier-guard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Maintain a menu of applications and services to automate the installation
84
+ of.
85
+ email: brewster1134@gmail.com
86
+ executables:
87
+ - yuyi
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".new"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - Gemfile
96
+ - Gemfile.lock
97
+ - Guardfile
98
+ - README.md
99
+ - bin/install
100
+ - bin/yuyi
101
+ - lib/yuyi.rb
102
+ - lib/yuyi/cli.rb
103
+ - lib/yuyi/core.rb
104
+ - lib/yuyi/menu.rb
105
+ - lib/yuyi/roll.rb
106
+ - lib/yuyi/source.rb
107
+ - spec/fixtures/menu.yaml
108
+ - spec/fixtures/menu2.yaml
109
+ - spec/fixtures/roll_dir/nested/bar_roll.rb
110
+ - spec/fixtures/roll_dir/nested/foo_roll.rb
111
+ - spec/fixtures/roll_zip.zip
112
+ - spec/lib/yuyi/cli_spec.rb
113
+ - spec/lib/yuyi/core_spec.rb
114
+ - spec/lib/yuyi/menu_spec.rb
115
+ - spec/lib/yuyi/roll_spec.rb
116
+ - spec/lib/yuyi/source_spec.rb
117
+ - spec/lib/yuyi_spec.rb
118
+ - spec/spec_helper.rb
119
+ homepage: https://github.com/brewster1134/Yuyi
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.3.0
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: Automation for installing/uninstalling/updating your machine environment
143
+ test_files:
144
+ - spec/fixtures/roll_dir/nested/bar_roll.rb
145
+ - spec/fixtures/roll_dir/nested/foo_roll.rb
146
+ - spec/lib/yuyi/cli_spec.rb
147
+ - spec/lib/yuyi/core_spec.rb
148
+ - spec/lib/yuyi/menu_spec.rb
149
+ - spec/lib/yuyi/roll_spec.rb
150
+ - spec/lib/yuyi/source_spec.rb
151
+ - spec/lib/yuyi_spec.rb
152
+ - spec/spec_helper.rb