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
@@ -1,47 +1,47 @@
1
1
  require "./lib/roger/release.rb"
2
2
  require "test/unit"
3
3
 
4
+ # Test Roger processors
4
5
  class ProcessorsTest < ::Test::Unit::TestCase
5
6
  def setup
6
7
  Roger::Release::Processors.map.clear
7
8
  end
8
9
 
9
10
  def test_register_processor
10
- processor = lambda{|e| raise "ProcessorName" }
11
+ processor = ->(_e) { fail "ProcessorName" }
11
12
  assert Roger::Release::Processors.register(:name, processor)
12
- assert_equal Roger::Release::Processors.map, {:name => processor}
13
+ assert_equal Roger::Release::Processors.map, name: processor
13
14
  end
14
15
 
15
16
  def test_register_processor_with_symbol_only_name
16
- processor = lambda{|e| raise "ProcessorName" }
17
+ processor = ->(_e) { fail "ProcessorName" }
17
18
 
18
- assert_raise(ArgumentError){
19
- Roger::Release::Processors.register("name", processor)
20
- }
19
+ assert_raise(ArgumentError) do
20
+ Roger::Release::Processors.register("name", processor)
21
+ end
21
22
 
22
- assert_raise(ArgumentError){
23
- Roger::Release::Processors.register("name", processor)
24
- }
23
+ assert_raise(ArgumentError) do
24
+ Roger::Release::Processors.register("name", processor)
25
+ end
25
26
  end
26
27
 
27
28
  def test_register_processor_with_same_name
28
- processor = lambda{|e| raise "ProcessorName" }
29
+ processor = ->(_e) { fail "ProcessorName" }
29
30
  Roger::Release::Processors.register(:name, processor)
30
31
 
31
- assert_raise(ArgumentError){
32
- Roger::Release::Processors.register(:name, processor)
33
- }
32
+ assert_raise(ArgumentError) do
33
+ Roger::Release::Processors.register(:name, processor)
34
+ end
34
35
  end
35
36
 
36
37
  def test_register_processor_with_same_contents
37
- processor = lambda{|e| raise "ProcessorName" }
38
+ processor = ->(_e) { fail "ProcessorName" }
38
39
  Roger::Release::Processors.register(:name, processor)
39
40
 
40
- assert_nothing_raised{
41
- Roger::Release::Processors.register(:name2, processor)
42
- }
41
+ assert_nothing_raised do
42
+ Roger::Release::Processors.register(:name2, processor)
43
+ end
43
44
 
44
- assert_equal Roger::Release::Processors.map, {:name => processor, :name2 => processor}
45
+ assert_equal Roger::Release::Processors.map, name: processor, name2: processor
45
46
  end
46
-
47
47
  end
@@ -3,20 +3,19 @@ require "./lib/roger/release.rb"
3
3
  require "test/unit"
4
4
 
5
5
  module Roger
6
+ # Test Roger Release
6
7
  class ReleaseTest < ::Test::Unit::TestCase
7
-
8
8
  def setup
9
- @project = Project.new(File.dirname(__FILE__) + "/../project", :mockupfile_path => false)
9
+ @project = Project.new(File.dirname(__FILE__) + "/../project", mockupfile_path: false)
10
10
  @mockupfile = Roger::Mockupfile.new(@project)
11
11
  end
12
12
 
13
-
14
13
  def test_run_should_set_project_mode
15
14
  assert_equal @project.mode, nil
16
15
 
17
16
  # Running a blank release
