roger 0.12.5 → 0.13.0

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.
@@ -1,8 +1,6 @@
1
1
  require 'rack'
2
2
  require File.dirname(__FILE__) + "/template"
3
- require File.dirname(__FILE__) + "/w3c_validator"
4
3
  require File.dirname(__FILE__) + "/rack/roger"
5
- require File.dirname(__FILE__) + "/rack/html_validator"
6
4
 
7
5
  require 'webrick'
8
6
  require 'webrick/https'
@@ -73,7 +71,6 @@ module Roger
73
71
  def application
74
72
  return @app if @app
75
73
 
76
- @stack.use Rack::HtmlValidator if self.options[:validate]
77
74
  @stack.run Rack::Roger.new(self.project)
78
75
 
79
76
  @app = @stack
@@ -0,0 +1,134 @@
1
+ require 'thor'
2
+ require File.dirname(__FILE__) + "/helpers/get_callable"
3
+ require File.dirname(__FILE__) + "/helpers/logging"
4
+
5
+ module Roger
6
+ class Test
7
+ class Cli < Thor
8
+ def self.exit_on_failure?
9
+ true
10
+ end
11
+
12
+ default_task :test
13
+
14
+ class << self
15
+ attr_accessor :stack_index
16
+ end
17
+
18
+ desc "test", "Run the test"
19
+ def test
20
+ unless Roger::Cli::Base.project.test.run_test!(self.class.stack_index)
21
+ raise Thor::Error, "The test failed"
22
+ end
23
+ end
24
+ end
25
+
26
+ include Roger::Helpers::Logging
27
+
28
+ attr_reader :config, :project
29
+
30
+ class << self
31
+ include Roger::Helpers::GetCallable
32
+
33
+ # Register a test method to Roger::Test so it can be used in the Mockupfile
34
+
35
+ def register(name, test, cli = nil)
36
+ raise ArgumentError, "Another test has already claimed the name #{name.inspect}" if self.map.has_key?(name)
37
+ raise ArgumentError, "Name must be a symbol" unless name.kind_of?(Symbol)
38
+ self.map[name] = test
39
+ self.cli_map[name] = cli if cli
40
+ end
41
+
42
+ # Mapping names to test callers
43
+ def map
44
+ @_map ||= {}
45
+ end
46
+
47
+ # Mapping names to CLI handlers (this gives the option to add custom subcommands like 'init')
48
+ def cli_map
49
+ @_cli_map ||= {}
50
+ end
51
+ end
52
+
53
+ def initialize(project, config = {})
54
+ defaults = {}
55
+
56
+ @config = {}.update(defaults).update(config)
57
+ @project = project
58
+ @stack = []
59
+ end
60
+
61
+ # Use a certain test, this will also register it on the CLI
62
+ #
63
+ # @examples
64
+ # test.use :jshint, config
65
+ def use(processor, options = {})
66
+ test = self.class.get_callable(processor, Roger::Test.map)
67
+ self.register_in_cli(processor, @stack.size, self.class.cli_map[processor])
68
+ @stack << [test, options]
69
+ end
70
+
71
+ # Run all tests and return true when succeeded
72
+ def run!
73
+ success = true
74
+ @stack.each do |task|
75
+ ret = call_test(task) # Don't put this on one line, you will fail... :)
76
+ success &&= ret
77
+ end
78
+
79
+ success
80
+ end
81
+
82
+ # Run a specific test by stack index.
83
+ def run_test!(index)
84
+ test = @stack[index]
85
+ if test
86
+ call_test(test)
87
+ else
88
+ false
89
+ end
90
+ end
91
+
92
+ # Get files from the project path
93
+ #
94
+ # @param [Array] globs an array of file path globs that will be globbed against the project path
95
+ # @param [Array] excludes an array of regexps that will be excluded from the result
96
+ def get_files(globs, excludes = [])
97
+ files = globs.map{|g| Dir.glob(self.project.path + g) }.flatten
98
+ if excludes.any?
99
+ files.reject{|c| excludes.detect{|e| e.match(c) } }
100
+ else
101
+ files
102
+ end
103
+ end
104
+
105
+ protected
106
+
107
+ def call_test(task)
108
+ if (task.kind_of?(Array))
109
+ task[0].call(self, task[1])
110
+ else
111
+ task.call(self)
112
+ end
113
+ end
114
+
115
+ def register_in_cli(name, stack_index, klass)
116
+ long_desc = "Run #{name} tests"
117
+
118
+ if klass && klass.kind_of?(Class) && klass <= Roger::Test::Cli
119
+ usage = "#{name} #{klass.arguments.map{ |arg| arg.banner }.join(" ")}"
120
+ thor_class = klass
121
+ else
122
+ usage = "#{name}"
123
+ thor_class = Class.new(Roger::Test::Cli)
124
+ end
125
+
126
+ if thor_class.respond_to?(:stack_index=)
127
+ thor_class.stack_index = stack_index
128
+ end
129
+
130
+ Roger::Cli::Test.register thor_class, name, usage, long_desc
131
+
132
+ end
133
+ end
134
+ end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "roger"
5
- s.version = "0.12.5"
5
+ s.version = "0.13.0"
6
6
 
