roger 1.1.3 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.hound.yml +2 -0
  3. data/.rubocop.yml +47 -0
  4. data/.travis.yml +1 -5
  5. data/CHANGELOG.md +8 -0
  6. data/Gemfile +3 -3
  7. data/Rakefile +10 -4
  8. data/bin/roger +1 -1
  9. data/doc/mockupfile.md +97 -0
  10. data/doc/templating.md +5 -1
  11. data/examples/default_template/Gemfile +1 -1
  12. data/lib/roger/cli.rb +41 -36
  13. data/lib/roger/cli/command.rb +2 -4
  14. data/lib/roger/cli/generate.rb +1 -0
  15. data/lib/roger/cli/release.rb +2 -2
  16. data/lib/roger/cli/serve.rb +11 -11
  17. data/lib/roger/cli/test.rb +6 -5
  18. data/lib/roger/extractor.rb +42 -43
  19. data/lib/roger/generators.rb +27 -19
  20. data/lib/roger/generators/generator.rb +7 -10
  21. data/lib/roger/generators/new.rb +56 -41
  22. data/lib/roger/generators/templates/generator.tt +5 -5
  23. data/lib/roger/helpers/get_callable.rb +15 -14
  24. data/lib/roger/helpers/logging.rb +35 -13
  25. data/lib/roger/mockupfile.rb +13 -23
  26. data/lib/roger/project.rb +41 -34
  27. data/lib/roger/rack/roger.rb +28 -29
  28. data/lib/roger/rack/sleep.rb +4 -5
  29. data/lib/roger/release.rb +95 -72
  30. data/lib/roger/release/cleaner.rb +14 -13
  31. data/lib/roger/release/finalizers.rb +10 -10
  32. data/lib/roger/release/finalizers/dir.rb +17 -19
  33. data/lib/roger/release/finalizers/git_branch.rb +76 -38
  34. data/lib/roger/release/finalizers/rsync.rb +60 -49
  35. data/lib/roger/release/finalizers/zip.rb +32 -29
  36. data/lib/roger/release/injector.rb +43 -37
  37. data/lib/roger/release/processors.rb +24 -22
  38. data/lib/roger/release/processors/mockup.rb +97 -69
  39. data/lib/roger/release/processors/url_relativizer.rb +57 -30
  40. data/lib/roger/release/scm.rb +30 -27
  41. data/lib/roger/release/scm/git.rb +101 -92
  42. data/lib/roger/resolver.rb +86 -61
  43. data/lib/roger/server.rb +52 -27
  44. data/lib/roger/template.rb +102 -74
  45. data/lib/roger/test.rb +16 -13
  46. data/lib/roger/version.rb +3 -2
  47. data/roger.gemspec +9 -5
  48. data/test/helpers/cli.rb +17 -15
  49. data/test/project/Gemfile +2 -2
  50. data/test/project/html/formats/csv.rcsv +0 -0
  51. data/test/project/lib/generators/test.rb +2 -3
  52. data/test/project/lib/tests/fail/fail.rb +5 -6
  53. data/test/project/lib/tests/noop/lib/cli.rb +2 -1
  54. data/test/project/lib/tests/noop/lib/test.rb +5 -5
  55. data/test/project/lib/tests/noop/noop.rb +2 -1
  56. data/test/project/lib/tests/succeed/succeed.rb +5 -6
  57. data/test/unit/cli/cli_base_test.rb +2 -3
  58. data/test/unit/cli/cli_generate_test.rb +9 -10
  59. data/test/unit/cli/cli_serve_test.rb +22 -18
  60. data/test/unit/cli/cli_test_test.rb +13 -15
  61. data/test/unit/cli/cli_version_test.rb +4 -4
  62. data/test/unit/generators_test.rb +8 -10
  63. data/test/unit/helpers/logging_test.rb +64 -0
  64. data/test/unit/rack/roger_test.rb +21 -0
  65. data/test/unit/release/cleaner_test.rb +23 -19
  66. data/test/unit/release/finalizers/git_branch_test.rb +2 -1
  67. data/test/unit/release/finalizers/zip_test.rb +48 -0
  68. data/test/unit/release/mockup_test.rb +48 -0
  69. data/test/unit/release/processors_test.rb +19 -19
  70. data/test/unit/release_test.rb +15 -14
  71. data/test/unit/resolver_test.rb +21 -14
  72. data/test/unit/server_test.rb +31 -0
  73. data/test/unit/template_test.rb +58 -36
  74. data/test/unit/test_test.rb +3 -2
  75. metadata +35 -9
  76. data/test/Mockupfile-syntax.rb +0 -93
