clash 1.6.1 → 2.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c03aaafb33c3668c4f61af1da5d246441686254
4
- data.tar.gz: 3fa8e1338d51c83468718718464cb5b9feb5b3e8
3
+ metadata.gz: 7578dd8975d4a2863c507063edeeb8c6e81b6947
4
+ data.tar.gz: 962ab2b1352c0d12cc081eea1cf7f99bca702659
5
5
  SHA512:
6
- metadata.gz: 42b3f13aa63fd678d7bf2301dfc7eed12e18d1b237a8a78bfa8e57b37998c8c488d262d1f407f961c079bf2f320461b8860991573f6ad85628f0e0a044bd7aee
7
- data.tar.gz: ccafd711ab65b82d79900cb43b482c5981e8a643ad449b6fab2c20c99258c053d71f24996080d9aa76919760e8c31af311d7c77d3fcbbe953cd386c917df0f84
6
+ metadata.gz: 72c7df0ac47463d509b9e86fcd6a3972ca62b4a2dc56e9de835b0fe683f2159dbc6f03c09a2096258040d2b8ea3ab63e4543482a4eb9a10757906ec862a49cb4
7
+ data.tar.gz: 79727676a8ff21a233e9d0e61536bf0c60cf8f8d54bcf672c8fb268a51bdc2391b3413f1b5f2a474258275b7e1e468eea1d18b4c72aa9c8d7bce35e6f3581a8b
data/bin/clash CHANGED
@@ -3,48 +3,16 @@
3
3
  $LOAD_PATH.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
4
4
 
5
5
  require 'clash'
6
+ require 'clash/help'
6
7
  require 'optparse'
7
8
 
8
9
  options = {}
9
10
 
10
- banner = <<-BANNER
11
- clash #{Clash::VERSION} -- Clash is a diff based testing suite for static sites.
12
-
13
- Usage:
14
- # Run tests
15
- clash [path] [tests] [options]
16
-
17
- To run only specific tests, pass test numbers separated by commas.
18
-
19
- $ clash # Run all tests
20
- $ clash 1 # Run only the first test
21
- $ clash 2,3 # Run the second and third tests
22
- $ clash 2-4 # Run the second, third, and fourth tests
23
- $ clash :10 # Run the test on line 10
24
- $ clash :10-:35 # Run all tests from line 10 to 35
25
- $ clash test # Run all tests in the 'test' directory, reading test/_clash.yml.
26
- $ clash test 1 # Run the first test in the 'test' directory.
27
-
28
- # Add testing scaffold
29
- clash init [path] [options]
30
-
31
- Options:
32
-
33
- BANNER
34
-
35
- config_info = <<-CONFIG
36
-
37
- Configuration:
38
-
39
- Clash reads its configuration from a .clash.yml file in the root of your project. Use the --file
40
- option to choose a different configuration file.
41
-
42
- View the README or visit https://github.com/imathis/clash for configuration info.
43
-
44
- CONFIG
45
-
46
11
  OptionParser.new do |opts|
47
- opts.banner = banner
12
+
13
+ if ARGV.first == 'accept'
14
+ options[:accept] = ARGV.shift
15
+ end
48
16
 
49
17
  if ARGV.first == 'init'
50
18
  options[:init] = ARGV.shift
@@ -52,12 +20,12 @@ OptionParser.new do |opts|
52
20
  opts.on("-f", "--force", "Overwrite existing content") do |f|
53
21
  options[:force] = f
54
22
  end
55
- else
56
- opts.on("-a", "--accept", "Accept failure: Copy test(s) build to expected path.") do |a|
57
- options[:accept] = a
58
- end
23
+ end
24
+
25
+ opts.banner = banner(options)
59
26
 
60
- opts.on("-b", "--build", "Build mode: Runs only 'before' and 'build' actions.") do |b|
27
+ if !options[:init] and !options[:accept]
28
+ opts.on("-b", "--build", "Build mode: Runs only 'before' and 'build' actions") do |b|
61
29
  options[:build_only] = b
62
30
  end
63
31
 
@@ -65,36 +33,39 @@ OptionParser.new do |opts|
65
33
  options[:context] = context
66
34
  end
67
35
 
68
- opts.on("-d", "--debug", "Display output from system commands") do |d|
69
- options[:debug] = d
36
+ opts.on("-t", "--trace", "Display output while running tests") do |t|
37
+ options[:trace] = t
70
38
  end
71
39
 
72
40
  opts.on("-l", "--list", "Print a list of tests' numbers and titles") do |l|
73
41
  options[:list] = l
74
42
  end
75
-
76
- opts.on("-f FILE", "--file FILE", "Use a specific test file (default: [PATH]/.clash.yml)") do |f|
77
- options[:file] = f
78
- end
79
-
80
43
  end
81
44
 
82
45
  opts.on("-h", "--help", "Show this message") do |h|
83
- puts opts
84
- puts config_info
85
- options[:help] = h
46
+ options[:help] = opts
86
47
  end
87
48
 
88
49
  end.parse!
89
50
 
90
- if options[:init]
51
+ if options[:help]
52
+ IO.popen("less", "w") do |f|
53
+ f.puts options[:help]
54
+ f.puts config_info
55
+ if options[:accept]
56
+ f.puts accept_examples
57
+ elsif !options[:init]
58
+ f.puts default_examples
59
+ end
60
+ end
61
+ elsif options[:init]
91
62
  Clash::Scaffold.new(ARGV, options)
92
- elsif !options[:help]
63
+ else
93
64
 
94
65
  unless ARGV.empty?
95
66
  # Parse input `clash 1 2 3` and `clash 1,2,3` and `clash 1-3` the same
96
67
  #
97
- options[:path] = ARGV.shift if ARGV.first =~ /^[^\d:].+/
68
+ options[:dir] = ARGV.shift if ARGV.first =~ /^[^\d:].+/
98
69
  options[:only] = ARGV
99
70
  end
100
71
 
data/lib/clash/help.rb ADDED
@@ -0,0 +1,110 @@
1
+ def version_banner
2
+ "Clash #{Clash::VERSION} -- a diff based testing suite for Jekyll."
3
+ end
4
+
5
+ def banner(options)
6
+ banner = if options[:init]
7
+ init_banner
8
+ elsif options[:accept]
9
+ accept_banner
10
+ else
11
+ default_banner
12
+ end
13
+
14
+ "#{version_banner}\n\n#{banner}"
15
+ end
16
+
17
+ def default_banner
18
+ <<-BANNER
19
+ 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
23
+
24
+ Options:
25
+ BANNER
26
+ end
27
+
28
+ def init_banner
29
+ <<-BANNER
30
+ Add testing scaffold.
31
+
32
+ Usage:
33
+ $ clash init PATH [options]
34
+
35
+ Options:
36
+ BANNER
37
+ end
38
+
39
+ def accept_banner
40
+ <<-BANNER
41
+ This accepts a build, overwriting expected files with build files.
42
+
43
+ Usage:
44
+ $ clash accept [dir] [tests] [options]
45
+
46
+ Options:
47
+ BANNER
48
+ end
49
+
50
+ def default_examples
51
+ <<-EXAMPLES
52
+
53
+ Examples:
54
+ To run only specific tests, pass test numbers separated by commas.
55
+
56
+ $ clash # Run all tests
57
+ $ clash 1 # Run only the first test
58
+ $ clash 2,3 # Run the second and third tests
59
+ $ clash 2-4 # Run the second, third, and fourth tests
60
+ $ clash :10 # Run the test on line 10
61
+ $ clash :10-:35 # Run all tests from line 10 to 35
62
+ $ clash awesome # Run all tests in the 'awesome' directory, reading awesome/_clash.yml.
63
+ $ clash awesome 1 # Run the first test in the 'awesome' directory.
64
+ EXAMPLES
65
+ end
66
+
67
+ def accept_examples
68
+ <<-EXAMPLES
69
+
70
+ Examples:
71
+ To run only specific tests, pass test numbers separated by commas.
72
+
73
+ $ clash accept # Accept all test builds
74
+ $ clash accept 1 # Accept build from test 1
75
+ $ clash accept 2,3 # Accept builds from tests 2 and 3
76
+ $ clash accept :10 # Accept build from test on line 10
77
+ $ clash accept :10-:35 # Accept builds from tests on line 10 through 35
78
+ $ clash accept awesome 1 # Accept the first build from tests in the awesome dir
79
+ EXAMPLES
80
+ end
81
+
82
+ def config_info
83
+ <<-CONFIG_INFO
84
+
85
+ Configuration:
86
+ Clash loads tests from a _clash.yml file in the current directory or the './test' directory if not found.
87
+ A simple clash file with one test might look like this:
88
+
89
+ title: Test Build # Name for your test
90
+ dir: site # Dir containing your Jekyll test site
91
+ build: true # Run Jekyll build
92
+ compare: _expected _site # Compare the contents of _expected/ to _site/
93
+
94
+ A clash test can be configured with the following options. Each of these is optional.
95
+
96
+ | Option | Type | Description |
97
+ |:-----------------|:---------------|:-----------------------------------------------------------|
98
+ | title | String | A descriptive name for the test |
99
+ | dir | String | Scope tests to this directory. |
100
+ | before | String/Array | Run system command(s) before running tests. |
101
+ | build | Boolean | Build the site with Jekyll. |
102
+ | config | Hash | Configure Jekyll, Octopress Ink plugins. (Info below) |
103
+ | compare | String/Array | Compare files or directories. Format: "_expected _site" |
104
+ | after | String/Array | Run system command(s) after running tests. |
105
+ | enforce_missing | String/Array | Ensure that these files are not found. |
106
+
107
+ View the README or visit https://github.com/imathis/clash to learn about configuration clash tests.
108
+
109
+ CONFIG_INFO
110
+ end
data/lib/clash/helpers.rb CHANGED
@@ -73,9 +73,9 @@ module Clash
73
73
 
