terrimporter 0.7.3 → 0.7.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.
- data/Gemfile.lock +1 -1
- data/README.rdoc +4 -0
- data/config/schema.yml +10 -0
- data/config/terrimporter.yml +5 -1
- data/lib/terrimporter/app_logger.rb +14 -11
- data/lib/terrimporter/array_monkeypatch.rb +1 -1
- data/lib/terrimporter/configuration.rb +60 -87
- data/lib/terrimporter/configuration_helper.rb +31 -22
- data/lib/terrimporter/configuration_loader.rb +85 -0
- data/lib/terrimporter/download_helper.rb +1 -1
- data/lib/terrimporter/downloader.rb +19 -10
- data/lib/terrimporter/error.rb +10 -0
- data/lib/terrimporter/importer.rb +57 -49
- data/lib/terrimporter/statistic.rb +37 -0
- data/lib/terrimporter/stylesheet_importer.rb +56 -0
- data/lib/terrimporter/version.rb +2 -2
- data/lib/terrimporter.rb +12 -2
- data/test/fixtures/invalid.config.yml +1 -0
- data/test/fixtures/js/dynplugin.js +1 -0
- data/test/fixtures/minimal.test.config.yml +1 -0
- data/test/fixtures/test.config.yml +3 -0
- data/test/unit/test_arraymonkeypatch.rb +1 -1
- data/test/unit/test_configuration.rb +14 -107
- data/test/unit/{test_config_helper.rb → test_configuration_helper.rb} +7 -6
- data/test/unit/test_configuration_loader.rb +86 -0
- data/test/unit/test_downloader.rb +16 -5
- data/test/unit/test_importer.rb +3 -1
- data/test/unit/test_statistics.rb +44 -0
- metadata +16 -6
@@ -0,0 +1,86 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
|
4
|
+
class ConfigurationLoaderTest < Test::Unit::TestCase
|
5
|
+
include ConfigurationHelper
|
6
|
+
|
7
|
+
def setup
|
8
|
+
FakeWeb.register_uri(:get, "http://terrific.url", :body => File.expand_path('test/fixtures/html/application_root.html'), :content_type => 'text/plain')
|
9
|
+
@loader = TerrImporter::Application::ConfigurationLoader.new(test_config_file_path)
|
10
|
+
end
|
11
|
+
|
12
|
+
should 'find a configuration in the local path and not raise an error' do
|
13
|
+
assert_nothing_raised do
|
14
|
+
@loader.determine_config_file_path
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'no configuration file around' do
|
19
|
+
setup { @loader = TerrImporter::Application::ConfigurationLoader.new }
|
20
|
+
|
21
|
+
should 'not find a configuration in the local path and raise an error' do
|
22
|
+
assert_raise TerrImporter::ConfigurationError do
|
23
|
+
@loader.load_configuration
|
24
|
+
@loader
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'invalid config file' do
|
30
|
+
setup do
|
31
|
+
@loader = TerrImporter::Application::ConfigurationLoader.new invalid_test_config_file_path
|
32
|
+
end
|
33
|
+
|
34
|
+
should 'throw an error on an invalid config file' do
|
35
|
+
assert_raise TerrImporter::ConfigurationError do
|
36
|
+
@loader.load_configuration
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'test config file independent functions' do
|
42
|
+
|
43
|
+
#should 'get the current working directory as config file path' do
|
44
|
+
# config_in_cwd = File.join(Dir.pwd, config_default_name)
|
45
|
+
# assert_equal config_in_cwd, @loader.determine_config_file_path
|
46
|
+
#end
|
47
|
+
|
48
|
+
should 'create a config file in the current directory' do
|
49
|
+
config_path = File.join(Dir.pwd, config_default_name)
|
50
|
+
FileUtils.rm_f config_path if File.exists? config_path
|
51
|
+
@loader.create_config_file
|
52
|
+
assert File.exists?(config_path)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'read additional configuration values from parent page' do
|
57
|
+
|
58
|
+
should 'extract version and app path from parent page' do
|
59
|
+
raw_html = File.open(File.expand_path('test/fixtures/html/application_root.html')).read
|
60
|
+
assert_nothing_raised do
|
61
|
+
version, application, js, css = @loader.determine_configuration_values_from_html raw_html
|
62
|
+
|
63
|
+
|
64
|
+
assert !version.nil?
|
65
|
+
assert !application.nil?
|
66
|
+
assert !js.nil?
|
67
|
+
assert !css.nil?
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
should 'throw a configuration error if the parent pages js values can\'t be read correctly' do
|
72
|
+
raw_html = File.open(File.expand_path('test/fixtures/html/application_root_js_error.html')).read
|
73
|
+
assert_raises TerrImporter::ConfigurationError do
|
74
|
+
@loader.determine_configuration_values_from_html raw_html
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
should 'throw a configuration error if the parent pages css values can\'t be read correctly' do
|
79
|
+
raw_html = File.open(File.expand_path('test/fixtures/html/application_root_css_error.html')).read
|
80
|
+
assert_raises TerrImporter::ConfigurationError do
|
81
|
+
@loader.determine_configuration_values_from_html raw_html
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
@@ -6,6 +6,7 @@ class DownloaderTest < Test::Unit::TestCase
|
|
6
6
|
@base_uri = 'http://terrific.url'
|
7
7
|
@downloader = TerrImporter::Application::Downloader.new @base_uri
|
8
8
|
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic/dynlib.js", :body => File.expand_path('test/fixtures/js/dynlib.js'), :content_type => 'text/plain')
|
9
|
+
FakeWeb.register_uri(:get, "http://terrific.url/js/plugins/dynamic/dynplugin.js", :body => File.expand_path('test/fixtures/js/dynplugin.js'), :content_type => 'text/plain')
|
9
10
|
FakeWeb.register_uri(:get, "http://terrific.url/img", :body => File.expand_path('test/fixtures/html/img_dir.html'), :content_type => 'text/html')
|
10
11
|
FakeWeb.register_uri(:get, "http://terrific.url/img/", :body => File.expand_path('test/fixtures/html/img_dir.html'), :content_type => 'text/html')
|
11
12
|
FakeWeb.register_uri(:get, "http://terrific.url/img", :body => File.expand_path('test/fixtures/html/img_dir.html'), :content_type => 'text/html')
|
@@ -35,17 +36,28 @@ class DownloaderTest < Test::Unit::TestCase
|
|
35
36
|
|
36
37
|
end
|
37
38
|
|
38
|
-
should 'download a remote
|
39
|
+
should 'download a remote path to string' do
|
39
40
|
result = @downloader.download 'js/libraries/dynamic/dynlib.js'
|
40
41
|
assert result.include?('This file represents a dynamic js library'), "result wrong, contains #{result.to_s}"
|
41
42
|
end
|
42
43
|
|
44
|
+
should 'download a remote uri to string' do
|
45
|
+
result = @downloader.download_to_buffer URI('http://terrific.url/js/libraries/dynamic/dynlib.js')
|
46
|
+
assert result.include?('This file represents a dynamic js library'), "result wrong, contains #{result.to_s}"
|
47
|
+
end
|
48
|
+
|
43
49
|
should 'download a file to the tmp folder' do
|
44
50
|
@target_dir = File.expand_path('/tmp/dynlib.js')
|
45
51
|
@downloader.download @base_uri + '/js/libraries/dynamic/dynlib.js', @target_dir
|
46
52
|
assert File.exists?(@target_dir), "File doesn't exist #{@target_dir}"
|
47
53
|
end
|
48
54
|
|
55
|
+
should 'download a file to the tmp folder' do
|
56
|
+
@target_dir = File.expand_path('/tmp/dynlib.js')
|
57
|
+
@downloader.download_to_file URI(@base_uri + '/js/libraries/dynamic/dynlib.js'), @target_dir
|
58
|
+
assert File.exists?(@target_dir), "File doesn't exist #{@target_dir}"
|
59
|
+
end
|
60
|
+
|
49
61
|
should 'raise DefaultError, raised by invalid url socket error' do
|
50
62
|
assert_raises TerrImporter::DefaultError do
|
51
63
|
@downloader = TerrImporter::Application::Downloader.new 'http://url.doesntex.ist'
|
@@ -88,11 +100,11 @@ class DownloaderTest < Test::Unit::TestCase
|
|
88
100
|
end
|
89
101
|
end
|
90
102
|
|
91
|
-
|
103
|
+
context 'file creation' do
|
92
104
|
|
93
105
|
should 'create a directory if it doesn\'t exist' do
|
94
106
|
directory = File.join(File.dirname(__FILE__), '..', 'tmp', 'test_mkdir')
|
95
|
-
created_or_exists = @downloader.
|
107
|
+
created_or_exists = @downloader.create_directory directory
|
96
108
|
assert File.directory? directory
|
97
109
|
assert created_or_exists
|
98
110
|
#cleanup
|
@@ -101,10 +113,9 @@ class DownloaderTest < Test::Unit::TestCase
|
|
101
113
|
|
102
114
|
should 'not create a directory if it exists, but report that it exists' do
|
103
115
|
directory = File.join(File.dirname(__FILE__), '..', 'tmp')
|
104
|
-
created_or_exists= @downloader.
|
116
|
+
created_or_exists= @downloader.create_directory directory
|
105
117
|
assert created_or_exists
|
106
118
|
end
|
107
119
|
|
108
120
|
end
|
109
|
-
|
110
121
|
end
|
data/test/unit/test_importer.rb
CHANGED
@@ -3,8 +3,9 @@ require "test_helper"
|
|
3
3
|
class TestImporter < Test::Unit::TestCase
|
4
4
|
def setup
|
5
5
|
create_tmp_test_directory
|
6
|
-
@importer = TerrImporter::Application::Importer.new({:config_file => test_config_file_path})
|
7
6
|
FakeWeb.register_uri(:get, "http://terrific.url", :body => File.expand_path('test/fixtures/html/application_root.html'), :content_type => 'text/plain')
|
7
|
+
|
8
|
+
@importer = TerrImporter::Application::Importer.new({:config_file => test_config_file_path})
|
8
9
|
FakeWeb.register_uri(:get, "http://terrific.url/", :body => File.expand_path('test/fixtures/html/application_root.html'), :content_type => 'text/plain')
|
9
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&debug=false&cache=false", :body => File.expand_path('test/fixtures/css/base.css'), :content_type => 'text/plain')
|
10
11
|
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')
|
@@ -20,6 +21,7 @@ class TestImporter < Test::Unit::TestCase
|
|
20
21
|
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic", :body => File.expand_path('test/fixtures/html/js_dyn_dir.html'), :content_type => 'text/html')
|
21
22
|
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic/", :body => File.expand_path('test/fixtures/html/js_dyn_dir.html'), :content_type => 'text/html')
|
22
23
|
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic/dynlib.js", :body => File.expand_path('test/fixtures/js/dynlib.js'), :content_type => 'text/plain')
|
24
|
+
FakeWeb.register_uri(:get, "http://terrific.url/js/plugins/dynamic/dynplugin.js", :body => File.expand_path('test/fixtures/js/dynplugin.js'), :content_type => 'text/plain')
|
23
25
|
FakeWeb.register_uri(:get, "http://terrific.url/js/libraries/dynamic/", :body => File.expand_path('test/fixtures/html/module.html'), :content_type => 'text/html')
|
24
26
|
FakeWeb.register_uri(:get, "http://terrific.url/terrific/module/details/moduleName/moduleTemplate//format/modulecontent", :body => File.expand_path('test/fixtures/html/modulecontent.html'), :content_type => 'text/html')
|
25
27
|
FakeWeb.register_uri(:get, "http://terrific.url/terrific/module/details/moduleName/moduleTemplate//format/module", :body => File.expand_path('test/fixtures/html/module.html'), :content_type => 'text/html')
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class StatisticTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@stat = Statistic.new
|
7
|
+
end
|
8
|
+
|
9
|
+
should 'add an entry to the statistic' do
|
10
|
+
@stat.add(:download, 1)
|
11
|
+
assert @stat.statistics[:download][:count] == 1
|
12
|
+
end
|
13
|
+
|
14
|
+
should 'update an entry in the statistics' do
|
15
|
+
@stat.add(:download, 1)
|
16
|
+
@stat.add(:download, 1)
|
17
|
+
assert @stat.statistics[:download][:count] == 2
|
18
|
+
end
|
19
|
+
|
20
|
+
should 'add a message to the statistic' do
|
21
|
+
@stat.add_message(:download, "Downloads")
|
22
|
+
end
|
23
|
+
|
24
|
+
should 'output the header' do
|
25
|
+
out = capture_stdout do
|
26
|
+
@stat.print_summary
|
27
|
+
end
|
28
|
+
assert out.string.include? 'SUMMARY'
|
29
|
+
end
|
30
|
+
|
31
|
+
should 'output the messages added' do
|
32
|
+
@stat.add_message(:download, "Downloads")
|
33
|
+
@stat.add(:download, 1)
|
34
|
+
@stat.add_message(:css, "CSS")
|
35
|
+
@stat.add(:css, 1)
|
36
|
+
|
37
|
+
out = capture_stdout do
|
38
|
+
@stat.print_summary
|
39
|
+
end
|
40
|
+
assert out.string.include? 'Downloads'
|
41
|
+
assert out.string.include? 'CSS'
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
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:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 7
|
9
|
-
-
|
10
|
-
version: 0.7.
|
9
|
+
- 4
|
10
|
+
version: 0.7.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-09-
|
18
|
+
date: 2011-09-29 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: kwalify
|
@@ -131,12 +131,16 @@ files:
|
|
131
131
|
- lib/terrimporter/array_monkeypatch.rb
|
132
132
|
- lib/terrimporter/configuration.rb
|
133
133
|
- lib/terrimporter/configuration_helper.rb
|
134
|
+
- lib/terrimporter/configuration_loader.rb
|
134
135
|
- lib/terrimporter/download_helper.rb
|
135
136
|
- lib/terrimporter/downloader.rb
|
137
|
+
- lib/terrimporter/error.rb
|
136
138
|
- lib/terrimporter/importer.rb
|
137
139
|
- lib/terrimporter/importer_helper.rb
|
138
140
|
- lib/terrimporter/options.rb
|
141
|
+
- lib/terrimporter/statistic.rb
|
139
142
|
- lib/terrimporter/string_monkeypatch.rb
|
143
|
+
- lib/terrimporter/stylesheet_importer.rb
|
140
144
|
- lib/terrimporter/version.rb
|
141
145
|
- public/javascripts/base.js
|
142
146
|
- public/stylesheets/base.css
|
@@ -157,17 +161,20 @@ files:
|
|
157
161
|
- test/fixtures/invalid.config.yml
|
158
162
|
- test/fixtures/js/base.js
|
159
163
|
- test/fixtures/js/dynlib.js
|
164
|
+
- test/fixtures/js/dynplugin.js
|
160
165
|
- test/fixtures/minimal.test.config.yml
|
161
166
|
- test/fixtures/test.config.yml
|
162
167
|
- test/test_helper.rb
|
163
168
|
- test/test_terrimporter.rb
|
164
169
|
- test/unit/test_app_logger.rb
|
165
170
|
- test/unit/test_arraymonkeypatch.rb
|
166
|
-
- test/unit/test_config_helper.rb
|
167
171
|
- test/unit/test_configuration.rb
|
172
|
+
- test/unit/test_configuration_helper.rb
|
173
|
+
- test/unit/test_configuration_loader.rb
|
168
174
|
- test/unit/test_downloader.rb
|
169
175
|
- test/unit/test_importer.rb
|
170
176
|
- test/unit/test_options.rb
|
177
|
+
- test/unit/test_statistics.rb
|
171
178
|
- test/unit/test_stringmonkeypatch.rb
|
172
179
|
- test/watch.rb
|
173
180
|
homepage: ""
|
@@ -221,16 +228,19 @@ test_files:
|
|
221
228
|
- test/fixtures/invalid.config.yml
|
222
229
|
- test/fixtures/js/base.js
|
223
230
|
- test/fixtures/js/dynlib.js
|
231
|
+
- test/fixtures/js/dynplugin.js
|
224
232
|
- test/fixtures/minimal.test.config.yml
|
225
233
|
- test/fixtures/test.config.yml
|
226
234
|
- test/test_helper.rb
|
227
235
|
- test/test_terrimporter.rb
|
228
236
|
- test/unit/test_app_logger.rb
|
229
237
|
- test/unit/test_arraymonkeypatch.rb
|
230
|
-
- test/unit/test_config_helper.rb
|
231
238
|
- test/unit/test_configuration.rb
|
239
|
+
- test/unit/test_configuration_helper.rb
|
240
|
+
- test/unit/test_configuration_loader.rb
|
232
241
|
- test/unit/test_downloader.rb
|
233
242
|
- test/unit/test_importer.rb
|
234
243
|
- test/unit/test_options.rb
|
244
|
+
- test/unit/test_statistics.rb
|
235
245
|
- test/unit/test_stringmonkeypatch.rb
|
236
246
|
- test/watch.rb
|