assert 2.17.0 → 2.18.4
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 +4 -4
- data/Gemfile +2 -2
- data/README.md +66 -41
- data/assert.gemspec +2 -3
- data/lib/assert.rb +0 -10
- data/lib/assert/actual_value.rb +127 -0
- data/lib/assert/assert_runner.rb +0 -3
- data/lib/assert/assertions.rb +10 -23
- data/lib/assert/cli.rb +30 -46
- data/lib/assert/config.rb +0 -4
- data/lib/assert/config_helpers.rb +0 -4
- data/lib/assert/context.rb +18 -9
- data/lib/assert/context/let_dsl.rb +13 -0
- data/lib/assert/context/method_missing.rb +19 -0
- data/lib/assert/context/setup_dsl.rb +0 -4
- data/lib/assert/context/subject_dsl.rb +23 -28
- data/lib/assert/context/suite_dsl.rb +0 -4
- data/lib/assert/context/test_dsl.rb +0 -4
- data/lib/assert/context_info.rb +0 -4
- data/lib/assert/default_runner.rb +0 -4
- data/lib/assert/default_suite.rb +0 -5
- data/lib/assert/default_view.rb +0 -4
- data/lib/assert/factory.rb +0 -3
- data/lib/assert/file_line.rb +0 -4
- data/lib/assert/macro.rb +0 -3
- data/lib/assert/macros/methods.rb +4 -10
- data/lib/assert/result.rb +2 -17
- data/lib/assert/runner.rb +0 -3
- data/lib/assert/stub.rb +15 -1
- data/lib/assert/suite.rb +0 -4
- data/lib/assert/test.rb +2 -7
- data/lib/assert/utils.rb +0 -4
- data/lib/assert/version.rb +1 -1
- data/lib/assert/view.rb +0 -3
- data/lib/assert/view_helpers.rb +0 -11
- data/log/{.gitkeep → .keep} +0 -0
- data/test/helper.rb +23 -29
- data/test/support/factory.rb +14 -0
- data/test/support/inherited_stuff.rb +0 -2
- data/test/system/stub_tests.rb +332 -352
- data/test/system/test_tests.rb +98 -124
- data/test/unit/actual_value_tests.rb +335 -0
- data/test/unit/assert_tests.rb +121 -46
- data/test/unit/assertions/assert_block_tests.rb +30 -35
- data/test/unit/assertions/assert_empty_tests.rb +33 -35
- data/test/unit/assertions/assert_equal_tests.rb +75 -83
- data/test/unit/assertions/assert_file_exists_tests.rb +32 -36
- data/test/unit/assertions/assert_includes_tests.rb +38 -41
- data/test/unit/assertions/assert_instance_of_tests.rb +34 -37
- data/test/unit/assertions/assert_kind_of_tests.rb +34 -37
- data/test/unit/assertions/assert_match_tests.rb +34 -37
- data/test/unit/assertions/assert_nil_tests.rb +30 -35
- data/test/unit/assertions/assert_raises_tests.rb +54 -60
- data/test/unit/assertions/assert_respond_to_tests.rb +36 -39
- data/test/unit/assertions/assert_same_tests.rb +86 -88
- data/test/unit/assertions/assert_true_false_tests.rb +60 -66
- data/test/unit/assertions_tests.rb +14 -17
- data/test/unit/config_helpers_tests.rb +41 -39
- data/test/unit/config_tests.rb +38 -37
- data/test/unit/context/let_dsl_tests.rb +10 -0
- data/test/unit/context/setup_dsl_tests.rb +68 -87
- data/test/unit/context/subject_dsl_tests.rb +15 -49
- data/test/unit/context/suite_dsl_tests.rb +15 -20
- data/test/unit/context/test_dsl_tests.rb +50 -57
- data/test/unit/context_info_tests.rb +23 -18
- data/test/unit/context_tests.rb +183 -194
- data/test/unit/default_runner_tests.rb +1 -7
- data/test/unit/default_suite_tests.rb +57 -56
- data/test/unit/factory_tests.rb +5 -6
- data/test/unit/file_line_tests.rb +33 -39
- data/test/unit/macro_tests.rb +14 -18
- data/test/unit/result_tests.rb +159 -196
- data/test/unit/runner_tests.rb +64 -71
- data/test/unit/suite_tests.rb +58 -59
- data/test/unit/test_tests.rb +125 -136
- data/test/unit/utils_tests.rb +43 -54
- data/test/unit/view_helpers_tests.rb +54 -58
- data/test/unit/view_tests.rb +22 -27
- metadata +15 -10
- data/tmp/.gitkeep +0 -0
@@ -4,15 +4,9 @@ require "assert/default_runner"
|
|
4
4
|
require "assert/runner"
|
5
5
|
|
6
6
|
class Assert::DefaultRunner
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Assert::DefaultRunner"
|
10
|
-
setup do
|
11
|
-
@config = Factory.modes_off_config
|
12
|
-
@runner = Assert::DefaultRunner.new(@config)
|
13
|
-
end
|
14
|
-
subject{ @runner }
|
15
9
|
|
10
|
+
# This is tested implicitly by running Assert's test suite
|
16
11
|
end
|
17
|
-
|
18
12
|
end
|
@@ -4,94 +4,95 @@ require "assert/default_suite"
|
|
4
4
|
require "assert/suite"
|
5
5
|
|
6
6
|
class Assert::DefaultSuite
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Assert::DefaultSuite"
|
10
|
-
|
11
|
-
ci = Factory.context_info(Factory.modes_off_context_class)
|
12
|
-
@test = Factory.test(Factory.string, ci){ }
|
9
|
+
subject { unit_class }
|
13
10
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
let(:unit_class) { Assert::DefaultSuite }
|
12
|
+
end
|
13
|
+
|
14
|
+
class InitTests < UnitTests
|
15
|
+
desc "when init"
|
16
|
+
subject { unit_class.new(config1) }
|
17
|
+
|
18
|
+
let(:ci1) { Factory.context_info(Factory.modes_off_context_class) }
|
19
|
+
let(:test1) { Factory.test(Factory.string, ci1) { } }
|
20
|
+
let(:config1) { Factory.modes_off_config }
|
18
21
|
|
19
22
|
should "be a Suite" do
|
20
|
-
|
23
|
+
assert_that(subject).is_kind_of(Assert::Suite)
|
21
24
|
end
|
22
25
|
|
23
26
|
should "default its test/result counts" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
assert_that(subject.test_count).equals(0)
|
28
|
+
assert_that(subject.result_count).equals(0)
|
29
|
+
assert_that(subject.pass_result_count).equals(0)
|
30
|
+
assert_that(subject.fail_result_count).equals(0)
|
31
|
+
assert_that(subject.error_result_count).equals(0)
|
32
|
+
assert_that(subject.skip_result_count).equals(0)
|
33
|
+
assert_that(subject.ignore_result_count).equals(0)
|
31
34
|
end
|
32
35
|
|
33
36
|
should "increment its test count on `before_test`" do
|
34
37
|
subject.before_test(@test)
|
35
|
-
|
38
|
+
assert_that(subject.test_count).equals(1)
|
36
39
|
end
|
37
40
|
|
38
41
|
should "increment its result counts on `on_result`" do
|
39
42
|
subject.on_result(Factory.pass_result)
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
assert_that(subject.result_count).equals(1)
|
44
|
+
assert_that(subject.pass_result_count).equals(1)
|
45
|
+
assert_that(subject.fail_result_count).equals(0)
|
46
|
+
assert_that(subject.error_result_count).equals(0)
|
47
|
+
assert_that(subject.skip_result_count).equals(0)
|
48
|
+
assert_that(subject.ignore_result_count).equals(0)
|
46
49
|
|
47
50
|
subject.on_result(Factory.fail_result)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
assert_that(subject.result_count).equals(2)
|
52
|
+
assert_that(subject.pass_result_count).equals(1)
|
53
|
+
assert_that(subject.fail_result_count).equals(1)
|
54
|
+
assert_that(subject.error_result_count).equals(0)
|
55
|
+
assert_that(subject.skip_result_count).equals(0)
|
56
|
+
assert_that(subject.ignore_result_count).equals(0)
|
54
57
|
|
55
58
|
subject.on_result(Factory.error_result)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
assert_that(subject.result_count).equals(3)
|
60
|
+
assert_that(subject.pass_result_count).equals(1)
|
61
|
+
assert_that(subject.fail_result_count).equals(1)
|
62
|
+
assert_that(subject.error_result_count).equals(1)
|
63
|
+
assert_that(subject.skip_result_count).equals(0)
|
64
|
+
assert_that(subject.ignore_result_count).equals(0)
|
62
65
|
|
63
66
|
subject.on_result(Factory.skip_result)
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
67
|
+
assert_that(subject.result_count).equals(4)
|
68
|
+
assert_that(subject.pass_result_count).equals(1)
|
69
|
+
assert_that(subject.fail_result_count).equals(1)
|
70
|
+
assert_that(subject.error_result_count).equals(1)
|
71
|
+
assert_that(subject.skip_result_count).equals(1)
|
72
|
+
assert_that(subject.ignore_result_count).equals(0)
|
70
73
|
|
71
74
|
subject.on_result(Factory.ignore_result)
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
75
|
+
assert_that(subject.result_count).equals(5)
|
76
|
+
assert_that(subject.pass_result_count).equals(1)
|
77
|
+
assert_that(subject.fail_result_count).equals(1)
|
78
|
+
assert_that(subject.error_result_count).equals(1)
|
79
|
+
assert_that(subject.skip_result_count).equals(1)
|
80
|
+
assert_that(subject.ignore_result_count).equals(1)
|
78
81
|
end
|
79
82
|
|
80
83
|
should "clear the run data on `on_start`" do
|
81
|
-
subject.before_test(
|
84
|
+
subject.before_test(test1)
|
82
85
|
subject.on_result(Factory.pass_result)
|
83
86
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
+
assert_that(subject.test_count).equals(1)
|
88
|
+
assert_that(subject.result_count).equals(1)
|
89
|
+
assert_that(subject.pass_result_count).equals(1)
|
87
90
|
|
88
91
|
subject.on_start
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
+
assert_that(subject.test_count).equals(0)
|
94
|
+
assert_that(subject.result_count).equals(0)
|
95
|
+
assert_that(subject.pass_result_count).equals(0)
|
93
96
|
end
|
94
|
-
|
95
97
|
end
|
96
|
-
|
97
98
|
end
|
data/test/unit/factory_tests.rb
CHANGED
@@ -4,16 +4,17 @@ require "assert/factory"
|
|
4
4
|
require "much-factory"
|
5
5
|
|
6
6
|
module Assert::Factory
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Assert::Factory"
|
10
|
-
subject{
|
9
|
+
subject { unit_class }
|
10
|
+
|
11
|
+
let(:unit_class) { Assert::Factory }
|
11
12
|
|
12
13
|
should "include and extend MuchFactory" do
|
13
|
-
|
14
|
+
assert_that(subject).includes(MuchFactory)
|
14
15
|
|
15
16
|
# https://stackoverflow.com/questions/5197166/ruby-get-a-list-of-extended-modules
|
16
|
-
|
17
|
+
assert_that(subject_metaclass.included_modules).includes(MuchFactory)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
@@ -23,7 +24,5 @@ module Assert::Factory
|
|
23
24
|
self
|
24
25
|
end
|
25
26
|
end
|
26
|
-
|
27
27
|
end
|
28
|
-
|
29
28
|
end
|
@@ -2,82 +2,76 @@ require "assert"
|
|
2
2
|
require "assert/file_line"
|
3
3
|
|
4
4
|
class Assert::FileLine
|
5
|
-
|
6
5
|
class UnitTests < Assert::Context
|
7
6
|
desc "Assert::FileLine"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
subject { unit_class }
|
8
|
+
|
9
|
+
let(:unit_class) { Assert::FileLine }
|
10
|
+
|
11
|
+
let(:file1) { "#{Factory.path}_tests.rb" }
|
12
|
+
let(:line1) { Factory.integer.to_s }
|
13
13
|
|
14
14
|
should have_imeths :parse
|
15
15
|
|
16
16
|
should "know how to parse and init from a file line path string" do
|
17
17
|
file_line_path = [
|
18
|
-
"#{
|
19
|
-
"#{
|
18
|
+
"#{file1}:#{line1}",
|
19
|
+
"#{file1}:#{line1} #{Factory.string}"
|
20
20
|
].sample
|
21
21
|
file_line = subject.parse(file_line_path)
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
assert_that(file_line.file).equals(file1)
|
24
|
+
assert_that(file_line.line).equals(line1)
|
25
25
|
end
|
26
26
|
|
27
27
|
should "handle parsing bad data gracefully" do
|
28
|
-
file_line = subject.parse(
|
29
|
-
|
30
|
-
|
28
|
+
file_line = subject.parse(file1)
|
29
|
+
assert_that(file_line.file).equals(file1)
|
30
|
+
assert_that(file_line.line).equals("")
|
31
31
|
|
32
|
-
file_line = subject.parse(
|
33
|
-
|
34
|
-
|
32
|
+
file_line = subject.parse(line1)
|
33
|
+
assert_that(file_line.file).equals(line1)
|
34
|
+
assert_that(file_line.line).equals("")
|
35
35
|
|
36
36
|
file_line = subject.parse("")
|
37
|
-
|
38
|
-
|
37
|
+
assert_that(file_line.file).equals("")
|
38
|
+
assert_that(file_line.line).equals("")
|
39
39
|
|
40
40
|
file_line = subject.parse(nil)
|
41
|
-
|
42
|
-
|
41
|
+
assert_that(file_line.file).equals("")
|
42
|
+
assert_that(file_line.line).equals("")
|
43
43
|
end
|
44
|
-
|
45
44
|
end
|
46
45
|
|
47
46
|
class InitTests < UnitTests
|
48
47
|
desc "when init"
|
49
|
-
|
50
|
-
@file_line = Assert::FileLine.new(@file, @line)
|
51
|
-
end
|
52
|
-
subject{ @file_line }
|
48
|
+
subject { unit_class.new(file1, line1) }
|
53
49
|
|
54
50
|
should have_readers :file, :line
|
55
51
|
|
56
52
|
should "know its file and line" do
|
57
|
-
|
58
|
-
|
53
|
+
assert_that(subject.file).equals(file1)
|
54
|
+
assert_that(subject.line).equals(line1)
|
59
55
|
|
60
|
-
file_line =
|
61
|
-
|
62
|
-
|
56
|
+
file_line = unit_class.new(file1)
|
57
|
+
assert_that(file_line.file).equals(file1)
|
58
|
+
assert_that(file_line.line).equals("")
|
63
59
|
|
64
|
-
file_line =
|
65
|
-
|
66
|
-
|
60
|
+
file_line = unit_class.new
|
61
|
+
assert_that(file_line.file).equals("")
|
62
|
+
assert_that(file_line.line).equals("")
|
67
63
|
end
|
68
64
|
|
69
65
|
should "know its string representation" do
|
70
|
-
|
66
|
+
assert_that(subject.to_s).equals("#{subject.file}:#{subject.line}")
|
71
67
|
end
|
72
68
|
|
73
69
|
should "know if it is equal to another file line" do
|
74
|
-
yes =
|
75
|
-
no =
|
70
|
+
yes = unit_class.new(file1, line1)
|
71
|
+
no = unit_class.new("#{Factory.path}_tests.rb", Factory.integer.to_s)
|
76
72
|
|
77
|
-
|
73
|
+
assert_that(subject).equals(yes)
|
78
74
|
assert_not_equal no, subject
|
79
75
|
end
|
80
|
-
|
81
76
|
end
|
82
|
-
|
83
77
|
end
|
data/test/unit/macro_tests.rb
CHANGED
@@ -2,35 +2,37 @@ require "assert"
|
|
2
2
|
require "assert/macro"
|
3
3
|
|
4
4
|
class Assert::Macro
|
5
|
-
|
6
5
|
class UnitTests < Assert::Context
|
7
6
|
desc "Assert::Macro"
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
subject { unit_class }
|
8
|
+
|
9
|
+
let(:unit_class) { Assert::Macro }
|
10
|
+
end
|
11
|
+
|
12
|
+
class InitTests < UnitTests
|
13
|
+
desc "when init"
|
14
|
+
subject { unit_class.new {} }
|
12
15
|
|
13
16
|
should "have an accessor for its (optional) name" do
|
14
|
-
|
15
|
-
|
17
|
+
assert_that(subject).responds_to(:name)
|
18
|
+
assert_that(subject).responds_to(:name=)
|
16
19
|
end
|
17
20
|
|
18
21
|
should "default its name if no given" do
|
19
|
-
|
22
|
+
assert_that((unit_class.new {}).name).equals("run this macro")
|
20
23
|
end
|
21
24
|
|
22
25
|
should "initialize with a given name" do
|
23
|
-
|
26
|
+
assert_that((unit_class.new("test") {}).name).equals("test")
|
24
27
|
end
|
25
28
|
|
26
29
|
should "be a Proc" do
|
27
|
-
|
30
|
+
assert_that(subject).is_kind_of(::Proc)
|
28
31
|
end
|
29
32
|
|
30
33
|
should "complain if you create a macro without a block" do
|
31
|
-
|
34
|
+
assert_that(-> { unit_class.new }).raises(ArgumentError)
|
32
35
|
end
|
33
|
-
|
34
36
|
end
|
35
37
|
|
36
38
|
class InstanceMethodsTests < Assert::Context
|
@@ -51,7 +53,6 @@ class Assert::Macro
|
|
51
53
|
should not_have_instance_methods :method_8, :method_9
|
52
54
|
should not_have_imeth :method_10
|
53
55
|
should not_have_imeths :method_11, :method_12
|
54
|
-
|
55
56
|
end
|
56
57
|
|
57
58
|
class ClassMethodsTests < Assert::Context
|
@@ -74,7 +75,6 @@ class Assert::Macro
|
|
74
75
|
should not_have_class_methods :method_8, :method_9
|
75
76
|
should not_have_cmeth :method_10
|
76
77
|
should not_have_cmeths :method_11, :method_12
|
77
|
-
|
78
78
|
end
|
79
79
|
|
80
80
|
class ReadersTests < Assert::Context
|
@@ -95,7 +95,6 @@ class Assert::Macro
|
|
95
95
|
should not_have_reader :method_8, :method_9
|
96
96
|
should not_have_readers :method_10
|
97
97
|
should not_have_readers :method_11, :method_12
|
98
|
-
|
99
98
|
end
|
100
99
|
|
101
100
|
class WritersTests < Assert::Context
|
@@ -116,7 +115,6 @@ class Assert::Macro
|
|
116
115
|
should not_have_writer :method_8, :method_9
|
117
116
|
should not_have_writers :method_10
|
118
117
|
should not_have_writers :method_11, :method_12
|
119
|
-
|
120
118
|
end
|
121
119
|
|
122
120
|
class AccessorsTests < Assert::Context
|
@@ -137,7 +135,5 @@ class Assert::Macro
|
|
137
135
|
should not_have_accessor :method_8, :method_9
|
138
136
|
should not_have_accessors :method_10
|
139
137
|
should not_have_accessors :method_11, :method_12
|
140
|
-
|
141
138
|
end
|
142
|
-
|
143
139
|
end
|
data/test/unit/result_tests.rb
CHANGED
@@ -4,13 +4,13 @@ require "assert/result"
|
|
4
4
|
require "assert/file_line"
|
5
5
|
|
6
6
|
module Assert::Result
|
7
|
-
|
8
7
|
class UnitTests < Assert::Context
|
9
8
|
desc "Assert::Result"
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
9
|
+
subject { unit_class }
|
10
|
+
|
11
|
+
let(:unit_class) { Assert::Result }
|
12
|
+
|
13
|
+
let(:test1) { Factory.test("a test name") }
|
14
14
|
|
15
15
|
should have_imeths :types, :new
|
16
16
|
|
@@ -22,41 +22,33 @@ module Assert::Result
|
|
22
22
|
:skip => Skip,
|
23
23
|
:error => Error
|
24
24
|
}
|
25
|
-
|
25
|
+
assert_that(subject.types).equals(exp)
|
26
26
|
|
27
|
-
|
27
|
+
assert_that(subject.types[Factory.string]).equals(Base)
|
28
28
|
end
|
29
29
|
|
30
30
|
should "create results from data hashes" do
|
31
31
|
type = Assert::Result.types.keys.sample
|
32
32
|
exp = Assert::Result.types[type].new(:type => type)
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def build_backtrace
|
39
|
-
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
40
|
-
(Factory.integer(3).times.map{ Factory.string } + [assert_lib_path]).shuffle
|
33
|
+
assert_that(Assert::Result.new(:type => type)).equals(exp)
|
41
34
|
end
|
42
|
-
|
43
35
|
end
|
44
36
|
|
45
|
-
class
|
46
|
-
desc "Base"
|
47
|
-
|
48
|
-
|
37
|
+
class InitBaseTests < UnitTests
|
38
|
+
desc "Base when init"
|
39
|
+
subject { Base.new(given_data1) }
|
40
|
+
|
41
|
+
let(:given_data1) {
|
42
|
+
{
|
49
43
|
:type => Factory.string,
|
50
44
|
:name => Factory.string,
|
51
45
|
:test_name => Factory.string,
|
52
46
|
:test_file_line => Assert::FileLine.new(Factory.string, Factory.integer),
|
53
47
|
:message => Factory.string,
|
54
48
|
:output => Factory.text,
|
55
|
-
:backtrace => Backtrace.new(
|
49
|
+
:backtrace => Backtrace.new(Factory.backtrace)
|
56
50
|
}
|
57
|
-
|
58
|
-
end
|
59
|
-
subject{ @result }
|
51
|
+
}
|
60
52
|
|
61
53
|
should have_cmeths :type, :name, :for_test
|
62
54
|
should have_imeths :type, :name, :test_name, :test_file_line
|
@@ -65,69 +57,69 @@ module Assert::Result
|
|
65
57
|
should have_imeths :backtrace, :trace
|
66
58
|
should have_imeths :set_backtrace, :set_with_bt, :with_bt_set?
|
67
59
|
should have_imeths :src_line, :file_line, :file_name, :line_num
|
68
|
-
should have_imeths
|
60
|
+
should have_imeths(*Assert::Result.types.keys.map{ |k| "#{k}?" })
|
69
61
|
should have_imeths :to_sym, :to_s
|
70
62
|
|
71
63
|
should "know its class-level type/name" do
|
72
|
-
|
73
|
-
|
64
|
+
assert_that(subject.class.type).equals(:unknown)
|
65
|
+
assert_that(subject.class.name).equals("")
|
74
66
|
end
|
75
67
|
|
76
68
|
should "know how to build a result for a given test" do
|
77
69
|
message = Factory.text
|
78
70
|
bt = Factory.integer(3).times.map{ Factory.string }
|
79
|
-
result = Base.for_test(
|
71
|
+
result = Base.for_test(test1, message, bt)
|
80
72
|
|
81
73
|
exp_backtrace = Backtrace.new(bt)
|
82
74
|
exp_trace = exp_backtrace.filtered.first.to_s
|
83
75
|
|
84
|
-
|
85
|
-
|
76
|
+
assert_that(result.test_name).equals(test1.name)
|
77
|
+
assert_that(result.test_id).equals(test1.file_line.to_s)
|
86
78
|
|
87
|
-
|
88
|
-
|
89
|
-
|
79
|
+
assert_that(result.message).equals(message)
|
80
|
+
assert_that(result.backtrace).equals(exp_backtrace)
|
81
|
+
assert_that(result.trace).equals(exp_trace)
|
90
82
|
|
91
|
-
|
83
|
+
assert_that(result.with_bt_set?).is_false
|
92
84
|
end
|
93
85
|
|
94
86
|
should "use any given attrs" do
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
87
|
+
assert_that(subject.type).equals(given_data1[:type].to_sym)
|
88
|
+
assert_that(subject.name).equals(given_data1[:name])
|
89
|
+
assert_that(subject.test_name).equals(given_data1[:test_name])
|
90
|
+
assert_that(subject.test_file_line).equals(given_data1[:test_file_line])
|
91
|
+
assert_that(subject.message).equals(given_data1[:message])
|
92
|
+
assert_that(subject.output).equals(given_data1[:output])
|
93
|
+
assert_that(subject.backtrace).equals(given_data1[:backtrace])
|
102
94
|
end
|
103
95
|
|
104
96
|
should "default its attrs" do
|
105
97
|
result = Base.new({})
|
106
98
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
99
|
+
assert_that(result.type).equals(:unknown)
|
100
|
+
assert_that(result.name).equals("")
|
101
|
+
assert_that(result.test_name).equals("")
|
102
|
+
assert_that(result.test_file_line).equals(Assert::FileLine.parse(""))
|
103
|
+
assert_that(result.message).equals("")
|
104
|
+
assert_that(result.output).equals("")
|
105
|
+
assert_that(result.backtrace).equals(Backtrace.new([]))
|
106
|
+
assert_that(result.trace).equals("")
|
115
107
|
end
|
116
108
|
|
117
109
|
should "know its test file line attrs" do
|
118
|
-
exp =
|
119
|
-
|
120
|
-
|
121
|
-
|
110
|
+
exp = given_data1[:test_file_line]
|
111
|
+
assert_that(subject.test_file_name).equals(exp.file)
|
112
|
+
assert_that(subject.test_line_num).equals(exp.line.to_i)
|
113
|
+
assert_that(subject.test_id).equals(exp.to_s)
|
122
114
|
end
|
123
115
|
|
124
116
|
should "allow setting a new backtrace" do
|
125
|
-
new_bt =
|
117
|
+
new_bt = Factory.backtrace
|
126
118
|
exp_backtrace = Backtrace.new(new_bt)
|
127
119
|
exp_trace = exp_backtrace.filtered.first.to_s
|
128
120
|
subject.set_backtrace(new_bt)
|
129
|
-
|
130
|
-
|
121
|
+
assert_that(subject.backtrace).equals(exp_backtrace)
|
122
|
+
assert_that(subject.trace).equals(exp_trace)
|
131
123
|
|
132
124
|
# test that the first bt line is used if filtered is empty
|
133
125
|
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
@@ -135,46 +127,46 @@ module Assert::Result
|
|
135
127
|
exp_backtrace = Backtrace.new(new_bt)
|
136
128
|
exp_trace = exp_backtrace.first.to_s
|
137
129
|
subject.set_backtrace(new_bt)
|
138
|
-
|
139
|
-
|
130
|
+
assert_that(subject.backtrace).equals(exp_backtrace)
|
131
|
+
assert_that(subject.trace).equals(exp_trace)
|
140
132
|
end
|
141
133
|
|
142
134
|
should "allow setting a with bt backtrace and know if one has been set" do
|
143
|
-
|
135
|
+
assert_that(subject.with_bt_set?).is_false
|
144
136
|
|
145
137
|
orig_backtrace = subject.backtrace
|
146
|
-
with_bt =
|
138
|
+
with_bt = Factory.backtrace
|
147
139
|
|
148
140
|
subject.set_with_bt(with_bt)
|
149
141
|
|
150
|
-
|
151
|
-
|
152
|
-
|
142
|
+
assert_that(subject.with_bt_set?).is_true
|
143
|
+
assert_that(subject.backtrace).equals(orig_backtrace)
|
144
|
+
assert_that(subject.src_line).equals(with_bt.first)
|
153
145
|
|
154
146
|
exp = Backtrace.to_s(with_bt + [orig_backtrace.filtered.first])
|
155
|
-
|
147
|
+
assert_that(subject.trace).equals(exp)
|
156
148
|
end
|
157
149
|
|
158
150
|
should "know its src/file line attrs" do
|
159
|
-
new_bt =
|
151
|
+
new_bt = Factory.backtrace
|
160
152
|
subject.set_backtrace(new_bt)
|
161
153
|
|
162
154
|
exp = Backtrace.new(new_bt).filtered.first.to_s
|
163
|
-
|
155
|
+
assert_that(subject.src_line).equals(exp)
|
164
156
|
|
165
157
|
exp = Assert::FileLine.parse(subject.src_line)
|
166
|
-
|
167
|
-
|
168
|
-
|
158
|
+
assert_that(subject.file_line).equals(exp)
|
159
|
+
assert_that(subject.file_name).equals(exp.file)
|
160
|
+
assert_that(subject.line_num).equals(exp.line.to_i)
|
169
161
|
|
170
162
|
# test you get the same file line attrs using `set_with_bt`
|
171
163
|
subject.set_with_bt(new_bt)
|
172
|
-
|
164
|
+
assert_that(subject.src_line).equals(new_bt.first.to_s)
|
173
165
|
|
174
166
|
exp = Assert::FileLine.parse(subject.src_line)
|
175
|
-
|
176
|
-
|
177
|
-
|
167
|
+
assert_that(subject.file_line).equals(exp)
|
168
|
+
assert_that(subject.file_name).equals(exp.file)
|
169
|
+
assert_that(subject.line_num).equals(exp.line.to_i)
|
178
170
|
|
179
171
|
# test that the first bt line is used if filtered is empty
|
180
172
|
assert_lib_path = File.join(ROOT_PATH, "lib/#{Factory.string}:#{Factory.integer}")
|
@@ -182,45 +174,45 @@ module Assert::Result
|
|
182
174
|
subject.set_backtrace(new_bt)
|
183
175
|
|
184
176
|
exp = new_bt.first.to_s
|
185
|
-
|
177
|
+
assert_that(subject.src_line).equals(exp)
|
186
178
|
|
187
179
|
exp = Assert::FileLine.parse(subject.src_line)
|
188
|
-
|
189
|
-
|
190
|
-
|
180
|
+
assert_that(subject.file_line).equals(exp)
|
181
|
+
assert_that(subject.file_name).equals(exp.file)
|
182
|
+
assert_that(subject.line_num).equals(exp.line.to_i)
|
191
183
|
end
|
192
184
|
|
193
185
|
should "know if it is a certain type of result" do
|
194
186
|
Assert::Result.types.keys.each do |type|
|
195
|
-
|
187
|
+
assert_that(subject.send("#{type}?")).is_false
|
196
188
|
Assert.stub(subject, :type){ type }
|
197
|
-
|
189
|
+
assert_that(subject.send("#{type}?")).is_true
|
198
190
|
end
|
199
191
|
end
|
200
192
|
|
201
193
|
should "know its symbol representation" do
|
202
|
-
|
194
|
+
assert_that(subject.to_sym).equals(subject.type)
|
203
195
|
end
|
204
196
|
|
205
197
|
should "know its string representation" do
|
206
198
|
str = subject.to_s
|
207
199
|
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
200
|
+
assert_that(str).includes(subject.name.upcase)
|
201
|
+
assert_that(str).includes(subject.test_name)
|
202
|
+
assert_that(str).includes(subject.message)
|
203
|
+
assert_that(str).includes(subject.trace)
|
212
204
|
|
213
|
-
|
205
|
+
assert_that(str.split("\n").count).equals(3)
|
214
206
|
|
215
207
|
Assert.stub(subject, :message){ "" }
|
216
208
|
Assert.stub(subject, :trace){ "" }
|
217
209
|
|
218
|
-
|
210
|
+
assert_that(subject.to_s.split("\n").count).equals(1)
|
219
211
|
end
|
220
212
|
|
221
213
|
should "know if it is equal to another result" do
|
222
|
-
other = Assert::Result::Base.new(
|
223
|
-
|
214
|
+
other = Assert::Result::Base.new(given_data1)
|
215
|
+
assert_that(subject).equals(other)
|
224
216
|
|
225
217
|
Assert.stub(other, [:type, :message].sample){ Factory.string }
|
226
218
|
assert_not_equal other, subject
|
@@ -231,220 +223,191 @@ module Assert::Result
|
|
231
223
|
"@message=#{subject.message.inspect} "\
|
232
224
|
"@file_line=#{subject.file_line.to_s.inspect} "\
|
233
225
|
"@test_file_line=#{subject.test_file_line.to_s.inspect}>"
|
234
|
-
|
226
|
+
assert_that(subject.inspect).equals(exp)
|
235
227
|
end
|
236
|
-
|
237
228
|
end
|
238
229
|
|
239
|
-
class
|
240
|
-
desc "Pass"
|
241
|
-
|
242
|
-
@result = Pass.new({})
|
243
|
-
end
|
244
|
-
subject { @result }
|
230
|
+
class InitPassTests < UnitTests
|
231
|
+
desc "Pass when init"
|
232
|
+
subject { Pass.new({}) }
|
245
233
|
|
246
234
|
should "know its type/name" do
|
247
|
-
|
248
|
-
|
249
|
-
|
235
|
+
assert_that(subject.type).equals(:pass)
|
236
|
+
assert_that(subject.class.type).equals(:pass)
|
237
|
+
assert_that(subject.class.name).equals("Pass")
|
250
238
|
end
|
251
|
-
|
252
239
|
end
|
253
240
|
|
254
|
-
class
|
255
|
-
desc "Ignore"
|
256
|
-
|
257
|
-
@result = Ignore.new({})
|
258
|
-
end
|
259
|
-
subject { @result }
|
241
|
+
class InitIgnoreTests < UnitTests
|
242
|
+
desc "Ignore when init"
|
243
|
+
subject { Ignore.new({}) }
|
260
244
|
|
261
245
|
should "know its type/name" do
|
262
|
-
|
263
|
-
|
264
|
-
|
246
|
+
assert_that(subject.type).equals(:ignore)
|
247
|
+
assert_that(subject.class.type).equals(:ignore)
|
248
|
+
assert_that(subject.class.name).equals("Ignore")
|
265
249
|
end
|
266
|
-
|
267
250
|
end
|
268
251
|
|
269
|
-
class
|
270
|
-
desc "HaltingTestResultError"
|
271
|
-
subject{ HaltingTestResultError.new }
|
252
|
+
class InitHaltingTestResultErrorTests < UnitTests
|
253
|
+
desc "HaltingTestResultError when init"
|
254
|
+
subject { HaltingTestResultError.new }
|
272
255
|
|
273
256
|
should have_accessors :assert_with_bt
|
274
257
|
|
275
258
|
should "be a runtime error" do
|
276
|
-
|
259
|
+
assert_that(subject).is_kind_of(RuntimeError)
|
277
260
|
end
|
278
|
-
|
279
261
|
end
|
280
262
|
|
281
|
-
class
|
282
|
-
desc "TestFailure"
|
283
|
-
subject{ TestFailure }
|
263
|
+
class InitTestFailureTests < UnitTests
|
264
|
+
desc "TestFailure when init"
|
265
|
+
subject { TestFailure.new }
|
284
266
|
|
285
267
|
should "be a halting test result error" do
|
286
|
-
|
268
|
+
assert_that(subject).is_kind_of(HaltingTestResultError)
|
287
269
|
end
|
288
|
-
|
289
270
|
end
|
290
271
|
|
291
|
-
class
|
292
|
-
desc "Fail"
|
293
|
-
|
294
|
-
@result = Fail.new({})
|
295
|
-
end
|
296
|
-
subject { @result }
|
272
|
+
class InitFailTests < UnitTests
|
273
|
+
desc "Fail when init"
|
274
|
+
subject { Fail.new({}) }
|
297
275
|
|
298
276
|
should "know its type/name" do
|
299
|
-
|
300
|
-
|
301
|
-
|
277
|
+
assert_that(subject.type).equals(:fail)
|
278
|
+
assert_that(subject.class.type).equals(:fail)
|
279
|
+
assert_that(subject.class.name).equals("Fail")
|
302
280
|
end
|
303
281
|
|
304
282
|
should "allow creating for a test with TestFailure exceptions" do
|
305
283
|
err = TestFailure.new
|
306
|
-
err.set_backtrace(
|
307
|
-
result = Fail.for_test(
|
284
|
+
err.set_backtrace(Factory.backtrace)
|
285
|
+
result = Fail.for_test(test1, err)
|
308
286
|
|
309
|
-
|
287
|
+
assert_that(result.message).equals(err.message)
|
310
288
|
|
311
289
|
err_backtrace = Backtrace.new(err.backtrace)
|
312
|
-
|
290
|
+
assert_that(result.backtrace).equals(err_backtrace)
|
313
291
|
|
314
292
|
# test assert with bt errors
|
315
|
-
err.assert_with_bt =
|
316
|
-
result = Fail.for_test(
|
293
|
+
err.assert_with_bt = Factory.backtrace
|
294
|
+
result = Fail.for_test(test1, err)
|
317
295
|
|
318
|
-
|
319
|
-
|
320
|
-
|
296
|
+
assert_that(result.message).equals(err.message)
|
297
|
+
assert_that(result.backtrace).equals(err.backtrace)
|
298
|
+
assert_that(result.src_line).equals(err.assert_with_bt.first)
|
321
299
|
|
322
300
|
exp = Backtrace.to_s(err.assert_with_bt + [err_backtrace.filtered.first])
|
323
|
-
|
301
|
+
assert_that(result.trace).equals(exp)
|
324
302
|
end
|
325
303
|
|
326
304
|
should "not allow creating for a test with non-TestFailure exceptions" do
|
327
|
-
|
305
|
+
assert_that(-> { Fail.for_test(test1, RuntimeError.new) }).raises(ArgumentError)
|
328
306
|
end
|
329
|
-
|
330
307
|
end
|
331
308
|
|
332
|
-
class
|
333
|
-
desc "TestSkipped"
|
334
|
-
subject{ TestSkipped }
|
309
|
+
class InitTestSkippedTests < UnitTests
|
310
|
+
desc "TestSkipped when init"
|
311
|
+
subject { TestSkipped.new }
|
335
312
|
|
336
313
|
should "be a halting test result error" do
|
337
|
-
|
314
|
+
assert_that(subject).is_kind_of(HaltingTestResultError)
|
338
315
|
end
|
339
|
-
|
340
316
|
end
|
341
317
|
|
342
|
-
class
|
343
|
-
desc "Skip"
|
344
|
-
|
345
|
-
@result = Skip.new({})
|
346
|
-
end
|
347
|
-
subject { @result }
|
318
|
+
class InitSkipTests < UnitTests
|
319
|
+
desc "Skip when init"
|
320
|
+
subject { Skip.new({}) }
|
348
321
|
|
349
322
|
should "know its type/name" do
|
350
|
-
|
351
|
-
|
352
|
-
|
323
|
+
assert_that(subject.type).equals(:skip)
|
324
|
+
assert_that(subject.class.type).equals(:skip)
|
325
|
+
assert_that(subject.class.name).equals("Skip")
|
353
326
|
end
|
354
327
|
|
355
328
|
should "allow creating for a test with TestSkipped exceptions" do
|
356
329
|
err = TestSkipped.new
|
357
|
-
err.set_backtrace(
|
358
|
-
result = Skip.for_test(
|
330
|
+
err.set_backtrace(Factory.backtrace)
|
331
|
+
result = Skip.for_test(test1, err)
|
359
332
|
|
360
|
-
|
333
|
+
assert_that(result.message).equals(err.message)
|
361
334
|
|
362
335
|
err_backtrace = Backtrace.new(err.backtrace)
|
363
|
-
|
336
|
+
assert_that(result.backtrace).equals(err_backtrace)
|
364
337
|
|
365
338
|
# test assert with bt errors
|
366
|
-
err.assert_with_bt =
|
367
|
-
result = Skip.for_test(
|
339
|
+
err.assert_with_bt = Factory.backtrace
|
340
|
+
result = Skip.for_test(test1, err)
|
368
341
|
|
369
|
-
|
370
|
-
|
371
|
-
|
342
|
+
assert_that(result.message).equals(err.message)
|
343
|
+
assert_that(result.backtrace).equals(err.backtrace)
|
344
|
+
assert_that(result.src_line).equals(err.assert_with_bt.first)
|
372
345
|
|
373
346
|
exp = Backtrace.to_s(err.assert_with_bt + [err_backtrace.filtered.first])
|
374
|
-
|
347
|
+
assert_that(result.trace).equals(exp)
|
375
348
|
end
|
376
349
|
|
377
350
|
should "not allow creating for a test with non-TestSkipped exceptions" do
|
378
|
-
|
351
|
+
assert_that(-> { Skip.for_test(test1, RuntimeError.new) }).raises(ArgumentError)
|
379
352
|
end
|
380
|
-
|
381
353
|
end
|
382
354
|
|
383
|
-
class
|
384
|
-
desc "Error"
|
385
|
-
|
386
|
-
@result = Error.new({})
|
387
|
-
end
|
388
|
-
subject { @result }
|
355
|
+
class InitErrorTests < UnitTests
|
356
|
+
desc "Error when init"
|
357
|
+
subject { Error.new({}) }
|
389
358
|
|
390
359
|
should "know its class-level type/name" do
|
391
|
-
|
392
|
-
|
360
|
+
assert_that(subject.class.type).equals(:error)
|
361
|
+
assert_that(subject.class.name).equals("Error")
|
393
362
|
end
|
394
363
|
|
395
364
|
should "allow creating for a test with exceptions" do
|
396
365
|
err = Exception.new
|
397
|
-
err.set_backtrace(
|
398
|
-
result = Error.for_test(
|
366
|
+
err.set_backtrace(Factory.backtrace)
|
367
|
+
result = Error.for_test(test1, err)
|
399
368
|
|
400
369
|
exp_msg = "#{err.message} (#{err.class.name})"
|
401
|
-
|
370
|
+
assert_that(result.message).equals(exp_msg)
|
402
371
|
|
403
372
|
exp_bt = Backtrace.new(err.backtrace)
|
404
|
-
|
405
|
-
|
373
|
+
assert_that(result.backtrace).equals(exp_bt)
|
374
|
+
assert_that(result.trace).equals(Backtrace.to_s(exp_bt))
|
406
375
|
end
|
407
376
|
|
408
377
|
should "not allow creating for a test without an exception" do
|
409
|
-
|
378
|
+
assert_that(-> { Error.for_test(test1, Factory.string) }).raises(ArgumentError)
|
410
379
|
end
|
411
|
-
|
412
380
|
end
|
413
381
|
|
414
|
-
class
|
415
|
-
desc "Backtrace"
|
416
|
-
|
417
|
-
@backtrace = Backtrace.new(build_backtrace)
|
418
|
-
end
|
419
|
-
subject { @backtrace }
|
382
|
+
class InitBacktraceTests < UnitTests
|
383
|
+
desc "Backtrace when init"
|
384
|
+
subject { Backtrace.new(Factory.backtrace) }
|
420
385
|
|
421
386
|
should have_cmeths :parse, :to_s
|
422
387
|
should have_imeths :filtered
|
423
388
|
|
424
389
|
should "be parseable from its string representation" do
|
425
|
-
|
390
|
+
assert_that(Backtrace.parse(Backtrace.to_s(subject))).equals(subject)
|
426
391
|
end
|
427
392
|
|
428
393
|
should "render as a string by joining on the newline" do
|
429
|
-
|
394
|
+
assert_that(Backtrace.to_s(subject)).equals(subject.join(Backtrace::DELIM))
|
430
395
|
end
|
431
396
|
|
432
397
|
should "be an Array" do
|
433
|
-
|
398
|
+
assert_that(subject).is_kind_of(::Array)
|
434
399
|
end
|
435
400
|
|
436
401
|
should "know its DELIM" do
|
437
|
-
|
402
|
+
assert_that(Backtrace::DELIM).equals("\n")
|
438
403
|
end
|
439
404
|
|
440
405
|
should "another backtrace when filtered" do
|
441
|
-
|
406
|
+
assert_that(subject).is_kind_of(Backtrace)
|
442
407
|
end
|
443
408
|
|
444
409
|
should "default itself when created from nil" do
|
445
|
-
|
410
|
+
assert_that(Backtrace.new).equals(["No backtrace"])
|
446
411
|
end
|
447
|
-
|
448
412
|
end
|
449
|
-
|
450
413
|
end
|