assert 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/bin/assert +7 -0
- data/lib/assert/cli.rb +137 -0
- data/lib/assert/rake_tasks.rb +2 -0
- data/lib/assert/version.rb +1 -1
- metadata +8 -6
data/README.md
CHANGED
@@ -193,6 +193,8 @@ $ rake test halt_on_fail=true # force halt on failure using an env v
|
|
193
193
|
|
194
194
|
## Rake Tasks
|
195
195
|
|
196
|
+
**Note**: rake task handling is deprecated and will be removed in v2.0
|
197
|
+
|
196
198
|
Assert provides some rake task helpers that will scan your test folder and recursively generate rake tasks for each one of your test folders or files. Test files must end in either `'_test.rb'` or `'_tests.rb'`. Use this as an alternative to running ruby on each one of your test files individually.
|
197
199
|
|
198
200
|
As an example, say your test folder has a file structure like so:
|
data/bin/assert
ADDED
data/lib/assert/cli.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'assert/version'
|
3
|
+
|
4
|
+
module Assert
|
5
|
+
|
6
|
+
class CLI
|
7
|
+
|
8
|
+
def self.run(*args)
|
9
|
+
self.new.run(*args)
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@cli = CLIRB.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def run(*args)
|
17
|
+
begin
|
18
|
+
@cli.parse!(*args)
|
19
|
+
tests = @cli.args
|
20
|
+
tests = ['test'] if tests.empty?
|
21
|
+
Assert::CLIRunner.new(*tests).run
|
22
|
+
rescue CLIRB::HelpExit
|
23
|
+
puts help
|
24
|
+
rescue CLIRB::VersionExit
|
25
|
+
puts Assert::VERSION
|
26
|
+
rescue CLIRB::Error => exception
|
27
|
+
puts "#{exception.message}\n"
|
28
|
+
puts help
|
29
|
+
exit(1)
|
30
|
+
rescue Exception => exception
|
31
|
+
puts "#{exception.class}: #{exception.message}"
|
32
|
+
puts exception.backtrace.join("\n") if ENV['DEBUG']
|
33
|
+
exit(1)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Don't call `exit(0)`. The test suite runs as the by an `at_exit`
|
37
|
+
# callback. Calling `exit(0)` bypasses that callback.
|
38
|
+
end
|
39
|
+
|
40
|
+
def help
|
41
|
+
"Usage: assert [TESTS] [options]\n\n"\
|
42
|
+
"Options:"\
|
43
|
+
"#{@cli}"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
class CLIRunner
|
49
|
+
TEST_FILE_SUFFIXES = ['_tests.rb', '_test.rb']
|
50
|
+
|
51
|
+
attr_reader :test_files
|
52
|
+
|
53
|
+
def initialize(*args)
|
54
|
+
options, test_paths = [
|
55
|
+
args.last.kind_of?(::Hash) ? args.pop : {},
|
56
|
+
args
|
57
|
+
]
|
58
|
+
|
59
|
+
@test_files = file_paths(test_paths).select{ |f| test_file?(f) }
|
60
|
+
end
|
61
|
+
|
62
|
+
def run
|
63
|
+
@test_files.each{ |file| require file }
|
64
|
+
require 'assert' if @test_files.empty? # show empty test output
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def file_paths(test_paths)
|
70
|
+
test_paths.inject(Set.new) do |paths, path|
|
71
|
+
paths += Dir.glob("#{path}*") + Dir.glob("#{path}*/**/*")
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def test_file?(path)
|
76
|
+
TEST_FILE_SUFFIXES.inject(false) do |result, suffix|
|
77
|
+
result || path =~ /#{suffix}$/
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
class CLIRB # Version 1.0.0, https://github.com/redding/cli.rb
|
83
|
+
Error = Class.new(RuntimeError);
|
84
|
+
HelpExit = Class.new(RuntimeError); VersionExit = Class.new(RuntimeError)
|
85
|
+
attr_reader :argv, :args, :opts, :data
|
86
|
+
|
87
|
+
def initialize(&block)
|
88
|
+
@options = []; instance_eval(&block) if block
|
89
|
+
require 'optparse'
|
90
|
+
@data, @args, @opts = [], [], {}; @parser = OptionParser.new do |p|
|
91
|
+
p.banner = ''; @options.each do |o|
|
92
|
+
@opts[o.name] = o.value; p.on(*o.parser_args){ |v| @opts[o.name] = v }
|
93
|
+
end
|
94
|
+
p.on_tail('--version', ''){ |v| raise VersionExit, v.to_s }
|
95
|
+
p.on_tail('--help', ''){ |v| raise HelpExit, v.to_s }
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def option(*args); @options << Option.new(*args); end
|
100
|
+
def parse!(argv)
|
101
|
+
@args = (argv || []).dup.tap do |args_list|
|
102
|
+
begin; @parser.parse!(args_list)
|
103
|
+
rescue OptionParser::ParseError => err; raise Error, err.message; end
|
104
|
+
end; @data = @args + [@opts]
|
105
|
+
end
|
106
|
+
def to_s; @parser.to_s; end
|
107
|
+
def inspect
|
108
|
+
"#<#{self.class}:#{'0x0%x' % (object_id << 1)} @data=#{@data.inspect}>"
|
109
|
+
end
|
110
|
+
|
111
|
+
class Option
|
112
|
+
attr_reader :name, :opt_name, :desc, :abbrev, :value, :klass, :parser_args
|
113
|
+
|
114
|
+
def initialize(name, *args)
|
115
|
+
settings, @desc = args.last.kind_of?(::Hash) ? args.pop : {}, args.pop || ''
|
116
|
+
@name, @opt_name, @abbrev = parse_name_values(name, settings[:abbrev])
|
117
|
+
@value, @klass = gvalinfo(settings[:value])
|
118
|
+
@parser_args = if [TrueClass, FalseClass, NilClass].include?(@klass)
|
119
|
+
["-#{@abbrev}", "--[no-]#{@opt_name}", @desc]
|
120
|
+
else
|
121
|
+
["-#{@abbrev}", "--#{@opt_name} #{@opt_name.upcase}", @klass, @desc]
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
private
|
126
|
+
|
127
|
+
def parse_name_values(name, custom_abbrev)
|
128
|
+
[ (processed_name = name.to_s.strip.downcase), processed_name.gsub('_', '-'),
|
129
|
+
custom_abbrev || processed_name.gsub(/[^a-z]/, '').chars.first || 'a'
|
130
|
+
]
|
131
|
+
end
|
132
|
+
def gvalinfo(v); v.kind_of?(Class) ? [nil,gklass(v)] : [v,gklass(v.class)]; end
|
133
|
+
def gklass(k); k == Fixnum ? Integer : k; end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
data/lib/assert/rake_tasks.rb
CHANGED
@@ -17,6 +17,8 @@ module Assert::RakeTasks
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def self.install
|
20
|
+
warn "[DEPRECATED] `Assert::RakeTasts` has been deprecated. Support for running tests with Rake will be removed in v2.0. Use the assert CLI instead."
|
21
|
+
|
20
22
|
assert_test_root = ENV['ASSERT_TEST_ROOT'] || './test'
|
21
23
|
|
22
24
|
if File.exists?(assert_test_root)
|
data/lib/assert/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: assert
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.0
|
10
|
+
version: 1.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Kelly Redding
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date:
|
19
|
+
date: 2013-02-13 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: ansi
|
@@ -37,8 +37,8 @@ description: Test::Unit style testing framework, just better than Test::Unit.
|
|
37
37
|
email:
|
38
38
|
- kelly@kellyredding.com
|
39
39
|
- collin.redding@me.com
|
40
|
-
executables:
|
41
|
-
|
40
|
+
executables:
|
41
|
+
- assert
|
42
42
|
extensions: []
|
43
43
|
|
44
44
|
extra_rdoc_files: []
|
@@ -51,9 +51,11 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- assert.gemspec
|
54
|
+
- bin/assert
|
54
55
|
- lib/assert.rb
|
55
56
|
- lib/assert/assertions.rb
|
56
57
|
- lib/assert/autorun.rb
|
58
|
+
- lib/assert/cli.rb
|
57
59
|
- lib/assert/context.rb
|
58
60
|
- lib/assert/macro.rb
|
59
61
|
- lib/assert/macros/methods.rb
|