-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
245 lines (202 loc) · 7.24 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# encoding: UTF-8
require 'bundler/setup'
require 'ruuuby'
require_relative 'helpers/helper_ruuuby'
require_relative 'helpers/static_test_data'
require 'rdoc'
require 'rake'
require 'rspec'
require 'rspec-benchmark'
class ::Module
# @param [Symbol] func_name
# @param [Symbol] alias_name
#
# @raise [ArgumentError]
#
# @return [Boolean] true, if this instance of Module has a function with provided name and alias
def ∃⨍_alias?(func_name, alias_name)
🛑syms❓([func_name, alias_name])
(self.instance_methods.include?(func_name) && self.instance_methods.include?(alias_name)) ? self.instance_method(func_name) == self.instance_method(alias_name) : false
end
# @param [Symbol] func_name
#
# @raise [ArgumentError]
#
# @return [Boolean] true, if this object's Class has either a public or private method with matching func_name
def ∃⨍?(func_name)
🛑sym❓('func_name', func_name)
self.method_defined?(func_name) ? true : self.∃🙈⨍?(func_name)
end
end
module HelpersSyntaxCache
def expect_syntax(the_class, syntax_id, syntax_before_processing)
expect(the_class.respond_to?(syntax_id)).to eq(true)
result = the_class.send(syntax_id)
expect(result.ⓣ).to eq(Regexp)
expect(result.source).to eq(syntax_before_processing)
expect(the_class.send(syntax_id).🆔).to eq(result.🆔)
expect{the_class.send("#{syntax_id}=".to_sym, 5).to raise_error(FrozenError)}
end
def expect_syntax_wo_cache(the_class, syntax_id, syntax_before_processing)
expect(the_class.respond_to?(syntax_id)).to eq(false)
expect(the_class::Syntax.constants.∋?(syntax_id)).to eq(true)
expect(the_class::Syntax.const_get(syntax_id)).to eq(syntax_before_processing)
expect{the_class.send("#{syntax_id}=".to_sym, 5).to raise_error(FrozenError)}
end
def do_not_expect_syntax(the_class, syntax_id)
expect(the_class.respond_to?(syntax_id)).to eq(false)
end
end
module HelpersFeature16
def expect_scenarios_power_operations(scenarios, superscripts, power_operation, to_pass=true)
if power_operation == 0
scenarios.∀ do |n|
expect((n^(superscripts)) == 1).to eq(to_pass)
end
elsif power_operation == 1
scenarios.∀ do |n|
expect((n^(superscripts)) == n).to eq(to_pass)
end
else
scenarios.∀ do |n|
expect((n^(superscripts)) == (n ** power_operation)).to eq(to_pass)
end
end
end
end
module HelpersGeneral
# @param [*] response
def expect_json_response(response)
expect(response.content_type_json?).to eq(true)
expect(response.content_type).to eq('application/json; charset=utf-8')
end
# @param [*] response
# @param [String, NilClass] expected_code
# @param [String, NilClass] expected_content
# @param [Integer, NilClass] expected_content_length
#
# @return [*] response
def expect_request_response(response, expected_code=nil, expected_content=nil, expected_content_length=nil)
expect(response.is_a?(::Net::HTTPResponse)).to eq(true)
unless expected_code.nil?
expect(response.code).to eq(expected_code)
end
unless expected_content.nil?
expect(response.body).to eq(expected_content)
end
unless expected_content_length.nil?
expect(response.body.length).to eq(expected_content_length)
end
response
end
def expect_needed_version(subject, version_expected, validate_matching_value=nil)
expect(subject.∃version?).to eq(true)
expect(subject.version_expected).to eq(version_expected)
expect(subject.version_current).to eq(version_expected)
unless validate_matching_value.nil?
expect(subject.version_current).to eq(validate_matching_value)
end
end
def expect≈≈(scenario, expected_value)
result = scenario.≈≈(expected_value)
if !result
puts "scenarios{#{scenario.to_s}} did not match {#{expected_value.to_s}}"
end
expect(result).to eq(true)
end
def expect_regular_int(val_scenario, val_expected)
expect(val_scenario).to eq(val_expected)
expect(val_scenario.ⓣ).to eq(Integer)
end
def expect_regular_flt(val_scenario, val_expected)
expect(val_scenario).to eq(val_expected)
expect(val_scenario.ⓣ).to eq(Float)
end
def expect_∃⨍(the_func, owner, expected_result=true)
if owner == ENV
expect(ENV.respond_to?(the_func)).to eq(expected_result)
else
expect(owner.∃⨍?(the_func)).to eq(expected_result)
end
end
def expect_∃⨍_with_alias(the_func, aliases, owner, expected_result=true)
expect(owner.∃⨍?(the_func)).to eq(expected_result)
if aliases.ary?
aliases.each do |a|
expect(owner.∃⨍_alias?(the_func, a)).to eq(expected_result)
end
else
expect(owner.∃⨍_alias?(the_func, aliases)).to eq(expected_result)
end
end
def expect_∃const_w_type(the_const, const_type, owner, expected_result=true)
expect(owner.const_defined?(the_const)).to eq(expected_result)
expect(owner.const_get(the_const).ⓣ).to eq(const_type)
end
def expect_∃const(the_const, owner, expected_result=true)
expect(owner.const_defined?(the_const)).to eq(expected_result)
end
def expect_∃⨍_static(the_func, owner, expected_result=true)
if owner == ::Kernel
expect(owner.instance_methods(false).∋?(the_func)).to eq(expected_result)
else
expect(owner.singleton_class.instance_methods(false).∋?(the_func)).to eq(expected_result)
end
end
# @param [Symbol] kmodule
# @param [Class] owner
def expect_∃ᶜ(kmodule, owner=::Kernel)
expect(🧬.∃ᶜ?(kmodule, owner)).to eq(true)
end
# @param [Symbol] kmodule
# @param [Class] owner
def expect_∄ᶜ(kmodule, owner)
expect(🧬.∃ᶜ?(kmodule, owner)).to eq(false)
end
# @param [Symbol] kmodule
# @param [Class] owner
def expect_∃ᵐ(kmodule, owner)
expect(🧬.∃ᵐ?(kmodule, owner)).to eq(true)
end
# @param [Symbol] kmodule
# @param [Class] owner
def expect_∄ᵐ(kmodule, owner)
expect(🧬.∃ᵐ?(kmodule, owner)).to eq(false)
end
# @param [Symbol] kmodule
def expect_∃ᴹ(kmodule)
expect(🧬.∃ᴹ?(kmodule)).to eq(true)
end
# @param [Symbol] kmodule
def expect_∄ᴹ(kmodule)
expect(🧬.∃ᴹ?(kmodule)).to eq(false)
end
end
if ENV['RSPEC_SYSTEM'] == 'on'
require_relative 'helpers/system/autoload_me'
end
RSpec.configure do |config|
# enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'
#config.add_setting(:start_time)
config.expect_with :rspec do |c|
c.syntax = :expect
end
config.profile_examples = 3
config.include(::Math::Trig) if ENV['RUUUBY_RSPEC_INTEGRATION'] == 'on'
config.include_context 'shared_context_general'
config.include_context 'shared_context_f24'
config.include_context 'shared_context_f27'
config.include_context 'shared_context_f32'
if ENV['RSPEC_SYSTEM'] == 'on'
config.include_context 'shared_context_f40'
end
config.include HelpersGeneral
config.include HelpersFeature16
config.include HelpersSyntaxCache
if ENV['RUUUBY_PERFORMANCE_LIMIT'] == 'off'
config.include PerformanceTestHelper, :performance
config.include RSpec::Benchmark::Matchers, :performance
config.include_context 'shared_context_performance', :performance
end
end