zassets 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ desc 'Run all specs'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+
7
+ task default: [:spec]
@@ -0,0 +1,14 @@
1
+ Feature: Builder
2
+
3
+ Scenario: builds assets
4
+ Given this config file:
5
+ """
6
+ paths:
7
+ - app
8
+ compile:
9
+ - app.js
10
+ """
11
+ And a file named "app/app.js" with "some_content"
12
+ When I build
13
+ Then the built file "public/assets/app-*.js" must exist
14
+ And the built file "public/assets/app-*.js" must contain "some_content"
@@ -0,0 +1,13 @@
1
+ Feature: Manifest
2
+
3
+ Scenario: builds a manifests of built assets
4
+ Given this config file:
5
+ """
6
+ paths:
7
+ - app
8
+ compile:
9
+ - app.js
10
+ """
11
+ And an empty file named "app/app.js"
12
+ When I build
13
+ Then the manifest should include build path for "app.js"
@@ -0,0 +1,8 @@
1
+ Feature: CLI usage
2
+
3
+ Scenario: prints the usage when -h argument is given
4
+ When I successfully run `zassets -h`
5
+ Then the output must contain:
6
+ """
7
+ Usage: zassets [options] compile|serve
8
+ """
@@ -0,0 +1,5 @@
1
+ Feature: Version information
2
+
3
+ Scenario: prints the version when -v argument is given
4
+ When I successfully run `zassets -V`
5
+ Then the output must match /\A\d+\.\d+\.\d+\n\z/
@@ -0,0 +1,10 @@
1
+ Feature: Config file loading
2
+
3
+ Scenario: loads options from `config/zassets.yaml' when this file exists
4
+ Given a file named "config/zassets.yaml" with:
5
+ """
6
+ &* invalid yaml
7
+ """
8
+ When I run `zassets compile`
9
+ Then it must fail to parse the config
10
+ And the output must contain "config/zassets.yaml"
@@ -0,0 +1,16 @@
1
+ Feature: CoffeeScript transpiler
2
+
3
+ Scenario: transpiles *.coffee files
4
+ Given this config file:
5
+ """
6
+ paths:
7
+ - app
8
+ compile:
9
+ - app.js
10
+ """
11
+ And a file named "app/app.coffee" with:
12
+ """
13
+ my_var = value
14
+ """
15
+ When I build
16
+ Then the built file "public/assets/app-*.js" must match /var\s+my_var/
@@ -0,0 +1,28 @@
1
+ Feature: SASS transpiler
2
+
3
+ Scenario: transpiles *.sass files
4
+ Given this config file:
5
+ """
6
+ paths:
7
+ - app
8
+ compile:
9
+ - styles/main.css
10
+ """
11
+ And a file named "app/styles/main.sass" with:
12
+ """
13
+ $gray_dark: #121212
14
+ $white: #d0d0d0
15
+
16
+ html
17
+ background-color: $gray_dark
18
+ color: $white
19
+ """
20
+ When I build
21
+ Then the built file "public/assets/styles/main-*.css" must match:
22
+ """
23
+ .*
24
+ html\s*\{
25
+ \s*
26
+ background-color:\s*#121212\s*;
27
+ .*
28
+ """
@@ -0,0 +1,13 @@
1
+ @server
2
+ Feature: Configurable rack handler
3
+
4
+ Scenario: uses puma as the default rack handler
5
+ Given the server is running
6
+ Then the rack handler must be "puma"
7
+
8
+ Scenario: uses the configured rack handler
9
+ Given the server is running with this config:
10
+ """
11
+ server: webrick
12
+ """
13
+ Then the rack handler must be "webrick"
@@ -0,0 +1,6 @@
1
+ Feature: SIGINT handling
2
+
3
+ Scenario: exits after SIGINT signal is received
4
+ Given the server is running
5
+ When I send the SIGINT signal
6
+ Then the server must stop successfully
@@ -0,0 +1,7 @@
1
+ @server
2
+ Feature: Logging on standard output
3
+
4
+ Scenario: logs requests on standard output
5
+ Given the server is running
6
+ When I request "/some_path"
7
+ Then the server output must match /::1.+GET\s+\/some_path\s+.*404/
@@ -0,0 +1,18 @@
1
+ @server
2
+ Feature: `public_file' option feature
3
+
4
+ Background:
5
+ Given a directory named "public"
6
+ And a file named "public/index.html" with:
7
+ """
8
+ some_index
9
+ """
10
+
11
+ Scenario: serves file path set for `public_file' when resource not found
12
+ Given the server is running with this config:
13
+ """
14
+ public_file: index.html
15
+ """
16
+ When I request "/inexistent_path"
17
+ Then the response status must be 200
18
+ And the body must be "some_index\n"
@@ -0,0 +1,15 @@
1
+ @server
2
+ Feature: Static files server
3
+
4
+ Background:
5
+ Given a directory named "public"
6
+ And a file named "public/some_file" with:
7
+ """
8
+ some_content
9
+ """
10
+
11
+ Scenario: serves files in `public' directory
12
+ Given the server is running
13
+ When I request "/some_file"
14
+ Then the response status must be 200
15
+ And the body must be "some_content\n"
@@ -0,0 +1,35 @@
1
+ Given /^a file named "([^"]*)" with "([^"]*)"$/ do |path, content|
2
+ write_file path, content
3
+ end
4
+
5
+
6
+ When /^I build$/ do
7
+ run_simple 'zassets compile'
8
+ end
9
+
10
+
11
+ Then /^the built file "([^"]*)" should exist$/ do |path|
12
+ prep_for_fs_check do
13
+ Dir[path].any?.should == true
14
+ end
15
+ end
16
+
17
+ Then /^the built file "([^"]*)" should contain "([^"]*)"$/ do |path, content|
18
+ prep_for_fs_check do
19
+ IO.read(Dir[path].first).should include(content)
20
+ end
21
+ end
22
+
23
+ Then /^the built file "([^"]*)" should match:/ do |path, content|
24
+ regexp = Regexp.compile(content, Regexp::EXTENDED)
25
+ prep_for_fs_check do
26
+ IO.read(Dir[path].first).should =~ regexp
27
+ end
28
+ end
29
+
30
+ Then /^the built file "([^"]*)" should match \/([^\/]*)\/$/ do |path, content|
31
+ regexp = Regexp.compile(content)
32
+ prep_for_fs_check do
33
+ IO.read(Dir[path].first).should =~ regexp
34
+ end
35
+ end
@@ -0,0 +1,8 @@
1
+ Given /^this config file:$/ do |config|
2
+ write_file DEFAULT_CONFIG_PATH, config
3
+ end
4
+
5
+
6
+ Then /^it should fail to parse the config$/ do
7
+ all_output.should =~ /yaml.+error/i
8
+ end
@@ -0,0 +1,7 @@
1
+ Then /^the manifest should include build path for "([^"]*)"$/ do |path|
2
+ prep_for_fs_check do
3
+ manifest = JSON.parse(IO.read('public/assets/manifest.json'))
4
+ built_path_pattern = path.gsub '.', '-[0-9a-f]+\.'
5
+ manifest['assets'][path].should =~ Regexp.compile(built_path_pattern)
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ Given /^the server is running$/ do
2
+ @_server ||= Server.new
3
+ in_current_dir { @_server.start }
4
+ end
5
+
6
+ Given /^the server is running with this config:$/ do |config|
7
+ write_file DEFAULT_CONFIG_PATH, config
8
+ @_server = Server.new
9
+ in_current_dir { @_server.start }
10
+ end
11
+
12
+
13
+ When /^I stop the server$/ do
14
+ @_server.stop
15
+ end
16
+
17
+ When /^I request "([^"]*)"$/ do |path|
18
+ @response = HTTParty.get(@_server.uri_for_path path)
19
+ end
20
+
21
+ When /^I send the SIGINT signal$/ do
22
+ @_server.sig_int
23
+ end
24
+
25
+
26
+ Then /^the server should stop successfully$/ do
27
+ @_server.wait_stop.should == true
28
+ @_server.exit_status.should == 0
29
+ end
30
+
31
+ Then /^the rack handler should be "([^"]*)"$/ do |handler|
32
+ @_server.stop
33
+ output = @_server.stdout + @_server.stderr
34
+ output.should match /#{handler}/i
35
+ end
36
+
37
+ Then /^the response status should be (\d+)$/ do |status|
38
+ @response.code.should == status.to_i
39
+ end
40
+
41
+ Then /^the body should be "([^"]*)"$/ do |body|
42
+ @response.body.should == body.gsub('\n', "\n")
43
+ end
44
+
45
+ Then /^the server output should match \/(.*)\/$/ do |pattern|
46
+ @_server.stop
47
+ output = @_server.stdout + @_server.stderr
48
+ output.should =~ Regexp.compile(pattern)
49
+ end
@@ -0,0 +1,3 @@
1
+ require 'httparty'
2
+
3
+ DEFAULT_CONFIG_PATH = 'config/zassets.yaml'
@@ -0,0 +1,16 @@
1
+ module Cucumber
2
+ class Runtime
3
+ alias :old_step_match :step_match
4
+
5
+ def step_match(step_name, name_to_report = nil)
6
+ if step_name.include? ' must '
7
+ name_to_report = step_name.dup
8
+ step_name.gsub! ' must ', ' should '
9
+ end
10
+
11
+ old_step_match(step_name, name_to_report)
12
+ end
13
+ end
14
+ end
15
+
16
+ require 'aruba/cucumber'
@@ -0,0 +1,23 @@
1
+ require 'cucumber/formatter/pretty'
2
+
3
+ module Cucumber
4
+ module Ast
5
+ class DocString
6
+ alias :old_initialize :initialize
7
+
8
+ def initialize(string, content_type)
9
+ old_initialize(string + "\n", content_type)
10
+ end
11
+ end
12
+ end
13
+
14
+ module Formatter
15
+ class Pretty
16
+ alias :old_doc_string :doc_string
17
+
18
+ def doc_string(string)
19
+ old_doc_string(string.chomp)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,93 @@
1
+ class Server
2
+ include Aruba::Api
3
+
4
+ DEFAULT_COMMAND = 'zassets serve'
5
+ DEFAULT_HOST = 'localhost'
6
+ DEFAULT_PORT = 9292
7
+
8
+ attr_reader :exit_status
9
+
10
+ def initialize
11
+ @pid = nil
12
+ @exit_status = nil
13
+ @r_out, @w_out = IO.pipe
14
+ @r_err, @w_err = IO.pipe
15
+ end
16
+
17
+ def uri_base
18
+ 'http://%s:%d' % [DEFAULT_HOST, DEFAULT_PORT]
19
+ end
20
+
21
+ def uri_for_path(path)
22
+ [uri_base, path].join
23
+ end
24
+
25
+ def stdout
26
+ @stdout ||= begin
27
+ @w_out.close
28
+ out = @r_out.read
29
+ @r_out.close
30
+ out
31
+ end
32
+ end
33
+
34
+ def stderr
35
+ @stderr ||= begin
36
+ @w_err.close
37
+ err = @r_err.read
38
+ @r_err.close
39
+ err
40
+ end
41
+ end
42
+
43
+ def running?
44
+ !!@pid
45
+ end
46
+
47
+ def start
48
+ @pid = fork do
49
+ $stdout.reopen @w_out
50
+ $stderr.reopen @w_err
51
+
52
+ exec DEFAULT_COMMAND
53
+ end
54
+
55
+ wait_ready
56
+ end
57
+
58
+ def wait_ready
59
+ TCPSocket.new DEFAULT_HOST, DEFAULT_PORT
60
+ rescue Errno::ECONNREFUSED
61
+ sleep 0.05
62
+ retry
63
+ end
64
+
65
+ def wait_stop
66
+ pid, status = Process.waitpid2(@pid)
67
+
68
+ if pid
69
+ @exit_status = status.exitstatus || status.termsig
70
+ end
71
+
72
+ !!pid
73
+ end
74
+
75
+ def stop
76
+ sig_int
77
+ Process.wait(@pid)
78
+ @pid = nil
79
+ end
80
+
81
+ def sig_int
82
+ Process.kill('INT', @pid)
83
+ end
84
+ end
85
+
86
+
87
+ Before('@server') do
88
+ @_server = Server.new
89
+ end
90
+
91
+ After('@server') do
92
+ @_server.stop if @_server.running?
93
+ end
@@ -2,6 +2,8 @@ require 'yaml'
2
2
 
