terrimporter 0.6.0 → 0.6.4

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.
@@ -4,6 +4,8 @@ class TestImporter < Test::Unit::TestCase
4
4
  def setup
5
5
  create_tmp_test_directory
6
6
  @importer = TerrImporter::Application::Importer.new({:config_file => test_config_file_path})
7
+ FakeWeb.register_uri(:get, "http://terrific.url", :body => File.expand_path('test/fixtures/html/application_root.html'), :content_type => 'text/plain')
8
+ FakeWeb.register_uri(:get, "http://terrific.url/", :body => File.expand_path('test/fixtures/html/application_root.html'), :content_type => 'text/plain')
7
9
  FakeWeb.register_uri(:get, "http://terrific.url/terrific/base/0.5/public/css/base/base.css.php?appbaseurl=&application=/terrific/webapp/path&layout=project&debug=false&cache=false", :body => File.expand_path('test/fixtures/css/base.css'), :content_type => 'text/plain')
8
10
  FakeWeb.register_uri(:get, "http://terrific.url/terrific/base/0.5/public/css/base/base.css.php?appbaseurl=&application=/terrific/webapp/path&layout=project&suffix=ie&debug=false&cache=false", :body => File.expand_path('test/fixtures/css/ie.css'), :content_type => 'text/plain')
9
11
  FakeWeb.register_uri(:get, "http://terrific.url/terrific/base/0.5/public/js/base/base.js.php?layout=project&cache=false&application=/terrific/webapp/path&debug=false", :body => File.expand_path('test/fixtures/js/base.js'), :content_type => 'text/plain')
@@ -24,13 +26,8 @@ class TestImporter < Test::Unit::TestCase
24
26
  delete_tmp_test_directory
25
27
  end
26
28
 
27
- should 'be a dummy test for more tests to follow....' do
28
- assert true
29
- end
30
29
 
31
30
  context 'css string replacement' do
32
-
33
-
34
31
  should 'replace a string in the stylesheet with the configured string' do
35
32
  line = "this line should replace the /img/ string with images"
36
33
  @importer.send(:stylesheet_replace_strings!, line)
@@ -38,11 +35,18 @@ class TestImporter < Test::Unit::TestCase
38
35
  end
39
36
 
40
37
  should 'replace a string in the stylesheet with the configured regex' do
41
- @importer.config['stylesheets']['replace'][0]['what'] = "r/(re.+ex)/"
38
+ @importer.config['stylesheets']['replace_strings'][0]['what'] = "r/(re.+ex)/"
42
39
  line = "this line should replace the regex string with images"
43
40
  @importer.send(:stylesheet_replace_strings!, line)
44
41
  assert line.include?("/images/"), "result not expected, is #{line}"
45
42
  end
43
+
44
+ #todo this tests is a fluke and not clean!
45
+ should 'not do any string replacement if not configured' do
46
+ @importer.config['stylesheets']['replace_strings'] = nil
47
+ @importer.import_css
48
+ assert true
49
+ end
46
50
  end
47
51
 
48
52
  context 'file creation' do
@@ -72,6 +76,10 @@ class TestImporter < Test::Unit::TestCase
72
76
  end
73
77
 
74
78
  context 'css and js export path construction' do
79
+ setup do
80
+ @importer.config['export_path'] = {'css' => 'base.css', 'js' => 'base.js'}
81
+ end
82
+
75
83
  should 'raise an error on wrongly supplied arguments' do
76
84
  assert_raise TerrImporter::DefaultError do
77
85
  @importer.send(:construct_export_path, :invalid)
@@ -125,7 +133,7 @@ class TestImporter < Test::Unit::TestCase
125
133
  end
126
134
 
127
135
  should 'download only files specified by file multiple extension' do
128
- @importer.send(:batch_download, '/img/backgrounds/', tmp_test_directory, "doesntexist jpg") #here broken
136
+ @importer.send(:batch_download, '/img/backgrounds/', tmp_test_directory, "doesntexist jpg") #here broken
129
137
  assert exists_in_tmp? 'background.jpg'