7
7
  s.authors = ["Flurin Egger", "Edwin van der Graaf", "Joran Kapteijns"]
8
8
  s.email = ["info@digitpaint.nl", "flurin@digitpaint.nl"]
@@ -25,13 +25,13 @@ Gem::Specification.new do |s|
25
25
 
26
26
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
27
27
 
28
- s.add_dependency("thor", ["~> 0.16.0"])
28
+ s.add_dependency("thor", ["~> 0.19.0"])
29
29
  s.add_dependency("rack", [">= 1.0.0"])
30
30
  s.add_dependency("tilt", ["~> 2.0.1"])
31
31
  s.add_dependency("mime-types", ["~> 2.2"])
32
32
  s.add_dependency("hpricot", [">= 0.6.4"])
33
33
  s.add_dependency("redcarpet", [">= 3.1.1"])
34
34
 
35
- s.add_development_dependency("test-unit", "~> 2.5.5")
35
+ s.add_development_dependency("test-unit", "~> 3.0.0")
36
36
  s.add_development_dependency("mocha", "~> 1.1.0")
37
37
  end
@@ -1,18 +1,25 @@
1
- # Example idea for a Mockupfile, a lot of this has to have a sensible default.
1
+ # Example for a Mockupfile, a lot of this has to have a sensible default.
2
2
 
3
3
  Sass::Plugin.options[:style] = :expanded
4
4
  Sass::Plugin.options[:template_location] = "./html/stylesheets"
5
5
  Sass::Plugin.options[:css_location] = "./html/stylesheets"
6
6
 
7
+ # Set verbosity to true
8
+ mockup.project.options[:verbose] = true
9
+
7
10
  # These are defaults, but can be set here
8
- # mockup.project.html_path = mockup.project.path + "html"
9
- # mockup.project.partial_path = mockup.project.path + "partials"
11
+ mockup.project.html_path = mockup.project.path + "html"
12
+ mockup.project.partial_path = mockup.project.path + "partials"
10
13
 
11
- mockup.serve(config) do |server|
14
+ mockup.serve do |server|
12
15
  server.use :sass
13
16
  end
14
17
 
15
- mockup.release(config) do |release|
18
+ mockup.test do |t|
19
+ t.use :jshint
20
+ end
21
+
22
+ mockup.release do |release|
16
23
 
17
24
  release.target_path # The target path where releases are put
18
25
  release.build_path # The path where the release gets built
@@ -28,16 +35,17 @@ mockup.release(config) do |release|
28
35
  release.scm.date # Get the git date
29
36
 
30
37
  # Create custom banner
31
- release.banner do
32
- "bla bla bla"
33
- end
34
-
38
+ #
35
39
  # The default banner looks like this:
36
40
  #
37
41
  # =======================
38
42
  # = Version : v1.0.0 =
39
43
  # = Date : 2012-06-20 =
40
- # =======================
44
+ # =======================
45
+ release.banner do
46
+ "bla bla bla"
47
+ end
48
+
41
49
 
42
50
  # Sassify CSS (this are the defaults too), all options except form :match and :skip are passed to Sass.compile_file
43
51
  # release.use :sass, :match => ["stylesheets/**/*.scss"], :skip => [/_.*\.scss\Z/], :style => :expanded
