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