130
138
  end
131
139
 
@@ -133,8 +141,7 @@ class TestImporter < Test::Unit::TestCase
133
141
 
134
142
  context 'test public grand import functions - everything is preconfigured' do
135
143
  should 'import all images' do
136
- @importer.import_images #here broken
137
-
144
+ @importer.import_images
138
145
  assert exists_in_tmp?('public/images/testimage1.png')
139
146
  assert exists_in_tmp?('public/images/testimage2.png')
140
147
  assert exists_in_tmp?('public/images/testimage3.png')
@@ -163,7 +170,7 @@ class TestImporter < Test::Unit::TestCase
163
170
  end
164
171
 
165
172
  should 'import js, css and images, not using the :all statement' do
166
- @importer.run #here broken
173
+ @importer.run
167
174
  #only cherry-pick tests
168
175
  assert exists_in_tmp?('public/images/testimage1.png')
169
176
  assert exists_in_tmp?('public/stylesheets/base.css')
@@ -176,7 +183,7 @@ class TestImporter < Test::Unit::TestCase
176
183
  @importer.options[:all] = true
177
184
  end
178
185
  should 'import js, css and images, using the :all statement' do
179
- @importer.run #here broken
186
+ @importer.run
180
187
  #only cherry-pick tests
181
188
  assert exists_in_tmp?('public/images/testimage1.png')
182
189
  assert exists_in_tmp?('public/stylesheets/base.css')
@@ -185,6 +192,20 @@ class TestImporter < Test::Unit::TestCase
185
192
 
186
193
  end
187
194
 
195
+ context 'read additional configuration values from parent page' do
196
+ should 'extract version and app path from parent page' do
197
+ assert_nothing_raised do
198
+ @importer.determine_configuration_values_from_uri
199
+ end
200
+
201
+ assert !@importer.config['version'].nil?
202
+ assert !@importer.config['export_settings']['application'].nil?
203
+ assert !@importer.config['export_path']['js'].nil?
204
+ assert !@importer.config['export_path']['css'].nil?
205
+ end
206
+ end
207
+
208
+
188
209
  def exists_in_tmp?(name)
189
210
  File.exists? File.join(tmp_test_directory, name)
190
211
  end
@@ -29,20 +29,6 @@ class TestOptions < Test::Unit::TestCase
29
29
  assert_nil @options[:import_images]
30
30
  end
31
31
 
32
- should 'show help if none of the required options are specified' do
33
- @options.show_help_on_no_options
34
- assert @options[:show_help]
35
-
36
- #self[:show_help] = true unless self[:import_css] or self[:import_js] or self[:import_images] or self[:init] or self[:version]
37
- end
38
-
39
- should 'not show help if one of the required options is specified' do
40
- @options[:import_css] = true
41
- @options.show_help_on_no_options
42
- assert_equal false, @options[:show_help]
43
- #self[:show_help] = true unless self[:import_css] or self[:import_js] or self[:import_images] or self[:init] or self[:version]
44
- end
45
-
46
32
  end
47
33
 
48
34
  for_options '--init' do
@@ -127,20 +113,12 @@ class TestOptions < Test::Unit::TestCase
127
113
  end
128
114
  end
129
115
 
130
-
131
116
  for_options '--version' do
132
117
  should 'show version' do
133
118
  assert @options[:show_version]
134
119
  end
135
120
  end
136
121
 
137
-
138
- for_options '' do
139
- should 'show help if no options supplied' do
140
- assert @options[:show_help]
141
- end
142
- end
143
-
144
122
  for_options '--config','param_config_file.yml', ' -a' do
145
123
  should 'use supplied yml file for configuration' do
146
124
  assert @options[:config_file].include?("param_config_file.yml")
@@ -159,5 +137,16 @@ class TestOptions < Test::Unit::TestCase
159
137
  end
160
138
  end
