colorcode_convert_rgb 0.1.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 +7 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +23 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/colorcode_convert_rgb.gemspec +30 -0
- data/exe/colorcode_convert_rgb +4 -0
- data/lib/colorcode_convert_rgb.rb +7 -0
- data/lib/colorcode_convert_rgb/cli.rb +13 -0
- data/lib/colorcode_convert_rgb/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/bin/colorcode_convert_rgb +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/bin/thor +27 -0
- data/vendor/bundle/ruby/2.5.0/cache/minitest-5.14.2.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/rake-12.3.3.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/cache/thor-1.0.1.gem +0 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/.autotest +34 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/History.rdoc +1397 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Manifest.txt +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/README.rdoc +764 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/Rakefile +74 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/design_rationale.rb +52 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/hoe/minitest.rb +32 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest.rb +1056 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/assertions.rb +807 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/autorun.rb +13 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/benchmark.rb +455 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/expectations.rb +303 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/hell.rb +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/mock.rb +240 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/parallel.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/pride_plugin.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/spec.rb +342 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/test.rb +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/lib/minitest/unit.rb +45 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/metametameta.rb +136 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_assertions.rb +1575 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_benchmark.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_mock.rb +872 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_reporter.rb +299 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_spec.rb +1061 -0
- data/vendor/bundle/ruby/2.5.0/gems/minitest-5.14.2/test/minitest/test_minitest_test.rb +1084 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/CONTRIBUTING.rdoc +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Gemfile +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/History.rdoc +2344 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/MIT-LICENSE +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/README.rdoc +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/Rakefile +41 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/azure-pipelines.yml +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/bundle +105 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/console +7 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rake +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rdoc +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/rubocop +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/bin/setup +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/command_line_usage.rdoc +158 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile1 +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/Rakefile2 +35 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/a.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/b.c +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/example/main.c +11 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/glossary.rdoc +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/jamis.rb +592 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/proto_rake.rdoc +127 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rake.1 +156 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rakefile.rdoc +622 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/doc/rational.rdoc +151 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/exe/rake +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake.rb +71 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/application.rb +824 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/backtrace.rb +24 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/clean.rb +78 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cloneable.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/cpu_counter.rb +107 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/default_loader.rb +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/dsl_definition.rb +195 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/early_time.rb +22 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/core.rb +26 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/ext/string.rb +176 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_creation_task.rb +25 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_list.rb +435 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_task.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils.rb +137 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/file_utils_ext.rb +145 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_chain.rb +57 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/invocation_exception_mixin.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/late_time.rb +18 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/linked_list.rb +112 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/loaders/makefile.rb +54 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/multi_task.rb +14 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/name_space.rb +38 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/packagetask.rb +207 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/phony.rb +16 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/private_reader.rb +21 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/promise.rb +100 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/pseudo_status.rb +30 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_module.rb +67 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rake_test_loader.rb +27 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/rule_recursion_overflow_error.rb +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/scope.rb +43 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task.rb +413 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_argument_error.rb +8 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_arguments.rb +109 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/task_manager.rb +324 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/tasklib.rb +12 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/testtask.rb +224 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_history_display.rb +49 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/thread_pool.rb +163 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/trace_output.rb +23 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/version.rb +10 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/lib/rake/win32.rb +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/rake-12.3.3/rake.gemspec +42 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/.document +5 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CHANGELOG.md +220 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/CONTRIBUTING.md +15 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/LICENSE.md +20 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/README.md +51 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/bin/thor +6 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor.rb +517 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions.rb +336 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_file.rb +104 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/create_link.rb +61 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/directory.rb +108 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/empty_directory.rb +143 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/file_manipulation.rb +373 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/actions/inject_into_file.rb +120 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/base.rb +699 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/command.rb +142 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb +97 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/error.rb +110 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/group.rb +281 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/invocation.rb +178 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor.rb +17 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/basic.rb +37 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/line_editor/readline.rb +88 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/nested_context.rb +29 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser.rb +4 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/argument.rb +70 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/arguments.rb +175 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/option.rb +159 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/parser/options.rb +236 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/rake_compat.rb +72 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/runner.rb +325 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell.rb +81 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/basic.rb +491 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/color.rb +153 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/shell/html.rb +126 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/util.rb +284 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/lib/thor/version.rb +3 -0
- data/vendor/bundle/ruby/2.5.0/gems/thor-1.0.1/thor.gemspec +28 -0
- data/vendor/bundle/ruby/2.5.0/specifications/minitest-5.14.2.gemspec +38 -0
- data/vendor/bundle/ruby/2.5.0/specifications/rake-12.3.3.gemspec +43 -0
- data/vendor/bundle/ruby/2.5.0/specifications/thor-1.0.1.gemspec +34 -0
- metadata +214 -0
@@ -0,0 +1,299 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "minitest/metametameta"
|
3
|
+
|
4
|
+
class Runnable
|
5
|
+
def woot
|
6
|
+
assert true
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
class TestMinitestReporter < MetaMetaMetaTestCase
|
11
|
+
|
12
|
+
attr_accessor :r, :io
|
13
|
+
|
14
|
+
def new_composite_reporter
|
15
|
+
reporter = Minitest::CompositeReporter.new
|
16
|
+
reporter << Minitest::SummaryReporter.new(self.io)
|
17
|
+
reporter << Minitest::ProgressReporter.new(self.io)
|
18
|
+
|
19
|
+
def reporter.first
|
20
|
+
reporters.first
|
21
|
+
end
|
22
|
+
|
23
|
+
def reporter.results
|
24
|
+
first.results
|
25
|
+
end
|
26
|
+
|
27
|
+
def reporter.count
|
28
|
+
first.count
|
29
|
+
end
|
30
|
+
|
31
|
+
def reporter.assertions
|
32
|
+
first.assertions
|
33
|
+
end
|
34
|
+
|
35
|
+
reporter
|
36
|
+
end
|
37
|
+
|
38
|
+
def setup
|
39
|
+
self.io = StringIO.new("")
|
40
|
+
self.r = new_composite_reporter
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_test
|
44
|
+
unless defined? @et then
|
45
|
+
@et = Minitest::Test.new(:woot)
|
46
|
+
@et.failures << Minitest::UnexpectedError.new(begin
|
47
|
+
raise "no"
|
48
|
+
rescue => e
|
49
|
+
e
|
50
|
+
end)
|
51
|
+
@et = Minitest::Result.from @et
|
52
|
+
end
|
53
|
+
@et
|
54
|
+
end
|
55
|
+
|
56
|
+
def fail_test
|
57
|
+
unless defined? @ft then
|
58
|
+
@ft = Minitest::Test.new(:woot)
|
59
|
+
@ft.failures << begin
|
60
|
+
raise Minitest::Assertion, "boo"
|
61
|
+
rescue Minitest::Assertion => e
|
62
|
+
e
|
63
|
+
end
|
64
|
+
@ft = Minitest::Result.from @ft
|
65
|
+
end
|
66
|
+
@ft
|
67
|
+
end
|
68
|
+
|
69
|
+
def passing_test
|
70
|
+
@pt ||= Minitest::Result.from Minitest::Test.new(:woot)
|
71
|
+
end
|
72
|
+
|
73
|
+
def skip_test
|
74
|
+
unless defined? @st then
|
75
|
+
@st = Minitest::Test.new(:woot)
|
76
|
+
@st.failures << begin
|
77
|
+
raise Minitest::Skip
|
78
|
+
rescue Minitest::Assertion => e
|
79
|
+
e
|
80
|
+
end
|
81
|
+
@st = Minitest::Result.from @st
|
82
|
+
end
|
83
|
+
@st
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_to_s
|
87
|
+
r.record passing_test
|
88
|
+
r.record fail_test
|
89
|
+
assert_match "woot", r.first.to_s
|
90
|
+
end
|
91
|
+
|
92
|
+
def test_passed_eh_empty
|
93
|
+
assert_predicate r, :passed?
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_passed_eh_failure
|
97
|
+
r.results << fail_test
|
98
|
+
|
99
|
+
refute_predicate r, :passed?
|
100
|
+
end
|
101
|
+
|
102
|
+
SKIP_MSG = "\n\nYou have skipped tests. Run with --verbose for details."
|
103
|
+
|
104
|
+
def test_passed_eh_error
|
105
|
+
r.start
|
106
|
+
|
107
|
+
r.results << error_test
|
108
|
+
|
109
|
+
refute_predicate r, :passed?
|
110
|
+
|
111
|
+
r.report
|
112
|
+
|
113
|
+
refute_match SKIP_MSG, io.string
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_passed_eh_skipped
|
117
|
+
r.start
|
118
|
+
r.results << skip_test
|
119
|
+
assert r.passed?
|
120
|
+
|
121
|
+
restore_env do
|
122
|
+
r.report
|
123
|
+
end
|
124
|
+
|
125
|
+
assert_match SKIP_MSG, io.string
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_passed_eh_skipped_verbose
|
129
|
+
r.first.options[:verbose] = true
|
130
|
+
|
131
|
+
r.start
|
132
|
+
r.results << skip_test
|
133
|
+
assert r.passed?
|
134
|
+
r.report
|
135
|
+
|
136
|
+
refute_match SKIP_MSG, io.string
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_start
|
140
|
+
r.start
|
141
|
+
|
142
|
+
exp = "Run options: \n\n# Running:\n\n"
|
143
|
+
|
144
|
+
assert_equal exp, io.string
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_record_pass
|
148
|
+
r.record passing_test
|
149
|
+
|
150
|
+
assert_equal ".", io.string
|
151
|
+
assert_empty r.results
|
152
|
+
assert_equal 1, r.count
|
153
|
+
assert_equal 0, r.assertions
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_record_fail
|
157
|
+
fail_test = self.fail_test
|
158
|
+
r.record fail_test
|
159
|
+
|
160
|
+
assert_equal "F", io.string
|
161
|
+
assert_equal [fail_test], r.results
|
162
|
+
assert_equal 1, r.count
|
163
|
+
assert_equal 0, r.assertions
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_record_error
|
167
|
+
error_test = self.error_test
|
168
|
+
r.record error_test
|
169
|
+
|
170
|
+
assert_equal "E", io.string
|
171
|
+
assert_equal [error_test], r.results
|
172
|
+
assert_equal 1, r.count
|
173
|
+
assert_equal 0, r.assertions
|
174
|
+
end
|
175
|
+
|
176
|
+
def test_record_skip
|
177
|
+
skip_test = self.skip_test
|
178
|
+
r.record skip_test
|
179
|
+
|
180
|
+
assert_equal "S", io.string
|
181
|
+
assert_equal [skip_test], r.results
|
182
|
+
assert_equal 1, r.count
|
183
|
+
assert_equal 0, r.assertions
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_report_empty
|
187
|
+
r.start
|
188
|
+
r.report
|
189
|
+
|
190
|
+
exp = clean <<-EOM
|
191
|
+
Run options:
|
192
|
+
|
193
|
+
# Running:
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
Finished in 0.00
|
198
|
+
|
199
|
+
0 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
200
|
+
EOM
|
201
|
+
|
202
|
+
assert_equal exp, normalize_output(io.string)
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_report_passing
|
206
|
+
r.start
|
207
|
+
r.record passing_test
|
208
|
+
r.report
|
209
|
+
|
210
|
+
exp = clean <<-EOM
|
211
|
+
Run options:
|
212
|
+
|
213
|
+
# Running:
|
214
|
+
|
215
|
+
.
|
216
|
+
|
217
|
+
Finished in 0.00
|
218
|
+
|
219
|
+
1 runs, 0 assertions, 0 failures, 0 errors, 0 skips
|
220
|
+
EOM
|
221
|
+
|
222
|
+
assert_equal exp, normalize_output(io.string)
|
223
|
+
end
|
224
|
+
|
225
|
+
def test_report_failure
|
226
|
+
r.start
|
227
|
+
r.record fail_test
|
228
|
+
r.report
|
229
|
+
|
230
|
+
exp = clean <<-EOM
|
231
|
+
Run options:
|
232
|
+
|
233
|
+
# Running:
|
234
|
+
|
235
|
+
F
|
236
|
+
|
237
|
+
Finished in 0.00
|
238
|
+
|
239
|
+
1) Failure:
|
240
|
+
Minitest::Test#woot [FILE:LINE]:
|
241
|
+
boo
|
242
|
+
|
243
|
+
1 runs, 0 assertions, 1 failures, 0 errors, 0 skips
|
244
|
+
EOM
|
245
|
+
|
246
|
+
assert_equal exp, normalize_output(io.string)
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_report_error
|
250
|
+
r.start
|
251
|
+
r.record error_test
|
252
|
+
r.report
|
253
|
+
|
254
|
+
exp = clean <<-EOM
|
255
|
+
Run options:
|
256
|
+
|
257
|
+
# Running:
|
258
|
+
|
259
|
+
E
|
260
|
+
|
261
|
+
Finished in 0.00
|
262
|
+
|
263
|
+
1) Error:
|
264
|
+
Minitest::Test#woot:
|
265
|
+
RuntimeError: no
|
266
|
+
FILE:LINE:in `error_test'
|
267
|
+
FILE:LINE:in `test_report_error'
|
268
|
+
|
269
|
+
1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
|
270
|
+
EOM
|
271
|
+
|
272
|
+
assert_equal exp, normalize_output(io.string)
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_report_skipped
|
276
|
+
r.start
|
277
|
+
r.record skip_test
|
278
|
+
|
279
|
+
restore_env do
|
280
|
+
r.report
|
281
|
+
end
|
282
|
+
|
283
|
+
exp = clean <<-EOM
|
284
|
+
Run options:
|
285
|
+
|
286
|
+
# Running:
|
287
|
+
|
288
|
+
S
|
289
|
+
|
290
|
+
Finished in 0.00
|
291
|
+
|
292
|
+
1 runs, 0 assertions, 0 failures, 0 errors, 1 skips
|
293
|
+
|
294
|
+
You have skipped tests. Run with --verbose for details.
|
295
|
+
EOM
|
296
|
+
|
297
|
+
assert_equal exp, normalize_output(io.string)
|
298
|
+
end
|
299
|
+
end
|
@@ -0,0 +1,1061 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "minitest/metametameta"
|
3
|
+
require "stringio"
|
4
|
+
|
5
|
+
class MiniSpecA < Minitest::Spec; end
|
6
|
+
class MiniSpecB < Minitest::Test; extend Minitest::Spec::DSL; end
|
7
|
+
class MiniSpecC < MiniSpecB; end
|
8
|
+
class NamedExampleA < MiniSpecA; end
|
9
|
+
class NamedExampleB < MiniSpecB; end
|
10
|
+
class NamedExampleC < MiniSpecC; end
|
11
|
+
class ExampleA; end
|
12
|
+
class ExampleB < ExampleA; end
|
13
|
+
|
14
|
+
describe Minitest::Spec do
|
15
|
+
# helps to deal with 2.4 deprecation of Fixnum for Integer
|
16
|
+
Int = 1.class
|
17
|
+
|
18
|
+
# do not parallelize this suite... it just can"t handle it.
|
19
|
+
|
20
|
+
def assert_triggered expected = "blah", klass = Minitest::Assertion
|
21
|
+
@assertion_count += 1
|
22
|
+
|
23
|
+
e = assert_raises(klass) do
|
24
|
+
yield
|
25
|
+
end
|
26
|
+
|
27
|
+
msg = e.message.sub(/(---Backtrace---).*/m, '\1')
|
28
|
+
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
|
29
|
+
msg.gsub!(/(\d\.\d{6})\d+/, '\1xxx') # normalize: ruby version, impl, platform
|
30
|
+
msg.gsub!(/:0x[Xa-fA-F0-9]{4,}[ @].+?>/, ":0xXXXXXX@PATH>")
|
31
|
+
|
32
|
+
if expected
|
33
|
+
@assertion_count += 1
|
34
|
+
case expected
|
35
|
+
when String then
|
36
|
+
assert_equal expected, msg
|
37
|
+
when Regexp then
|
38
|
+
@assertion_count += 1
|
39
|
+
assert_match expected, msg
|
40
|
+
else
|
41
|
+
flunk "Unknown: #{expected.inspect}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def assert_success spec
|
47
|
+
assert_equal true, spec
|
48
|
+
end
|
49
|
+
|
50
|
+
before do
|
51
|
+
@assertion_count = 4
|
52
|
+
end
|
53
|
+
|
54
|
+
after do
|
55
|
+
_(self.assertions).must_equal @assertion_count if passed? and not skipped?
|
56
|
+
end
|
57
|
+
|
58
|
+
it "needs to be able to catch a Minitest::Assertion exception" do
|
59
|
+
@assertion_count = 1
|
60
|
+
|
61
|
+
assert_triggered "Expected 1 to not be equal to 1." do
|
62
|
+
_(1).wont_equal 1
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
it "needs to check for file existence" do
|
67
|
+
@assertion_count = 3
|
68
|
+
|
69
|
+
assert_success _(__FILE__).path_must_exist
|
70
|
+
|
71
|
+
assert_triggered "Expected path 'blah' to exist." do
|
72
|
+
_("blah").path_must_exist
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "needs to check for file non-existence" do
|
77
|
+
@assertion_count = 3
|
78
|
+
|
79
|
+
assert_success _("blah").path_wont_exist
|
80
|
+
|
81
|
+
assert_triggered "Expected path '#{__FILE__}' to not exist." do
|
82
|
+
_(__FILE__).path_wont_exist
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
it "needs to be sensible about must_include order" do
|
87
|
+
@assertion_count += 3 # must_include is 2 assertions
|
88
|
+
|
89
|
+
assert_success _([1, 2, 3]).must_include(2)
|
90
|
+
|
91
|
+
assert_triggered "Expected [1, 2, 3] to include 5." do
|
92
|
+
_([1, 2, 3]).must_include 5
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_triggered "msg.\nExpected [1, 2, 3] to include 5." do
|
96
|
+
_([1, 2, 3]).must_include 5, "msg"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it "needs to be sensible about wont_include order" do
|
101
|
+
@assertion_count += 3 # wont_include is 2 assertions
|
102
|
+
|
103
|
+
assert_success _([1, 2, 3]).wont_include(5)
|
104
|
+
|
105
|
+
assert_triggered "Expected [1, 2, 3] to not include 2." do
|
106
|
+
_([1, 2, 3]).wont_include 2
|
107
|
+
end
|
108
|
+
|
109
|
+
assert_triggered "msg.\nExpected [1, 2, 3] to not include 2." do
|
110
|
+
_([1, 2, 3]).wont_include 2, "msg"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "needs to catch an expected exception" do
|
115
|
+
@assertion_count = 2
|
116
|
+
|
117
|
+
expect { raise "blah" }.must_raise RuntimeError
|
118
|
+
expect { raise Minitest::Assertion }.must_raise Minitest::Assertion
|
119
|
+
end
|
120
|
+
|
121
|
+
it "needs to catch an unexpected exception" do
|
122
|
+
@assertion_count -= 2 # no positive
|
123
|
+
|
124
|
+
msg = <<-EOM.gsub(/^ {6}/, "").chomp
|
125
|
+
[RuntimeError] exception expected, not
|
126
|
+
Class: <StandardError>
|
127
|
+
Message: <"woot">
|
128
|
+
---Backtrace---
|
129
|
+
EOM
|
130
|
+
|
131
|
+
assert_triggered msg do
|
132
|
+
expect { raise StandardError, "woot" }.must_raise RuntimeError
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_triggered "msg.\n#{msg}" do
|
136
|
+
expect { raise StandardError, "woot" }.must_raise RuntimeError, "msg"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
it "needs to ensure silence" do
|
141
|
+
@assertion_count -= 1 # no msg
|
142
|
+
@assertion_count += 2 # assert_output is 2 assertions
|
143
|
+
|
144
|
+
assert_success expect {}.must_be_silent
|
145
|
+
|
146
|
+
assert_triggered "In stdout.\nExpected: \"\"\n Actual: \"xxx\"" do
|
147
|
+
expect { print "xxx" }.must_be_silent
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
it "needs to have all methods named well" do
|
152
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
153
|
+
|
154
|
+
@assertion_count = 2
|
155
|
+
|
156
|
+
methods = Minitest::Expectations.public_instance_methods.grep(/must|wont/)
|
157
|
+
methods.map!(&:to_s) if Symbol === methods.first
|
158
|
+
|
159
|
+
musts, wonts = methods.sort.partition { |m| m =~ /must/ }
|
160
|
+
|
161
|
+
expected_musts = %w[must_be
|
162
|
+
must_be_close_to
|
163
|
+
must_be_empty
|
164
|
+
must_be_instance_of
|
165
|
+
must_be_kind_of
|
166
|
+
must_be_nil
|
167
|
+
must_be_same_as
|
168
|
+
must_be_silent
|
169
|
+
must_be_within_delta
|
170
|
+
must_be_within_epsilon
|
171
|
+
must_equal
|
172
|
+
must_include
|
173
|
+
must_match
|
174
|
+
must_output
|
175
|
+
must_raise
|
176
|
+
must_respond_to
|
177
|
+
must_throw
|
178
|
+
path_must_exist]
|
179
|
+
|
180
|
+
bad = %w[not raise throw send output be_silent]
|
181
|
+
|
182
|
+
expected_wonts = expected_musts.map { |m| m.sub(/must/, "wont") }.sort
|
183
|
+
expected_wonts.reject! { |m| m =~ /wont_#{Regexp.union(*bad)}/ }
|
184
|
+
|
185
|
+
_(musts).must_equal expected_musts
|
186
|
+
_(wonts).must_equal expected_wonts
|
187
|
+
end
|
188
|
+
|
189
|
+
it "needs to raise if an expected exception is not raised" do
|
190
|
+
@assertion_count -= 2 # no positive test
|
191
|
+
|
192
|
+
assert_triggered "RuntimeError expected but nothing was raised." do
|
193
|
+
expect { 42 }.must_raise RuntimeError
|
194
|
+
end
|
195
|
+
|
196
|
+
assert_triggered "msg.\nRuntimeError expected but nothing was raised." do
|
197
|
+
expect { 42 }.must_raise RuntimeError, "msg"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
it "needs to verify binary messages" do
|
202
|
+
assert_success _(42).wont_be(:<, 24)
|
203
|
+
|
204
|
+
assert_triggered "Expected 24 to not be < 42." do
|
205
|
+
_(24).wont_be :<, 42
|
206
|
+
end
|
207
|
+
|
208
|
+
assert_triggered "msg.\nExpected 24 to not be < 42." do
|
209
|
+
_(24).wont_be :<, 42, "msg"
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
it "needs to verify emptyness" do
|
214
|
+
@assertion_count += 3 # empty is 2 assertions
|
215
|
+
|
216
|
+
assert_success _([]).must_be_empty
|
217
|
+
|
218
|
+
assert_triggered "Expected [42] to be empty." do
|
219
|
+
_([42]).must_be_empty
|
220
|
+
end
|
221
|
+
|
222
|
+
assert_triggered "msg.\nExpected [42] to be empty." do
|
223
|
+
_([42]).must_be_empty "msg"
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
it "needs to verify equality" do
|
228
|
+
@assertion_count += 1
|
229
|
+
|
230
|
+
assert_success _(6 * 7).must_equal(42)
|
231
|
+
|
232
|
+
assert_triggered "Expected: 42\n Actual: 54" do
|
233
|
+
_(6 * 9).must_equal 42
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_triggered "msg.\nExpected: 42\n Actual: 54" do
|
237
|
+
_(6 * 9).must_equal 42, "msg"
|
238
|
+
end
|
239
|
+
|
240
|
+
assert_triggered(/^-42\n\+#<Proc:0xXXXXXX[ @]PATH>\n/) do
|
241
|
+
_(proc { 42 }).must_equal 42 # proc isn't called, so expectation fails
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
it "needs to warn on equality with nil" do
|
246
|
+
@assertion_count += 1 # extra test
|
247
|
+
|
248
|
+
out, err = capture_io do
|
249
|
+
assert_success _(nil).must_equal(nil)
|
250
|
+
end
|
251
|
+
|
252
|
+
exp = "DEPRECATED: Use assert_nil if expecting nil from #{__FILE__}:#{__LINE__-3}. " \
|
253
|
+
"This will fail in Minitest 6.\n"
|
254
|
+
exp = "" if $-w.nil?
|
255
|
+
|
256
|
+
assert_empty out
|
257
|
+
assert_equal exp, err
|
258
|
+
end
|
259
|
+
|
260
|
+
it "needs to verify floats outside a delta" do
|
261
|
+
@assertion_count += 1 # extra test
|
262
|
+
|
263
|
+
assert_success _(24).wont_be_close_to(42)
|
264
|
+
|
265
|
+
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= 0.001." do
|
266
|
+
_(6 * 7.0).wont_be_close_to 42
|
267
|
+
end
|
268
|
+
|
269
|
+
x = "1.0e-05"
|
270
|
+
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
271
|
+
_(6 * 7.0).wont_be_close_to 42, 0.00001
|
272
|
+
end
|
273
|
+
|
274
|
+
assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
|
275
|
+
_(6 * 7.0).wont_be_close_to 42, 0.00001, "msg"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
it "needs to verify floats outside an epsilon" do
|
280
|
+
@assertion_count += 1 # extra test
|
281
|
+
|
282
|
+
assert_success _(24).wont_be_within_epsilon(42)
|
283
|
+
|
284
|
+
x = "0.042"
|
285
|
+
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
286
|
+
_(6 * 7.0).wont_be_within_epsilon 42
|
287
|
+
end
|
288
|
+
|
289
|
+
x = "0.00042"
|
290
|
+
assert_triggered "Expected |42 - 42.0| (0.0) to not be <= #{x}." do
|
291
|
+
_(6 * 7.0).wont_be_within_epsilon 42, 0.00001
|
292
|
+
end
|
293
|
+
|
294
|
+
assert_triggered "msg.\nExpected |42 - 42.0| (0.0) to not be <= #{x}." do
|
295
|
+
_(6 * 7.0).wont_be_within_epsilon 42, 0.00001, "msg"
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
it "needs to verify floats within a delta" do
|
300
|
+
@assertion_count += 1 # extra test
|
301
|
+
|
302
|
+
assert_success _(6.0 * 7).must_be_close_to(42.0)
|
303
|
+
|
304
|
+
assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.001." do
|
305
|
+
_(1.0 / 100).must_be_close_to 0.0
|
306
|
+
end
|
307
|
+
|
308
|
+
x = "1.0e-06"
|
309
|
+
assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
310
|
+
_(1.0 / 1000).must_be_close_to 0.0, 0.000001
|
311
|
+
end
|
312
|
+
|
313
|
+
assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= #{x}." do
|
314
|
+
_(1.0 / 1000).must_be_close_to 0.0, 0.000001, "msg"
|
315
|
+
end
|
316
|
+
end
|
317
|
+
|
318
|
+
it "needs to verify floats within an epsilon" do
|
319
|
+
@assertion_count += 1 # extra test
|
320
|
+
|
321
|
+
assert_success _(6.0 * 7).must_be_within_epsilon(42.0)
|
322
|
+
|
323
|
+
assert_triggered "Expected |0.0 - 0.01| (0.01) to be <= 0.0." do
|
324
|
+
_(1.0 / 100).must_be_within_epsilon 0.0
|
325
|
+
end
|
326
|
+
|
327
|
+
assert_triggered "Expected |0.0 - 0.001| (0.001) to be <= 0.0." do
|
328
|
+
_(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001
|
329
|
+
end
|
330
|
+
|
331
|
+
assert_triggered "msg.\nExpected |0.0 - 0.001| (0.001) to be <= 0.0." do
|
332
|
+
_(1.0 / 1000).must_be_within_epsilon 0.0, 0.000001, "msg"
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
it "needs to verify identity" do
|
337
|
+
assert_success _(1).must_be_same_as(1)
|
338
|
+
|
339
|
+
assert_triggered "Expected 1 (oid=N) to be the same as 2 (oid=N)." do
|
340
|
+
_(1).must_be_same_as 2
|
341
|
+
end
|
342
|
+
|
343
|
+
assert_triggered "msg.\nExpected 1 (oid=N) to be the same as 2 (oid=N)." do
|
344
|
+
_(1).must_be_same_as 2, "msg"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
|
348
|
+
it "needs to verify inequality" do
|
349
|
+
@assertion_count += 2
|
350
|
+
assert_success _(42).wont_equal(6 * 9)
|
351
|
+
assert_success _(proc {}).wont_equal(42)
|
352
|
+
|
353
|
+
assert_triggered "Expected 1 to not be equal to 1." do
|
354
|
+
_(1).wont_equal 1
|
355
|
+
end
|
356
|
+
|
357
|
+
assert_triggered "msg.\nExpected 1 to not be equal to 1." do
|
358
|
+
_(1).wont_equal 1, "msg"
|
359
|
+
end
|
360
|
+
end
|
361
|
+
|
362
|
+
it "needs to verify instances of a class" do
|
363
|
+
assert_success _(42).wont_be_instance_of(String)
|
364
|
+
|
365
|
+
assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
|
366
|
+
_(42).wont_be_kind_of Int
|
367
|
+
end
|
368
|
+
|
369
|
+
assert_triggered "msg.\nExpected 42 to not be an instance of #{Int.name}." do
|
370
|
+
_(42).wont_be_instance_of Int, "msg"
|
371
|
+
end
|
372
|
+
end
|
373
|
+
|
374
|
+
it "needs to verify kinds of a class" do
|
375
|
+
@assertion_count += 2
|
376
|
+
|
377
|
+
assert_success _(42).wont_be_kind_of(String)
|
378
|
+
assert_success _(proc {}).wont_be_kind_of(String)
|
379
|
+
|
380
|
+
assert_triggered "Expected 42 to not be a kind of #{Int.name}." do
|
381
|
+
_(42).wont_be_kind_of Int
|
382
|
+
end
|
383
|
+
|
384
|
+
assert_triggered "msg.\nExpected 42 to not be a kind of #{Int.name}." do
|
385
|
+
_(42).wont_be_kind_of Int, "msg"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
|
389
|
+
it "needs to verify kinds of objects" do
|
390
|
+
@assertion_count += 3 # extra test
|
391
|
+
|
392
|
+
assert_success _(6 * 7).must_be_kind_of(Int)
|
393
|
+
assert_success _(6 * 7).must_be_kind_of(Numeric)
|
394
|
+
|
395
|
+
assert_triggered "Expected 42 to be a kind of String, not #{Int.name}." do
|
396
|
+
_(6 * 7).must_be_kind_of String
|
397
|
+
end
|
398
|
+
|
399
|
+
assert_triggered "msg.\nExpected 42 to be a kind of String, not #{Int.name}." do
|
400
|
+
_(6 * 7).must_be_kind_of String, "msg"
|
401
|
+
end
|
402
|
+
|
403
|
+
exp = "Expected #<Proc:0xXXXXXX@PATH> to be a kind of String, not Proc."
|
404
|
+
assert_triggered exp do
|
405
|
+
_(proc {}).must_be_kind_of String
|
406
|
+
end
|
407
|
+
end
|
408
|
+
|
409
|
+
it "needs to verify mismatch" do
|
410
|
+
@assertion_count += 3 # match is 2
|
411
|
+
|
412
|
+
assert_success _("blah").wont_match(/\d+/)
|
413
|
+
|
414
|
+
assert_triggered "Expected /\\w+/ to not match \"blah\"." do
|
415
|
+
_("blah").wont_match(/\w+/)
|
416
|
+
end
|
417
|
+
|
418
|
+
assert_triggered "msg.\nExpected /\\w+/ to not match \"blah\"." do
|
419
|
+
_("blah").wont_match(/\w+/, "msg")
|
420
|
+
end
|
421
|
+
end
|
422
|
+
|
423
|
+
it "needs to verify nil" do
|
424
|
+
assert_success _(nil).must_be_nil
|
425
|
+
|
426
|
+
assert_triggered "Expected 42 to be nil." do
|
427
|
+
_(42).must_be_nil
|
428
|
+
end
|
429
|
+
|
430
|
+
assert_triggered "msg.\nExpected 42 to be nil." do
|
431
|
+
_(42).must_be_nil "msg"
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
it "needs to verify non-emptyness" do
|
436
|
+
@assertion_count += 3 # empty is 2 assertions
|
437
|
+
|
438
|
+
assert_success _(["some item"]).wont_be_empty
|
439
|
+
|
440
|
+
assert_triggered "Expected [] to not be empty." do
|
441
|
+
_([]).wont_be_empty
|
442
|
+
end
|
443
|
+
|
444
|
+
assert_triggered "msg.\nExpected [] to not be empty." do
|
445
|
+
_([]).wont_be_empty "msg"
|
446
|
+
end
|
447
|
+
end
|
448
|
+
|
449
|
+
it "needs to verify non-identity" do
|
450
|
+
assert_success _(1).wont_be_same_as(2)
|
451
|
+
|
452
|
+
assert_triggered "Expected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
453
|
+
_(1).wont_be_same_as 1
|
454
|
+
end
|
455
|
+
|
456
|
+
assert_triggered "msg.\nExpected 1 (oid=N) to not be the same as 1 (oid=N)." do
|
457
|
+
_(1).wont_be_same_as 1, "msg"
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
it "needs to verify non-nil" do
|
462
|
+
assert_success _(42).wont_be_nil
|
463
|
+
|
464
|
+
assert_triggered "Expected nil to not be nil." do
|
465
|
+
_(nil).wont_be_nil
|
466
|
+
end
|
467
|
+
|
468
|
+
assert_triggered "msg.\nExpected nil to not be nil." do
|
469
|
+
_(nil).wont_be_nil "msg"
|
470
|
+
end
|
471
|
+
end
|
472
|
+
|
473
|
+
it "needs to verify objects not responding to a message" do
|
474
|
+
assert_success _("").wont_respond_to(:woot!)
|
475
|
+
|
476
|
+
assert_triggered "Expected \"\" to not respond to to_s." do
|
477
|
+
_("").wont_respond_to :to_s
|
478
|
+
end
|
479
|
+
|
480
|
+
assert_triggered "msg.\nExpected \"\" to not respond to to_s." do
|
481
|
+
_("").wont_respond_to :to_s, "msg"
|
482
|
+
end
|
483
|
+
end
|
484
|
+
|
485
|
+
it "needs to verify output in stderr" do
|
486
|
+
@assertion_count -= 1 # no msg
|
487
|
+
|
488
|
+
assert_success expect { $stderr.print "blah" }.must_output(nil, "blah")
|
489
|
+
|
490
|
+
assert_triggered "In stderr.\nExpected: \"blah\"\n Actual: \"xxx\"" do
|
491
|
+
expect { $stderr.print "xxx" }.must_output(nil, "blah")
|
492
|
+
end
|
493
|
+
end
|
494
|
+
|
495
|
+
it "needs to verify output in stdout" do
|
496
|
+
@assertion_count -= 1 # no msg
|
497
|
+
|
498
|
+
assert_success expect { print "blah" }.must_output("blah")
|
499
|
+
|
500
|
+
assert_triggered "In stdout.\nExpected: \"blah\"\n Actual: \"xxx\"" do
|
501
|
+
expect { print "xxx" }.must_output("blah")
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
it "needs to verify regexp matches" do
|
506
|
+
@assertion_count += 3 # must_match is 2 assertions
|
507
|
+
|
508
|
+
assert_success _("blah").must_match(/\w+/)
|
509
|
+
|
510
|
+
assert_triggered "Expected /\\d+/ to match \"blah\"." do
|
511
|
+
_("blah").must_match(/\d+/)
|
512
|
+
end
|
513
|
+
|
514
|
+
assert_triggered "msg.\nExpected /\\d+/ to match \"blah\"." do
|
515
|
+
_("blah").must_match(/\d+/, "msg")
|
516
|
+
end
|
517
|
+
end
|
518
|
+
|
519
|
+
describe "expect" do
|
520
|
+
before do
|
521
|
+
@assertion_count -= 3
|
522
|
+
end
|
523
|
+
|
524
|
+
it "can use expect" do
|
525
|
+
_(1 + 1).must_equal 2
|
526
|
+
end
|
527
|
+
|
528
|
+
it "can use expect with a lambda" do
|
529
|
+
_ { raise "blah" }.must_raise RuntimeError
|
530
|
+
end
|
531
|
+
|
532
|
+
it "can use expect in a thread" do
|
533
|
+
Thread.new { _(1 + 1).must_equal 2 }.join
|
534
|
+
end
|
535
|
+
|
536
|
+
it "can NOT use must_equal in a thread. It must use expect in a thread" do
|
537
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
538
|
+
assert_raises RuntimeError do
|
539
|
+
capture_io do
|
540
|
+
Thread.new { (1 + 1).must_equal 2 }.join
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
it "fails gracefully when expectation used outside of `it`" do
|
546
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
547
|
+
|
548
|
+
@assertion_count += 1
|
549
|
+
|
550
|
+
e = assert_raises RuntimeError do
|
551
|
+
capture_io do
|
552
|
+
Thread.new { # forces ctx to be nil
|
553
|
+
describe("woot") do
|
554
|
+
(1 + 1).must_equal 2
|
555
|
+
end
|
556
|
+
}.join
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
assert_equal "Calling #must_equal outside of test.", e.message
|
561
|
+
end
|
562
|
+
|
563
|
+
it "deprecates expectation used without _" do
|
564
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
565
|
+
|
566
|
+
@assertion_count += 3
|
567
|
+
|
568
|
+
exp = /DEPRECATED: global use of must_equal from/
|
569
|
+
|
570
|
+
assert_output "", exp do
|
571
|
+
(1 + 1).must_equal 2
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
575
|
+
# https://github.com/seattlerb/minitest/issues/837
|
576
|
+
# https://github.com/rails/rails/pull/39304
|
577
|
+
it "deprecates expectation used without _ with empty backtrace_filter" do
|
578
|
+
skip "N/A" if ENV["MT_NO_EXPECTATIONS"]
|
579
|
+
|
580
|
+
@assertion_count += 3
|
581
|
+
|
582
|
+
exp = /DEPRECATED: global use of must_equal from/
|
583
|
+
|
584
|
+
with_empty_backtrace_filter do
|
585
|
+
assert_output "", exp do
|
586
|
+
(1 + 1).must_equal 2
|
587
|
+
end
|
588
|
+
end
|
589
|
+
end
|
590
|
+
end
|
591
|
+
|
592
|
+
it "needs to verify throw" do
|
593
|
+
@assertion_count += 2 # 2 extra tests
|
594
|
+
|
595
|
+
assert_success expect { throw :blah }.must_throw(:blah)
|
596
|
+
|
597
|
+
assert_triggered "Expected :blah to have been thrown." do
|
598
|
+
expect {}.must_throw :blah
|
599
|
+
end
|
600
|
+
|
601
|
+
assert_triggered "Expected :blah to have been thrown, not :xxx." do
|
602
|
+
expect { throw :xxx }.must_throw :blah
|
603
|
+
end
|
604
|
+
|
605
|
+
assert_triggered "msg.\nExpected :blah to have been thrown." do
|
606
|
+
expect {}.must_throw :blah, "msg"
|
607
|
+
end
|
608
|
+
|
609
|
+
assert_triggered "msg.\nExpected :blah to have been thrown, not :xxx." do
|
610
|
+
expect { throw :xxx }.must_throw :blah, "msg"
|
611
|
+
end
|
612
|
+
end
|
613
|
+
|
614
|
+
it "needs to verify types of objects" do
|
615
|
+
assert_success _(6 * 7).must_be_instance_of(Int)
|
616
|
+
|
617
|
+
exp = "Expected 42 to be an instance of String, not #{Int.name}."
|
618
|
+
|
619
|
+
assert_triggered exp do
|
620
|
+
_(6 * 7).must_be_instance_of String
|
621
|
+
end
|
622
|
+
|
623
|
+
assert_triggered "msg.\n#{exp}" do
|
624
|
+
_(6 * 7).must_be_instance_of String, "msg"
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
628
|
+
it "needs to verify using any (negative) predicate" do
|
629
|
+
@assertion_count -= 1 # doesn"t take a message
|
630
|
+
|
631
|
+
assert_success _("blah").wont_be(:empty?)
|
632
|
+
|
633
|
+
assert_triggered "Expected \"\" to not be empty?." do
|
634
|
+
_("").wont_be :empty?
|
635
|
+
end
|
636
|
+
end
|
637
|
+
|
638
|
+
it "needs to verify using any binary operator" do
|
639
|
+
@assertion_count -= 1 # no msg
|
640
|
+
|
641
|
+
assert_success _(41).must_be(:<, 42)
|
642
|
+
|
643
|
+
assert_triggered "Expected 42 to be < 41." do
|
644
|
+
_(42).must_be(:<, 41)
|
645
|
+
end
|
646
|
+
end
|
647
|
+
|
648
|
+
it "needs to verify using any predicate" do
|
649
|
+
@assertion_count -= 1 # no msg
|
650
|
+
|
651
|
+
assert_success _("").must_be(:empty?)
|
652
|
+
|
653
|
+
assert_triggered "Expected \"blah\" to be empty?." do
|
654
|
+
_("blah").must_be :empty?
|
655
|
+
end
|
656
|
+
end
|
657
|
+
|
658
|
+
it "needs to verify using respond_to" do
|
659
|
+
assert_success _(42).must_respond_to(:+)
|
660
|
+
|
661
|
+
assert_triggered "Expected 42 (#{Int.name}) to respond to #clear." do
|
662
|
+
_(42).must_respond_to :clear
|
663
|
+
end
|
664
|
+
|
665
|
+
assert_triggered "msg.\nExpected 42 (#{Int.name}) to respond to #clear." do
|
666
|
+
_(42).must_respond_to :clear, "msg"
|
667
|
+
end
|
668
|
+
end
|
669
|
+
end
|
670
|
+
|
671
|
+
describe Minitest::Spec, :let do
|
672
|
+
i_suck_and_my_tests_are_order_dependent!
|
673
|
+
|
674
|
+
def _count
|
675
|
+
$let_count ||= 0
|
676
|
+
end
|
677
|
+
|
678
|
+
let :count do
|
679
|
+
$let_count += 1
|
680
|
+
$let_count
|
681
|
+
end
|
682
|
+
|
683
|
+
it "is evaluated once per example" do
|
684
|
+
_(_count).must_equal 0
|
685
|
+
|
686
|
+
_(count).must_equal 1
|
687
|
+
_(count).must_equal 1
|
688
|
+
|
689
|
+
_(_count).must_equal 1
|
690
|
+
end
|
691
|
+
|
692
|
+
it "is REALLY evaluated once per example" do
|
693
|
+
_(_count).must_equal 1
|
694
|
+
|
695
|
+
_(count).must_equal 2
|
696
|
+
_(count).must_equal 2
|
697
|
+
|
698
|
+
_(_count).must_equal 2
|
699
|
+
end
|
700
|
+
|
701
|
+
it 'raises an error if the name begins with "test"' do
|
702
|
+
expect { self.class.let(:test_value) { true } }.must_raise ArgumentError
|
703
|
+
end
|
704
|
+
|
705
|
+
it "raises an error if the name shadows a normal instance method" do
|
706
|
+
expect { self.class.let(:message) { true } }.must_raise ArgumentError
|
707
|
+
end
|
708
|
+
|
709
|
+
it "doesn't raise an error if it is just another let" do
|
710
|
+
v = proc do
|
711
|
+
describe :outer do
|
712
|
+
let(:bar)
|
713
|
+
describe :inner do
|
714
|
+
let(:bar)
|
715
|
+
end
|
716
|
+
end
|
717
|
+
:good
|
718
|
+
end.call
|
719
|
+
_(v).must_equal :good
|
720
|
+
end
|
721
|
+
|
722
|
+
it "procs come after dont_flip" do
|
723
|
+
p = proc {}
|
724
|
+
assert_respond_to p, :call
|
725
|
+
_(p).must_respond_to :call
|
726
|
+
end
|
727
|
+
end
|
728
|
+
|
729
|
+
describe Minitest::Spec, :subject do
|
730
|
+
attr_reader :subject_evaluation_count
|
731
|
+
|
732
|
+
subject do
|
733
|
+
@subject_evaluation_count ||= 0
|
734
|
+
@subject_evaluation_count += 1
|
735
|
+
@subject_evaluation_count
|
736
|
+
end
|
737
|
+
|
738
|
+
it "is evaluated once per example" do
|
739
|
+
_(subject).must_equal 1
|
740
|
+
_(subject).must_equal 1
|
741
|
+
_(subject_evaluation_count).must_equal 1
|
742
|
+
end
|
743
|
+
end
|
744
|
+
|
745
|
+
class TestMetaStatic < Minitest::Test
|
746
|
+
def test_children
|
747
|
+
Minitest::Spec.children.clear # prevents parallel run
|
748
|
+
|
749
|
+
y = z = nil
|
750
|
+
x = describe "top-level thingy" do
|
751
|
+
y = describe "first thingy" do end
|
752
|
+
|
753
|
+
it "top-level-it" do end
|
754
|
+
|
755
|
+
z = describe "second thingy" do end
|
756
|
+
end
|
757
|
+
|
758
|
+
assert_equal [x], Minitest::Spec.children
|
759
|
+
assert_equal [y, z], x.children
|
760
|
+
assert_equal [], y.children
|
761
|
+
assert_equal [], z.children
|
762
|
+
end
|
763
|
+
|
764
|
+
def test_it_wont_remove_existing_child_test_methods
|
765
|
+
Minitest::Spec.children.clear # prevents parallel run
|
766
|
+
|
767
|
+
inner = nil
|
768
|
+
outer = describe "outer" do
|
769
|
+
inner = describe "inner" do
|
770
|
+
it do
|
771
|
+
assert true
|
772
|
+
end
|
773
|
+
end
|
774
|
+
it do
|
775
|
+
assert true
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
779
|
+
assert_equal 1, outer.public_instance_methods.grep(/^test_/).count
|
780
|
+
assert_equal 1, inner.public_instance_methods.grep(/^test_/).count
|
781
|
+
end
|
782
|
+
|
783
|
+
def test_it_wont_add_test_methods_to_children
|
784
|
+
Minitest::Spec.children.clear # prevents parallel run
|
785
|
+
|
786
|
+
inner = nil
|
787
|
+
outer = describe "outer" do
|
788
|
+
inner = describe "inner" do end
|
789
|
+
it do
|
790
|
+
assert true
|
791
|
+
end
|
792
|
+
end
|
793
|
+
|
794
|
+
assert_equal 1, outer.public_instance_methods.grep(/^test_/).count
|
795
|
+
assert_equal 0, inner.public_instance_methods.grep(/^test_/).count
|
796
|
+
end
|
797
|
+
end
|
798
|
+
|
799
|
+
class TestMeta < MetaMetaMetaTestCase
|
800
|
+
# do not call parallelize_me! here because specs use register_spec_type globally
|
801
|
+
|
802
|
+
def util_structure
|
803
|
+
y = z = nil
|
804
|
+
before_list = []
|
805
|
+
after_list = []
|
806
|
+
x = describe "top-level thingy" do
|
807
|
+
before { before_list << 1 }
|
808
|
+
after { after_list << 1 }
|
809
|
+
|
810
|
+
it "top-level-it" do end
|
811
|
+
|
812
|
+
y = describe "inner thingy" do
|
813
|
+
before { before_list << 2 }
|
814
|
+
after { after_list << 2 }
|
815
|
+
it "inner-it" do end
|
816
|
+
|
817
|
+
z = describe "very inner thingy" do
|
818
|
+
before { before_list << 3 }
|
819
|
+
after { after_list << 3 }
|
820
|
+
it "inner-it" do end
|
821
|
+
|
822
|
+
it { } # ignore me
|
823
|
+
specify { } # anonymous it
|
824
|
+
end
|
825
|
+
end
|
826
|
+
end
|
827
|
+
|
828
|
+
return x, y, z, before_list, after_list
|
829
|
+
end
|
830
|
+
|
831
|
+
def test_register_spec_type
|
832
|
+
original_types = Minitest::Spec::TYPES.dup
|
833
|
+
|
834
|
+
assert_includes Minitest::Spec::TYPES, [//, Minitest::Spec]
|
835
|
+
|
836
|
+
Minitest::Spec.register_spec_type(/woot/, TestMeta)
|
837
|
+
|
838
|
+
p = lambda do |_| true end
|
839
|
+
Minitest::Spec.register_spec_type TestMeta, &p
|
840
|
+
|
841
|
+
keys = Minitest::Spec::TYPES.map(&:first)
|
842
|
+
|
843
|
+
assert_includes keys, /woot/
|
844
|
+
assert_includes keys, p
|
845
|
+
ensure
|
846
|
+
Minitest::Spec::TYPES.replace original_types
|
847
|
+
end
|
848
|
+
|
849
|
+
def test_spec_type
|
850
|
+
original_types = Minitest::Spec::TYPES.dup
|
851
|
+
|
852
|
+
Minitest::Spec.register_spec_type(/A$/, MiniSpecA)
|
853
|
+
Minitest::Spec.register_spec_type MiniSpecB do |desc|
|
854
|
+
desc.superclass == ExampleA
|
855
|
+
end
|
856
|
+
Minitest::Spec.register_spec_type MiniSpecC do |_desc, *addl|
|
857
|
+
addl.include? :woot
|
858
|
+
end
|
859
|
+
|
860
|
+
assert_equal MiniSpecA, Minitest::Spec.spec_type(ExampleA)
|
861
|
+
assert_equal MiniSpecB, Minitest::Spec.spec_type(ExampleB)
|
862
|
+
assert_equal MiniSpecC, Minitest::Spec.spec_type(ExampleB, :woot)
|
863
|
+
ensure
|
864
|
+
Minitest::Spec::TYPES.replace original_types
|
865
|
+
end
|
866
|
+
|
867
|
+
def test_bug_dsl_expectations
|
868
|
+
spec_class = Class.new MiniSpecB do
|
869
|
+
it "should work" do
|
870
|
+
_(0).must_equal 0
|
871
|
+
end
|
872
|
+
end
|
873
|
+
|
874
|
+
test_name = spec_class.instance_methods.sort.grep(/test/).first
|
875
|
+
|
876
|
+
spec = spec_class.new test_name
|
877
|
+
|
878
|
+
result = spec.run
|
879
|
+
|
880
|
+
assert spec.passed?
|
881
|
+
assert result.passed?
|
882
|
+
assert_equal 1, result.assertions
|
883
|
+
end
|
884
|
+
|
885
|
+
def test_name
|
886
|
+
spec_a = describe ExampleA do; end
|
887
|
+
spec_b = describe ExampleB, :random_method do; end
|
888
|
+
spec_c = describe ExampleB, :random_method, :addl_context do; end
|
889
|
+
|
890
|
+
assert_equal "ExampleA", spec_a.name
|
891
|
+
assert_equal "ExampleB::random_method", spec_b.name
|
892
|
+
assert_equal "ExampleB::random_method::addl_context", spec_c.name
|
893
|
+
end
|
894
|
+
|
895
|
+
def test_name2
|
896
|
+
assert_equal "NamedExampleA", NamedExampleA.name
|
897
|
+
assert_equal "NamedExampleB", NamedExampleB.name
|
898
|
+
assert_equal "NamedExampleC", NamedExampleC.name
|
899
|
+
|
900
|
+
spec_a = describe ExampleA do; end
|
901
|
+
spec_b = describe ExampleB, :random_method do; end
|
902
|
+
|
903
|
+
assert_equal "ExampleA", spec_a.name
|
904
|
+
assert_equal "ExampleB::random_method", spec_b.name
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_structure
|
908
|
+
x, y, z, * = util_structure
|
909
|
+
|
910
|
+
assert_equal "top-level thingy", x.to_s
|
911
|
+
assert_equal "top-level thingy::inner thingy", y.to_s
|
912
|
+
assert_equal "top-level thingy::inner thingy::very inner thingy", z.to_s
|
913
|
+
|
914
|
+
assert_equal "top-level thingy", x.desc
|
915
|
+
assert_equal "inner thingy", y.desc
|
916
|
+
assert_equal "very inner thingy", z.desc
|
917
|
+
|
918
|
+
top_methods = %w[setup teardown test_0001_top-level-it]
|
919
|
+
inner_methods1 = %w[setup teardown test_0001_inner-it]
|
920
|
+
inner_methods2 = inner_methods1 +
|
921
|
+
%w[test_0002_anonymous test_0003_anonymous]
|
922
|
+
|
923
|
+
assert_equal top_methods, x.instance_methods(false).sort.map(&:to_s)
|
924
|
+
assert_equal inner_methods1, y.instance_methods(false).sort.map(&:to_s)
|
925
|
+
assert_equal inner_methods2, z.instance_methods(false).sort.map(&:to_s)
|
926
|
+
end
|
927
|
+
|
928
|
+
def test_structure_postfix_it
|
929
|
+
z = nil
|
930
|
+
y = describe "outer" do
|
931
|
+
# NOT here, below the inner-describe!
|
932
|
+
# it "inner-it" do end
|
933
|
+
|
934
|
+
z = describe "inner" do
|
935
|
+
it "inner-it" do end
|
936
|
+
end
|
937
|
+
|
938
|
+
# defined AFTER inner describe means we'll try to wipe out the inner-it
|
939
|
+
it "inner-it" do end
|
940
|
+
end
|
941
|
+
|
942
|
+
assert_equal %w[test_0001_inner-it], y.instance_methods(false).map(&:to_s)
|
943
|
+
assert_equal %w[test_0001_inner-it], z.instance_methods(false).map(&:to_s)
|
944
|
+
end
|
945
|
+
|
946
|
+
def test_setup_teardown_behavior
|
947
|
+
_, _, z, before_list, after_list = util_structure
|
948
|
+
|
949
|
+
@tu = z
|
950
|
+
|
951
|
+
run_tu_with_fresh_reporter
|
952
|
+
|
953
|
+
size = z.runnable_methods.size
|
954
|
+
assert_equal [1, 2, 3] * size, before_list
|
955
|
+
assert_equal [3, 2, 1] * size, after_list
|
956
|
+
end
|
957
|
+
|
958
|
+
def test_describe_first_structure
|
959
|
+
x1 = x2 = y = z = nil
|
960
|
+
x = describe "top-level thingy" do
|
961
|
+
y = describe "first thingy" do end
|
962
|
+
|
963
|
+
x1 = it "top level it" do end
|
964
|
+
x2 = it "не латинские &いった α, β, γ, δ, ε hello!!! world" do end
|
965
|
+
|
966
|
+
z = describe "second thingy" do end
|
967
|
+
end
|
968
|
+
|
969
|
+
test_methods = ["test_0001_top level it",
|
970
|
+
"test_0002_не латинские &いった α, β, γ, δ, ε hello!!! world",
|
971
|
+
].sort
|
972
|
+
|
973
|
+
assert_equal test_methods, [x1, x2]
|
974
|
+
assert_equal test_methods, x.instance_methods.grep(/^test/).map(&:to_s).sort
|
975
|
+
assert_equal [], y.instance_methods.grep(/^test/)
|
976
|
+
assert_equal [], z.instance_methods.grep(/^test/)
|
977
|
+
end
|
978
|
+
|
979
|
+
def test_structure_subclasses
|
980
|
+
z = nil
|
981
|
+
x = Class.new Minitest::Spec do
|
982
|
+
def xyz; end
|
983
|
+
end
|
984
|
+
y = Class.new x do
|
985
|
+
z = describe("inner") { }
|
986
|
+
end
|
987
|
+
|
988
|
+
assert_respond_to x.new(nil), "xyz"
|
989
|
+
assert_respond_to y.new(nil), "xyz"
|
990
|
+
assert_respond_to z.new(nil), "xyz"
|
991
|
+
end
|
992
|
+
end
|
993
|
+
|
994
|
+
class TestSpecInTestCase < MetaMetaMetaTestCase
|
995
|
+
def setup
|
996
|
+
super
|
997
|
+
|
998
|
+
Thread.current[:current_spec] = self
|
999
|
+
@tc = self
|
1000
|
+
@assertion_count = 2
|
1001
|
+
end
|
1002
|
+
|
1003
|
+
def assert_triggered expected, klass = Minitest::Assertion
|
1004
|
+
@assertion_count += 1
|
1005
|
+
|
1006
|
+
e = assert_raises klass do
|
1007
|
+
yield
|
1008
|
+
end
|
1009
|
+
|
1010
|
+
msg = e.message.sub(/(---Backtrace---).*/m, "\1")
|
1011
|
+
msg.gsub!(/\(oid=[-0-9]+\)/, "(oid=N)")
|
1012
|
+
|
1013
|
+
assert_equal expected, msg
|
1014
|
+
end
|
1015
|
+
|
1016
|
+
def teardown
|
1017
|
+
msg = "expected #{@assertion_count} assertions, not #{@tc.assertions}"
|
1018
|
+
assert_equal @assertion_count, @tc.assertions, msg
|
1019
|
+
end
|
1020
|
+
|
1021
|
+
def test_expectation
|
1022
|
+
@tc.assert_equal true, _(1).must_equal(1)
|
1023
|
+
end
|
1024
|
+
|
1025
|
+
def test_expectation_triggered
|
1026
|
+
assert_triggered "Expected: 2\n Actual: 1" do
|
1027
|
+
_(1).must_equal 2
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
|
1031
|
+
include Minitest::Spec::DSL::InstanceMethods
|
1032
|
+
|
1033
|
+
def test_expectation_with_a_message
|
1034
|
+
assert_triggered "woot.\nExpected: 2\n Actual: 1" do
|
1035
|
+
_(1).must_equal 2, "woot"
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
class ValueMonadTest < Minitest::Test
|
1041
|
+
attr_accessor :struct
|
1042
|
+
|
1043
|
+
def setup
|
1044
|
+
@struct = { :_ => "a", :value => "b", :expect => "c" }
|
1045
|
+
def @struct.method_missing k # think openstruct
|
1046
|
+
self[k]
|
1047
|
+
end
|
1048
|
+
end
|
1049
|
+
|
1050
|
+
def test_value_monad_method
|
1051
|
+
assert_equal "a", struct._
|
1052
|
+
end
|
1053
|
+
|
1054
|
+
def test_value_monad_value_alias
|
1055
|
+
assert_equal "b", struct.value
|
1056
|
+
end
|
1057
|
+
|
1058
|
+
def test_value_monad_expect_alias
|
1059
|
+
assert_equal "c", struct.expect
|
1060
|
+
end
|
1061
|
+
end
|