@@ -7,9 +7,8 @@ require File.dirname(__FILE__) + "/../../project/lib/tests/fail/fail"
7
7
  require File.dirname(__FILE__) + "/../../project/lib/tests/succeed/succeed"
8
8
  require File.dirname(__FILE__) + "/../../project/lib/tests/noop/noop"
9
9
 
10
- # These tests ar for the roger test command
11
-
12
10
  module Roger
11
+ # These tests ar for the roger test command
13
12
  class CliTestTest < ::Test::Unit::TestCase
14
13
  include TestCli
15
14
 
@@ -36,13 +35,13 @@ module Roger
36
35
 
37
36
  # roger test all
38
37
  def test_subcommand_all_runs_all_tests
39
- out, err = run_test_command %w{test all}
38
+ out, _err = run_test_command %w(test all)
40
39
  assert_includes out, "RogerNoopTest::Test"
41
40
  assert_includes out, "RogerSucceedTest::Test"
42
41
  end
43
42
 
44
43
  def test_subcommand_all_runs_all_tests_in_order_1
45
- out, err = run_test_command %w{test all} do |t|
44
+ out, _err = run_test_command %w(test all) do |t|
46
45
  t.use :succeed
47
46
  t.use :noop
48
47
  end
@@ -50,7 +49,7 @@ module Roger
50
49
  end
51
50
 
52
51
  def test_subcommand_all_runs_all_tests_in_order_2
53
- out, err = run_test_command %w{test all} do |t|
52
+ out, _err = run_test_command %w(test all) do |t|
54
53
  t.use :noop
55
54
  t.use :succeed
56
55
  end
@@ -59,7 +58,7 @@ module Roger
59
58
 
60
59
  # roger test
61
60
  def test_default_runs_all_tests
62
- out, err = run_test_command %w{test}
61
+ out, _err = run_test_command %w(test)
63
62
  assert_includes out, "RogerNoopTest::Test"
64
63
  assert_includes out, "RogerSucceedTest::Test"
65
64
  end
@@ -68,7 +67,7 @@ module Roger
68
67
  def test_has_option_v
69
68
  # A somewhat a-typical test,
70
69
  # just to make it work
71
- cli = ::Roger::Cli::Base.new [], %w{--verbose}
70
+ cli = ::Roger::Cli::Base.new [], %w(--verbose)
72
71
  cli.class.project.mockupfile.test do |t|
73
72
  t.use :noop
74
73
  end
@@ -82,7 +81,7 @@ module Roger
82
81
 
83
82
  # roger help test
84
83
  def test_help_shows_available_subcommands
85
- out, err = run_test_command %w{help test}
84
+ out, _err = run_test_command %w(help test)
86
85
  assert_includes out, "test all"
87
86
  assert_includes out, "test succeed"
88
87
  assert_includes out, "test noop"
@@ -90,14 +89,14 @@ module Roger
90
89
 
91
90
  # roger test noop
92
91
  def test_subcommand_x_runs_only_test_x
93
- out, err = run_test_command %w{test noop}
92
+ out, _err = run_test_command %w(test noop)
94
93
  assert_includes out, "RogerNoopTest::Test"
95
94
  assert_not_includes out, "RogerSucceedTest::Test"
96
95
  end
97
96
 
98
97
  def test_subcommand_x_has_exit_code_1_on_failure
99
98
  assert_raise(Thor::Error) do
100
- out, err = run_test_command %w{test fail} do |t|
99
+ run_test_command %w(test fail) do |t|
101
100
  t.use :noop
102
101
  t.use :fail
103
102
  end
@@ -106,7 +105,7 @@ module Roger
106
105
 
107
106
  def test_subcommand_x_has_exit_code_0_on_success
108
107
  assert_nothing_raised do
109
- out, err = run_test_command %w{test noop} do |t|
108
+ run_test_command %w(test noop) do |t|
110
109
  t.use :noop
