-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathtest_helper.rb
76 lines (66 loc) · 1.97 KB
/
test_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
require "minitest/pride"
require 'minitest/reporters'
Minitest::Reporters.use!(Minitest::Reporters::SpecReporter.new)
require_relative "../lib/parse/stack.rb"
require "minitest/autorun"
Parse.use_shortnames!
module ConstraintTests
TEST_VALUES = [
"v", [1, "test", :other, true],
nil, Parse::User.pointer(12345), true, false,
]
def build(value)
{ "field" => { @key.to_s => Parse::Constraint.formatted_value(value) } }
end
def test_operator
assert_equal @operand, @klass.operand
# Some constraint classes are macros and do not have operator keys.
# The reason for putting them in this block is because in MT6 (mini-test),
# assert_equal will fail if we are comparing nil.
if @key.nil? # for Parse::Constraint, Parse::Constraint::ObjectIdConstraint
assert_nil @klass.key
else
assert_equal @key, @klass.key
end
@keys.each do |o|
assert_respond_to(:field, o)
op = :field.send(o)
assert_instance_of(Parse::Operation, op)
assert_instance_of(@klass, op.constraint)
if @key.nil?
assert_nil op.constraint.key
else
assert_equal @key, op.constraint.key
end
value = { "operand" => "field", "operator" => o.to_s }
assert_equal value, op.as_json
end
end
def test_scalar_values
return if @skip_scalar_values_test.present?
TEST_VALUES.each do |value|
constraint = @klass.new(:field, value)
expected = build(value).as_json
assert_equal expected, constraint.build.as_json
end
end
end
module MiniTest
module Assertions
def refute_raises(*exp)
msg = "#{exp.pop}.\n" if String === exp.last
begin
yield
rescue MiniTest::Skip => e
return e if exp.include? MiniTest::Skip
raise e
rescue Exception => e
exp = exp.first if exp.size == 1
flunk "unexpected exception raised: #{e}"
end
end
end
module Expectations
infect_an_assertion :refute_raises, :wont_raise
end
end