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