111
110
  t.use :fail
112
111
  end
@@ -115,7 +114,7 @@ module Roger
115
114
 
116
115
  def test_subcommand_all_has_exit_code_1_on_failure
117
116
  assert_raise(Thor::Error) do
118
- out, err = run_test_command %w{test} do |t|
117
+ run_test_command %w(test) do |t|
119
118
  t.use :noop
120
119
  t.use :fail
121
120
  end
@@ -124,12 +123,11 @@ module Roger
124
123
 
125
124
  def test_subcommand_all_has_exit_code_0_on_success
126
125
  assert_nothing_raised do
127
- out, err = run_test_command %w{test} do |t|
126
+ run_test_command %w(test) do |t|
128
127
  t.use :noop
129
128
  t.use :succeed
130
129
  end
131
130
  end
132
131
  end
133
-
134
132
  end
135
- end
133
+ end
@@ -3,19 +3,19 @@ require "test/unit"
3
3
 
4
4
  require File.dirname(__FILE__) + "/../../helpers/cli"
5
5
 
6
-
7
6
  module Roger
7
+ # Test `roger --version` command
8
8
  class CliVersionTest < ::Test::Unit::TestCase
9
9
  include TestCli
10
10
 
11
11
  def test_minus_minus_verson
12
- out,err = run_command(%w{--version})
12
+ out, _err = run_command(%w(--version))
13
13
  assert_includes out, Roger::VERSION
14
14
  end
15
15
 
16
16
  def test_version_command
17
- out,err = run_command(%w{version})
17
+ out, _err = run_command(%w(version))
18
18
  assert_includes out, Roger::VERSION
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -4,32 +4,31 @@ require "test/unit"
4
4
 
5
5
  module CustomGens
6
6
  module Generators
7
-
7
+ # Simple Mock generator
8
8
  class MockedGenerator < Roger::Generators::Base
9
-
10
9
  desc "@mocked description"
11
- argument :path, :type => :string, :required => false, :desc => "Path to generate mockup into"
12
- argument :another_arg, :type => :string, :required => false, :desc => "Mocked or what?!"
10
+ argument :path, type: :string, required: false, desc: "Path to generate mockup into"
11
+ argument :another_arg, type: :string, required: false, desc: "Mocked or what?!"
13
12
 
14
13
  def test
15
14
  # Somewhat ugly way of checking
16
- raise NotImplementedError
15
+ fail NotImplementedError
17
16
  end
18
17
  end
19
18
 
19
+ # Simple Mocku generator that has a project
20
20
  class MockedWithProjectGenerator < Roger::Generators::Base
21
-
22
21
  desc "Returns a project"
23
22
  def test
24
23
  # Somewhat ugly way of checking
25
- raise StandardError if @project
24
+ fail StandardError if @project
26
25
  end
27
26
  end
28
-
29
27
  end
30
28
  end
31
29
 
32
30
  module Roger
31
+ # Test Roger Generators
33
32
  class GeneratorTest < ::Test::Unit::TestCase
34
33
  def setup
35
34
  @cli = Cli::Base.new
@@ -61,7 +60,6 @@ module Roger
61
60
  end
62
61
 
63
62
  def test_cli_help_shows_all_available_generators
64
-
65
63
  end
66
64
 
67
65
  def test_default_generator
@@ -85,4 +83,4 @@ module Roger
85
83
  end
86
84
  end
87
85
  end