3
3
  module ZAssets
4
4
  class Config
5
+ DEFAULT_CONFIG_PATH = 'config/zassets.yaml'
6
+
5
7
  DEFAULT_OPTIONS = {
6
8
  verbose: false,
7
9
  host: '::1',
@@ -18,6 +20,7 @@ module ZAssets
18
20
 
19
21
  def initialize(options = {})
20
22
  o = default_options
23
+ o.merge! load_options if default_config_file?
21
24
  o.merge! load_options(options[:config_file]) if options[:config_file]
22
25
  o.merge! options
23
26
  @options = o
@@ -28,7 +31,7 @@ module ZAssets
28
31
  DEFAULT_OPTIONS.dup
29
32
  end
30
33
 
31
- def load_options(filepath)
34
+ def load_options(filepath = DEFAULT_CONFIG_PATH)
32
35
  return {} unless options = YAML.load_file(filepath)
33
36
  options.keys.each do |key|
34
37
  options[(key.to_sym rescue key) || key] = options.delete(key)
@@ -36,6 +39,10 @@ module ZAssets
36
39
  options
37
40
  end
38
41
 
42
+ def default_config_file?
43
+ File.exist? DEFAULT_CONFIG_PATH
44
+ end
45
+
39
46
  def register_plugins!
40
47
  return unless load_plugins!
41
48
 
@@ -1,3 +1,3 @@
1
1
  module ZAssets
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
@@ -77,10 +77,35 @@ module ZAssets
77
77
  end
78
78
 
79
79
  describe '#load_options' do
80
- it 'loads symbolized options from YAML file' do
81
- config.load_options(config_file).should == {
82
- file_option: :file_value
83
- }
80
+ context 'when path is given as argument' do
81
+ it 'loads symbolized options from YAML file' do
82
+ config.load_options(config_file).should == {
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
+ config.default_config_file?.should be_false
100
+ end
101
+ end
102
+
103
+ context 'when file exists' do
104
+ it 'returns true' do
105
+ within_fixture_path do
106
+ config.default_config_file?.should be_true
107
+ end
108
+ end
84
109
  end
85
110
  end
86
111
 
data/zassets.gemspec CHANGED
@@ -24,5 +24,9 @@ Gem::Specification.new do |s|
24
24
  s.add_dependency 'execjs', '~> 1.4.0'
25
25
  s.add_dependency 'coffee-script', '~> 2.2.0'
26
26
 
27
- s.add_development_dependency 'rspec', '~> 2.14.1'
27
+ s.add_development_dependency 'rspec', '~> 2.14.1'
28
+ s.add_development_dependency 'cucumber', '~> 1.3.10'
29
+ s.add_development_dependency 'aruba', '~> 0.5.3'
30
+ s.add_development_dependency 'httparty', '~> 0.12.0'
31
+ s.add_development_dependency 'rake'
28
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zassets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-08-08 00:00:00.000000000 Z
12
+ date: 2013-11-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sprockets
@@ -107,6 +107,70 @@ dependencies:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
109
  version: 2.14.1
110
+ - !ruby/object:Gem::Dependency
111
+ name: cucumber
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: 1.3.10
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ~>
124
+ - !ruby/object:Gem::Version
125
+ version: 1.3.10
126
+ - !ruby/object:Gem::Dependency
127
+ name: aruba
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.5.3
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ~>
140
+ - !ruby/object:Gem::Version
141
+ version: 0.5.3
142
+ - !ruby/object:Gem::Dependency
143
+ name: httparty
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ~>
148
+ - !ruby/object:Gem::Version
149
+ version: 0.12.0
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ~>
156
+ - !ruby/object:Gem::Version
157
+ version: 0.12.0
158
+ - !ruby/object:Gem::Dependency
159
+ name: rake
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
110
174
  description: ! 'Standalone asset pipeline based on sprockets.
111
175
 
112
176
  '
@@ -121,7 +185,28 @@ files:
121
185
  - Guardfile
122
186
  - LICENSE
123
187
  - README.md
188
+ - Rakefile
124
189
  - bin/zassets
190
+ - features/builder/build.feature
191
+ - features/builder/manifest.feature
192
+ - features/cli/usage.feature
193
+ - features/cli/version.feature
194
+ - features/config/file.feature
195
+ - features/engines/coffee.feature
196
+ - features/engines/sass.feature
197
+ - features/server/handler.feature
198
+ - features/server/interrupt.feature
199
+ - features/server/logging.feature
200
+ - features/server/public_file.feature
201
+ - features/server/static_files.feature
202
+ - features/step_definitions/builder_steps.rb
203
+ - features/step_definitions/config_steps.rb
204
+ - features/step_definitions/manifest_steps.rb
205
+ - features/step_definitions/server_steps.rb
206
+ - features/support/env.rb
207
+ - features/support/env_aruba.rb
208
+ - features/support/env_cucumber-doc_string.rb
209
+ - features/support/env_server.rb
125
210
  - lib/zassets.rb
126
211
  - lib/zassets/cli.rb
127
212
  - lib/zassets/compiler.rb
@@ -168,7 +253,7 @@ rubyforge_project:
168
253
  rubygems_version: 1.8.23
169
254
  signing_key:
170
255
  specification_version: 3
171
- summary: zassets-0.2.1
256
+ summary: zassets-0.2.2
172
257
  test_files:
173
258
  - spec/fixtures/assets/app.js
174
259
  - spec/fixtures/config/zassets.yaml
@@ -183,4 +268,3 @@ test_files:
183
268
  - spec/zassets/memory_file_spec.rb
184
269
  - spec/zassets/server_spec.rb
185
270
  - spec/zassets/sprockets_env_spec.rb
186
- has_rdoc: