clash 2.0.2 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa8e17d2b33bdda371233addd72f726f2ca34a59
4
- data.tar.gz: eef3b0704b518e294f8e2dc18a22b7b433a21c04
3
+ metadata.gz: f038c9d8b4b1cc0df3cb05eb1e66a09bcc33e5d6
4
+ data.tar.gz: 5ffd37edc3f92f74b9268d2fc9eb827cffc77c76
5
5
  SHA512:
6
- metadata.gz: e15d52a5b5de0b8c02e635f8fbaa286d83245d787fb063829630b1e64f09867d79edda348e702d80758083a0c75882ca8cccb16edd3c88ef378fe6e1b54862ef
7
- data.tar.gz: 7b9c122892998a636f7529b114d0b6cc5eee93f3db10909c88d0463ac75a803b0bee4dff1dcfb4584ea197f5aca2acee8c068a87bb60889345c73d60fcad81db
6
+ metadata.gz: a79902e390843533618c831035f9c6fd20c9df2a148827b826781b6173c75291cf9a834ca7b531e5b4e058b4c324e0b4dc34d60d998bb60f6c1b30b48e23ae49
7
+ data.tar.gz: 6a45656ef314abe34543bf54312b7b6404e1dc59f335f9686dbfd5829eb85ed88f17d29f21a8c88cb8f090dccfea77325637c46a47250629e6c78e9b3a1655ac
data/bin/clash CHANGED
@@ -12,19 +12,28 @@ OptionParser.new do |opts|
12
12
 
13
13
  if ARGV.first == 'accept'
14
14
  options[:accept] = ARGV.shift
15
+ elsif ARGV.first == 'new' || ARGV.first == 'init'
16
+ options[:new] = ARGV.shift
17
+ elsif ARGV.first == 'list'
18
+ options[:list] = ARGV.shift
15
19
  end
16
20
 
17
- if ARGV.first == 'init'
18
- options[:init] = ARGV.shift
19
-
20
- opts.on("-f", "--force", "Overwrite existing content") do |f|
21
- options[:force] = f
22
- end
21
+ if !(options[:list] || options[:new] || options[:accept])
22
+ options[:normal] = true
23
23
  end
24
24
 
25
25
  opts.banner = banner(options)
26
26
 
27
- if !options[:init] and !options[:accept]
27
+ if options[:new]
28
+ opts.on("-t", "--title TITLE", String, "Enter a title for your test (default: \"Test Build\")") do |title|
29
+ options[:title] = title
30
+ end
31
+ opts.on("-d", "--dir SITE_DIR", String, "Enter a directory name for your new test site (default: test-site)") do |dir|
32
+ options[:dir] = dir
33
+ end
34
+ end
35
+
36
+ if options[:normal]
28
37
  opts.on("-b", "--build", "Build mode: Runs only 'before' and 'build' actions") do |b|
29
38
  options[:build_only] = b
30
39
  end
@@ -37,21 +46,18 @@ OptionParser.new do |opts|
37
46
  options[:trace] = t
38
47
  end
39
48
 
40
- opts.on("-l", "--list", "Print a list of tests' numbers and titles") do |l|
41
- options[:list] = l
49
+ opts.on("-v", "--version", "Show version number") do |v|
50
+ options[:version] = v
42
51
  end
43
52
  end
44
53
 
45
- opts.on("-v", "--version", "Show version number") do |v|
46
- options[:version] = v
47
- end
48
-
49
54
  opts.on("-h", "--help", "Show this message") do |h|
50
55
  options[:help] = opts
51
56
  end
52
57
 
53
58
  end.parse!
54
59
 
60
+
55
61
  if options[:version]
56
62
  puts "Clash #{Clash::VERSION}"
57
63
  abort
@@ -60,17 +66,33 @@ end
60
66
  if options[:help]
61
67
  IO.popen("less", "w") do |f|
62
68
  f.puts options[:help]
63
- f.puts config_info
69
+
64
70
  if options[:accept]
65
71
  f.puts accept_examples
66
- elsif !options[:init]
72
+ elsif options[:list]
73
+ f.puts list_examples
74
+ end
75
+
76
+ if options[:normal]
67
77
  f.puts default_examples
78
+ f.puts config_info
68
79
  end
69
80
  end
70
- elsif options[:init]
71
- Clash::Scaffold.new(ARGV, options)
72
81
  else
73
82
 
83
+ if options[:new]
84
+ # Grab path from args if it exists
85
+ #
86
+ if !(path = ARGV.join(" ")).empty?
87
+ options[:path] = path
88
+ end
89
+
90
+ Clash::Scaffold.new(options).add_test
91
+
92
+ # List tests bceause that's nice.
93
+ options[:list] = true
94
+ end
95
+
74
96
  unless ARGV.empty?