88
- end
86
+ end
@@ -0,0 +1,64 @@
1
+ require "./lib/roger/helpers/logging"
2
+ require "test/unit"
3
+ require File.dirname(__FILE__) + "/../../helpers/cli"
4
+
5
+ # Empty logging class
6
+ class MyLogger
7
+ include Roger::Helpers::Logging
8
+
9
+ attr_accessor :project
10
+ end
11
+
12
+ # Test Logging module
13
+ class LoggingTest < ::Test::Unit::TestCase
14
+ include Roger::TestCli
15
+
16
+ def setup
17
+ @logger = MyLogger.new
18
+ @logger.project = stub(
19
+ options: {},
20
+ shell: Thor::Shell::Color.new
21
+ )
22
+ end
23
+
24
+ def test_log
25
+ out, _err = capture { @logger.log(@logger, "log") }
26
+ assert out.include?("MyLogger")
27
+ assert out.include?("log")
28
+ end
29
+
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
35
+
36
+ def test_log_with_block
37
+ out, _err = capture do
38
+ @logger.log(@logger, "log") do
39
+ @logger.log(@logger, "indent")
40
+ end
41
+ end
42
+
43
+ assert out.include?("MyLogger")
44
+ assert out.include?("log")
45
+ assert out.include?(" MyLogger : indent"), out
46
+ end
47
+
48
+ def test_debug
49
+ out, _err = capture { @logger.debug(@logger, "debug") }
50
+ assert_equal out, ""
51
+
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
57
+
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")
63
+ end
64
+ end
@@ -0,0 +1,21 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "../../../../lib/roger/rack/roger"
3
+
4
+ module Roger
5
+ module Rack
6
+ # Test Roger Rack
7
+ class ServerTest < ::Test::Unit::TestCase
8
+ def setup
9
+ @project = Project.new(File.dirname(__FILE__) + "/../../project", mockupfile_path: false)
10
+ @app = ::Roger::Rack::Roger.new(@project)
11
+ end
12
+
13
+ def test_middleware_renders_template
14
+ request = ::Rack::MockRequest.new(@app)
15
+ response = request.get("/formats/erb")
16
+
17
+ assert response.body.include?("ERB format")
18
+ end
19
+ end
20
+ end
21
+ end
@@ -2,23 +2,19 @@ require "./lib/roger/release.rb"
2
2
  require "./lib/roger/release/cleaner.rb"
3
3
  require "test/unit"
4
4
 
5
+ # Test Roger Cleaner
5
6
  class CleanerTest < ::Test::Unit::TestCase
6
-
7
7
  def setup
8
8
  @base = File.dirname(__FILE__) + "/../../project"
9
9
  end
10
10
 
11
11
  def test_use_array_as_pattern
12
- dirs = ["dir1", "dir2"]
12
+ dirs = %w(dir1 dir2)
13
13
 
14
- dirs.each do |dir|
15
- path = @base + "/" +dir
16
- mkdir path unless File.directory?(path)
17
- assert(File.directory?(path))
18
- end
14
+ create_and_assert_directories(dirs)
19
15
 
20
16
  project = Roger::Project.new(@base)
21
- release = Roger::Release.new(project, :build_path => Pathname.new(@base))
17
+ release = Roger::Release.new(project, build_path: Pathname.new(@base))
22
18
 
23
19
  cleaner = Roger::Release::Cleaner.new(dirs)
24
20
  cleaner.call(release)
@@ -30,39 +26,47 @@ class CleanerTest < ::Test::Unit::TestCase
30
26
  end
31
27
 
32
28
  def test_only_clean_inside_build_path_relative
33
-
34
29
  cleaner = Roger::Release::Cleaner.new(@base)
35
- inside_build_path = cleaner.send :is_inside_build_path, @base, @base + "/html/formats"
30
+ inside_build_path = cleaner.send :inside_build_path?, @base, @base + "/html/formats"
36
31
 
37
32
  assert(inside_build_path, "Only delete content inside build_path")
38
- end
33
+ end
39
34
 
40
35
  def test_only_clean_inside_build_path_absolute
41
36
  path = Pathname.new(@base).realpath.to_s
42
37
  cleaner = Roger::Release::Cleaner.new(path)
43
38
 
44
- inside_build_path = cleaner.send :is_inside_build_path, path, @base + "/html/formats"
39
+ inside_build_path = cleaner.send :inside_build_path?, path, @base + "/html/formats"
45
40
 
46
41
  assert(inside_build_path, "Only delete content inside build_path")
47
- end
42
+ end
48
43
 
49
-
50
44
  def test_dont_clean_outside_build_path
51
45
  path = File.dirname(__FILE__)
52
46
  cleaner = Roger::Release::Cleaner.new(path)
53
47
 
54
48
  assert_raise RuntimeError do
55
- inside_build_path = cleaner.send :is_inside_build_path, path, @base + "/html/formats"
49
+ cleaner.send :inside_build_path?, path, @base + "/html/formats"
56
50
  end
57
-
58
51
  end
59
-
52
+
60
53
  def test_dont_fail_on_nonexistent_files
61
54
  path = "bla"
