zassets 0.2.7 → 0.2.8

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.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +390 -39
  3. data/lib/zassets/config.rb +18 -5
  4. data/lib/zassets/version.rb +1 -1
  5. metadata +62 -136
  6. data/.gitignore +0 -3
  7. data/Gemfile +0 -5
  8. data/Guardfile +0 -12
  9. data/LICENSE +0 -23
  10. data/Rakefile +0 -7
  11. data/features/builder/build.feature +0 -14
  12. data/features/builder/manifest.feature +0 -13
  13. data/features/cli/default_action.feature +0 -5
  14. data/features/cli/usage.feature +0 -8
  15. data/features/cli/version.feature +0 -5
  16. data/features/config/file.feature +0 -10
  17. data/features/config/paths.feature +0 -11
  18. data/features/engines/coffee.feature +0 -16
  19. data/features/engines/sass.feature +0 -28
  20. data/features/server/handler.feature +0 -13
  21. data/features/server/interrupt.feature +0 -6
  22. data/features/server/logging.feature +0 -7
  23. data/features/server/public_file.feature +0 -18
  24. data/features/server/static_files.feature +0 -15
  25. data/features/step_definitions/builder_steps.rb +0 -41
  26. data/features/step_definitions/config_steps.rb +0 -8
  27. data/features/step_definitions/manifest_steps.rb +0 -7
  28. data/features/step_definitions/server_steps.rb +0 -49
  29. data/features/support/env.rb +0 -3
  30. data/features/support/env_aruba.rb +0 -16
  31. data/features/support/env_cucumber-doc_string.rb +0 -23
  32. data/features/support/env_server.rb +0 -91
  33. data/spec/fixtures/assets/app.js +0 -1
  34. data/spec/fixtures/config/zassets.yaml +0 -1
  35. data/spec/fixtures/public/hello.txt +0 -1
  36. data/spec/fixtures/public/index.html +0 -1
  37. data/spec/spec_helper.rb +0 -3
  38. data/spec/support/fixtures_helpers.rb +0 -13
  39. data/spec/zassets-plugins-dummy.rb +0 -17
  40. data/spec/zassets/builder_spec.rb +0 -52
  41. data/spec/zassets/cli_spec.rb +0 -158
  42. data/spec/zassets/config_spec.rb +0 -139
  43. data/spec/zassets/memory_file_spec.rb +0 -46
  44. data/spec/zassets/server_spec.rb +0 -116
  45. data/spec/zassets/sprockets_env_spec.rb +0 -44
  46. data/zassets.gemspec +0 -30
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ZAssets
4
- describe Builder do
5
- let(:config) { Config.new }
6
- subject(:builder) { Builder.new(config) }
7
-
8
- describe '#build' do
9
- it 'compiles the manifest' do
10
- builder.manifest = double('manifest')
11
- expect(builder.manifest).to receive :compile
12
- builder.build
13
- end
14
- end
15
-
16
- describe '#manifest' do
17
- it 'builds a sprockets manifest' do
18
- expect(Sprockets::Manifest).to receive(:new).with(
19
- builder.environment,
20
- builder.manifest_path
21
- )
22
- builder.manifest
23
- end
24
-
25
- it 'returns the sprockets manifest' do
26
- manifest = double('manifest')
27
- allow(Sprockets::Manifest).to receive(:new) { manifest }
28
- expect(builder.manifest).to be manifest
29
- end
30
- end
31
-
32
- describe '#manifest_path' do
33
- it 'returns the manifest file path' do
34
- expected_path = File.join(config[:build_path], 'manifest.json')
35
- expect(builder.manifest_path).to eq expected_path
36
- end
37
- end
38
-
39
- describe '#environment' do
40
- it 'builds a sprockets env' do
41
- expect(SprocketsEnv).to receive(:new).with(config)
42
- builder.environment
43
- end
44
-
45
- it 'returns the sprockets env' do
46
- environment = double('environment')
47
- allow(SprocketsEnv).to receive(:new) { environment }
48
- expect(builder.environment).to be environment
49
- end
50
- end
51
- end
52
- end
@@ -1,158 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ZAssets
4
- describe CLI do
5
- let(:args) { ['serve'] }
6
- subject(:cli) { CLI.new(args) }
7
-
8
- describe '#initialize' do
9
- context 'action arguments parsing' do
10
- it 'parses the action' do
11
- expect(cli.action).to eq :serve
12
- end
13
-
14
- context 'when action is not provided' do
15
- let(:args) { [] }
16
-
17
- it 'defaults to build' do
18
- expect(cli.action).to eq :build
19
- end
20
- end
21
- end
22
-
23
- context 'option arguments parsing' do
24
- def with_option(option, value = nil)
25
- if value
26
- CLI.new [option, value, *args]
27
- else
28
- CLI.new [option, *args]
29
- end
30
- end
31
-
32
- it 'parses the -v option' do
33
- expect(with_option('-v').options[:verbose]).to be true
34
- end
35
-
36
- it 'parses the -c option' do
37
- expect(with_option('-c', 'config').options[:config_file])
38
- .to eq 'config'
39
- end
40
-
41
- it 'parses the -o option' do
42
- expect(with_option('-o', '::0').options[:host]).to eq '::0'
43
- end
44
-
45
- it 'parses the -p option' do
46
- expect(with_option('-p', '9393').options[:port]).to eq '9393'
47
- end
48
-
49
- it 'parses the -s option' do
50
- expect(with_option('-s', 'thin').options[:server]).to eq 'thin'
51
- end
52
-
53
- context '-h option' do
54
- let(:args) { ['-h'] }
55
- let(:output) { StringIO.new }
56
- subject(:cli) { CLI.new(args, output) }
57
-
58
- it 'prints the usage help' do
59
- begin
60
- cli
61
- rescue SystemExit
62
- end
63
- expect(output.string).to match /\AUsage: /
64
- end
65
-
66
- it 'exits' do
67
- expect { cli }.to raise_error SystemExit
68
- end
69
- end
70
-
71
- context '-V option' do
72
- let(:args) { ['-V'] }
73
- let(:output) { StringIO.new }
74
- subject(:cli) { CLI.new(args, output) }
75
-
76
- it 'prints the version' do
77
- begin
78
- cli
79
- rescue SystemExit
80
- end
81
- expect(output.string.chomp).to eq VERSION
82
- end
83
-
84
- it 'exits' do
85
- expect { cli }.to raise_error SystemExit
86
- end
87
- end
88
- end
89
- end
90
-
91
- describe '#action' do
92
- it 'return the current action' do
93
- expect(cli.action).to eq args.last.to_sym
94
- end
95
- end
96
-
97
- describe '#config' do
98
- it 'builds a config' do
99
- expect(Config).to receive(:new).with(cli.options)
100
- cli.config
101
- end
102
-
103
- it 'returns the config' do
104
- config = double('config')
105
- allow(Config).to receive(:new) { config }
106
- expect(cli.config).to be config
107
- end
108
- end
109
-
110
- describe '#run' do
111
- context 'serve action' do
112
- it 'runs the server' do
113
- server = double('server')
114
- allow(cli).to receive(:server) { server }
115
- expect(server).to receive :run
116
- cli.run
117
- end
118
- end
119
-
120
- context 'build action' do
121
- let(:args) { ['build'] }
122
-
123
- it 'runs the builder' do
124
- builder = double('builder')
125
- allow(cli).to receive(:builder) { builder }
126
- expect(builder).to receive :build
127
- cli.run
128
- end
129
- end
130
- end
131
-
132
- describe '#builder' do
133
- it 'builds a builder' do
134
- expect(Builder).to receive(:new).with(cli.config)
135
- cli.builder
136
- end
137
-
138
- it 'returns the builder' do
139
- builder = double('builder')
140
- allow(Builder).to receive(:new) { builder }
141
- expect(cli.builder).to be builder
142
- end
143
- end
144
-
145
- describe '#server' do
146
- it 'builds a server' do
147
- expect(Server).to receive(:new).with(cli.config)
148
- cli.server
149
- end
150
-
151
- it 'returns the server' do
152
- server = double('server')
153
- allow(Server).to receive(:new) { server }
154
- expect(cli.server).to be server
155
- end
156
- end
157
- end
158
- end
@@ -1,139 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ZAssets
4
- describe Config do
5
- include FixturesHelpers
6
-
7
- let(:config_file) { fixture_path_for 'config/zassets.yaml' }
8
- subject(:config) { Config.new }
9
-
10
- describe '#initialize' do
11
- it 'assigns #default_options to @options' do
12
- expect(config.instance_eval { @options }).to eq config.default_options
13
- end
14
-
15
- it 'registers plugins' do
16
- expect_any_instance_of(Config).to receive :register_plugins!
17
- Config.new
18
- end
19
-
20
- context 'with a non-empty option hash' do
21
- it 'merges the option hash' do
22
- config = Config.new(verbose: true)
23
- expect(config[:verbose]).to be true
24
- end
25
- end
26
-
27
- context 'with config_file option' do
28
- subject(:config) { Config.new(config_file: config_file) }
29
-
30
- it 'merges the config file options in @options' do
31
- expect(config[:file_option]).to eq :file_value
32
- end
33
-
34
- it 'merges the config file options before argument options' do
35
- config = Config.new(file_option: :argument_value)
36
- expect(config[:file_option]).to eq :argument_value
37
- end
38
- end
39
- end
40
-
41
- describe '#default_options' do
42
- it 'sets verbose to false' do
43
- expect(config.default_options[:verbose]).to be false
44
- end
45
-
46
- it 'sets host to ::1' do
47
- expect(config.default_options[:host]).to eq '::1'
48
- end
49
-
50
- it 'sets port to 9292' do
51
- expect(config.default_options[:port]).to eq 9292
52
- end
53
-
54
- it 'sets server to puma' do
55
- expect(config.default_options[:server]).to eq :puma
56
- end
57
-
58
- it 'sets base_url to /assets' do
59
- expect(config.default_options[:base_url]).to eq '/assets'
60
- end
61
-
62
- it 'sets paths to app directory' do
63
- expect(config.default_options[:paths]).to eq ['app']
64
- end
65
-
66
- it 'sets public_path to public directory' do
67
- expect(config.default_options[:public_path]).to eq 'public'
68
- end
69
-
70
- it 'sets build_path to public/assets directory' do
71
- expect(config.default_options[:build_path]).to eq 'public/assets'
72
- end
73
-
74
- it 'sets build empty' do
75
- expect(config.default_options[:build]).to eq []
76
- end
77
- end
78
-
79
- describe '#load_options' do
80
- context 'when path is given as argument' do
81
- it 'loads symbolized options from YAML file' do
82
- expect(config.load_options(config_file)).to eq({
83
- file_option: :file_value
84
- })
85
- end
86
- end
87
-
88
- context 'without argument' do
89
- it 'loads the default config file path' do
90
- expect { config.load_options }
91
- .to raise_error /.*no such.+config\/zassets.yaml/i
92
- end
93
- end
94
- end
95
-
96
- describe '#default_config_file?' do
97
- context 'when file does not exist' do
98
- it 'returns false' do
99
- expect(config.default_config_file?).to be false
100
- end
101
- end
102
-
103
- context 'when file exists' do
104
- it 'returns true' do
105
- within_fixture_path do
106
- expect(config.default_config_file?).to be true
107
- end
108
- end
109
- end
110
- end
111
-
112
- describe '#register_plugins!' do
113
- subject(:config) { Config.new(plugins: ['dummy']) }
114
-
115
- it 'loads plugins' do
116
- config
117
- expect(Plugins::Dummy).to be
118
- end
119
-
120
- it 'registers them with current config' do
121
- expect(config[:dummy_plugin]).to eq :registered
122
- end
123
- end
124
-
125
- describe '#[]' do
126
- it 'returns an @options value from its key' do
127
- config.instance_eval { @options[:foo] = :bar }
128
- expect(config[:foo]).to eq :bar
129
- end
130
- end
131
-
132
- describe '#[]=' do
133
- it 'stores a value under given key' do
134
- config[:foo] = :bar
135
- expect(config[:foo]).to eq :bar
136
- end
137
- end
138
- end
139
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ZAssets
4
- describe MemoryFile do
5
- include FixturesHelpers
6
-
7
- let(:file_path) { fixture_path_for('public/index.html') }
8
- let(:file) { File.new file_path }
9
- subject(:memfile) { MemoryFile.new(file) }
10
-
11
- describe '#headers' do
12
- it 'sets the content type to text/html' do
13
- expect(memfile.headers['Content-Type']).to eq 'text/html'
14
- end
15
-
16
- it 'sets the content length to the file length' do
17
- expect(memfile.headers['Content-Length']).to eq file.size.to_s
18
- end
19
- end
20
-
21
- describe '#body' do
22
- it 'returns the file content' do
23
- expect(memfile.body).to eq File.read(file_path)
24
- end
25
- end
26
-
27
- describe '#call' do
28
- require 'rack'
29
-
30
- let(:app) { Rack::MockRequest.new(memfile) }
31
- let(:response) { app.get '/' }
32
-
33
- it 'returns a successful response' do
34
- expect(response).to be_ok
35
- end
36
-
37
- it 'sets required headers' do
38
- expect(response.headers).to eq memfile.headers
39
- end
40
-
41
- it 'returns the body' do
42
- expect(response.body).to eq memfile.body
43
- end
44
- end
45
- end
46
- end
@@ -1,116 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module ZAssets
4
- describe Server do
5
- let(:config) { Config.new }
6
- subject(:server) { Server.new(config) }
7
-
8
- describe '#run' do
9
- let(:handler) { double 'handler' }
10
-
11
- it 'runs the rack app' do
12
- allow(server).to receive(:handler) { handler }
13
- expect(handler).to receive(:run).with(server.app, server.options)
14
- server.run
15
- end
16
- end
17
-
18
- describe '#handler' do
19
- it 'returns the configured rack handler' do
20
- expect(server.handler).to eq Rack::Handler::Puma
21
- end
22
- end
23
-
24
- describe '#options' do
25
- it 'sets rack environment to development' do
26
- expect(server.options[:environment]).to eq :development
27
- end
28
-
29
- it 'sets rack handler host to configured host' do
30
- expect(server.options[:Host]).to eq config[:host]
31
- end
32
-
33
- it 'sets rack handler port to configured port' do
34
- expect(server.options[:Port]).to eq config[:port]
35
- end
36
- end
37
-
38
- describe '#app' do
39
- it 'returns a rack application' do
40
- expect(server.app).to respond_to :call
41
- end
42
-
43
- it 'builds the rack app once' do
44
- # When building a rack app with Rack::Builder.new, the app will be
45
- # built on each request. We dont want that so we need to either build
46
- # using Rack::Builder.app or call #to_app on the returned instance. We
47
- # can test if it was done by checking #to_app method absence.
48
- expect(server.app).not_to respond_to :to_app
49
- end
50
-
51
- context 'Rack application' do
52
- include FixturesHelpers
53
-
54
- let(:app) { Rack::MockRequest.new(server.app) }
55
- let(:path) { '/' }
56
- let(:response) { app.get path }
57
-
58
- it 'logs queries' do
59
- expect(response.errors).to match(/GET \/.+404.+/)
60
- end
61
-
62
- it 'shows exceptions' do
63
- allow_any_instance_of(SprocketsEnv).to receive(:call) { raise RuntimeError }
64
- response = app.get(config[:base_url])
65
- expect(response).to be_server_error
66
- expect(response.body).to match /RuntimeError/
67
- end
68
-
69
- context 'assets mount point' do
70
- let(:path) { [config[:base_url], 'app.js'].join '/' }
71
- let(:config) { Config.new(paths: [fixture_path_for('assets')]) }
72
-
73
- it 'maps the sprockets env' do
74
- within_fixture_path do
75
- expect(response).to be_ok
76
- expect(response.content_type).to eq 'application/javascript'
77
- expect(response.body).to eq "console.log('hello!');\n"
78
- end
79
- end
80
- end
81
-
82
- context 'root mount point' do
83
- let(:path) { '/hello.txt' }
84
-
85
- it 'maps the static file handler' do
86
- within_fixture_path do
87
- expect(response).to be_ok
88
- expect(response.content_type).to eq 'text/plain'
89
- expect(response.body).to eq "hello!\n"
90
- end
91
- end
92
-
93
- context 'when a public file is configured' do
94
- let(:config) { Config.new(public_file: 'index.html') }
95
-
96
- it 'serves the public file' do
97
- within_fixture_path do
98
- response = app.get('/')
99
- expect(response).to be_ok
100
- expect(response.content_type).to eq 'text/html'
101
- expect(response.body).to eq "hello HTML!\n"
102
- end
103
- end
104
-
105
- it 'serves static file' do
106
- within_fixture_path do
107
- response = app.get('/hello.txt')
108
- expect(response.body).to eq "hello!\n"
109
- end
110
- end
111
- end
112
- end
113
- end
114
- end
115
- end
116
- end