75
97
  # Parse input `clash 1 2 3` and `clash 1,2,3` and `clash 1-3` the same
76
98
  #
@@ -1,12 +1,14 @@
1
1
  def version_banner
2
- "Clash #{Clash::VERSION} -- a diff based testing suite for Jekyll."
2
+ "Clash #{Clash::VERSION} -- a diff based testing suite for Jekyll sites and plugins."
3
3
  end
4
4
 
5
5
  def banner(options)
6
- banner = if options[:init]
7
- init_banner
6
+ banner = if options[:new]
7
+ new_banner
8
8
  elsif options[:accept]
9
9
  accept_banner
10
+ elsif options[:list]
11
+ list_banner
10
12
  else
11
13
  default_banner
12
14
  end
@@ -17,20 +19,34 @@ end
17
19
  def default_banner
18
20
  <<-BANNER
19
21
  Usage:
20
- $ clash [dir] [tests] [options] # Run tests
21
- $ clash accept [dir] [tests] [options] # Accept build: overwrite expected files with build files
22
- $ clash init PATH [options] # Add testing scaffold
22
+ $ clash [path] [tests] [options] # Run tests
23
+ $ clash list [path] [tests] [options] # Print a list of tests
24
+ $ clash accept [path] [tests] [options] # Accept build: overwrite expected files with build files
25
+ $ clash new [path] [options] # Add a new testing scaffold
23
26
 
24
27
  Options:
25
28
  BANNER
26
29
  end
27
30
 
28
- def init_banner
31
+ def new_banner
29
32
  <<-BANNER
30
- Add testing scaffold.
33
+ Add a new testing scaffold or a new test site to your existing test suite.
31
34
 
32
35
  Usage:
33
- $ clash init PATH [options]
36
+ $ clash new [path] [options]
37
+
38
+ Note: path defaults to `./test`.
39
+
40
+ Options:
41
+ BANNER
42
+ end
43
+
44
+ def list_banner
45
+ <<-BANNER
46
+ Print a list of test numbers and titles
47
+
48
+ Usage:
49
+ $ clash list [path] [tests] [options]
34
50
 
35
51
  Options:
36
52
  BANNER
@@ -41,7 +57,7 @@ def accept_banner
41
57
  This accepts a build, overwriting expected files with build files.
42
58
 
43
59
  Usage:
44
- $ clash accept [dir] [tests] [options]
60
+ $ clash accept [path] [tests] [options]
45
61
 
46
62
  Options:
47
63
  BANNER
@@ -64,6 +80,23 @@ Examples:
64
80
  EXAMPLES
65
81
  end
66
82
 
83
+ def list_examples
84
+ <<-EXAMPLES
85
+
86
+ Examples:
87
+ To run only specific tests, pass test numbers separated by commas.
88
+
89
+ $ clash list # List all tests
90
+ $ clash list 1 # List only the first test
91
+ $ clash list 2,3 # List the second and third tests
92
+ $ clash list 2-4 # List the second, third, and fourth tests
93
+ $ clash list :10 # List the test on line 10
94
+ $ clash list :10-:35 # List all tests from line 10 to 35
95
+ $ clash list awesome # List all tests in the 'awesome' directory, reading awesome/_clash.yml.
96
+ $ clash list awesome 1 # List the first test in the 'awesome' directory.
97
+ EXAMPLES
98
+ end
99
+
67
100
  def accept_examples
68
101
  <<-EXAMPLES
69
102
 
@@ -2,32 +2,98 @@ module Clash
2
2
  class Scaffold
3
3
  attr_accessor :options
4
4
 
5
- def initialize(args, options = {})
6
- raise 'You must specify a path.' if args.empty?
5
+ def initialize(options = {})
6
+ @options = {
7
+ path: 'test',
8
+ title: 'Test Build',
9
+ dir: 'test-site',
10
+ force: false
11
+ }.merge(options)
7
12
 
8
- test_path = File.expand_path(args.join(" "), Dir.pwd)
9
- FileUtils.mkdir_p test_path
10
- if preserve_source_location?(test_path, options)
11
- abort "Conflict: #{test_path} exists and is not empty."
13
+ @options[:path] = File.expand_path(@options[:path], Dir.pwd)
14
+ end
15
+
16
+ def add_test
17
+ config = File.join(@options[:path], '_clash.yml')
18
+
19
+ prevent_dir_name_collisions
20
+ content = test_content
21
+
22
+ if !File.exist?(config)
23
+ content.lstrip!
12
24
  end
13
25
 
14
- add_test_scaffold test_path
26
+ path = File.join(@options[:path], @options[:dir])
27
+
28
+ FileUtils.mkdir_p path
29
+ FileUtils.cp_r test_template + '/.', path
30
+
15
31
 
16
- puts "Clash test added to #{test_path}."
32
+ File.open(config, 'a') do |f|
33
+ f.write content
34
+ end
35
+
36
+ puts "New Clash test added to " + @options[:path].yellow
37
+ print_test_files(path)
38
+ puts "Tests:"
17
39
  end
18
40
 
19
- def add_test_scaffold(path)
20
- FileUtils.cp_r test_template + '/.', path
41
+ private
42
+
43
+ def print_test_files(path)
44
+ FileUtils.cd path do
45
+ files = Dir['**/*']
46
+ files.map! { |f|
47
+ if f.match /\//
48
+ f.gsub!(/[^\/]+\//, ' ')
49
+ end
50
+ if File.directory?(f)
51
+ f += '/'
52
+ end
53
+ "+ #{f}"
54
+ }
55
+ puts "\n+ #{@options[:dir]}/\n#{files.join("\n")}\n".green
56
+ end
21
57
  end
22
58
 
23
59
  def test_template
24
- File.expand_path("../../scaffold", File.dirname(__FILE__))
60
+ File.expand_path("../../scaffold/site", File.dirname(__FILE__))
25
61
  end
26
62
 
27
- private
63
+ # If necessary append a number to directory to avoid directory collision
64
+ #
65
+ def prevent_dir_name_collisions
66
+
67
+ # Find directories beginning with test directory name
68
+ #
69
+ dirs = Dir.glob("#{@options[:path]}/*").select { |d|
70
+ File.directory?(d) && d.match(/#{@options[:dir]}($|-\d+$)/)
71
+ }.size
72
+
73
+ # If matching directories are found, increment the dir name
74
+ # e.g. "test-site-2"
75
+ #
76
+ if dirs > 0
77
+ @options[:dir] << "-#{dirs += 1}"
78
+ end
79
+ end
80
+
81
+ def preserve_source_location?
82
+ !@options[:force] && !Dir["#{@options[:path]}/**/*"].empty?
83
+ end
84
+
85
+ def dasherize(string)
86
+ string.gsub(/ /,'-').gsub(/[^\w-]/,'').gsub(/-{2,}/,'-').downcase
87
+ end
28
88
 
29
- def preserve_source_location?(path, options)
30
- !options[:force] && !Dir["#{path}/**/*"].empty?
89
+ def test_content
90
+ %Q{
91
+ -
92
+ title: "#{@options[:title]}"
93
+ dir: #{@options[:dir]}
94
+ build: true
95
+ compare: _expected _site
96
+ }
31
97
  end
32
98
  end
33
99
  end
@@ -1,3 +1,3 @@
1
1
  module Clash
2
- VERSION = "2.0.2"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -1,4 +1,3 @@
1
1
  name: Test site
2
- gems: []
3
2
  timezone: UTC
4
- markdown: redcarpet
3
+ gems: []
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ </head>
6
+ <body>
7
+ <div class='site'>{{ content }}</div>
8
+ </body>
9
+ </html>
@@ -1,4 +1,5 @@
1
1
  ---
2
+ layout: default
2
3
  ---
3
4
 
4
5
  Test content
@@ -1,5 +1,5 @@
1
1
  -
2
- title: Test Build
3
- dir: site
2
+ title: "Test Build"
3
+ dir: test-site
4
4
  build: true
5
5
  compare: _expected _site
@@ -0,0 +1,3 @@
1
+ name: Test site
2
+ timezone: UTC
3
+ gems: []
@@ -0,0 +1,9 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ </head>
6
+ <body>
7
+ <div class='site'>{{ content }}</div>
8
+ </body>
9
+ </html>
@@ -0,0 +1,5 @@
1
+ ---
2
+ layout: default
3
+ ---
4
+
5
+ Test content
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Mathis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-23 00:00:00.000000000 Z
11
+ date: 2015-04-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -125,10 +125,15 @@ files:
125
125
  - lib/clash/test.rb
126
126
  - lib/clash/tests.rb
127
127
  - lib/clash/version.rb
128
- - scaffold/_clash.yml
129
128
  - scaffold/site/_config.yml
130
129
  - scaffold/site/_expected/index.html
130
+ - scaffold/site/_layouts/default.html
131
131
  - scaffold/site/index.html
132
+ - test/test-scaffold/_clash.yml
133
+ - test/test-scaffold/test-site/_config.yml
134
+ - test/test-scaffold/test-site/_expected/index.html
135
+ - test/test-scaffold/test-site/_layouts/default.html
136
+ - test/test-scaffold/test-site/index.html
132
137
  homepage: https://github.com/imathis/clash
133
138
  licenses:
134
139
  - MIT