62
55
  cleaner = Roger::Release::Cleaner.new(path)
63
56
 
64
- assert !cleaner.send(:is_inside_build_path, @base + "/html/formats", path), "Failed on nonexistent directories/files"
57
+ assert(
58
+ !cleaner.send(:inside_build_path?, @base + "/html/formats", path),
59
+ "Failed on nonexistent directories/files"
60
+ )
61
+ end
65
62
 
66
- end
63
+ protected
67
64
 
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))
70
+ end
71
+ end
68
72
  end
@@ -3,6 +3,7 @@ require "test/unit"
3
3
  require "mocha/test_unit"
4
4
  require "tmpdir"
5
5
 
6
+ # Test for Roger GitBranchFinalizer
6
7
  class GitBranchTest < Test::Unit::TestCase
7
8
  def setup
8
9
  # Mock git repo
@@ -43,7 +44,7 @@ class GitBranchTest < Test::Unit::TestCase
43
44
 
44
45
  Dir.chdir(output_dir + "clone") do
45
46
  commit_msg = `git log --pretty=oneline --abbrev-commit`
46
- assert_match /Release 0.1.999/, commit_msg
47
+ assert_match(/Release 0.1.999/, commit_msg)
47
48
  end
48
49
 
49
50
  FileUtils.rm_rf(output_dir)
@@ -0,0 +1,48 @@
1
+ require "./lib/roger/release/finalizers/zip"
2
+ require "test/unit"
3
+ require "mocha/test_unit"
4
+ require "tmpdir"
5
+
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)
11
+
12
+ project_path = @tmp_dir + "project"
13
+ FileUtils.mkdir(project_path)
14
+
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`
22
+ end
23
+
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
40
+
41
+ def test_basic_functionality
42
+ finalizer = Roger::Release::Finalizers::Zip.new
43
+
44
+ finalizer.call(@release_mock)
45
+
46
+ assert File.exist?(@release_path + "html-1.0.0.zip")
47
+ end
48
+ end
@@ -0,0 +1,48 @@
1
+ require "./lib/roger/release.rb"
2
+ require "test/unit"
3
+
4
+ # Test Roger Mockup
5
+ class MockupTest < ::Test::Unit::TestCase
6
+ def setup
7
+ @base = File.dirname(__FILE__) + "/../../project"
8
+ end
9
+ end
10
+
11
+ # Test the target_path function of Mockup
12
+ class MockupTargetPathTest < ::Test::Unit::TestCase
13
+ def setup
14
+ @base = File.dirname(__FILE__) + "/../../project"
15
+ @template = Roger::Template.open(@base + "/html/formats/erb.html.erb")
16
+ @processor = Roger::Release::Processors::Mockup.new
17
+ end
18
+
19
+ def test_with_html_extension
20
+ assert_equal "bla/test.html", @processor.target_path("bla/test.html", @template).to_s
21
+ assert_equal "test.html", @processor.target_path("test.html", @template).to_s
22
+ end
23
+
24
+ def test_with_double_extension
25
+ assert_equal "bla/test.html", @processor.target_path("bla/test.html.erb", @template).to_s
26
+ assert_equal "test.html", @processor.target_path("test.html.erb", @template).to_s
27
+ assert_equal "test.html", @processor.target_path("test.html.test", @template).to_s
28
+ end
29
+
30
+ def test_with_unknown_template_mime
31
+ assert_equal "bla/test.rhtml", @processor.target_path("bla/test.rhtml", @template).to_s
32
+ assert_equal "test.rhtml", @processor.target_path("test.rhtml", @template).to_s
33
+ end
34
+
35
+ def test_with_template_mime_with_existing_extension
36
+ template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
37
+
38
+ assert_equal "bla/test.csv", @processor.target_path("bla/test.rcsv", template).to_s
39
+ assert_equal "test.csv", @processor.target_path("test.erb", template).to_s
40
+ end
41
+
42
+ def test_with_template_mime_without_existing_extension
43
+ template = Roger::Template.open(@base + "/html/formats/csv.rcsv")
44
+
45
+ assert_equal "bla/test.csv", @processor.target_path("bla/test", template).to_s
46
+ assert_equal "test.csv", @processor.target_path("test", template).to_s
47
+ end
48
+ end