terrimporter 0.4.0 → 0.5.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.
Files changed (51) hide show
  1. data/.gitignore +1 -0
  2. data/Gemfile.lock +6 -9
  3. data/Rakefile +69 -0
  4. data/bin/terrimporter +5 -1
  5. data/config/schema.yml +0 -3
  6. data/config/terrimporter.config.yml +4 -7
  7. data/lib/{app_logger.rb → terrimporter/app_logger.rb} +0 -0
  8. data/lib/terrimporter/config_helper.rb +46 -0
  9. data/lib/{config_validator.rb → terrimporter/config_validator.rb} +0 -0
  10. data/lib/terrimporter/configuration.rb +72 -0
  11. data/lib/terrimporter/downloader.rb +38 -0
  12. data/lib/terrimporter/importer.rb +185 -0
  13. data/lib/{options.rb → terrimporter/options.rb} +16 -8
  14. data/lib/terrimporter/version.rb +3 -2
  15. data/lib/terrimporter.rb +30 -26
  16. data/tasks/load_tasks.rb +3 -0
  17. data/tasks/version.rake +2 -0
  18. data/terrimporter.gemspec +7 -4
  19. data/test/fixtures/css/base.css +1 -0
  20. data/test/fixtures/css/ie.css +1 -0
  21. data/test/fixtures/html/img_backgrounds_dir.html +43 -0
  22. data/test/fixtures/html/img_dir.html +67 -0
  23. data/test/fixtures/html/js_dyn_dir.html +44 -0
  24. data/test/fixtures/img/background.jpg +0 -0
  25. data/test/fixtures/img/testimage.png +0 -0
  26. data/test/fixtures/invalid.config.yml +27 -0
  27. data/test/fixtures/js/base.js +1 -0
  28. data/test/fixtures/js/dynlib.js +1 -0
  29. data/test/fixtures/test.config.yml +64 -0
  30. data/test/helper.rb +0 -19
  31. data/test/terrimporter.config.yml +68 -0
  32. data/test/test/tmp/public/javascripts/base.js +1 -0
  33. data/test/test/tmp/public/javascripts/lib/dynlib.js +1 -0
  34. data/test/test/tmp/public/stylesheets/base.css +1 -0
  35. data/test/test/tmp/public/stylesheets/ie.css +1 -0
  36. data/test/test_helper.rb +47 -0
  37. data/test/test_terrimporter.rb +66 -4
  38. data/test/unit/test_app_logger.rb +51 -0
  39. data/test/unit/test_config_helper.rb +33 -0
  40. data/test/unit/test_config_validator.rb +20 -0
  41. data/test/unit/test_configuration.rb +30 -26
  42. data/test/unit/test_downloader.rb +38 -0
  43. data/test/unit/test_importer.rb +159 -23
  44. data/test/unit/test_options.rb +45 -7
  45. metadata +80 -24
  46. data/lib/configuration.rb +0 -93
  47. data/lib/importer.rb +0 -190
  48. data/public/javascripts/base.js +0 -0
  49. data/public/javascripts/pngfix.js +0 -0
  50. data/public/javascripts/warning.js +0 -0
  51. data/test/unit/test_terrimporter.rb +0 -23
data/lib/terrimporter.rb CHANGED
@@ -1,51 +1,55 @@
1
1
  require 'shellwords'
2
- require 'options'
3
- require 'importer'
2
+ require 'terrimporter/version'
3
+ require 'terrimporter/app_logger'
4
+ require 'terrimporter/options'
5
+ require 'terrimporter/importer'
6
+ require 'terrimporter/config_helper'
7
+ require 'terrimporter/config_validator'
8
+ require 'terrimporter/configuration'
9
+ require 'terrimporter/downloader'
4
10
 
5
11
  module TerrImporter
6
12
  class Application
7
13
  class << self
8
14
  include Shellwords
15
+ include ConfigHelper
9
16
 
10
17
  def run!(*arguments)
11
18
  options = build_options(arguments)
12
19
 
13
- if options[:init]
14
- #todo the config path can be differen in importer, extract to special class for loading and managing
15
- #todo raise error instead of puts and exit
16
- if File.exists?(File.join(Dir.pwd, CONFIG_DEFAULT_NAME))
17
- puts "Configuration already existing, use the force option to override"
18
- return 1
20
+ begin
21
+ unless options[:init].nil?
22
+ if config_working_directory_exists? and options[:init] != :backup and options[:init] != :replace
23
+ raise TerrImporter::ConfigurationError, "Configuration already exists, use the override or backup option"
24
+ end
25
+ create_config_file
26
+ return 0
19
27
  end
20
- create_config
21
- return 0
22
- end
23
28
 
24
- if options[:invalid_argument]
25
- $stderr.puts options[:invalid_argument]
26
- options[:show_help] = true
27
- end
29
+ if options[:invalid_argument]
30
+ $stderr.puts options[:invalid_argument]
31
+ options[:show_help] = true
32
+ end
28
33
 
29
- if options[:show_help]
30
- $stderr.puts options.opts
31
- return 1
32
- end
34
+ if options[:show_help]
35
+ $stderr.puts options.opts
36
+ return 1
37
+ end
33
38
 
34
- #if options[:input_file].nil?
35
- # $stderr.puts options.opts
36
- # return 1
37
- #end
39
+ if options[:show_version]
40
+ puts TerrImporter::VERSION
41
+ return 0
42
+ end
38
43
 
39
- begin
40
- importer = TerrImporter::Importer.new(options)
44
+ importer = TerrImporter::Application::Importer.new(options)
41
45
  importer.run
42
46
  return 0
43
47
  rescue TerrImporter::ConfigurationError
44
48
  $stderr.puts %Q{Configuration Error #{ $!.message }}
49
+ return 1
45
50
  rescue TerrImporter::DefaultError
46
51
  $stderr.puts %Q{Unspecified Error #{ $!.message }}
47
52
  return 1
48
-
49
53
  end
50
54
  end
51
55
 
@@ -0,0 +1,3 @@
1
+ require 'rake'
2
+
3
+ Dir["#{File.dirname(__FILE__)}/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,2 @@
1
+
2
+
data/terrimporter.gemspec CHANGED
@@ -4,7 +4,7 @@ require "terrimporter/version"
4
4
 
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "terrimporter"
7
- s.version = Terrimporter::VERSION
7
+ s.version = TerrImporter::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Daniel Kummer"]
10
10
  s.email = ["daniel.kummer@gmail.com"]
@@ -17,13 +17,16 @@ Gem::Specification.new do |s|
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
20
+ s.require_paths = ["lib", "tasks"]
21
21
 
22
- s.add_dependency "kwalify"
22
+ s.default_executable = 'bin/terrimporter'
23
+
24
+ s.add_dependency "kwalify", [">= 0.7.2"]
23
25
 
24
26
  s.add_development_dependency "shoulda", [">= 0"]
25
27
  s.add_development_dependency "bundler", ["~> 1.0.0"]
26
- s.add_development_dependency "jeweler", ["~> 1.6.4"]
28
+ s.add_development_dependency "rake", [">= 0"]
27
29
  s.add_development_dependency "rcov", [">= 0"]
30
+ s.add_development_dependency "fakeweb"
28
31
 
29
32
  end
@@ -0,0 +1 @@
1
+ This is the base.css file
@@ -0,0 +1 @@
1
+ This is the ie.css file
@@ -0,0 +1,43 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
+ <html>
3
+ <head>
4
+ <title>Index of /img/backgrounds</title>
5
+ </head>
6
+ <body>
7
+ <h1>Index of /img/backgrounds</h1>
8
+ <table>
9
+ <tr>
10
+ <th><img src="/icons/blank.gif" alt="[ICO]"></th>
11
+ <th><a href="?C=N;O=D">Name</a></th>
12
+ <th><a href="?C=M;O=A">Last modified</a></th>
13
+ <th><a href="?C=S;O=A">Size</a></th>
14
+ <th><a href="?C=D;O=A">Description</a></th>
15
+ </tr>
16
+ <tr>
17
+ <th colspan="5">
18
+ <hr>
19
+ </th>
20
+ </tr>
21
+
22
+ <tr>
23
+ <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>
24
+ <td><a href="/img/">Parent Directory</a></td>
25
+ <td>&nbsp;</td>
26
+ <td align="right"> -</td>
27
+ <td>&nbsp;</td>
28
+ </tr>
29
+ <tr>
30
+ <td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td>
31
+ <td><a href="background.jpg">background.jpg</a></td>
32
+ <td align="right">16-Aug-2011 13:17</td>
33
+ <td align="right"> 71K</td>
34
+ <td>&nbsp;</td>
35
+ </tr>
36
+ <tr>
37
+ <th colspan="5">
38
+ <hr>
39
+ </th>
40
+ </tr>
41
+ </table>
42
+ </body>
43
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
+ <html>
3
+ <head>
4
+ <title>Index of /img</title>
5
+ </head>
6
+ <body>
7
+ <h1>Index of /img</h1>
8
+ <table>
9
+ <tr>
10
+ <th><img src="/icons/blank.gif" alt="[ICO]"></th>
11
+ <th><a href="?C=N;O=D">Name</a></th>
12
+ <th><a href="?C=M;O=A">Last modified</a></th>
13
+ <th><a href="?C=S;O=A">Size</a></th>
14
+ <th><a href="?C=D;O=A">Description</a></th>
15
+ </tr>
16
+ <tr>
17
+ <th colspan="5">
18
+ <hr>
19
+ </th>
20
+ </tr>
21
+
22
+ <tr>
23
+ <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>
24
+ <td><a href="/">Parent Directory</a></td>
25
+ <td>&nbsp;</td>
26
+ <td align="right"> -</td>
27
+ <td>&nbsp;</td>
28
+ </tr>
29
+
30
+ <tr>
31
+ <td valign="top"><img src="/icons/folder.gif" alt="[DIR]"></td>
32
+ <td><a href="backgrounds/">backgrounds/</a></td>
33
+ <td align="right">16-Aug-2011 13:17</td>
34
+ <td align="right"> -</td>
35
+ <td>&nbsp;</td>
36
+ </tr>
37
+
38
+ <tr>
39
+ <td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td>
40
+ <td><a href="testimage1.png">testimage1.png</a></td>
41
+ <td align="right">16-Aug-2011 13:17</td>
42
+ <td align="right">412</td>
43
+ <td>&nbsp;</td>
44
+ </tr>
45
+ <tr>
46
+ <td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td>
47
+ <td><a href="testimage2.png">testimage2.png</a></td>
48
+ <td align="right">16-Aug-2011 13:17</td>
49
+ <td align="right"> 22K</td>
50
+ <td>&nbsp;</td>
51
+ </tr>
52
+ <tr>
53
+ <td valign="top"><img src="/icons/image2.gif" alt="[IMG]"></td>
54
+ <td><a href="testimage3.png">testimage3.png</a></td>
55
+ <td align="right">16-Aug-2011 13:17</td>
56
+ <td align="right"> 18K</td>
57
+ <td>&nbsp;</td>
58
+ </tr>
59
+
60
+ <tr>
61
+ <th colspan="5">
62
+ <hr>
63
+ </th>
64
+ </tr>
65
+ </table>
66
+ </body>
67
+ </html>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
2
+ <html>
3
+ <head>
4
+ <title>Index of /js/libraries/dynamic</title>
5
+ </head>
6
+ <body>
7
+ <h1>Index of /js/libraries/dynamic</h1>
8
+ <table>
9
+ <tr>
10
+ <th><img src="/icons/blank.gif" alt="[ICO]"></th>
11
+ <th><a href="?C=N;O=D">Name</a></th>
12
+ <th><a href="?C=M;O=A">Last modified</a></th>
13
+ <th><a href="?C=S;O=A">Size</a></th>
14
+ <th><a href="?C=D;O=A">Description</a></th>
15
+ </tr>
16
+ <tr>
17
+ <th colspan="5">
18
+ <hr>
19
+ </th>
20
+ </tr>
21
+
22
+ <tr>
23
+ <td valign="top"><img src="/icons/back.gif" alt="[DIR]"></td>
24
+ <td><a href="/js/libraries/">Parent Directory</a></td>
25
+ <td>&nbsp;</td>
26
+ <td align="right"> -</td>
27
+ <td>&nbsp;</td>
28
+ </tr>
29
+ <tr>
30
+ <td valign="top"><img src="/icons/unknown.gif" alt="[ ]"></td>
31
+ <td><a href="dynlib.js">dynlib.js</a></td>
32
+ <td align="right">16-Aug-2011 13:17</td>
33
+ <td align="right">1.5K</td>
34
+ <td>&nbsp;</td>
35
+ </tr>
36
+ <tr>
37
+ <th colspan="5">
38
+ <hr>
39
+ </th>
40
+ </tr>
41
+ </table>
42
+
43
+ </body>
44
+ </html>
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ version:
2
+ url: http://terrific.url
3
+ app_path: /terrific/webapp/path
4
+ export_path: /terrific/base/%2$s/public/%1$s/base/base.%1$s.php
5
+ libraries_source_path: /js/libraries/dynamic
6
+ image_base_path: /img
7
+ export_settings:
8
+ layout: project
9
+ debug: false
10
+ cache: false
11
+ stylesheets:
12
+ dest: test/tmp/public/stylesheets/
13
+ styles: ie.css
14
+ replace:
15
+ - what: /img/
16
+ with: /images/
17
+ javascripts:
18
+ dest: test/tmp/public/javascripts/
19
+ dynamic_libraries: dynlib.js
20
+ libraries_dest: /lib
21
+ images:
22
+ - src: /
23
+ dest: test/tmp/public/images/
24
+ types: jpg png gif
25
+ - src: /backgrounds
26
+ dest: test/tmp/public/images/backgrounds/
27
+ types: jpg
@@ -0,0 +1 @@
1
+ This is the base.js file
@@ -0,0 +1 @@
1
+ This file represents a dynamic js library.
@@ -0,0 +1,64 @@
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
+ export_settings:
45
+ layout: project
46
+ debug: false
47
+ cache: false
48
+ stylesheets:
49
+ dest: test/tmp/public/stylesheets/
50
+ styles: ie
51
+ replace:
52
+ - what: /img/
53
+ with: /images/
54
+ javascripts:
55
+ dest: test/tmp/public/javascripts/
56
+ dynamic_libraries: dynlib
57
+ libraries_dest: /lib
58
+ images:
59
+ - src: /
60
+ dest: test/tmp/public/images/
61
+ types: jpg png gif
62
+ - src: /backgrounds
63
+ dest: test/tmp/public/images/backgrounds/
64
+ types: jpg
data/test/helper.rb CHANGED
@@ -1,19 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- begin
4
- Bundler.setup(:default, :development)
5
- rescue Bundler::BundlerError => e
6
- $stderr.puts e.message
7
- $stderr.puts "Run `bundle install` to install missing gems"
8
- exit e.status_code
9
- end
10
- require 'test/unit'
11
- require 'shoulda'
12
-
13
-
14
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
- $LOAD_PATH.unshift(File.dirname(__FILE__))
16
- require 'terrimporter'
17
-
18
- class Test::Unit::TestCase
19
- end
@@ -0,0 +1,68 @@
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
@@ -0,0 +1 @@
1
+ /Users/dkummer/_projects/terrimporter/test/test/fixtures/js/base.js
@@ -0,0 +1 @@
1
+ /Users/dkummer/_projects/terrimporter/test/test/fixtures/js/dynlib.js
@@ -0,0 +1 @@
1
+ /Users/dkummer/_projects/terrimporter/test/test/fixtures/css/base.css
@@ -0,0 +1 @@
1
+ /Users/dkummer/_projects/terrimporter/test/test/fixtures/css/ie.css
@@ -0,0 +1,47 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'fake_web'
13
+
14
+
15
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
16
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib', 'terrimporter'))
17
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
18
+ require 'terrimporter'
19
+
20
+ class Test::Unit::TestCase
21
+ def schema_file_path
22
+ File.join(File.dirname(__FILE__), '..', 'config', schema_default_name)
23
+ end
24
+
25
+ def invalid_test_config_file_path
26
+ File.join(File.dirname(__FILE__), 'fixtures', 'invalid.config.yml')
27
+ end
28
+
29
+ def test_config_file_path
30
+ File.join(File.dirname(__FILE__), 'fixtures', 'test.config.yml')
31
+ end
32
+
33
+ def tmp_test_directory
34
+ File.join(File.dirname(__FILE__), 'tmp')
35
+ end
36
+
37
+ def create_tmp_test_directory
38
+ FileUtils.mkdir tmp_test_directory unless File.exists? tmp_test_directory
39
+ end
40
+
41
+ def delete_tmp_test_directory
42
+ FileUtils.rm_rf tmp_test_directory
43
+ end
44
+
45
+
46
+
47
+ end
@@ -1,8 +1,70 @@
1
- require 'helper'
1
+ require 'test_helper'
2
2
 
3
3
  class TestTerrimporter < Test::Unit::TestCase
4
- should "probably rename this file and start testing for real" do
5
- #flunk "hey buddy, you should probably rename this file and start testing for real"
6
- assert true
4
+ include ConfigHelper
5
+
6
+ def setup
7
+ ENV['TERRIMPORTER_OPTS'] = nil
8
+ end
9
+
10
+ def teardown
11
+ File.delete config_file if File.exists? config_file
12
+ end
13
+
14
+ should 'build options as a combination form argument options and environment options' do
15
+ ENV['TERRIMPORTER_OPTS'] = "-j"
16
+ arguments = ["testfile", '-c']
17
+ merged_options = TerrImporter::Application.build_options(arguments)
18
+ assert merged_options.include?(:import_js)
19
+ assert merged_options.include?(:import_css)
20
+ end
21
+
22
+ should 'merge environment and argument options' do
23
+ ENV['TERRIMPORTER_OPTS'] = '-j -c'
24
+ merged_options = TerrImporter::Application.build_options([''] + ['-i', '--verbose'])
25
+ expected_options = {:import_css => true,
26
+ :import_js => true,
27
+ :import_images => true,
28
+ :show_help => false,
29
+ :verbose => true}
30
+
31
+ assert_contains merged_options, expected_options
32
+ end
33
+
34
+
35
+ should 'run the importer with the init command and a non existing configuration file' do
36
+ TerrImporter::Application.run!(["test"], '--init')
37
+ assert File.exists? config_file
38
+ end
39
+
40
+ should 'run the importer with the init command and a non existing configuration file' do
41
+ TerrImporter::Application.run!(["test"], '--init replace')
42
+ assert File.exists? config_file
43
+ end
44
+
45
+ should 'run the importer with the init command and a non existing configuration file' do
46
+ TerrImporter::Application.run!(["test"], '--init','backup')
47
+ assert File.exists? config_file
48
+ end
49
+
50
+ should 'run the importer with the init command and an existing configuration file, this leads to an error' do
51
+ TerrImporter::Application.run!(["test"], '--init')
52
+ return_code = TerrImporter::Application.run!(["test"], '--init')
53
+ assert return_code == 1
54
+ end
55
+
56
+ should 'run the importer with an invalid argument, display help and return error code' do
57
+ return_code = TerrImporter::Application.run!(["test"], '--invalid')
58
+ assert return_code == 1
59
+ end
60
+
61
+ should 'run the importer show help argument, display help and return error code' do
62
+ return_code = TerrImporter::Application.run!(["test"], '--help')
63
+ assert return_code == 1
7
64
  end
65
+
66
+ def config_file
67
+ File.join(File.dirname(__FILE__), '..', config_default_name)
68
+ end
69
+
8
70
  end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+
4
+ class LoggingTest < Test::Unit::TestCase
5
+ include Logging
6
+
7
+ def wrapped_log(message)
8
+ original_stdout = $stdout
9
+ original_stderr = $stderr
10
+
11
+ fake_stdout = StringIO.new
12
+ fake_stderr = StringIO.new
13
+
14
+ $stdout = fake_stdout
15
+ $stderr = fake_stderr
16
+
17
+ begin
18
+ log message
19
+ ensure
20
+ $stdout = original_stdout
21
+ $stderr = original_stderr
22
+ end
23
+
24
+ @stdout = fake_stdout.string
25
+ @stderr = fake_stderr.string
26
+
27
+ end
28
+
29
+ context "supported logging operations" do
30
+ should "log info to stdout" do
31
+ wrapped_log :info => "hello world"
32
+ assert @stdout.grep(/INFO.*hello world/)
33
+ end
34
+
35
+ should "log debug to stdout" do
36
+ wrapped_log :debug => "hello world"
37
+ assert @stdout.grep(/DEBUG.*hello world/)
38
+ end
39
+
40
+ should "log error to stdout" do
41
+ wrapped_log :error => "hello world"
42
+ assert @stdout.grep(/ERROR.*hello world/)
43
+ end
44
+ end
45
+
46
+ should "not log anything unsupported" do
47
+ wrapped_log :not_supported => "hello world"
48
+ assert @stdout.strip.empty?
49
+ end
50
+
51
+ end