161
139
 
140
+ context 'use application uri' do
141
+ setup do
142
+ @uri = 'http://terrific.app.uri'
143
+ @options = TerrImporter::Application::Options.new([@uri])
144
+ end
145
+
146
+ should 'display the correct application uri if passes as main param' do
147
+ assert_equal @uri, @options[:application_url]
148
+ end
149
+ end
150
+
162
151
 
163
152
  end
@@ -0,0 +1,12 @@
1
+ require "test_helper"
2
+
3
+ class TestStringMonkeypatch < Test::Unit::TestCase
4
+
5
+ should 'split a string' do
6
+ expected = ["this", "is", "a", "test"]
7
+
8
+ assert_equal expected, expected.join(", ").robust_split
9
+ assert_equal expected, expected.join(" ").robust_split
10
+ end
11
+
12
+ end
data/test/watch.rb ADDED
@@ -0,0 +1,71 @@
1
+ ENV["WATCHR"] = "1"
2
+ system 'clear'
3
+
4
+ def growl(message)
5
+ growlnotify = `which growlnotify`.chomp
6
+ title = "Watchr Test Results"
7
+ image = message.include?('0 failures, 0 errors') ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
8
+ options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
9
+ system %(#{growlnotify} #{options} &)
10
+ end
11
+
12
+ def run(cmd)
13
+ puts(cmd)
14
+ `#{cmd}`
15
+ end
16
+
17
+ def run_test_file(file)
18
+ system('clear')
19
+ result = run(%Q(ruby -I"lib:test" -rubygems #{file}))
20
+ growl result.split("\n").last rescue nil
21
+ puts result
22
+ end
23
+
24
+ def run_all_tests
25
+ system('clear')
26
+ result = run "rake test"
27
+ growl result.split("\n").last rescue nil
28
+ puts result
29
+ end
30
+
31
+ def run_all_features
32
+ system('clear')
33
+ end
34
+
35
+ def related_test_files(path)
36
+ Dir['test/**/*.rb'].select { |file| file =~ /#{File.basename(path).split(".").first}_test.rb/ }
37
+ end
38
+
39
+ def run_suite
40
+ run_all_tests
41
+ run_all_features
42
+ end
43
+
44
+ watch('test/test_helper\.rb') { run_all_tests }
45
+ watch('test/.*/.*_test\.rb') { |m| run_test_file(m[0]) }
46
+ watch('app/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
47
+ watch('lib/.*/.*\.rb') { |m| related_test_files(m[0]).map {|tf| run_test_file(tf) } }
48
+ watch('features/.*/.*\.feature') { run_all_features }
49
+
50
+ # Ctrl-\
51
+ Signal.trap 'QUIT' do
52
+ puts " --- Running all tests ---\n\n"
53
+ run_all_tests
54
+ end
55
+
56
+ @interrupted = false
57
+
58
+ # Ctrl-C
59
+ Signal.trap 'INT' do
60
+ if @interrupted then
61
+ @wants_to_quit = true
62
+ abort("\n")
63
+ else
64
+ puts "Interrupt a second time to quit"
65
+ @interrupted = true
66
+ Kernel.sleep 1.5
67
+ # raise Interrupt, nil # let the run loop catch it
68
+ run_suite
69
+ end
70
+ end
71
+
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terrimporter
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 0
10
- version: 0.6.0
9
+ - 4
10
+ version: 0.6.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel Kummer
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-28 00:00:00 Z
18
+ date: 2011-08-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: kwalify
@@ -128,18 +128,19 @@ files:
128
128
  - config/terrimporter.config.yml
129
129
  - lib/terrimporter.rb
130
130
  - lib/terrimporter/app_logger.rb
131
+ - lib/terrimporter/array_monkeypatch.rb
131
132
  - lib/terrimporter/config_helper.rb
132
- - lib/terrimporter/config_validator.rb
133
133
  - lib/terrimporter/configuration.rb
134
134
  - lib/terrimporter/downloader.rb
135
135
  - lib/terrimporter/importer.rb
136
136
  - lib/terrimporter/options.rb
137
+ - lib/terrimporter/string_monkeypatch.rb
137
138
  - lib/terrimporter/version.rb
138
- - tasks/load_tasks.rb
139
- - tasks/version.rake
139
+ - terrimporter.config.yml.bak
140
140
  - terrimporter.gemspec
141
141
  - test/fixtures/css/base.css
142
142
  - test/fixtures/css/ie.css
143
+ - test/fixtures/html/application_root.html
143
144
  - test/fixtures/html/img_backgrounds_dir.html
144
145
  - test/fixtures/html/img_dir.html
145
146
  - test/fixtures/html/js_dyn_dir.html
@@ -148,9 +149,8 @@ files:
148
149
  - test/fixtures/invalid.config.yml
149
150
  - test/fixtures/js/base.js
150
151
  - test/fixtures/js/dynlib.js
152
+ - test/fixtures/minimal.test.config.yml
151
153
  - test/fixtures/test.config.yml
152
- - test/helper.rb
153
- - test/terrimporter.config.yml
154
154
  - test/test/tmp/public/javascripts/base.js
155
155
  - test/test/tmp/public/javascripts/lib/dynlib.js
156
156
  - test/test/tmp/public/stylesheets/base.css
@@ -158,12 +158,14 @@ files:
158
158
  - test/test_helper.rb
159
159
  - test/test_terrimporter.rb
160
160
  - test/unit/test_app_logger.rb
161
+ - test/unit/test_arraymonkeypatch.rb
161
162
  - test/unit/test_config_helper.rb
162
- - test/unit/test_config_validator.rb
163
163
  - test/unit/test_configuration.rb
164
164
  - test/unit/test_downloader.rb
165
165
  - test/unit/test_importer.rb
166
166
  - test/unit/test_options.rb
167
+ - test/unit/test_stringmonkeypatch.rb
168
+ - test/watch.rb
167
169
  homepage: ""
168
170
  licenses: []
169
171
 
@@ -201,6 +203,7 @@ summary: Import terrific javascripts, css files and images into a web project
201
203
  test_files:
202
204
  - test/fixtures/css/base.css
203
205
  - test/fixtures/css/ie.css
206
+ - test/fixtures/html/application_root.html
204
207
  - test/fixtures/html/img_backgrounds_dir.html
205
208
  - test/fixtures/html/img_dir.html
206
209
  - test/fixtures/html/js_dyn_dir.html
@@ -209,9 +212,8 @@ test_files:
209
212
  - test/fixtures/invalid.config.yml
210
213
  - test/fixtures/js/base.js
211
214
  - test/fixtures/js/dynlib.js
215
+ - test/fixtures/minimal.test.config.yml
212
216
  - test/fixtures/test.config.yml
213
- - test/helper.rb
214
- - test/terrimporter.config.yml
215
217
  - test/test/tmp/public/javascripts/base.js
216
218
  - test/test/tmp/public/javascripts/lib/dynlib.js
217
219
  - test/test/tmp/public/stylesheets/base.css
@@ -219,9 +221,11 @@ test_files:
219
221
  - test/test_helper.rb
220
222
  - test/test_terrimporter.rb
221
223
  - test/unit/test_app_logger.rb
224
+ - test/unit/test_arraymonkeypatch.rb
222
225
  - test/unit/test_config_helper.rb
223
- - test/unit/test_config_validator.rb
224
226
  - test/unit/test_configuration.rb
225
227
  - test/unit/test_downloader.rb
226
228
  - test/unit/test_importer.rb
227
229
  - test/unit/test_options.rb
230
+ - test/unit/test_stringmonkeypatch.rb
231
+ - test/watch.rb
@@ -1,21 +0,0 @@
1
- require 'kwalify'
2
-
3
- class ConfigValidator < Kwalify::Validator
4
- ## hook method called by Validator#validate()
5
- def validate_hook(value, rule, path, errors)
6
- case rule.name
7
- when 'css'
8
- #todo split space separated values and check for .css
9
- if value =~ /\.css/
10
- msg = "no .css extension allowed, use filename only."
11
- errors << Kwalify::ValidationError.new(msg, path)
12
- end
13
- when 'js'
14
- if value =~ /\.js/
15
- msg = "no .js extension allowed, use filename only."
16
- errors << Kwalify::ValidationError.new(msg, path)
17
- end
18
- end
19
- end
20
-
21
- end
data/tasks/load_tasks.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'rake'
2
-
3
- Dir["#{File.dirname(__FILE__)}/*.rake"].sort.each { |ext| load ext }
data/tasks/version.rake DELETED
@@ -1,2 +0,0 @@
1
-
2
-
data/test/helper.rb DELETED
File without changes
@@ -1,68 +0,0 @@
1
- ########################################################################################################################
2
- # Terrific import configuration file, adjust as needed.
3
- #
4
- # version: Define the terrific version in use
5
- # url: Terrific base url
6
- # app_path Terrific application path (must start with '/')
7
- # export_path You most probably won't have to change this
8
- # image_base_path: The Terrific image base path. You most probably won't have to change this
9
- # libraries_source_path: The library source path. You most probably won't have to change this
10
- # downloader: The downloader to use, supported are 'curl' and 'wget'
11
- #
12
- # export_settings: The settings below are added as query parameters for base.js and base.css
13
- # layout: You most probably won't have to change this
14
- # debug: False compacts the base.js and base.css files
15
- # cache: You most probably won't have to change this
16
- #
17
- # stylesheets: Define the stylesheets in the following form:
18
- # dest: The destination directory, relative from the current running directory
19
- # styles: Name of the stylesheets, space separated without the .css extension. ex: ie ie6 ie7 ie8
20
- # the main style base.css is included by default and MUST NOT BE SPECIFIED
21
- # replace: Define path replacements after the stylesheets have been downloaded
22
- # you can define multiple replacements by repeating the '-what: with:' statements
23
- # - what: What to replace, default is string. if you want to use regex, use the format r/[regex]/
24
- # for help on regular expressions see http://www.rubular.com/ (an online editor/tester)
25
- # with: Replace with this (string)
26
- #
27
- # javascripts: Define the javascript files in the following form
28
- # dest: Destination of the javascript base.js file
29
- # dynamic_libraries: Dynamic libraries definition, space separated without the .js extension. ex: warning pngfix
30
- # libraries_dest: Destination of the dynamic libraries relative to the 'dest' path. '/' means they're included in 'dest'
31
- #
32
- # images: Define the images to be downloaded, the terrific base path is always "img", so the src root is "img/"
33
- # each of the entries describes one path for images to be downloaded
34
- # -src: The source path, "/" means "img/"
35
- # dest: The destination directory, relative from the current running directory
36
- # types: The image endings to be downloaded, specified as a space separated string
37
- ########################################################################################################################
38
- version: 0.5
39
- url: http://terrific.url
40
- app_path: /terrific/webapp/path
41
- export_path: /terrific/base/%2$s/public/%1$s/base/base.%1$s.php
42
- libraries_source_path: /js/libraries/dynamic
43
- image_base_path: /img
44
- downloader: curl
45
- export_settings:
46
- layout: project
47
- debug: false
48
- cache: false
49
- stylesheets:
50
- dest: public/stylesheets/
51
- styles: ie
52
- replace:
53
- - what: /img/
54
- with: /images/
55
- javascripts:
56
- dest: public/javascripts/
57
- dynamic_libraries: dynlib
58
- libraries_dest: /
59
- images:
60
- - src: /
61
- dest: public/images/
62
- types: jpg png gif
63
- - src: /
64
- dest: public/
65
- types: ico
66
- - src: /backgrounds/
67
- dest: public/images/backgrounds/
68
- types: jpg