18
- @mockupfile.release(:blank => true) do |r|
19
- r.use Proc.new{|release|
17
+ @mockupfile.release(blank: true) do |r|
18
+ r.use proc{|release|
20
19
  assert_equal release.project.mode, :release
21
20
  }
22
21
  end
@@ -26,7 +25,7 @@ module Roger
26
25
  end
27
26
 
28
27
  def test_blank_release_should_have_no_processors_and_finalizers
29
- @mockupfile.release(:blank => true)
28
+ @mockupfile.release(blank: true)
30
29
  @project.release.run!
31
30
 
32
31
  assert @project.release.stack.empty?
@@ -34,31 +33,33 @@ module Roger
34
33
  end
35
34
 
36
35
  def test_get_callable
37
- p = lambda{}
36
+ p = -> {}
38
37
  assert_equal Release.get_callable(p, {}), p
39
- assert_raise(ArgumentError){ Release.get_callable(nil, {})}
38
+ assert_raise(ArgumentError) { Release.get_callable(nil, {}) }
40
39
  end
41
40
 
42
41
  def test_get_callable_with_map
43
- p = lambda{}
42
+ p = -> {}
44
43
  map = {
45
- :lambda => p,
44
+ lambda: p
46
45
  }
47
46
 
48
47
  assert_equal Release.get_callable(:lambda, map), p
49
- assert_raise(ArgumentError){ Release.get_callable(:huh, map)}
48
+ assert_raise(ArgumentError) { Release.get_callable(:huh, map) }
50
49
  end
51
50
 
51
+ # A Release class that is valid
52
52
  class Works
53
53
  def call; end
54
54
  end
55
+
56
+ # A Release class that is invalid
55
57
  class Breaks
56
58
  end
57
59
 
58
60
  def test_get_callable_with_class
59
61
  assert Release.get_callable(Works, {}).instance_of?(Works)
60
- assert_raise(ArgumentError){ Release.get_callable(Breaks, {}) }
62
+ assert_raise(ArgumentError) { Release.get_callable(Breaks, {}) }
61
63
  end
62
-
63
64
  end
64
- end
65
+ end
@@ -3,6 +3,7 @@ require "./lib/roger/resolver.rb"
3
3
  require "test/unit"
4
4
 
5
5
  module Roger
6
+ # Test Roger resolver
6
7
  class ResolverTest < ::Test::Unit::TestCase
7
8
  def setup
8
9
  @base = Pathname.new(File.dirname(__FILE__) + "/../project/html")
@@ -27,19 +28,22 @@ module Roger
27
28
 
28
29
  def test_find_template_with_template_extension
29
30
  assert_equal @resolver.find_template("formats/markdown"), @base + "formats/markdown.md"
30
- end
31
+ end
31
32
 
32
33
  def test_find_template_with_double_extensions
33
34
  assert_equal @resolver.find_template("formats/erb"), @base + "formats/erb.html.erb"
34
35
  assert_equal @resolver.find_template("formats/erb.html"), @base + "formats/erb.html.erb"
35
36
 
36
37
  assert_equal @resolver.find_template("formats/json.json"), @base + "formats/json.json.erb"
37
- end
38
+ end
38
39
 
39
40
  def test_find_template_with_preferred_extension
40
- assert_equal @resolver.find_template("formats/json", :preferred_extension => "json"), @base + "formats/json.json.erb"
41
+ assert_equal(
42
+ @resolver.find_template("formats/json", preferred_extension: "json"),
43
+ @base + "formats/json.json.erb"
44
+ )
41
45
  end
42
-
46
+
43
47
  def test_find_template_exact_match
44
48
  # TODO
45
49
  end
@@ -49,15 +53,24 @@ module Roger
49
53
  end
50
54
 
51
55
  def test_path_to_url_relative_to_relative_path
52
- assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb", "../front_matter/erb.html.erb"), "../formats/erb.html.erb"
56
+ assert_equal(
57
+ @resolver.path_to_url(@base + "formats/erb.html.erb", "../front_matter/erb.html.erb"),
58
+ "../formats/erb.html.erb"
59
+ )
53
60
  end
54
61
 
55
62
  def test_path_to_url_relative_to_absolute_path
56
- assert_equal @resolver.path_to_url(@base + "formats/erb.html.erb", @base.realpath + "front_matter/erb.html.erb"), "../formats/erb.html.erb"
63
+ assert_equal(
64
+ @resolver.path_to_url(
65
+ @base + "formats/erb.html.erb",
66
+ @base.realpath + "front_matter/erb.html.erb"
67
+ ),
68
+ "../formats/erb.html.erb"
69
+ )
57
70
  end
58
-
59
71
  end
60
72
 
73
+ # Test resolver with multiple load paths
61
74
  class ResolverMultipleTest < ::Test::Unit::TestCase
62
75
  def setup
63
76
  @base = Pathname.new(File.dirname(__FILE__) + "/../project")
@@ -82,11 +95,5 @@ module Roger
82
95
 
83
96
  assert_equal @resolver.find_template("formats/erb"), @base + "partials/formats/erb.html.erb"
84
97
  end
85
-
86
-
87
-
88
-
89
-
90
98
  end
91
-
92
- end
99
+ end
@@ -0,0 +1,31 @@
1
+ require "test/unit"
2
+ require File.dirname(__FILE__) + "../../../lib/roger/rack/roger"
3
+
4
+ module Roger
5
+ # Test Roger Server test
6
+ class ServerTest < ::Test::Unit::TestCase
7
+ def setup
8
+ @project = Project.new(File.dirname(__FILE__) + "/../../project", mockupfile_path: false)
9
+ @server = Server.new(@project)
10
+ end
11
+
12
+ # Test to see if env["roger.project"] is set
13
+ def test_env_roger_project_is_set
14
+ test = Class.new do
15
+ def initialize(_app)
16
+ end
17
+
18
+ def call(env)
19
+ [200, {}, [env["roger.project"].object_id.to_s]]
20
+ end
21
+ end
22
+
23
+ @server.use test
24
+
25
+ request = ::Rack::MockRequest.new(@server.send(:application))
26
+
27
+ # This is a bit of a clunky comparison but it suffices for now
28
+ assert_equal @project.object_id.to_s, request.get("/").body
29
+ end
30
+ end
31
+ end
@@ -4,18 +4,19 @@ require "./lib/roger/template.rb"
4
4
  require "test/unit"
5
5
 
6
6
  module Roger
7
+ # Roger template tests
7
8
  class TemplateTest < ::Test::Unit::TestCase
8
9
  def setup
9
10
  @base = Pathname.new(File.dirname(__FILE__) + "/../project")
10
11
  @config = {
11
- :partials_path => @base + "partials",
12
- :layouts_path => @base + "layouts"
12
+ partials_path: @base + "partials",
13
+ layouts_path: @base + "layouts",
14
+ source_path: @base + "html/test.html.erb"
13
15
  }
14
16
  @template_path = @base + "html"
15
17
  end
16
18
 
17
19
  def test_encoding
18
-
19
20
  end
20
21
 
21
22
  # Extension
@@ -30,8 +31,11 @@ module Roger
30
31
  }
