Module: TestPuma::Assertions
Relationships & Source Files | |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Defined in: | test/helpers/test_puma/assertions.rb |
Constant Summary
-
RE_8601 =
iso8601 2022-12-14T00:05:49Z
/\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z\z/
Instance Method Summary
- #assert_end_with(obj, str, msg = nil)
- #assert_hash(exp, act)
-
#assert_match(matcher, obj, msg = nil)
if obj is longer than 80 characters, show as string, not inspected.
- #assert_start_with(obj, str, msg = nil)
Instance Method Details
#assert_end_with(obj, str, msg = nil)
[ GitHub ]# File 'test/helpers/test_puma/assertions.rb', line 17
def assert_end_with(obj, str, msg = nil) msg = (msg) { "Expected\n#{obj}\nto end with #{str}" } assert_respond_to obj, :end_with? assert obj.end_with?(str), msg end
#assert_hash(exp, act)
[ GitHub ]# File 'test/helpers/test_puma/assertions.rb', line 37
def assert_hash(exp, act) exp.each do |exp_k, exp_v| if exp_v.is_a? Class assert_instance_of exp_v, act[exp_k], "Key #{exp_k} has invalid class" elsif exp_v.is_a? ::Regexp assert_match exp_v, act[exp_k], "Key #{exp_k} has invalid match" elsif exp_v.is_a?(Array) || exp_v.is_a?(Range) assert_includes exp_v, act[exp_k], "Key #{exp_k} isn't included" else assert_equal exp_v, act[exp_k], "Key #{exp_k} bad value" end end end
#assert_match(matcher, obj, msg = nil)
if obj is longer than 80 characters, show as string, not inspected
# File 'test/helpers/test_puma/assertions.rb', line 26
def assert_match(matcher, obj, msg = nil) msg = if obj.length < 80 (msg) { "Expected #{mu_pp matcher} to match #{mu_pp obj}" } else (msg) { "Expected #{mu_pp matcher} to match:\n#{obj}\n" } end assert_respond_to matcher, :"=~" matcher = Regexp.new Regexp.escape matcher if String === matcher assert matcher =~ obj, msg end
#assert_start_with(obj, str, msg = nil)
[ GitHub ]# File 'test/helpers/test_puma/assertions.rb', line 9
def assert_start_with(obj, str, msg = nil) msg = (msg) { "Expected\n#{obj}\nto start with #{str}" } assert_respond_to obj, :start_with? assert obj.start_with?(str), msg end