-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_template.erb
123 lines (108 loc) · 4.13 KB
/
test_template.erb
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
require 'helper'
require '<%= vars['resource_name'] %>'
# <%= mock_class_name %> = Mock<%= vars['class_name'] %><%= vars['singular'] ? 'Singular' : 'Plural' %>Backend
# Abbreviation not used outside this file
#=============================================================================#
# Constructor Tests
#=============================================================================#
class <%= vars['class_name'] %>ConstructorTest < Minitest::Test
def setup
<%= vars['class_name'] %>::BackendFactory.select(<%= mock_class_name %>::Empty)
end
<% if vars['empty_param_ok'] %>
def test_accepts_empty_params
<%=vars['class_name']%>.new
end
<% else %>
def test_rejects_empty_params
assert_raises(ArgumentError) { <%=vars['class_name']%>.new }
end
<% end %>
<% if vars['scalar_param_ok'] %>
def test_accepts_<%=vars['param_name'] %>_as_scalar
<%=vars['class_name']%>.new('<%=vars['assert_param'] %>')
end
<% else %>
def test_rejects_empty_params
assert_raises(ArgumentError) { <%=vars['class_name']%>.new('_<%=vars['assert_param'] %>') }
end
<% end %>
<% if vars['param_name'] %>
def test_accepts_<%=vars['param_name'] %>_as_hash
<%=vars['class_name']%>.new(<%=vars['param_name'] %>: '<%=vars['assert_param'] %>')
end
<% end %>
def test_rejects_unrecognized_params
assert_raises(ArgumentError) { <%=vars['class_name']%>.new(invalid: 9) }
end
end
#=============================================================================#
# Search / Recall
#=============================================================================#
class <%=vars['class_name']%>RecallTest < Minitest::Test
def setup
<%=vars['class_name']%>::BackendFactory.select(<%= mock_class_name %>::Basic)
end
<% if vars['scalar_param_ok'] %>
def test_search_hit_via_scalar_works
assert <%=vars['class_name']%>.new('<%=vars['assert_param']%>').exists?
end
<% end %>
<% if vars['param_name'] %>
def test_search_hit_via_hash_works
assert <%=vars['class_name']%>.new(<%=vars['param_name']%>: '<%=vars['assert_param']%>').exists?
end
<% end %>
<% if vars['param_name'] %>
def test_search_miss_is_not_an_exception
refute <%=vars['class_name']%>.new(<%=vars['param_name']%>: 'non-existant').exists?
end
<% end %>
end
#=============================================================================#
# Properties
#=============================================================================#
class <%=vars['class_name']%>PropertiesTest < Minitest::Test
def setup
<%=vars['class_name']%>::BackendFactory.select(<%= mock_class_name %>::Basic)
end
<% vars['properties'].each do |property| %>
def test_property_<%=property%>
assert_equal('CHANGE_ME', <%=vars['class_name']%>.new('<%=vars['assert_param']%>').<%=property%>)
assert_nil(<%=vars['class_name']%>.new(<%=vars['param_name']%>: 'non-existant').<%=property%>)
end
<% end %>
end
#=============================================================================#
# Matchers
#=============================================================================#
class <%=vars['class_name']%>MatchersTest < Minitest::Test
def setup
<%=vars['class_name']%>::BackendFactory.select(<%= mock_class_name %>::Basic)
end
<% vars['matchers'].each do |matcher| %>
def test_matcher_<%=matcher%>_positive
assert <%=vars['class_name']%>.new('<%=vars['assert_param']%>').<%=matcher%>?
end
def test_matcher_<%=matcher%>_negative
refute <%=vars['class_name']%>.new('<%=vars['refute_param']%>').<%=matcher%>?
end
<% end %>
end
#=============================================================================#
# Test Fixtures
#=============================================================================#
module <%= mock_class_name %>
class Empty < <%=vars['class_name']%>::Backend
def CHANGE_ME(query)
OpenStruct.new(CHANGE_ME: [])
end
end
class Basic < <%=vars['class_name']%>::Backend
def CHANGE_ME(query)
fixtures = [
]
OpenStruct.new({ CHANGE_ME: fixtures })
end
end
end