31
32
 
32
33
  mime_types.each do |ext, ext_out|
33
- assert_equal ext_out, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).source_extension
34
- end
34
+ assert_equal(
35
+ ext_out,
36
+ Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).source_extension
37
+ )
38
+ end
35
39
  end
36
40
 
37
41
  def test_target_extension
@@ -44,11 +48,13 @@ module Roger
44
48
  }
45
49
 
46
50
  mime_types.each do |ext, ext_out|
47
- assert_equal ext_out, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).target_extension
48
- end
51
+ assert_equal(
52
+ ext_out,
53
+ Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).target_extension
54
+ )
55
+ end
49
56
  end
50
57
 
51
-
52
58
  # Mime type
53
59
  def test_target_mime_type
54
60
  mime_types = {
@@ -59,16 +65,19 @@ module Roger
59
65
  }
60
66
 
61
67
  mime_types.each do |ext, mime|
62
- assert_equal mime, Template.new("", @config.update(:source_path => @base + "html/file.#{ext}")).target_mime_type
68
+ assert_equal(
69
+ mime,
70
+ Template.new("", @config.update(source_path: @base + "html/file.#{ext}")).target_mime_type
71
+ )
63
72
  end
64
73
  end
65
74
 
66
75
  # Front-matter
67
76
 
68
77
  def test_front_matter_partial_access
69
- template = Template.new("---\ntest: yay!\n---\n<%= partial 'test/front_matter' %>", @config.update(:source_path => @base + "html/test.html.erb"))
78
+ template = Template.new("---\ntest: yay!\n---\n<%= partial 'test/front_matter' %>", @config)
70
79
  assert_equal template.render, "yay!"
71
- end
80
+ end
72
81
 
73
82
  # Partials
74
83
 
@@ -76,39 +85,46 @@ module Roger
76
85
  end
77
86
 
78
87
  def test_partial
79
- template = Template.new("<%= partial 'test/simple' %>", @config.update(:source_path => @base + "html/test.html.erb"))
88
+ template = Template.new("<%= partial 'test/simple' %>", @config)
80
89
  assert_equal template.render, "ERB"
81
90
 
82
- template = Template.new("<%= partial 'test/simple.html' %>", @config.update(:source_path => @base + "html/test.erb"))
91
+ template = Template.new(
92
+ "<%= partial 'test/simple.html' %>",
93
+ @config.update(source_path: @base + "html/test.erb")
94
+ )
83
95
  assert_equal template.render, "ERB"
84
96
  end
85
97
 
86
98
  def test_partial_with_double_template_extensions
87
- template = Template.new("<%= partial 'test/json.json' %>", @config.update(:source_path => @base + "html/test.erb"))
99
+ template = Template.new(
100
+ "<%= partial 'test/json.json' %>",
101
+ @config.update(source_path: @base + "html/test.erb")
102
+ )
88
103
  assert_equal template.render, "{ key: value }"
89
104
  end
90
105
 
91
106
  def test_partial_with_preferred_extension
92
- template = Template.new("<%= partial 'test/json' %>", @config.update(:source_path => @base + "html/test.html.erb"))
93
- assert_raise(ArgumentError) {
107
+ template = Template.new("<%= partial 'test/json' %>", @config)
108
+ assert_raise(ArgumentError) do
94
109
  template.render
95
- }
96
-
97
- template = Template.new("<%= partial 'test/json' %>", @config.update(:source_path => @base + "html/test.json.erb"))
110
+ end
111
+ template = Template.new(
112
+ "<%= partial 'test/json' %>",
113
+ @config.update(source_path: @base + "html/test.json.erb")
114
+ )
98
115
  assert_equal template.render, "{ key: value }"
