protest 0.5.5 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/bin/protest +42 -0
- data/lib/protest.rb +2 -2
- data/lib/protest/runner.rb +41 -3
- data/lib/protest/test_case.rb +16 -9
- data/lib/protest/version.rb +1 -1
- data/protest.gemspec +1 -0
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 439d4e269d0734881434e16de18e3833b913820e
|
4
|
+
data.tar.gz: 0ab904dd4a5fbb6f279064fbf31c6e22459a5578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 932dc1b2230fc6b3336a82956059a4654250f5486b023cb910b0ef65791d0eb3a138182e04a896e7f03bc42b81b7a7130f8ed9eedde3980a1740f93a6cb4a331
|
7
|
+
data.tar.gz: fc39bae7899847e3d910a9b0bf99f51cee44ab0b778960822cc98c83b5eac442482dcdf9afb210f8939eff37ccf3b4753d2de16557b114340dc2f6a0e76137da
|
data/README.md
CHANGED
@@ -258,6 +258,20 @@ Protest.fail_early = true
|
|
258
258
|
This feature can be configured by passing a `PROTEST_FAIL_EARLY` environment
|
259
259
|
variable, to activate it you must set it to `"true"`.
|
260
260
|
|
261
|
+
### Command-Line
|
262
|
+
|
263
|
+
Protest comes with a command-line interface for running tests:
|
264
|
+
|
265
|
+
```
|
266
|
+
$ protest --help
|
267
|
+
Usage:
|
268
|
+
protest --help # Show this help text
|
269
|
+
protest # Run all tests in test/**/*.rb
|
270
|
+
protest DIR # Run all tests in DIR/**/*.rb
|
271
|
+
protest FILE1.rb FILE2.rb # Run all tests in FILE1.rb and FILE2.rb
|
272
|
+
protest FILE.rb:15 # Run tests in FILE.rb on line 15
|
273
|
+
```
|
274
|
+
|
261
275
|
## Using Rails?
|
262
276
|
|
263
277
|
If you are using Rails you may want to take a look at [protest-rails](http://github.com/matflores/protest-rails).
|
data/bin/protest
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "protest"
|
4
|
+
|
5
|
+
usage = <<-TEXT
|
6
|
+
Usage:
|
7
|
+
protest --help # Show this help text
|
8
|
+
protest # Run all tests in test/**/*.rb
|
9
|
+
protest DIR # Run all tests in DIR/**/*.rb
|
10
|
+
protest FILE1.rb FILE2.rb # Run all tests in FILE1.rb and FILE2.rb
|
11
|
+
protest FILE.rb:15 # Run tests in FILE.rb on line 15
|
12
|
+
TEXT
|
13
|
+
|
14
|
+
test_files = case ARGV.first
|
15
|
+
when "-h", "--help" then warn usage; exit 0
|
16
|
+
when nil then Dir["test/**/*.rb"]
|
17
|
+
else
|
18
|
+
line_numbers = ARGV
|
19
|
+
.select { |path| path[/:\d+$/] }
|
20
|
+
.map { |path| path.split(":") }
|
21
|
+
.map { |filename, line| [File.expand_path(filename), Integer(line)] }
|
22
|
+
.to_h
|
23
|
+
|
24
|
+
ARGV.flat_map do |path|
|
25
|
+
if File.directory?(path)
|
26
|
+
Dir["#{path}/**/*.rb"]
|
27
|
+
else
|
28
|
+
path.sub(/:\d+$/, "")
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
test_files.each { |rb| require "./#{rb}" }
|
34
|
+
|
35
|
+
options = {}
|
36
|
+
options[:line_numbers] = line_numbers if line_numbers
|
37
|
+
|
38
|
+
Protest.autorun = false
|
39
|
+
Protest.run_all_tests!(options)
|
40
|
+
|
41
|
+
report = Protest.instance_variable_get(:@report)
|
42
|
+
exit report.failures_and_errors.empty?
|
data/lib/protest.rb
CHANGED
@@ -46,8 +46,8 @@ module Protest
|
|
46
46
|
# arguments to the Report constructor here.
|
47
47
|
#
|
48
48
|
# See Protest.add_test_case and Protest.report_with
|
49
|
-
def self.run_all_tests!(
|
50
|
-
Runner.new(@report).run(
|
49
|
+
def self.run_all_tests!(options = {})
|
50
|
+
Runner.new(@report).run(test_cases, options)
|
51
51
|
end
|
52
52
|
|
53
53
|
# Select the name of the Report to use when running tests. See
|
data/lib/protest/runner.rb
CHANGED
@@ -9,11 +9,18 @@ module Protest
|
|
9
9
|
# Run a set of test cases, provided as arguments. This will fire relevant
|
10
10
|
# events on the runner's report, at the +start+ and +end+ of the test run,
|
11
11
|
# and before and after each test case (+enter+ and +exit+.)
|
12
|
-
def run(
|
12
|
+
def run(test_cases, options = {})
|
13
13
|
fire_event :start
|
14
|
-
|
14
|
+
|
15
|
+
if options[:line_numbers]
|
16
|
+
test_groups = nearest_test_groups(test_cases, options[:line_numbers])
|
17
|
+
else
|
18
|
+
test_groups = test_cases.zip(test_cases.map(&:tests))
|
19
|
+
end
|
20
|
+
|
21
|
+
test_groups.each do |test_case, tests|
|
15
22
|
fire_event :enter, test_case
|
16
|
-
|
23
|
+
tests.each { |test| report(test) }
|
17
24
|
fire_event :exit, test_case
|
18
25
|
end
|
19
26
|
rescue Interrupt
|
@@ -45,5 +52,36 @@ module Protest
|
|
45
52
|
event_handler_method = :"on_#{event}"
|
46
53
|
@report.send(event_handler_method, *args) if @report.respond_to?(event_handler_method)
|
47
54
|
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def nearest_test_groups(test_cases, line_numbers)
|
59
|
+
test_groups = []
|
60
|
+
grouped_test_cases = test_cases.group_by(&:filename)
|
61
|
+
|
62
|
+
grouped_test_cases.each do |filename, test_cases|
|
63
|
+
if line_numbers.key?(filename)
|
64
|
+
line_number = line_numbers[filename]
|
65
|
+
runnables = test_cases + test_cases.flat_map(&:tests)
|
66
|
+
runnables.sort_by!(&:line_number).reverse!
|
67
|
+
|
68
|
+
runnable = runnables.find { |runnable| runnable.line_number <= line_number }
|
69
|
+
next if runnable.nil?
|
70
|
+
|
71
|
+
if runnable.is_a?(TestCase)
|
72
|
+
test_groups << [runnable.class, [runnable]]
|
73
|
+
elsif runnable < TestCase
|
74
|
+
test_groups << [runnable, runnable.tests]
|
75
|
+
test_cases.each do |test_case|
|
76
|
+
test_groups << [test_case, test_case.tests] if test_case < runnable
|
77
|
+
end
|
78
|
+
end
|
79
|
+
else
|
80
|
+
test_groups.concat test_cases.zip(test_cases.map(&:tests))
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
test_groups
|
85
|
+
end
|
48
86
|
end
|
49
87
|
end
|
data/lib/protest/test_case.rb
CHANGED
@@ -13,7 +13,7 @@ module Protest
|
|
13
13
|
# ...
|
14
14
|
# end
|
15
15
|
def self.context(description, &block)
|
16
|
-
TestCase.context(description, &block)
|
16
|
+
TestCase.context(description, caller.at(0), &block)
|
17
17
|
end
|
18
18
|
|
19
19
|
class << self
|
@@ -29,12 +29,6 @@ module Protest
|
|
29
29
|
# your tests by declaring nested contexts inside the class. See
|
30
30
|
# TestCase.context.
|
31
31
|
class TestCase
|
32
|
-
# Run all tests in this context. Takes a Runner instance in order to
|
33
|
-
# provide output.
|
34
|
-
def self.run(runner)
|
35
|
-
tests.each {|test| runner.report(test) }
|
36
|
-
end
|
37
|
-
|
38
32
|
# Tests added to this context.
|
39
33
|
def self.tests
|
40
34
|
@tests ||= []
|
@@ -65,17 +59,18 @@ module Protest
|
|
65
59
|
# Define a new test context nested under the current one. All +setup+ and
|
66
60
|
# +teardown+ blocks defined on the current context will be inherited by the
|
67
61
|
# new context. This method is aliased as +describe+ for your comfort.
|
68
|
-
def self.context(description, &block)
|
62
|
+
def self.context(description, location = caller.at(0), &block)
|
69
63
|
subclass = Class.new(self)
|
70
64
|
subclass.class_eval(&block) if block
|
71
65
|
subclass.description = description
|
66
|
+
subclass.location = location
|
72
67
|
const_set(sanitize_description(description), subclass)
|
73
68
|
end
|
74
69
|
|
75
70
|
class << self
|
76
71
|
# Fancy name for your test case, reports can use this to give nice,
|
77
72
|
# descriptive output when running your tests.
|
78
|
-
attr_accessor :description
|
73
|
+
attr_accessor :description, :location
|
79
74
|
|
80
75
|
alias_method :describe, :context
|
81
76
|
alias_method :it, :test
|
@@ -100,6 +95,14 @@ module Protest
|
|
100
95
|
warn "[DEPRECATED] `after` alias is deprecated. Use `teardown` instead."
|
101
96
|
teardown(&block)
|
102
97
|
end
|
98
|
+
|
99
|
+
def line_number
|
100
|
+
Integer(location.match(/:/).post_match[/^\d+/])
|
101
|
+
end
|
102
|
+
|
103
|
+
def filename
|
104
|
+
location.match(/:/).pre_match
|
105
|
+
end
|
103
106
|
end
|
104
107
|
|
105
108
|
# Initialize a new instance of a single test. This test can be run in
|
@@ -168,6 +171,10 @@ module Protest
|
|
168
171
|
@name
|
169
172
|
end
|
170
173
|
|
174
|
+
def line_number
|
175
|
+
Integer(@location.match(/:/).post_match[/^\d+/])
|
176
|
+
end
|
177
|
+
|
171
178
|
private
|
172
179
|
|
173
180
|
def setup #:nodoc:
|
data/lib/protest/version.rb
CHANGED
data/protest.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: protest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nicolás Sanguinetti
|
@@ -9,11 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2018-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Protest is a tiny, simple, and easy-to-extend test framework for ruby.
|
15
15
|
email: flores.matias@gmail.com
|
16
|
-
executables:
|
16
|
+
executables:
|
17
|
+
- protest
|
17
18
|
extensions: []
|
18
19
|
extra_rdoc_files: []
|
19
20
|
files:
|
@@ -22,6 +23,7 @@ files:
|
|
22
23
|
- LICENSE
|
23
24
|
- README.md
|
24
25
|
- Rakefile
|
26
|
+
- bin/protest
|
25
27
|
- lib/protest.rb
|
26
28
|
- lib/protest/report.rb
|
27
29
|
- lib/protest/reports.rb
|
@@ -58,9 +60,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
60
|
version: '0'
|
59
61
|
requirements: []
|
60
62
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.
|
63
|
+
rubygems_version: 2.6.11
|
62
64
|
signing_key:
|
63
65
|
specification_version: 4
|
64
66
|
summary: Protest is a tiny, simple, and easy-to-extend test framework
|
65
67
|
test_files: []
|
66
|
-
has_rdoc:
|