palimpsest 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,305 @@
1
+ require 'spec_helper'
2
+
3
+ describe Palimpsest::Environment do
4
+
5
+ let(:site_1) { double name: 'site_1' }
6
+ let(:site_2) { double name: 'site_2' }
7
+
8
+ subject(:environment) { Palimpsest::Environment.new }
9
+
10
+ after :all do
11
+ Dir.glob("#{Palimpsest::Environment.new.options[:tmp_dir]}/#{Palimpsest::Environment.new.options[:dir_prefix]}*").each do |dir|
12
+ FileUtils.remove_entry_secure dir
13
+ end
14
+ end
15
+
16
+ describe ".new" do
17
+
18
+ it "sets default options" do
19
+ expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS
20
+ end
21
+
22
+ it "merges default options" do
23
+ environment = Palimpsest::Environment.new options: { tmp_dir: '/tmp/path' }
24
+ expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS.merge(tmp_dir: '/tmp/path')
25
+ end
26
+ end
27
+
28
+ describe "#options" do
29
+
30
+ it "merges with default options" do
31
+ environment.options[:tmp_dir] = '/tmp/path'
32
+ expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS.merge(tmp_dir: '/tmp/path')
33
+ end
34
+
35
+ it "can be called twice and merge options" do
36
+ environment.options[:tmp_dir] = '/tmp/path'
37
+ environment.options[:dir_prefix] = '/tmp/path'
38
+ expect(environment.options).to eq Palimpsest::Environment::DEFAULT_OPTIONS.merge(tmp_dir: '/tmp/path', dir_prefix: '/tmp/path')
39
+ end
40
+ end
41
+
42
+ describe "#site" do
43
+
44
+ it "cannot be redefinfed while populated" do
45
+ environment.site = site_1
46
+ allow(environment).to receive(:populated).and_return(true)
47
+ expect { environment.site = site_2 }.to raise_error RuntimeError, /populated/
48
+ end
49
+ end
50
+
51
+ describe "#treeish" do
52
+
53
+ it "must be a string" do
54
+ expect { environment.treeish = 1 }.to raise_error TypeError
55
+ end
56
+
57
+ it "cannot be redefinfed while populated" do
58
+ environment.treeish = 'treeish_1'
59
+ allow(environment).to receive(:populated).and_return(true)
60
+ expect { environment.treeish = 'treeish_2' }.to raise_error RuntimeError, /populated/
61
+ end
62
+ end
63
+
64
+ describe "#directory" do
65
+
66
+ context "when required values set" do
67
+
68
+ subject(:environment) { Palimpsest::Environment.new site: site_1 }
69
+
70
+ before :each do
71
+ allow(Palimpsest::Utility).to receive(:make_random_directory).and_return('/tmp/rand_dir')
72
+ end
73
+
74
+ context "when directory is unset" do
75
+
76
+ it "makes and returns a random directory" do
77
+ expect(environment.directory).to eq '/tmp/rand_dir'
78
+ end
79
+ end
80
+
81
+ context "when directory is set" do
82
+
83
+ it "returns the current directory" do
84
+ expect(Palimpsest::Utility).to receive(:make_random_directory).once
85
+ environment.directory
86
+ expect(environment.directory).to eq '/tmp/rand_dir'
87
+ end
88
+ end
89
+ end
90
+
91
+ context "when required values are not set" do
92
+
93
+ it "fails if site is not set" do
94
+ expect { environment.directory }.to raise_error RuntimeError
95
+ end
96
+ end
97
+ end
98
+
99
+ describe "#cleanup" do
100
+
101
+ subject(:environment) { Palimpsest::Environment.new site: site_1 }
102
+
103
+ it "removes the directory and resets @directory" do
104
+ environment.directory
105
+ FileUtils.should_receive(:remove_entry_secure).with(environment.directory)
106
+ environment.cleanup
107
+ expect(environment.instance_variable_get :@directory).to eq nil
108
+ end
109
+ end
110
+
111
+ describe "#populate" do
112
+
113
+ it "fails when missing site" do
114
+ environment.treeish = 'master'
115
+ expect { environment.populate }.to raise_error RuntimeError, /populate without/
116
+ end
117
+
118
+ context "populate from repo" do
119
+
120
+ subject(:environment) { Palimpsest::Environment.new site: site_1, treeish: 'master' }
121
+
122
+ before :each do
123
+ allow(site_1).to receive(:repo).and_return(double Grit::Repo)
124
+ allow(Palimpsest::Utility).to receive :extract_repo
125
+ end
126
+
127
+ it "extracts the repo to the directory and sets populated true" do
128
+ expect(Palimpsest::Utility).to receive(:extract_repo).with(site_1.repo, 'master', environment.directory)
129
+ environment.populate
130
+ expect(environment.populated).to eq true
131
+ end
132
+
133
+ it "fails when missing treeish" do
134
+ environment.site = site_1
135
+ environment.treeish = ''
136
+ expect { environment.populate }.to raise_error RuntimeError, /populate without/
137
+ end
138
+
139
+ it "returns itself" do
140
+ expect(environment.populate).to be environment
141
+ end
142
+
143
+ it "will cleanup if populated" do
144
+ environment.populate
145
+ expect(environment).to receive :cleanup
146
+ environment.populate
147
+ end
148
+ end
149
+
150
+ context "populate from directory" do
151
+
152
+ it "copies the source files to the directory" do
153
+ environment.site = site_1
154
+ allow(site_1).to receive(:source).and_return('/path/to/source')
155
+ allow(Dir).to receive(:[]).with('/path/to/source/*').and_return( %w(dir_1 dir_2) )
156
+ expect(FileUtils).to receive(:cp_r).with( %w(dir_1 dir_2), environment.directory )
157
+ environment.populate from: :source
158
+ end
159
+ end
160
+ end
161
+
162
+ describe "config" do
163
+
164
+ subject(:environment) { Palimpsest::Environment.new site: site_1, treeish: 'master' }
165
+
166
+ before :each do
167
+ allow(YAML).to receive(:load_file)
168
+ end
169
+
170
+ it "populate if not populated" do
171
+ expect(environment).to receive :populate
172
+ environment.config
173
+ end
174
+
175
+ it "populate only if not populated" do
176
+ allow(environment).to receive(:populated).and_return(true)
177
+ expect(environment).not_to receive :populate
178
+ environment.config
179
+ end
180
+
181
+ it "loads the config if populated" do
182
+ allow(environment).to receive(:populated).and_return(true)
183
+ expect(YAML).to receive(:load_file).with("#{environment.directory}/palimpsest_config.yml")
184
+ environment.config
185
+ end
186
+ end
187
+
188
+ describe "methods that modify the working directory" do
189
+
190
+ let(:config) do
191
+ YAML.load <<-EOF
192
+ :assets:
193
+ :options:
194
+ :output: compiled
195
+ :src_pre: "(%"
196
+ :sources:
197
+ - public
198
+ - app/src
199
+ :javascripts:
200
+ :options:
201
+ :js_compressor: :uglifier
202
+ :gzip: true
203
+ :paths:
204
+ - assets/javascripts
205
+ - other/javascripts
206
+ :stylesheets:
207
+ :options:
208
+ :output: css
209
+ :css_compressor: :sass
210
+ :paths:
211
+ - assets/stylesheets
212
+ EOF
213
+ end
214
+
215
+ before :each do
216
+ environment.site = site_1
217
+ environment.directory
218
+ allow(environment).to receive(:populated).and_return(true)
219
+ allow(environment).to receive(:config).and_return(config)
220
+ end
221
+
222
+ describe "#assets" do
223
+
224
+ subject(:assets) { environment.assets }
225
+
226
+ it "returns an array" do
227
+ expect(assets).to be_a Array
228
+ end
229
+
230
+ it "returns an array of asset objects" do
231
+ expect(assets[0]).to be_a Palimpsest::Assets
232
+ expect(assets[1]).to be_a Palimpsest::Assets
233
+ end
234
+
235
+ it "sets the directory for each asset" do
236
+ expect(assets[0].directory).to eq environment.directory
237
+ expect(assets[1].directory).to eq environment.directory
238
+ end
239
+
240
+ it "sets the options for each asset" do
241
+ expect(assets[0].options).to include output: 'compiled'
242
+ expect(assets[0].options).to include js_compressor: :uglifier
243
+ expect(assets[0].options).to include gzip: true
244
+ expect(assets[1].options).to include output: 'css'
245
+ expect(assets[1].options).to include css_compressor: :sass
246
+ end
247
+
248
+ it "sets the paths for each asset" do
249
+ expect(assets[0].paths).to include 'assets/javascripts'
250
+ expect(assets[0].paths).to include 'other/javascripts'
251
+ expect(assets[1].paths).to include 'assets/stylesheets'
252
+ end
253
+
254
+ it "only loads the paths for each type of asset" do
255
+ expect(assets[0].paths).to_not include 'assets/stylesheets'
256
+ expect(assets[1].paths).to_not include 'assets/javascripts'
257
+ end
258
+
259
+ it "does not fail if assets are not configured" do
260
+ allow(environment).to receive(:config).and_return({})
261
+ expect { assets }.not_to raise_error
262
+ end
263
+ end
264
+
265
+ describe "#sources_with_assets" do
266
+
267
+ let(:dir) { environment.directory }
268
+
269
+ it "looks for all asset types" do
270
+ expect(Palimpsest::Assets).to receive(:find_tags).twice.with(anything, nil, anything)
271
+ environment.sources_with_assets
272
+ end
273
+
274
+ it "uses options as options" do
275
+ expect(Palimpsest::Assets).to receive(:find_tags).twice.with(anything, anything, { src_pre: '(%' } )
276
+ environment.sources_with_assets
277
+ end
278
+
279
+ it "returns assets with tags" do
280
+ allow(Palimpsest::Assets).to receive(:find_tags).with(dir + '/public', anything, anything).and_return(dir + '/public/header.html')
281
+ allow(Palimpsest::Assets).to receive(:find_tags).with(dir + '/app/src', anything, anything).and_return(dir + '/app/src/head.tpl')
282
+ expect(environment.sources_with_assets).to eq [ "#{dir}/public/header.html", "#{dir}/app/src/head.tpl" ]
283
+ end
284
+ end
285
+
286
+ describe "#compile_assets" do
287
+
288
+ let(:sources) { [ "#{environment.directory}/public/header.html", "#{environment.directory}/app/src/head.tpl" ] }
289
+
290
+ it "returns itself" do
291
+ allow(environment).to receive(:sources_with_assets).and_return([])
292
+ expect(environment.compile_assets).to be environment
293
+ end
294
+
295
+ it "compiles the assets and writes the sources" do
296
+ allow(environment).to receive(:sources_with_assets).and_return sources
297
+ allow(File).to receive(:read).with(sources[0]).and_return('data_1')
298
+ allow(File).to receive(:read).with(sources[1]).and_return('data_2')
299
+ expect(Palimpsest::Utility).to receive(:write).with 'data_1', sources[0]
300
+ expect(Palimpsest::Utility).to receive(:write).with 'data_2', sources[1]
301
+ environment.compile_assets
302
+ end
303
+ end
304
+ end
305
+ end
@@ -0,0 +1,15 @@
1
+ require 'palimpsest'
2
+
3
+ require 'coveralls'
4
+ require 'simplecov'
5
+
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+
11
+ SimpleCov.start
12
+
13
+ RSpec.configure do |c|
14
+ c.expect_with(:rspec) { |e| e.syntax = :expect }
15
+ end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe Palimpsest::Utility do
4
+
5
+ describe ".make_random_directory" do
6
+
7
+ root, prefix = '/tmp', 'rspec'
8
+
9
+ it "makes a directory where expected" do
10
+ dir = Palimpsest::Utility.make_random_directory root, prefix
11
+ expect(Dir.exists? dir).to be_true
12
+ FileUtils.remove_entry_secure dir if dir =~ %r{^/tmp}
13
+ end
14
+ end
15
+
16
+ describe ".validate_path" do
17
+
18
+ context "valid path" do
19
+
20
+ it "returns the input path" do
21
+ expect(Palimpsest::Utility.validate_path '/path').to eq '/path'
22
+ end
23
+
24
+ it "returns the input path when the root path matches" do
25
+ expect(Palimpsest::Utility.validate_path '/path/to/dir', '/path/to').to eq '/path/to/dir'
26
+ end
27
+
28
+ end
29
+
30
+ context "bad path" do
31
+
32
+ it "rasises an error if path contains '../'" do
33
+ expect { Palimpsest::Utility.validate_path 'path/with/../in/it' }.to raise_error RuntimeError
34
+ end
35
+
36
+ it "rasises an error if using '~/'" do
37
+ expect { Palimpsest::Utility.validate_path '~/path' }.to raise_error RuntimeError
38
+ end
39
+
40
+ it "rasises an error if given root does not match path root" do
41
+ expect { Palimpsest::Utility.validate_path '/other_root/path', '/root/path' }.to raise_error RuntimeError
42
+ end
43
+ end
44
+ end
45
+
46
+ describe "write" do
47
+
48
+ let(:file) { double File }
49
+
50
+ it "writes to file" do
51
+ allow(File).to receive(:open).with('path/to/file', 'w').and_yield(file)
52
+ expect(file).to receive(:write).with('data')
53
+ Palimpsest::Utility.write 'data', 'path/to/file'
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,297 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: palimpsest
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Evan Boyd Sosenko
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: archive-tar-minitar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.5.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.5.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: grit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.5.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.5.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: sprockets
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.10.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.10.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.3'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.3'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.1'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.1'
97
+ - !ruby/object:Gem::Dependency
98
+ name: bump
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.4'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.8.7.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.8.7.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: redcarpet
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '='
130
+ - !ruby/object:Gem::Version
131
+ version: 3.0.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '='
137
+ - !ruby/object:Gem::Version
138
+ version: 3.0.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: github-markup
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 0.7.5
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 0.7.5
153
+ - !ruby/object:Gem::Dependency
154
+ name: rspec
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - "~>"
158
+ - !ruby/object:Gem::Version
159
+ version: 2.14.1
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - "~>"
165
+ - !ruby/object:Gem::Version
166
+ version: 2.14.1
167
+ - !ruby/object:Gem::Dependency
168
+ name: simplecov
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 0.7.1
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 0.7.1
181
+ - !ruby/object:Gem::Dependency
182
+ name: coveralls
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - "~>"
186
+ - !ruby/object:Gem::Version
187
+ version: 0.7.0
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - "~>"
193
+ - !ruby/object:Gem::Version
194
+ version: 0.7.0
195
+ - !ruby/object:Gem::Dependency
196
+ name: fuubar
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 1.2.1
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 1.2.1
209
+ - !ruby/object:Gem::Dependency
210
+ name: guard-rspec
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: 3.1.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - "~>"
221
+ - !ruby/object:Gem::Version
222
+ version: 3.1.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: guard-yard
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - "~>"
228
+ - !ruby/object:Gem::Version
229
+ version: 2.1.0
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - "~>"
235
+ - !ruby/object:Gem::Version
236
+ version: 2.1.0
237
+ description: 'No web framework, no problem: Palimpsest gives any custom or legacy
238
+ project a modern workflow and toolset.'
239
+ email:
240
+ - razorx@evansosenko.com
241
+ executables: []
242
+ extensions: []
243
+ extra_rdoc_files: []
244
+ files:
245
+ - ".gitignore"
246
+ - ".kateproject"
247
+ - ".rspec"
248
+ - ".travis.yml"
249
+ - ".yardopts"
250
+ - CHANGELOG.md
251
+ - Gemfile
252
+ - Guardfile
253
+ - LICENSE.txt
254
+ - README.md
255
+ - Rakefile
256
+ - lib/palimpsest.rb
257
+ - lib/palimpsest/assets.rb
258
+ - lib/palimpsest/environment.rb
259
+ - lib/palimpsest/utility.rb
260
+ - lib/palimpsest/version.rb
261
+ - palimpsest.gemspec
262
+ - spec/assets_spec.rb
263
+ - spec/environment_spec.rb
264
+ - spec/spec_helper.rb
265
+ - spec/utility_spec.rb
266
+ homepage: https://github.com/razor-x/palimpsest
267
+ licenses:
268
+ - MIT
269
+ metadata: {}
270
+ post_install_message:
271
+ rdoc_options: []
272
+ require_paths:
273
+ - lib
274
+ required_ruby_version: !ruby/object:Gem::Requirement
275
+ requirements:
276
+ - - ">="
277
+ - !ruby/object:Gem::Version
278
+ version: '0'
279
+ required_rubygems_version: !ruby/object:Gem::Requirement
280
+ requirements:
281
+ - - ">="
282
+ - !ruby/object:Gem::Version
283
+ version: '0'
284
+ requirements: []
285
+ rubyforge_project:
286
+ rubygems_version: 2.0.3
287
+ signing_key:
288
+ specification_version: 4
289
+ summary: Built flexible, simple, and customizable. Palimpsest runs on top of any project
290
+ and acts as a post processor for your code. Features a Sprockets asset pipeline
291
+ and easy integration with Kit.
292
+ test_files:
293
+ - spec/assets_spec.rb
294
+ - spec/environment_spec.rb
295
+ - spec/spec_helper.rb
296
+ - spec/utility_spec.rb
297
+ has_rdoc: