roger 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +4 -1
  4. data/CHANGELOG.md +7 -0
  5. data/Gemfile +2 -0
  6. data/Rakefile +2 -2
  7. data/lib/roger/release/cleaner.rb +1 -1
  8. data/lib/roger/release/processors/url_relativizer.rb +8 -7
  9. data/lib/roger/release/scm/fixed.rb +22 -0
  10. data/lib/roger/release/scm.rb +1 -0
  11. data/lib/roger/release.rb +3 -1
  12. data/lib/roger/testing/mock_project.rb +43 -0
  13. data/lib/roger/testing/mock_release.rb +39 -0
  14. data/lib/roger/version.rb +1 -1
  15. data/roger.gemspec +3 -1
  16. data/test/unit/cli/cli_base_test.rb +2 -2
  17. data/test/unit/cli/cli_generate_test.rb +2 -2
  18. data/test/unit/cli/cli_serve_test.rb +2 -2
  19. data/test/unit/cli/cli_test_test.rb +2 -2
  20. data/test/unit/cli/cli_version_test.rb +2 -2
  21. data/test/unit/generators_test.rb +4 -1
  22. data/test/unit/helpers/logging_test.rb +46 -44
  23. data/test/unit/rack/roger_test.rb +1 -1
  24. data/test/unit/release/cleaner_test.rb +50 -53
  25. data/test/unit/release/finalizers/git_branch_test.rb +31 -43
  26. data/test/unit/release/finalizers/zip_test.rb +21 -38
  27. data/test/unit/release/processors/mockup_test.rb +61 -0
  28. data/test/unit/release/processors/url_relativizer_test.rb +35 -0
  29. data/test/unit/release/processors_test.rb +41 -33
  30. data/test/unit/release/scm/fixed_test.rb +29 -0
  31. data/test/unit/release_test.rb +1 -1
  32. data/test/unit/resolver_test.rb +1 -1
  33. data/test/unit/server_test.rb +1 -1
  34. data/test/unit/template_test.rb +1 -1
  35. data/test/unit/test_helper.rb +12 -0
  36. data/test/unit/test_test.rb +1 -2
  37. metadata +41 -4
  38. data/test/unit/release/mockup_test.rb +0 -57
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8734e7002c869383a206f45d200f686b6cf8177a
4
- data.tar.gz: d8e8a6f790efa7312086969786f98020682976d0
3
+ metadata.gz: 82428d41225658ef4f4a435a7eabb2e6de235b17
4
+ data.tar.gz: ee81c7a3c011d6eef41986e569de45dc5775fe1e
5
5
  SHA512:
6
- metadata.gz: 01910cc0b9f9f1a27a1fa205900c89d1cbb52a5a9924977d6b5bd38f68092dce201d7da46367329bc07df25ed4a361eb9ef9949c9d9f3c35e3a5baa06fc7ecf0
7
- data.tar.gz: 8449f9c1f295f0d1da6b3e931925439235a086cfb0ea4db2a7dda09762cce56813c5f23ae78ad103c6fcceaeb6d386e16e7f5e2ae361dd2ca0135d528f17e275
6
+ metadata.gz: 6c45c703a4040c8dcf26312a95d98d2bd0a6b7ffba74267e3d5fc0540523d09e6afaa231b59ef2a536ac7ba15a6a06872bc0f6d1bade9cfda49b92eedd2c03ae
7
+ data.tar.gz: 00ab6343db81d1143885a632f1b805f3a10ae36ff685c2b10f52e529afa01ef35379ff672aaaada880ca4311a95289e68386ab1bfaad466562e2730f4434ac54
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg/*
2
2
  Gemfile.lock
3
+ coverage
data/.travis.yml CHANGED
@@ -8,4 +8,7 @@ before_script:
8
8
  - git config --global user.email "travis-ci@digitpaint.nl"
9
9
  - git config --global user.name "Travis-CI"
10
10
  matrix:
11
- fast_finish: true
11
+ fast_finish: true
12
+ env:
13
+ global:
14
+ secure: eMPdp74VWvC6r7CSzN06FEMf5Wq9AfxqIgjfr4Z4AMxUsehApSJe1y/blaqN6XcpLK4TYw4bwzRUjAzUjOMMW5aJ4Kr1nrW2k6bJehbubhkkPfDxcc+NzYUZ+oxqbPMOZP6zQoSRRd5rhY2qd3xVkKecK1KZOxlA1/pce6y15YU=
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 1.3.0
4
+ * Add fixed SCM for testing (you can set a fixed version number)
5
+ * Fix for missing variable in UrlRelativizer
6
+ * Add Mocks for Project and Release to use in testing (can also be used by external plugins)
7
+ * Refactoring of tests
8
+ * Add CodeClimate (https://codeclimate.com/github/DigitPaint/roger)
9
+
3
10
  ## Version 1.2.2
4
11
  * Fix missing variables in release
5
12
 
data/Gemfile CHANGED
@@ -3,3 +3,5 @@ source "https://rubygems.org"
3
3
  gemspec name: "roger"
4
4
 
5
5
  gem "rake"
6
+ # Only coverage support in CI, CODECLIMATE TOKEN is part of travis.yml
7
+ gem "codeclimate-test-reporter", group: :test, require: nil if ENV["CODECLIMATE_REPO_TOKEN"]
data/Rakefile CHANGED
@@ -9,7 +9,7 @@ task :rubocop do
9
9
  end
10
10
 
11
11
  Rake::TestTask.new do |t|
12
- t.libs << "test"
12
+ t.libs << "test/unit"
13
13
  t.test_files = FileList["test/unit/**/*_test.rb"]
14
- t.verbose = true
14
+ t.verbose = false
15
15
  end
@@ -46,7 +46,7 @@ module Roger
46
46
  return false
47
47
  end
48
48
 
49
- if path[build_path]
49
+ if path =~ /\A#{Regexp.escape(build_path)}/
50
50
  return true
51
51
  else
52
52
  fail "Cleaning pattern is not inside build directory"
@@ -18,11 +18,12 @@ module Roger::Release::Processors
18
18
  def call(release, options = {})
19
19
  options = {}.update(@options).update(options)
20
20
 
21
- log_call(options)
21
+ log_call(release, options)
22
22
 
23
23
  @resolver = Roger::Resolver.new(release.build_path)
24
24
 
25
25
  relativize_attributes_in_files(
26
+ release,
26
27
  options[:url_attributes],
27
28
  release.get_files(options[:match], options[:skip])
28
29
  )
@@ -30,29 +31,29 @@ module Roger::Release::Processors
30
31
 
31
32
  protected
32
33
 
33
- def log_call(options)
34
+ def log_call(release, options)
34
35
  log_message = "Relativizing all URLS in #{options[:match].inspect}"
35
36
  log_message << "files in attributes #{options[:url_attributes].inspect},"
36
37
  log_message << "skipping #{options[:skip].any? ? options[:skip].inspect : 'none' }"
37
38
  release.log(self, log_message)
38
39
  end
39
40
 
40
- def relativize_attributes_in_files(attributes, files)
41
+ def relativize_attributes_in_files(release, attributes, files)
41
42
  files.each do |file_path|
42
43
  release.debug(self, "Relativizing URLS in #{file_path}") do
43
- relativize_attributes_in_file(attributes, file_path)
44
+ relativize_attributes_in_file(release, attributes, file_path)
44
45
  end
45
46
  end
46
47
  end
47
48
 
48
- def relativize_attributes_in_file(attributes, file_path)
49
+ def relativize_attributes_in_file(release, attributes, file_path)
49
50
  orig_source = File.read(file_path)
50
51
  File.open(file_path, "w") do |f|
51
- f.write(relativize_attributes_in_source(attributes, orig_source, file_path))
52
+ f.write(relativize_attributes_in_source(release, attributes, orig_source, file_path))
52
53
  end
53
54
  end
54
55
 
55
- def relativize_attributes_in_source(attributes, source, file_path)
56
+ def relativize_attributes_in_source(release, attributes, source, file_path)
56
57
  doc = Hpricot(source)
57
58
  attributes.each do |attribute|
58
59
  (doc / "*[@#{attribute}]").each do |tag|
@@ -0,0 +1,22 @@
1
+ module Roger
2
+ class Release
3
+ module Scm
4
+ # The Fixed SCM implementation for Roger release
5
+ # Here you define everything in the config or set it later with the different accessors.
6
+ class Fixed < Base
7
+ attr_accessor :version, :date, :previous
8
+
9
+ # @option config [String] :version Version to use (default "0.0.0")
10
+ # @option config [Time] :date Date to use (default Time.now)
11
+ # @option config [String] :previous Previous version to use (default "0.0.0")
12
+ def initialize(config = {})
13
+ super(config)
14
+
15
+ self.version = config[:version] || "0.0.0"
16
+ self.date = config[:date] || Time.now
17
+ self.previous = config[:previous] || "0.0.0"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -33,3 +33,4 @@ module Roger
33
33
  end
34
34
 
35
35
  require File.dirname(__FILE__) + "/scm/git"
36
+ require File.dirname(__FILE__) + "/scm/fixed"
data/lib/roger/release.rb CHANGED
@@ -25,7 +25,7 @@ module Roger
25
25
  end
26
26
  end
27
27
 
28
- # @option config [Symbol] :scm The SCM to use (default = :git)
28
+ # @option config [:git, :fixed] :scm The SCM to use (default = :git)
29
29
  # @option config [String, Pathname] :target_path The path/directory to put the release into
30
30
  # @option config [String, Pathname]:build_path Temporary path used to build the release
31
31
  # @option config [Boolean] :cleanup_build Wether or not to remove the build_path after we're
@@ -84,6 +84,8 @@ module Roger
84
84
  case config[:scm]
85
85
  when :git
86
86
  @_scm = Release::Scm::Git.new(path: source_path)
87
+ when :fixed
88
+ @_scm = Release::Scm::Fixed.new
87
89
  else
88
90
  fail "Unknown SCM #{options[:scm].inspect}"
89
91
  end
@@ -0,0 +1,43 @@
1
+ require "test_construct"
2
+
3
+ module Roger
4
+ module Testing
5
+ # A Mock project. If initialized without a path it will
6
+ # create a test_construct with the following (empty) paths:
7
+ #
8
+ # - html
9
+ # - partials
10
+ # - layouts
11
+ # - releases
12
+ #
13
+ # Use MockProject in testing but never forget to call:
14
+ #
15
+ # MockProject#destroy
16
+ #
17
+ # in teardown otherwise you pollute your filesystem with build directories
18
+ class MockProject < Project
19
+ include TestConstruct::Helpers
20
+
21
+ attr_accessor :construct
22
+
23
+ def initialize(path = nil, config = {})
24
+ unless path
25
+ self.construct = setup_construct
26
+ path = construct
27
+
28
+ %w(html partials layouts releases).each do |dir|
29
+ construct.directory dir
30
+ end
31
+ end
32
+
33
+ # Call super to initialize
34
+ super(path, config)
35
+ end
36
+
37
+ # Destroy will remove all files/directories
38
+ def destroy
39
+ teardown_construct(construct) if construct
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + "/mock_project"
2
+
3
+ module Roger
4
+ module Testing
5
+ # Creates a mock release object. It is the same as a regular release
6
+ # with the following "presets"
7
+ #
8
+ # - it will automatically use the :fixed SCM
9
+ # - it will automatically initialize a MockProject if you don't
10
+ # pass a project to the initializer
11
+ #
12
+ # Use MockRelease in testing but never forget to call:
13
+ #
14
+ # MockRelease#destroy
15
+ #
16
+ # in teardown otherwise you pollute your filesystem with build directories
17
+ #
18
+ class MockRelease < Release
19
+ def initialize(project = nil, config = {})
20
+ config = {
21
+ scm: :fixed
22
+ }.update(config)
23
+
24
+ unless project
25
+ # Create a mock project that's completely empty
26
+ project = MockProject.new
27
+ end
28
+
29
+ # Call super to initialize
30
+ super(project, config)
31
+ end
32
+
33
+ # Destroy will remove all files/directories
34
+ def destroy
35
+ project.destroy if project.is_a?(MockProject)
36
+ end
37
+ end
38
+ end
39
+ end
data/lib/roger/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  # Roger main namespace
2
2
  module Roger
3
- VERSION = "1.2.2"
3
+ VERSION = "1.3.0"
4
4
  end
data/roger.gemspec CHANGED
@@ -39,6 +39,8 @@ Gem::Specification.new do |s|
39
39
 
40
40
  s.add_development_dependency("test-unit", "~> 3.0.0")
41
41
  s.add_development_dependency("mocha", "~> 1.1.0")
42
+ s.add_development_dependency("simplecov", "~> 0.10.0")
42
43
  s.add_development_dependency("puma", "~> 2.10.0")
43
- s.add_development_dependency "rubocop", "~> 0.31.0"
44
+ s.add_development_dependency("rubocop", "~> 0.31.0")
45
+ s.add_development_dependency("test_construct", "~> 2.0")
44
46
  end
@@ -1,5 +1,5 @@
1
- require "./lib/roger/cli.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
3
 
4
4
  module Roger
5
5
  # Test for roger base commands
@@ -1,5 +1,5 @@
1
- require "./lib/roger/cli.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
@@ -1,5 +1,5 @@
1
- require "./lib/roger/cli.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
@@ -1,5 +1,5 @@
1
- require "./lib/roger/cli.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
@@ -1,5 +1,5 @@
1
- require "./lib/roger/cli.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/cli"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
@@ -1,6 +1,6 @@
1
1
  # Generators register themself on the CLI module
2
+ require "test_helper"
2
3
  require "./lib/roger/generators.rb"
3
- require "test/unit"
4
4
 
5
5
  module CustomGens
6
6
  module Generators
@@ -72,6 +72,9 @@ module Roger
72
72
  path = "./tmp"
73
73
  generators.invoke :generator, [name, path]
74
74
  assert File.exist? "#{path}/#{name}_generator.rb"
75
+
76
+ # Remove generated generator
77
+ File.unlink "#{path}/#{name}_generator.rb"
75
78
  end
76
79
 
77
80
  def test_invoke_mocked_generator
@@ -1,64 +1,66 @@
1
+ require "test_helper"
1
2
  require "./lib/roger/helpers/logging"
2
- require "test/unit"
3
- require File.dirname(__FILE__) + "/../../helpers/cli"
4
3
 
5
4
  # Empty logging class
5
+ # This is outside of the Roger namespace by design.
6
6
  class MyLogger
7
7
  include Roger::Helpers::Logging
8
8
 
9
9
  attr_accessor :project
10
10
  end
11
11
 
12
- # Test Logging module
13
- class LoggingTest < ::Test::Unit::TestCase
14
- include Roger::TestCli
12
+ module Roger
13
+ # Test Logging module
14
+ class LoggingTest < ::Test::Unit::TestCase
15
+ include Roger::TestCli
15
16
 
16
- def setup
17
- @logger = MyLogger.new
18
- @logger.project = stub(
19
- options: {},
20
- shell: Thor::Shell::Color.new
21
- )
22
- end
17
+ def setup
18
+ @logger = MyLogger.new
19
+ @logger.project = stub(
20
+ options: {},
21
+ shell: Thor::Shell::Color.new
22
+ )
23
+ end
23
24
 
24
- def test_log
25
- out, _err = capture { @logger.log(@logger, "log") }
26
- assert out.include?("MyLogger")
27
- assert out.include?("log")
28
- end
25
+ def test_log
26
+ out, _err = capture { @logger.log(@logger, "log") }
27
+ assert out.include?("MyLogger")
28
+ assert out.include?("log")
29
+ end
29
30
 
30
- def test_log_with_string_part
31
- out, _err = capture { @logger.log("string_test", "log") }
32
- assert out.include?("string_test")
33
- assert out.include?("log")
34
- end
31
+ def test_log_with_string_part
32
+ out, _err = capture { @logger.log("string_test", "log") }
33
+ assert out.include?("string_test")
34
+ assert out.include?("log")
35
+ end
35
36
 
36
- def test_log_with_block
37
- out, _err = capture do
38
- @logger.log(@logger, "log") do
39
- @logger.log(@logger, "indent")
37
+ def test_log_with_block
38
+ out, _err = capture do
39
+ @logger.log(@logger, "log") do
40
+ @logger.log(@logger, "indent")
41
+ end
40
42
  end
41
- end
42
43
 
43
- assert out.include?("MyLogger")
44
- assert out.include?("log")
45
- assert out.include?(" MyLogger : indent"), out
46
- end
44
+ assert out.include?("MyLogger")
45
+ assert out.include?("log")
46
+ assert out.include?(" MyLogger : indent"), out
47
+ end
47
48
 
48
- def test_debug
49
- out, _err = capture { @logger.debug(@logger, "debug") }
50
- assert_equal out, ""
49
+ def test_debug
50
+ out, _err = capture { @logger.debug(@logger, "debug") }
51
+ assert_equal out, ""
51
52
 
52
- @logger.project.options[:verbose] = true
53
- out, _err = capture { @logger.debug(@logger, "debug") }
54
- assert out.include?("MyLogger")
55
- assert out.include?("debug")
56
- end
53
+ @logger.project.options[:verbose] = true
54
+ out, _err = capture { @logger.debug(@logger, "debug") }
55
+ assert out.include?("MyLogger")
56
+ assert out.include?("debug")
57
+ end
57
58
 
58
- # TODO: test if color is outputted as well.
59
- def test_warn
60
- out, _err = capture { @logger.warn(@logger, "warn") }
61
- assert out.include?("MyLogger")
62
- assert out.include?("warn")
59
+ # TODO: test if color is outputted as well.
60
+ def test_warn
61
+ out, _err = capture { @logger.warn(@logger, "warn") }
62
+ assert out.include?("MyLogger")
63
+ assert out.include?("warn")
64
+ end
63
65
  end
64
66
  end
@@ -1,4 +1,4 @@
1
- require "test/unit"
1
+ require "test_helper"
2
2
  require File.dirname(__FILE__) + "../../../../lib/roger/rack/roger"
3
3
 
4
4
  module Roger
@@ -1,72 +1,69 @@
1
- require "./lib/roger/release.rb"
2
- require "./lib/roger/release/cleaner.rb"
3
- require "test/unit"
4
-
5
- # Test Roger Cleaner
6
- class CleanerTest < ::Test::Unit::TestCase
7
- def setup
8
- @base = File.dirname(__FILE__) + "/../../project"
9
- end
1
+ require "test_helper"
2
+ require "roger/testing/mock_release"
3
+
4
+ module Roger
5
+ # Test Roger Cleaner
6
+ class CleanerTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @release = Testing::MockRelease.new
9
+ end
10
10
 
11
- def test_use_array_as_pattern
12
- dirs = %w(dir1 dir2)
11
+ def teardown
12
+ @release.destroy
13
+ @release = nil
14
+ end
13
15
 
14
- create_and_assert_directories(dirs)
16
+ def test_use_array_as_pattern
17
+ dirs = %w(dir1 dir2)
15
18
 
16
- project = Roger::Project.new(@base)
17
- release = Roger::Release.new(project, build_path: Pathname.new(@base))
19
+ dirs.each do |dir|
20
+ @release.project.construct.directory "build/#{dir}"
21
+ end
18
22
 
19
- cleaner = Roger::Release::Cleaner.new(dirs)
20
- cleaner.call(release)
23
+ cleaner = Roger::Release::Cleaner.new(dirs)
24
+ cleaner.call(@release)
21
25
 
22
- dirs.each do |dir|
23
- path = @base + "/" + dir
24
- assert(!File.directory?(path))
26
+ dirs.each do |dir|
27
+ path = @release.build_path + dir
28
+ assert(!File.directory?(path))
29
+ end
25
30
  end
26
- end
27
-
28
- def test_only_clean_inside_build_path_relative
29
- cleaner = Roger::Release::Cleaner.new(@base)
30
- inside_build_path = cleaner.send :inside_build_path?, @base, @base + "/html/formats"
31
31
 
32
- assert(inside_build_path, "Only delete content inside build_path")
33
- end
32
+ def test_only_clean_inside_build_path_relative
33
+ project_path = @release.project.path
34
+ cleaner = Roger::Release::Cleaner.new(project_path)
35
+ inside = cleaner.send :inside_build_path?, project_path, project_path + "html"
34
36
 
35
- def test_only_clean_inside_build_path_absolute
36
- path = Pathname.new(@base).realpath.to_s
37
- cleaner = Roger::Release::Cleaner.new(path)
38
-
39
- inside_build_path = cleaner.send :inside_build_path?, path, @base + "/html/formats"
37
+ assert(inside, "Only delete content inside build_path")
38
+ end
40
39
 
41
- assert(inside_build_path, "Only delete content inside build_path")
42
- end
40
+ def test_only_clean_inside_build_path_absolute
41
+ project_path = @release.project.path
42
+ path = Pathname.new(project_path).realpath.to_s
43
+ cleaner = Roger::Release::Cleaner.new(path)
43
44
 
44
- def test_dont_clean_outside_build_path
45
- path = File.dirname(__FILE__)
46
- cleaner = Roger::Release::Cleaner.new(path)
45
+ inside = cleaner.send :inside_build_path?, path, project_path + "html"
47
46
 
48
- assert_raise RuntimeError do
49
- cleaner.send :inside_build_path?, path, @base + "/html/formats"
47
+ assert(inside, "Only delete content inside build_path")
50
48
  end
51
- end
52
49
 
53
- def test_dont_fail_on_nonexistent_files
54
- path = "bla"
55
- cleaner = Roger::Release::Cleaner.new(path)
50
+ def test_dont_clean_outside_build_path
51
+ path = File.dirname(__FILE__)
52
+ cleaner = Roger::Release::Cleaner.new(path)
56
53
 
57
- assert(
58
- !cleaner.send(:inside_build_path?, @base + "/html/formats", path),
59
- "Failed on nonexistent directories/files"
60
- )
61
- end
54
+ assert_raise RuntimeError do
55
+ cleaner.send :inside_build_path?, path, @release.project.path + "html"
56
+ end
57
+ end
62
58
 
63
- protected
59
+ def test_dont_fail_on_nonexistent_files
60
+ path = "bla"
61
+ cleaner = Roger::Release::Cleaner.new(path)
64
62
 
65
- def create_and_assert_directories(dirs)
66
- dirs.each do |dir|
67
- path = @base + "/" + dir
68
- mkdir path unless File.directory?(path)
69
- assert(File.directory?(path))
63
+ assert(
64
+ !cleaner.send(:inside_build_path?, @release.project.path + "/html", path),
65
+ "Failed on nonexistent directories/files"
66
+ )
70
67
  end
71
68
  end
72
69
  end
@@ -1,52 +1,40 @@
1
- require "./lib/roger/release/finalizers/git_branch.rb"
2
- require "test/unit"
3
- require "mocha/test_unit"
4
- require "tmpdir"
5
-
6
- # Test for Roger GitBranchFinalizer
7
- class GitBranchTest < Test::Unit::TestCase
8
- def setup
9
- # Mock git repo
10
- @tmp_dir = Pathname.new(Dir.mktmpdir)
11
- mock_repo_path = @tmp_dir + "mock_repo"
12
- FileUtils.mkdir(mock_repo_path)
13
- Dir.chdir(mock_repo_path) do
14
- `git init`
15
- `mkdir releases`
16
- `touch releases/index.html`
17
- end
1
+ require "test_helper"
2
+ require "roger/testing/mock_release"
18
3
 
19
- # Mock release object
20
- @release_mock = stub(project: stub(path: mock_repo_path))
4
+ module Roger
5
+ # Test for Roger GitBranchFinalizer
6
+ class GitBranchTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @release = Testing::MockRelease.new
21
9
 
22
- @release_mock.stubs(
23
- scm: stub(version: "0.1.999"),
24
- log: true,
25
- build_path: mock_repo_path.to_s + "/releases"
26
- )
27
- end
10
+ # Create a file to release in the build dir
11
+ @release.project.construct.file "build/index.html"
28
12
 
29
- # called after every single test
30
- def teardown
31
- FileUtils.rm_rf(@tmp_dir)
32
- @release_mock = nil
33
- end
13
+ # Set fixed version
14
+ @release.scm.version = "1.0.0"
15
+ end
34
16
 
35
- def test_basic_functionality
36
- git_branch_finalizers = Roger::Release::Finalizers::GitBranch.new
17
+ def teardown
18
+ @release.destroy
19
+ @release = nil
20
+ end
37
21
 
38
- output_dir = git_branch_finalizers.call(
39
- @release_mock,
40
- remote: "http://we.aint.go/nna.push.git",
41
- push: false,
42
- cleanup: false
43
- )
22
+ def test_basic_functionality
23
+ git_branch_finalizers = Roger::Release::Finalizers::GitBranch.new
44
24
 
45
- Dir.chdir(output_dir + "clone") do
46
- commit_msg = `git log --pretty=oneline --abbrev-commit`
47
- assert_match(/Release 0.1.999/, commit_msg)
48
- end
25
+ output_dir = git_branch_finalizers.call(
26
+ @release,
27
+ remote: "http://we.aint.go/nna.push.git",
28
+ push: false,
29
+ cleanup: false
30
+ )
49
31
 
50
- FileUtils.rm_rf(output_dir)
32
+ Dir.chdir(output_dir + "clone") do
33
+ commit_msg = `git log --pretty=oneline --abbrev-commit`
34
+ assert_match(/Release 1.0.0/, commit_msg)
35
+ end
36
+
37
+ FileUtils.rm_rf(output_dir)
38
+ end
51
39
  end
52
40
  end
@@ -1,48 +1,31 @@
1
- require "./lib/roger/release/finalizers/zip"
2
- require "test/unit"
3
- require "mocha/test_unit"
4
- require "tmpdir"
1
+ require "test_helper"
2
+ require "roger/testing/mock_release"
5
3
 
6
- # Test for Roger Zip finalizer
7
- class ZipTest < Test::Unit::TestCase
8
- def setup
9
- # Mock git repo
10
- @tmp_dir = Pathname.new(Dir.mktmpdir)
4
+ module Roger
5
+ # Test for Roger Zip finalizer
6
+ class ZipTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @release = Testing::MockRelease.new
11
9
 
12
- project_path = @tmp_dir + "project"
13
- FileUtils.mkdir(project_path)
10
+ # Create a file to release in the build dir
11
+ @release.project.construct.file "build/index.html"
14
12
 
15
- @release_path = @tmp_dir + "releases"
16
- FileUtils.mkdir(@release_path)
17
-
18
- Dir.chdir(project_path) do
19
- `git init`
20
- `mkdir html`
21
- `touch html/index.html`
13
+ # Set fixed version
14
+ @release.scm.version = "1.0.0"
22
15
  end
23
16
 
24
- # Mock release object
25
- @release_mock = stub(project: stub(path: project_path))
26
-
27
- @release_mock.stubs(
28
- scm: stub(version: "1.0.0"),
29
- log: true,
30
- target_path: @release_path,
31
- build_path: project_path + "html"
32
- )
33
- end
34
-
35
- # called after every single test
36
- def teardown
37
- FileUtils.rm_rf(@tmp_dir)
38
- @release_mock = nil
39
- end
17
+ # called after every single test
18
+ def teardown
19
+ @release.destroy
20
+ @release = nil
21
+ end
40
22
 
41
- def test_basic_functionality
42
- finalizer = Roger::Release::Finalizers::Zip.new
23
+ def test_basic_functionality
24
+ finalizer = Roger::Release::Finalizers::Zip.new
43
25
 
44
- finalizer.call(@release_mock)
26
+ finalizer.call(@release)
45
27
 
46
- assert File.exist?(@release_path + "html-1.0.0.zip")
28
+ assert File.exist?(@release.target_path + "html-1.0.0.zip"), @release.target_path.inspect
29
+ end
47
30
  end
48
31
  end
@@ -0,0 +1,61 @@
1
+ require "test_helper"
2
+ require "roger/testing/mock_release"
3
+
4
+ module Roger
5
+ # Test Roger Mockup
6
+ class MockupTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @release = Testing::MockRelease.new
9
+ @mockup = Roger::Release::Processors::Mockup.new
10
+ end
11
+
12
+ def teardown
13
+ @release.destroy
14
+ @release = nil
15
+ end
16
+
17
+ def test_empty_release_runs
18
+ files = @mockup.call(@release)
19
+ assert_equal 0, files.length
20
+ end
21
+ end
22
+
23
+ # Test the target_path function of Mockup
24
+ class MockupTargetPathTest < ::Test::Unit::TestCase
25
+ def setup
26
+ @base = File.dirname(__FILE__) + "/../../../project"
27
+ @template = Roger::Template.open(@base + "/html/formats/erb.html.erb")
28
+ @processor = Roger::Release::Processors::Mockup.new
29
+ end
30
+
31
+ def test_with_html_extension
32
+ assert_equal "bla/test.html", @processor.target_path("bla/test.html", @template).to_s
33
+ assert_equal "test.html", @processor.target_path("test.html", @template).to_s
34
+ end
35
+
36
+ def test_with_double_extension
37
+ assert_equal "bla/test.html", @processor.target_path("bla/test.html.erb", @template).to_s
38
+ assert_equal "test.html", @processor.target_path("test.html.erb", @template).to_s
39
+ assert_equal "test.html", @processor.target_path("test.html.test", @template).to_s
40
+ end
41
+
42
+ def test_with_unknown_template_mime
43
+ assert_equal "bla/test.rhtml", @processor.target_path("bla/test.rhtml", @template).to_s
44
+ assert_equal "test.rhtml", @processor.target_path("test.rhtml", @template).to_s
45
+ end
46
+
47
+ def test_with_template_mime_with_existing_extension
48
+ template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
49
+
50
+ assert_equal "bla/test.csv", @processor.target_path("bla/test.rcsv", template).to_s
51
+ assert_equal "test.csv", @processor.target_path("test.erb", template).to_s
52
+ end
53
+
54
+ def test_with_template_mime_without_existing_extension
55
+ template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
56
+
57
+ assert_equal "bla/test.csv", @processor.target_path("bla/test", template).to_s
58
+ assert_equal "test.csv", @processor.target_path("test", template).to_s
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+ require "roger/testing/mock_release"
3
+
4
+ module Roger
5
+ # Test Roger Mockup
6
+ class UrlRelativizerTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @release = Testing::MockRelease.new
9
+ @processor = Roger::Release::Processors::UrlRelativizer.new
10
+ end
11
+
12
+ def teardown
13
+ @release.destroy
14
+ @release = nil
15
+ end
16
+
17
+ def test_empty_release_runs
18
+ files = @processor.call(@release)
19
+ assert_equal 0, files.length
20
+ end
21
+
22
+ def test_basic_relativization
23
+ @release.project.construct.directory "build/sub" do |dir|
24
+ dir.file "test.html", "<a href='/test.html'>link</a>"
25
+ end
26
+ @release.project.construct.file "build/test.html"
27
+
28
+ files = @processor.call(@release)
29
+ assert_equal 2, files.length
30
+
31
+ contents = File.read((@release.build_path + "sub/test.html").to_s)
32
+ assert contents.include?("../test.html")
33
+ end
34
+ end
35
+ end
@@ -1,47 +1,55 @@
1
- require "./lib/roger/release.rb"
2
- require "test/unit"
1
+ require "test_helper"
2
+ require "./lib/roger/release"
3
+
4
+ module Roger
5
+ # Test Roger processors
6
+ class ProcessorsTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @origmap = Roger::Release::Processors.map.dup
9
+ Roger::Release::Processors.map.clear
10
+ end
3
11
 
4
- # Test Roger processors
5
- class ProcessorsTest < ::Test::Unit::TestCase
6
- def setup
7
- Roger::Release::Processors.map.clear
8
- end
12
+ def teardown
13
+ Roger::Release::Processors.map.clear
14
+ Roger::Release::Processors.map.update(@origmap)
15
+ end
9
16
 
10
- def test_register_processor
11
- processor = ->(_e) { fail "ProcessorName" }
12
- assert Roger::Release::Processors.register(:name, processor)
13
- assert_equal Roger::Release::Processors.map, name: processor
14
- end
17
+ def test_register_processor
18
+ processor = ->(_e) { fail "ProcessorName" }
19
+ assert Roger::Release::Processors.register(:name, processor)
20
+ assert_equal Roger::Release::Processors.map, name: processor
21
+ end
15
22
 
16
- def test_register_processor_with_symbol_only_name
17
- processor = ->(_e) { fail "ProcessorName" }
23
+ def test_register_processor_with_symbol_only_name
24
+ processor = ->(_e) { fail "ProcessorName" }
18
25
 
19
- assert_raise(ArgumentError) do
20
- Roger::Release::Processors.register("name", processor)
21
- end
26
+ assert_raise(ArgumentError) do
27
+ Roger::Release::Processors.register("name", processor)
28
+ end
22
29
 
23
- assert_raise(ArgumentError) do
24
- Roger::Release::Processors.register("name", processor)
30
+ assert_raise(ArgumentError) do
31
+ Roger::Release::Processors.register("name", processor)
32
+ end
25
33
  end
26
- end
27
34
 
28
- def test_register_processor_with_same_name
29
- processor = ->(_e) { fail "ProcessorName" }
30
- Roger::Release::Processors.register(:name, processor)
31
-
32
- assert_raise(ArgumentError) do
35
+ def test_register_processor_with_same_name
36
+ processor = ->(_e) { fail "ProcessorName" }
33
37
  Roger::Release::Processors.register(:name, processor)
38
+
39
+ assert_raise(ArgumentError) do
40
+ Roger::Release::Processors.register(:name, processor)
41
+ end
34
42
  end
35
- end
36
43
 
37
- def test_register_processor_with_same_contents
38
- processor = ->(_e) { fail "ProcessorName" }
39
- Roger::Release::Processors.register(:name, processor)
44
+ def test_register_processor_with_same_contents
45
+ processor = ->(_e) { fail "ProcessorName" }
46
+ Roger::Release::Processors.register(:name, processor)
40
47
 
41
- assert_nothing_raised do
42
- Roger::Release::Processors.register(:name2, processor)
43
- end
48
+ assert_nothing_raised do
49
+ Roger::Release::Processors.register(:name2, processor)
50
+ end
44
51
 
45
- assert_equal Roger::Release::Processors.map, name: processor, name2: processor
52
+ assert_equal Roger::Release::Processors.map, name: processor, name2: processor
53
+ end
46
54
  end
47
55
  end
@@ -0,0 +1,29 @@
1
+ require "test_helper"
2
+ require "mocha/test_unit"
3
+
4
+ module Roger
5
+ # Test for Roger Zip finalizer
6
+ class FixedScmTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @scm = Roger::Release::Scm::Fixed.new
9
+ end
10
+
11
+ def test_implements_scm_interfase
12
+ assert @scm.respond_to?(:version)
13
+ assert @scm.respond_to?(:date)
14
+ assert @scm.respond_to?(:previous)
15
+ end
16
+
17
+ def test_has_defaults
18
+ assert_equal "0.0.0", @scm.version
19
+ assert_equal "0.0.0", @scm.previous
20
+ assert @scm.date
21
+ end
22
+
23
+ def test_input_equals_output
24
+ assert_equal "0.0.0", @scm.version
25
+ @scm.version = "1"
26
+ assert_equal "1", @scm.version
27
+ end
28
+ end
29
+ end
@@ -1,6 +1,6 @@
1
1
  # Generators register themself on the CLI module
2
+ require "test_helper"
2
3
  require "./lib/roger/release.rb"
3
- require "test/unit"
4
4
 
5
5
  module Roger
6
6
  # Test Roger Release
@@ -1,6 +1,6 @@
1
1
  # Generators register themself on the CLI module
2
+ require "test_helper"
2
3
  require "./lib/roger/resolver.rb"
3
- require "test/unit"
4
4
 
5
5
  module Roger
6
6
  # Test Roger resolver
@@ -1,4 +1,4 @@
1
- require "test/unit"
1
+ require "test_helper"
2
2
  require File.dirname(__FILE__) + "../../../lib/roger/rack/roger"
3
3
 
4
4
  module Roger
@@ -1,7 +1,7 @@
1
1
  # encoding: UTF-8
2
2
  # Generators register themself on the CLI module
3
+ require "test_helper"
3
4
  require "./lib/roger/template.rb"
4
- require "test/unit"
5
5
 
6
6
  module Roger
7
7
  # Roger template tests
@@ -0,0 +1,12 @@
1
+ if ENV["CODECLIMATE_REPO_TOKEN"]
2
+ require "codeclimate-test-reporter"
3
+ CodeClimate::TestReporter.start
4
+ else
5
+ require "simplecov"
6
+ SimpleCov.start
7
+ end
8
+
9
+ require "test/unit"
10
+ require "mocha/test_unit"
11
+
12
+ require File.dirname(__FILE__) + "/../helpers/cli"
@@ -1,6 +1,5 @@
1
1
  # encoding: UTF-8
2
- require "test/unit"
3
- require "mocha/test_unit"
2
+ require "test_helper"
4
3
  require "./lib/roger/test.rb"
5
4
 
6
5
  module Roger
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flurin Egger
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-06-17 00:00:00.000000000 Z
13
+ date: 2015-06-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: thor
@@ -124,6 +124,20 @@ dependencies:
124
124
  - - ~>
125
125
  - !ruby/object:Gem::Version
126
126
  version: 1.1.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: simplecov
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: 0.10.0
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ~>
139
+ - !ruby/object:Gem::Version
140
+ version: 0.10.0
127
141
  - !ruby/object:Gem::Dependency
128
142
  name: puma
129
143
  requirement: !ruby/object:Gem::Requirement
@@ -152,6 +166,20 @@ dependencies:
152
166
  - - ~>
153
167
  - !ruby/object:Gem::Version
154
168
  version: 0.31.0
169
+ - !ruby/object:Gem::Dependency
170
+ name: test_construct
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ~>
174
+ - !ruby/object:Gem::Version
175
+ version: '2.0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ~>
181
+ - !ruby/object:Gem::Version
182
+ version: '2.0'
155
183
  description: See homepage for more information.
156
184
  email:
157
185
  - info@digitpaint.nl
@@ -215,11 +243,14 @@ files:
215
243
  - lib/roger/release/processors/mockup.rb
216
244
  - lib/roger/release/processors/url_relativizer.rb
217
245
  - lib/roger/release/scm.rb
246
+ - lib/roger/release/scm/fixed.rb
218
247
  - lib/roger/release/scm/git.rb
219
248
  - lib/roger/resolver.rb
220
249
  - lib/roger/server.rb
221
250
  - lib/roger/template.rb
222
251
  - lib/roger/test.rb
252
+ - lib/roger/testing/mock_project.rb
253
+ - lib/roger/testing/mock_release.rb
223
254
  - lib/roger/version.rb
224
255
  - roger.gemspec
225
256
  - test/helpers/cli.rb
@@ -269,12 +300,15 @@ files:
269
300
  - test/unit/release/cleaner_test.rb
270
301
  - test/unit/release/finalizers/git_branch_test.rb
271
302
  - test/unit/release/finalizers/zip_test.rb
272
- - test/unit/release/mockup_test.rb
303
+ - test/unit/release/processors/mockup_test.rb
304
+ - test/unit/release/processors/url_relativizer_test.rb
273
305
  - test/unit/release/processors_test.rb
306
+ - test/unit/release/scm/fixed_test.rb
274
307
  - test/unit/release_test.rb
275
308
  - test/unit/resolver_test.rb
276
309
  - test/unit/server_test.rb
277
310
  - test/unit/template_test.rb
311
+ - test/unit/test_helper.rb
278
312
  - test/unit/test_test.rb
279
313
  homepage: http://github.com/digitpaint/roger
280
314
  licenses:
@@ -349,10 +383,13 @@ test_files:
349
383
  - test/unit/release/cleaner_test.rb
350
384
  - test/unit/release/finalizers/git_branch_test.rb
351
385
  - test/unit/release/finalizers/zip_test.rb
352
- - test/unit/release/mockup_test.rb
386
+ - test/unit/release/processors/mockup_test.rb
387
+ - test/unit/release/processors/url_relativizer_test.rb
353
388
  - test/unit/release/processors_test.rb
389
+ - test/unit/release/scm/fixed_test.rb
354
390
  - test/unit/release_test.rb
355
391
  - test/unit/resolver_test.rb
356
392
  - test/unit/server_test.rb
357
393
  - test/unit/template_test.rb
394
+ - test/unit/test_helper.rb
358
395
  - test/unit/test_test.rb
@@ -1,57 +0,0 @@
1
- require "./lib/roger/release.rb"
2
- require "./lib/roger/release.rb"
3
- require "test/unit"
4
-
5
- # Test Roger Mockup
6
- class MockupTest < ::Test::Unit::TestCase
7
- def setup
8
- @base = File.dirname(__FILE__) + "/../../project"
9
- @project = Roger::Project.new(@base)
10
- @release = Roger::Release.new(@project)
11
- @mockup = Roger::Release::Processors::Mockup.new
12
- end
13
-
14
- def test_empty_release_runs
15
- files = @mockup.call(@release)
16
- assert_equal 0, files.length
17
- end
18
- end
19
-
20
- # Test the target_path function of Mockup
21
- class MockupTargetPathTest < ::Test::Unit::TestCase
22
- def setup
23
- @base = File.dirname(__FILE__) + "/../../project"
24
- @template = Roger::Template.open(@base + "/html/formats/erb.html.erb")
25
- @processor = Roger::Release::Processors::Mockup.new
26
- end
27
-
28
- def test_with_html_extension
29
- assert_equal "bla/test.html", @processor.target_path("bla/test.html", @template).to_s
30
- assert_equal "test.html", @processor.target_path("test.html", @template).to_s
31
- end
32
-
33
- def test_with_double_extension
34
- assert_equal "bla/test.html", @processor.target_path("bla/test.html.erb", @template).to_s
35
- assert_equal "test.html", @processor.target_path("test.html.erb", @template).to_s
36
- assert_equal "test.html", @processor.target_path("test.html.test", @template).to_s
37
- end
38
-
39
- def test_with_unknown_template_mime
40
- assert_equal "bla/test.rhtml", @processor.target_path("bla/test.rhtml", @template).to_s
41
- assert_equal "test.rhtml", @processor.target_path("test.rhtml", @template).to_s
42
- end
43
-
44
- def test_with_template_mime_with_existing_extension
45
- template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
46
-
47
- assert_equal "bla/test.csv", @processor.target_path("bla/test.rcsv", template).to_s
48
- assert_equal "test.csv", @processor.target_path("test.erb", template).to_s
49
- end
50
-
51
- def test_with_template_mime_without_existing_extension
52
- template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
53
-
54
- assert_equal "bla/test.csv", @processor.target_path("bla/test", template).to_s
55
- assert_equal "test.csv", @processor.target_path("test", template).to_s
56
- end
57
- end