74
74
  def system(*cmd)
75
75
  cmd = cmd.join(' ')
76
- # Don't ouput to /dev/null if in debug mode
76
+ # Don't ouput to /dev/null if in trace mode
77
77
  # or if a command supplies its own ouput
78
- if !ENV['DEBUG'] && !(cmd =~ / > /)
78
+ if !ENV['TRACE'] && !(cmd =~ / > /)
79
79
  cmd << " > /dev/null"
80
80
  end
81
81
 
data/lib/clash/tests.rb CHANGED
@@ -9,8 +9,8 @@ module Clash
9
9
 
10
10
  ENV['JEKYLL_ENV'] = 'test'
11
11
 
12
- if @options[:debug]
13
- ENV['DEBUG'] = 'true'
12
+ if @options[:trace]
13
+ ENV['TRACE'] = 'true'
14
14
  end
15
15
 
16
16
  @results = []
@@ -20,7 +20,7 @@ module Clash
20
20
 
21
21
  @options[:only] ||= []
22
22
  @options[:exit] ||= true
23
- @options[:path] ||= '.'
23
+ @options[:dir] ||= '.'
24
24
  @options[:file] ||= '_clash.yml'
25
25
 
26
26
  @clashfile = read_config
@@ -43,7 +43,7 @@ module Clash
43
43
  end
44
44
 
45
45
  def run
46
- Dir.chdir(@options[:path]) do
46
+ Dir.chdir(@options[:dir]) do
47
47
  @tests.each_with_index do |options, index|
48
48
  # If tests are limited, only run specified tests
49
49
  #
@@ -56,7 +56,7 @@ module Clash
56
56
  end
57
57
 
58
58
  def accept
59
- Dir.chdir(@options[:path]) do
59
+ Dir.chdir(@options[:dir]) do
60
60
  @tests.each_with_index do |options, index|
61
61
  # If tests are limited, only run specified tests
62
62
  #
@@ -114,6 +114,7 @@ module Clash
114
114
  def read_config
115
115
  # Find the config file (fall back to legacy filename)
116
116
  if path = config_path || config_path('.clash.yml')
117
+
117
118
  read_test_line_numbers(path)
118
119
  config = SafeYAML.load_file(path)
119
120
  config = [config] unless config.is_a?(Array)
@@ -126,15 +127,27 @@ module Clash
126
127
 
127
128
  def config_path(file=nil)
128
129
  file ||= @options[:file]
129
- path = File.join('./', @options[:path])
130
+ path = File.join('./', @options[:dir])
130
131
  paths = []
131
132
 
133
+ # By default search for clash config in the test directory.
134
+ default_path = "test/_clash.yml"
135
+
136
+ # Walk up the directory tree looking for a clash file.
132
137
  (path.count('/') + 1).times do
133
138
  paths << File.join(path, file)
134
139
  path.sub!(/\/[^\/]+$/, '')
135
140
  end
136
141
 
137
- paths.find {|p| File.file?(p) }
142
+ path = paths.find {|p| File.file?(p) }
143
+
144
+ # If path wasn't found, try default path
145
+ if !path && File.file?(default_path)
146
+ @options[:dir] = File.dirname(default_path)
147
+ path = default_path
148
+ end
149
+
150
+ path
138
151
  end
139
152
 
140
153
  def print_results
data/lib/clash/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clash
2
- VERSION = "1.6.1"
2
+ VERSION = "2.0.0"
3
3
  end
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: 1.6.1
4
+ version: 2.0.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-05 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: diffy
@@ -119,6 +119,7 @@ files:
119
119
  - bin/clash
120
120
  - lib/clash.rb
121
121
  - lib/clash/diff.rb
122
+ - lib/clash/help.rb
122
123
  - lib/clash/helpers.rb
123
124
  - lib/clash/scaffold.rb
124
125
  - lib/clash/test.rb