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