@@ -1,4 +1,7 @@
1
1
  require File.dirname(__FILE__) + "/lib/generators/test"
2
+ require File.dirname(__FILE__) + "/lib/tests/noop/noop"
3
+ require File.dirname(__FILE__) + "/lib/tests/fail/fail"
4
+ require File.dirname(__FILE__) + "/lib/tests/succeed/succeed"
2
5
 
3
6
  mockup.project.options[:verbose] = true;
4
7
 
@@ -7,10 +10,12 @@ mockup.project.partial_path = [mockup.project.path + "partials", mockup.project.
7
10
  mockup.serve do |s|
8
11
  end
9
12
 
10
- mockup.test do |t|
11
13
 
12
- t.use :jshint
13
14
 
15
+ mockup.test do |t|
16
+ t.use :noop
17
+ t.use :fail
18
+ t.use :succeed
14
19
  end
15
20
 
16
21
  mockup.release do |r|
@@ -1 +1,10 @@
1
- Just an index.html
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <title>Title</title>
5
+ <meta charset="utf-8">
6
+ </head>
7
+ <body>
8
+ Just an index.html
9
+ </body>
10
+ </html>
@@ -0,0 +1,17 @@
1
+ module RogerFailTest
2
+ class Test
3
+
4
+ def initialize(options={})
5
+ @options = {}
6
+ @options.update(options) if options
7
+ end
8
+
9
+ def call(test, options={})
10
+ test.log(self, "Going to fail")
11
+ false
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ Roger::Test.register :fail, RogerFailTest::Test
@@ -0,0 +1,8 @@
1
+ module RogerNoopTest
2
+ class Cli < Roger::Test::Cli
3
+ desc "init", "init noop tests"
4
+ def init
5
+ puts "initialized"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,15 @@
1
+ module RogerNoopTest
2
+ class Test
3
+
4
+ def initialize(options={})
5
+ @options = {}
6
+ @options.update(options) if options
7
+ end
8
+
9
+ def call(test, options={})
10
+ test.log(self, "NOOP")
11
+ true
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + "/lib/test"
2
+ require File.dirname(__FILE__) + "/lib/cli"
3
+
4
+ module RogerNoopTest
5
+ end
6
+
7
+ Roger::Test.register :noop, RogerNoopTest::Test, RogerNoopTest::Cli
@@ -0,0 +1,17 @@
1
+ module RogerSucceedTest
2
+ class Test
3
+
4
+ def initialize(options={})
5
+ @options = {}
6
+ @options.update(options) if options
7
+ end
8
+
9
+ def call(test, options={})
10
+ test.log(self, "Going to succeed")
11
+ true
12
+ end
13
+
14
+ end
15
+ end
16
+
17
+ Roger::Test.register :succeed, RogerSucceedTest::Test
@@ -0,0 +1,24 @@
1
+ require "./lib/roger/cli.rb"
2
+ require "test/unit"
3
+
4
+ module Roger
5
+ class CliBaseTest < ::Test::Unit::TestCase
6
+
7
+ def test_has_test_command
8
+ assert_includes Cli::Base.tasks.keys, "test"
9
+ end
10
+
11
+ def test_has_serve_command
12
+ assert_includes Cli::Base.tasks.keys, "serve"
13
+ end
14
+
15
+ def test_has_release_command
16
+ assert_includes Cli::Base.tasks.keys, "release"
17
+ end
18
+
19
+ def test_has_generate_command
20
+ assert_includes Cli::Base.tasks.keys, "generate"
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,142 @@
1
+ require "./lib/roger/cli.rb"
2
+ require "test/unit"
3
+ require "stringio"
4
+
5
+ require File.dirname(__FILE__) + "/../../project/lib/tests/fail/fail"
6
+ require File.dirname(__FILE__) + "/../../project/lib/tests/succeed/succeed"
7
+ require File.dirname(__FILE__) + "/../../project/lib/tests/noop/noop"
8
+
9
+ # These tests ar for the roger test command
10
+
11
+ module Roger
12
+ class CliTestTest < ::Test::Unit::TestCase
13
+
14
+ def setup
15
+ @base_path = File.dirname(__FILE__) + "/../../project"
16
+ end
17
+
18
+
19
+ # Capture stdout/stderr output
20
+ def capture
21
+ @_orig_stdout, @_orig_stderr = $stdout, $stderr
22
+
23
+ $stdout = StringIO.new
24
+ $stderr = StringIO.new
25
+
26
+ yield
27
+
28
+ return [$stdout.string, $stderr.string]
29
+ ensure
30
+ $stdout, $stderr = @_orig_stdout, @_orig_stderr
31
+ end
32
+
33
+ def run_test_command(args, &block)
34
+ project = Project.new(@base_path, :mockupfile_path => false)
35
+
36
+ mockupfile = Roger::Mockupfile.new(project)
37
+
38
+ if block_given?
39
+ mockupfile.test(&block)
40
+ else
41
+ mockupfile.test do |t|
42
+ t.use :succeed
43
+ t.use :noop
44
+ end
45
+ end
46
+
47
+ project.mockupfile = mockupfile
48
+
49
+ Cli::Base.project = project
50
+
51
+ capture do
52
+ Cli::Base.start(args, :debug => true)
53
+ end
54
+ end
55
+
56
+ def test_has_subcommand_all
57
+ assert_includes Cli::Base.tasks.keys, "test"
58
+ end
59
+
60
+ # roger test all
61
+ def test_subcommand_all_runs_all_tests
62
+ out, err = run_test_command %w{test all}
63
+ assert_includes out, "RogerNoopTest::Test"
64
+ assert_includes out, "RogerSucceedTest::Test"
65
+ end
66
+
67
+ def test_subcommand_all_runs_all_tests_in_order_1
68
+ out, err = run_test_command %w{test all} do |t|
69
+ t.use :succeed
70
+ t.use :noop
71
+ end
72
+ assert out.index("RogerNoopTest::Test") > out.index("RogerSucceedTest::Test")
73
+ end
74
+
75
+ def test_subcommand_all_runs_all_tests_in_order_2
76
+ out, err = run_test_command %w{test all} do |t|
77
+ t.use :noop
78
+ t.use :succeed
79
+ end
80
+ assert out.index("RogerSucceedTest::Test") > out.index("RogerNoopTest::Test")
81
+ end
82
+
83
+ # roger test
84
+ def test_default_runs_all_tests
85
+ out, err = run_test_command %w{test}
86
+ assert_includes out, "RogerNoopTest::Test"
87
+ assert_includes out, "RogerSucceedTest::Test"
88
+ end
89
+
90
+ # roger help test
91
+ def test_help_shows_available_subcommands
92
+ out, err = run_test_command %w{help test}
93
+ assert_includes out, "test all"
94
+ assert_includes out, "test succeed"
95
+ assert_includes out, "test noop"
96
+ end
97
+
98
+ # roger test noop
99
+ def test_subcommand_x_runs_only_test_x
100
+ out, err = run_test_command %w{test noop}
101
+ assert_includes out, "RogerNoopTest::Test"
102
+ assert_not_includes out, "RogerSucceedTest::Test"
103
+ end
104
+
105
+ def test_subcommand_x_has_exit_code_1_on_failure
106
+ assert_raise(Thor::Error) do
107
+ out, err = run_test_command %w{test fail} do |t|
108
+ t.use :noop
109
+ t.use :fail
110
+ end
111
+ end
112
+ end
113
+
114
+ def test_subcommand_x_has_exit_code_0_on_success
115
+ assert_nothing_raised do
116
+ out, err = run_test_command %w{test noop} do |t|
117
+ t.use :noop
118
+ t.use :fail
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_subcommand_all_has_exit_code_1_on_failure
124
+ assert_raise(Thor::Error) do
125
+ out, err = run_test_command %w{test} do |t|
126
+ t.use :noop
127
+ t.use :fail
128
+ end
129
+ end
130
+ end
131
+
132
+ def test_subcommand_all_has_exit_code_0_on_success
133
+ assert_nothing_raised do
134
+ out, err = run_test_command %w{test} do |t|
135
+ t.use :noop
136
+ t.use :succeed
137
+ end
138
+ end
139
+ end
140
+
141
+ end
142
+ end