99
-
100
116
  end
101
117
 
102
118
  def test_partial_with_block
103
- template = Template.new("<% partial 'test/yield' do %>CONTENT<% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
119
+ template = Template.new("<% partial 'test/yield' do %>CONTENT<% end %>", @config)
104
120
  assert_equal template.render, "B-CONTENT-A"
105
121
 
106
- template = Template.new("<% partial 'test/yield' do %><%= 'CONTENT' %><% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
122
+ template = Template.new("<% partial 'test/yield' do %><%= 'CONTENT' %><% end %>", @config)
107
123
  assert_equal template.render, "B-CONTENT-A"
108
124
  end
109
125
 
110
126
  def test_partial_with_block_without_yield
111
- template = Template.new("<% partial 'test/simple' do %>CONTENT<% end %>", @config.update(:source_path => @base + "html/test.html.erb"))
127
+ template = Template.new("<% partial 'test/simple' do %>CONTENT<% end %>", @config)
112
128
  assert_equal template.render, "ERB"
113
129
  end
114
130
 
@@ -117,37 +133,43 @@ module Roger
117
133
  def test_content_for_not_returning_in_template
118
134
  content_for_block = 'B<% content_for :one do %><%= "one" %><% end %>A'
119
135
 
120
- template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.erb"))
136
+ template = Template.new(
137
+ content_for_block,
138
+ @config.update(source_path: @base + "html/test.erb")
139
+ )
121
140
  assert_equal template.render, "BA"
122
141
  end
123
142
 
124
143
  def test_content_for_yield_in_layout
125
- content_for_block = "---\nlayout: \"yield\"\n---\nB<% content_for :one do %><%= \"one\" %><% end %>A"
144
+ content_for_block = "---\nlayout: \"yield\"\n---\n"
145
+ content_for_block << "B<% content_for :one do %><%= \"one\" %><% end %>A"
126
146
 
127
- template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.html.erb"))
128
- assert_equal template.render, "BAone"
147
+ template = Template.new(content_for_block, @config)
148
+ assert_equal template.render, "BAone"
129
149
  end
130
150
 
131
151
  def test_content_for_yield_in_layout_without_content_for
132
152
  content_for_block = "---\nlayout: \"yield\"\n---\nBA"
133
153
 
134
- template = Template.new(content_for_block, @config.update(:source_path => @base + "html/test.html.erb"))
154
+ template = Template.new(content_for_block, @config)
135
155
  assert_equal template.render, "BA"
136
- end
156
+ end
137
157
 
138
158
  def test_content_for_yield_with_partial_with_block
139
- template = Template.new("---\nlayout: \"yield\"\n---\nB<% content_for :one do %><% partial 'test/yield' do %>CONTENT<% end %><% end %>A", @config.update(:source_path => @base + "html/test.html.erb"))
159
+ template_string = "---\nlayout: \"yield\"\n---\nB"
160
+ template_string << "<% content_for :one do %>"
161
+ template_string << "<% partial 'test/yield' do %>CONTENT<% end %>"
162
+ template_string << "<% end %>A"
163
+
164
+ template = Template.new(template_string, @config)
140
165
  assert_equal template.render, "BAB-CONTENT-A"
141
166
  end
142
167
 
143
168
  # Environment
144
169
 
145
170
  def test_template_env
146
- template = Template.new("<%= env[:test] %>", @config.update(:source_path => @base + "html/test.html.erb"))
147
- assert_equal template.render(:test => "test"), "test"
171
+ template = Template.new("<%= env[:test] %>", @config)
172
+ assert_equal template.render(test: "test"), "test"
148
173
  end
149
-
150
-
151
-
152
174
  end
153
- end
175
+ end
@@ -4,13 +4,14 @@ require "mocha/test_unit"
4
4
  require "./lib/roger/test.rb"
5
5
 
6
6
  module Roger
7
+ # Testing the Roger Test fucntionality
7
8
  class TestTest < ::Test::Unit::TestCase
8
9
  def setup
9
10
  @files = ["html/javascripts/site.js",
10
11
  "html/vendor/underscore/underscore.js"]
11
12
  @globs = stub(map: @files)
12
13
 
13
- @project = Project.new(File.dirname(__FILE__) + "/../project", :mockupfile_path => false)
14
+ @project = Project.new(File.dirname(__FILE__) + "/../project", mockupfile_path: false)
14
15
  @mockupfile = Roger::Mockupfile.new(@project)
15
16
  end
16
17
 
@@ -18,7 +19,7 @@ module Roger
18
19
  assert_equal @project.mode, nil
19
20
 
20
21
  @mockupfile.test do |t|
21
- t.use Proc.new{|test|
22
+ t.use proc{|test|
22
23
  assert_equal test.project.mode, :test
23
24
  }
24
25
  end