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