omghax-test_rails 1.0.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.
- data/History.txt +5 -0
- data/Manifest.txt +21 -0
- data/README.txt +110 -0
- data/Rakefile +13 -0
- data/lib/test/rails/controller_test_case.rb +382 -0
- data/lib/test/rails/functional_test_case.rb +79 -0
- data/lib/test/rails/helper_test_case.rb +64 -0
- data/lib/test/rails/ivar_proxy.rb +31 -0
- data/lib/test/rails/pp_html_document.rb +74 -0
- data/lib/test/rails/rake_tasks.rb +50 -0
- data/lib/test/rails/render_tree.rb +93 -0
- data/lib/test/rails/test_case.rb +28 -0
- data/lib/test/rails/version.rb +11 -0
- data/lib/test/rails/view_test_case.rb +597 -0
- data/lib/test/rails.rb +295 -0
- data/lib/test/zentest_assertions.rb +134 -0
- data/test/test_help.rb +36 -0
- data/test/test_rails_controller_test_case.rb +58 -0
- data/test/test_rails_helper_test_case.rb +48 -0
- data/test/test_rails_view_test_case.rb +275 -0
- data/test/test_zentest_assertions.rb +128 -0
- metadata +94 -0
@@ -0,0 +1,275 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/zentest_assertions'
|
3
|
+
|
4
|
+
unless defined? $TESTING_RTC then
|
5
|
+
$TESTING_RTC = true
|
6
|
+
|
7
|
+
begin
|
8
|
+
require 'test/rails'
|
9
|
+
rescue LoadError, NameError
|
10
|
+
$TESTING_RTC = false
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module Rails
|
15
|
+
module VERSION
|
16
|
+
STRING = '99.99.99' unless defined? STRING # HACK
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestRailsViewTestCase < Test::Rails::ViewTestCase
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@assert_tag = []
|
24
|
+
@assert_no_tag = []
|
25
|
+
|
26
|
+
@assert_select = []
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_assert_field
|
30
|
+
assert_field :text, :game, :amount
|
31
|
+
|
32
|
+
assert_equal 2, @assert_select.length
|
33
|
+
|
34
|
+
expected = ["input[type='text'][name='game[amount]']"]
|
35
|
+
|
36
|
+
assert_equal expected, @assert_select.first
|
37
|
+
|
38
|
+
expected = ["label[for='game_amount']"]
|
39
|
+
|
40
|
+
assert_equal expected, @assert_select.last
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_assert_field_form
|
44
|
+
assert_field '/game/save', :text, :game, :amount
|
45
|
+
|
46
|
+
assert_equal 4, @assert_select.length
|
47
|
+
|
48
|
+
assert_equal @assert_select.shift, ["form[action='/game/save']"]
|
49
|
+
assert_equal(@assert_select.shift,
|
50
|
+
["input[type='text'][name='game[amount]']"])
|
51
|
+
|
52
|
+
assert_equal @assert_select.shift, ["form[action='/game/save']"]
|
53
|
+
assert_equal @assert_select.shift, ["label[for='game_amount']"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_assert_form
|
57
|
+
assert_form '/game/save'
|
58
|
+
|
59
|
+
assert_equal 1, @assert_select.length
|
60
|
+
assert_equal ["form[action='/game/save']"], @assert_select.first
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_assert_form_method
|
64
|
+
assert_form '/game/save', :post
|
65
|
+
|
66
|
+
assert_equal 1, @assert_select.length
|
67
|
+
assert_equal ["form[action='/game/save'][method='post']"],
|
68
|
+
@assert_select.first
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_assert_form_enctype
|
72
|
+
assert_form '/game/save', nil, 'multipart/form-data'
|
73
|
+
|
74
|
+
assert_equal 1, @assert_select.length
|
75
|
+
assert_equal ["form[action='/game/save'][enctype='multipart/form-data']"],
|
76
|
+
@assert_select.first
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_assert_h
|
80
|
+
assert_h 1, 'hi'
|
81
|
+
|
82
|
+
assert_equal [['h1', { :text => 'hi' }]], @assert_select
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_assert_img
|
86
|
+
assert_image '/images/bucket.jpg'
|
87
|
+
|
88
|
+
assert_equal [["img[src='/images/bucket.jpg']"]], @assert_select
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_assert_input
|
92
|
+
assert_input :text, 'game[amount]'
|
93
|
+
|
94
|
+
assert_equal 1, @assert_select.length
|
95
|
+
assert_equal ["input[type='text'][name='game[amount]']"],
|
96
|
+
@assert_select.first
|
97
|
+
end
|
98
|
+
|
99
|
+
def test_assert_input_form
|
100
|
+
assert_input '/game/save', :text, 'game[amount]'
|
101
|
+
|
102
|
+
assert_equal 2, @assert_select.length
|
103
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
104
|
+
assert_equal ["input[type='text'][name='game[amount]']"],
|
105
|
+
@assert_select.shift
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_assert_input_value
|
109
|
+
assert_input :text, 'game[amount]', 5
|
110
|
+
|
111
|
+
expected = ["input[type='text'][name='game[amount]'][value='5']"]
|
112
|
+
|
113
|
+
assert_equal 1, @assert_select.length
|
114
|
+
assert_equal expected, @assert_select.first
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_assert_label
|
118
|
+
assert_label 'game_amount'
|
119
|
+
|
120
|
+
expected = ["label[for='game_amount']"]
|
121
|
+
|
122
|
+
assert_equal 1, @assert_select.length
|
123
|
+
assert_equal expected, @assert_select.first
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_assert_label_form
|
127
|
+
assert_label '/game/save', 'game_amount'
|
128
|
+
|
129
|
+
assert_equal 2, @assert_select.length
|
130
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
131
|
+
assert_equal ["label[for='game_amount']"], @assert_select.shift
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_assert_links_to
|
135
|
+
assert_links_to '/game/show/1', 'hi'
|
136
|
+
|
137
|
+
expected = ["a[href='/game/show/1']", { :text => 'hi' }]
|
138
|
+
|
139
|
+
|
140
|
+
assert_equal 1, @assert_select.length
|
141
|
+
assert_equal expected, @assert_select.first
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_assert_multipart_form
|
145
|
+
assert_multipart_form '/game/save'
|
146
|
+
|
147
|
+
expected = [
|
148
|
+
"form[action='/game/save'][method='post'][enctype='multipart/form-data']"
|
149
|
+
]
|
150
|
+
|
151
|
+
assert_equal 1, @assert_select.length
|
152
|
+
assert_equal expected, @assert_select.first
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_assert_post_form
|
156
|
+
assert_post_form '/game/save'
|
157
|
+
|
158
|
+
expected = ["form[action='/game/save'][method='post']"]
|
159
|
+
|
160
|
+
assert_equal 1, @assert_select.length
|
161
|
+
assert_equal expected, @assert_select.first
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_assert_select_tag
|
165
|
+
assert_select_tag :game, :location_id,
|
166
|
+
'Ballet' => 1, 'Guaymas' => 2
|
167
|
+
|
168
|
+
assert_equal 2, @assert_select.length
|
169
|
+
|
170
|
+
assert_include(@assert_select,
|
171
|
+
["select[name='game[location_id]'] option[value='2']",
|
172
|
+
{ :text => 'Guaymas' }])
|
173
|
+
assert_include(@assert_select,
|
174
|
+
["select[name='game[location_id]'] option[value='1']",
|
175
|
+
{ :text => 'Ballet' }])
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_assert_select_tag_form
|
179
|
+
assert_select_tag '/game/save', :game, :location_id,
|
180
|
+
'Ballet' => 1, 'Guaymas' => 2
|
181
|
+
|
182
|
+
assert_equal 4, @assert_select.length
|
183
|
+
|
184
|
+
assert_include @assert_select, ["form[action='/game/save']"]
|
185
|
+
assert_include(@assert_select,
|
186
|
+
["select[name='game[location_id]'] option[value='2']",
|
187
|
+
{ :text => 'Guaymas' }])
|
188
|
+
assert_include @assert_select, ["form[action='/game/save']"]
|
189
|
+
assert_include(@assert_select,
|
190
|
+
["select[name='game[location_id]'] option[value='1']",
|
191
|
+
{ :text => 'Ballet' }])
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_assert_submit
|
195
|
+
assert_submit 'Save!'
|
196
|
+
|
197
|
+
assert_equal 1, @assert_select.length
|
198
|
+
assert_equal ["input[type='submit'][value='Save!']"], @assert_select.first
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_assert_submit_form
|
202
|
+
assert_submit '/game/save', 'Save!'
|
203
|
+
|
204
|
+
assert_equal 2, @assert_select.length
|
205
|
+
assert_equal ["form[action='/game/save']"], @assert_select.shift
|
206
|
+
assert_equal ["input[type='submit'][value='Save!']"], @assert_select.shift
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_assert_tag_in_form
|
210
|
+
assert_tag_in_form '/game/save', :tag => 'input'
|
211
|
+
|
212
|
+
expected = {
|
213
|
+
:tag => "form",
|
214
|
+
:attributes => { :action => "/game/save" },
|
215
|
+
:descendant => { :tag => "input" },
|
216
|
+
}
|
217
|
+
|
218
|
+
assert_equal 1, @assert_tag.length
|
219
|
+
assert_equal expected, @assert_tag.first
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_assert_text_area
|
223
|
+
assert_text_area 'post[body]'
|
224
|
+
|
225
|
+
assert_equal 1, @assert_select.length
|
226
|
+
assert_equal ["textarea[name='post[body]']"], @assert_select.shift
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_assert_text_area_body
|
230
|
+
assert_text_area 'post[body]', 'OMG!1! that skank stole my BF!~1!'
|
231
|
+
|
232
|
+
assert_equal 1, @assert_select.length
|
233
|
+
assert_equal ["textarea[name='post[body]']",
|
234
|
+
{ :text => 'OMG!1! that skank stole my BF!~1!' }],
|
235
|
+
@assert_select.shift
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_assert_text_area_form
|
239
|
+
assert_text_area '/post/save', 'post[body]'
|
240
|
+
|
241
|
+
assert_equal 2, @assert_select.length
|
242
|
+
assert_equal ["form[action='/post/save']"], @assert_select.shift
|
243
|
+
assert_equal ["textarea[name='post[body]']"], @assert_select.shift
|
244
|
+
end
|
245
|
+
|
246
|
+
def test_assert_title
|
247
|
+
assert_title 'hi'
|
248
|
+
|
249
|
+
assert_equal [['title', { :text => 'hi' }]], @assert_select
|
250
|
+
end
|
251
|
+
|
252
|
+
def test_deny_links_to
|
253
|
+
deny_links_to '/game/show/1', 'hi'
|
254
|
+
|
255
|
+
expected = ["a[href='/game/show/1']", { :text => 'hi', :count => 0 }]
|
256
|
+
|
257
|
+
assert_equal 1, @assert_select.length
|
258
|
+
assert_equal expected, @assert_select.first
|
259
|
+
end
|
260
|
+
|
261
|
+
def assert_tag(arg)
|
262
|
+
@assert_tag << arg
|
263
|
+
end
|
264
|
+
|
265
|
+
def assert_no_tag(arg)
|
266
|
+
@assert_no_tag << arg
|
267
|
+
end
|
268
|
+
|
269
|
+
def assert_select(*args)
|
270
|
+
@assert_select << args
|
271
|
+
yield if block_given?
|
272
|
+
end
|
273
|
+
|
274
|
+
end if $TESTING_RTC
|
275
|
+
|
@@ -0,0 +1,128 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/zentest_assertions'
|
3
|
+
|
4
|
+
class TestZenTestAssertions < Test::Unit::TestCase
|
5
|
+
@@has_mini = defined? Mini
|
6
|
+
@@exception = if @@has_mini then
|
7
|
+
Mini::Assertion
|
8
|
+
else
|
9
|
+
Test::Unit::AssertionFailedError
|
10
|
+
end
|
11
|
+
|
12
|
+
def util_assert_triggered expected
|
13
|
+
e = assert_raises @@exception do
|
14
|
+
yield
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_equal expected, e.message.sub(/(---Backtrace---).*/m, '\1')
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_assert_empty
|
21
|
+
assert_empty []
|
22
|
+
|
23
|
+
msg = if @@has_mini then
|
24
|
+
"Expected [true] to be empty."
|
25
|
+
else
|
26
|
+
"[true] expected to be empty."
|
27
|
+
end
|
28
|
+
|
29
|
+
util_assert_triggered msg do
|
30
|
+
assert_empty [true]
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_assert_include
|
35
|
+
assert_include [true], true
|
36
|
+
|
37
|
+
msg = if @@has_mini then
|
38
|
+
"Expected [true] to include false."
|
39
|
+
else
|
40
|
+
"[true]\ndoes not include\nfalse."
|
41
|
+
end
|
42
|
+
|
43
|
+
util_assert_triggered msg do
|
44
|
+
assert_include [true], false
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_assert_in_epsilon
|
49
|
+
assert_in_epsilon 1.234, 1.234, 0.0001
|
50
|
+
|
51
|
+
msg = if @@has_mini then
|
52
|
+
"Expected 1.235 - 1.234 (0.00100000000000011) to be < 0.0001234."
|
53
|
+
else
|
54
|
+
"1.235 expected to be within 0.01% of 1.234, was 0.000809716599190374"
|
55
|
+
end
|
56
|
+
|
57
|
+
util_assert_triggered msg do
|
58
|
+
assert_in_epsilon 1.235, 1.234, 0.0001
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_deny
|
63
|
+
deny false
|
64
|
+
deny nil
|
65
|
+
|
66
|
+
e = assert_raises Test::Unit::AssertionFailedError do
|
67
|
+
deny true
|
68
|
+
end
|
69
|
+
|
70
|
+
assert_match(/Failed refutation, no message given/, e.message)
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_deny_empty
|
74
|
+
deny_empty [true]
|
75
|
+
|
76
|
+
msg = if @@has_mini then
|
77
|
+
"Expected [] to not be empty."
|
78
|
+
else
|
79
|
+
"[] expected to have stuff."
|
80
|
+
end
|
81
|
+
|
82
|
+
util_assert_triggered msg do
|
83
|
+
deny_empty []
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_deny_equal
|
89
|
+
deny_equal true, false
|
90
|
+
|
91
|
+
assert_raises Test::Unit::AssertionFailedError do
|
92
|
+
deny_equal true, true
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_deny_include
|
97
|
+
deny_include [true], false
|
98
|
+
|
99
|
+
msg = if @@has_mini then
|
100
|
+
"Expected [true] to not include true."
|
101
|
+
else
|
102
|
+
"[true] includes true."
|
103
|
+
end
|
104
|
+
|
105
|
+
util_assert_triggered msg do
|
106
|
+
deny_include [true], true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_deny_nil
|
111
|
+
deny_nil false
|
112
|
+
|
113
|
+
assert_raises Test::Unit::AssertionFailedError do
|
114
|
+
deny_nil nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_util_capture
|
119
|
+
out, err = util_capture do
|
120
|
+
puts 'out'
|
121
|
+
$stderr.puts 'err'
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_equal "out\n", out
|
125
|
+
assert_equal "err\n", err
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: omghax-test_rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Davis
|
8
|
+
- Eric Hodel
|
9
|
+
- Dray Lacy
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2009-03-12 00:00:00 -07:00
|
15
|
+
default_executable:
|
16
|
+
dependencies:
|
17
|
+
- !ruby/object:Gem::Dependency
|
18
|
+
name: hoe
|
19
|
+
type: :development
|
20
|
+
version_requirement:
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - ">="
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: 1.8.3
|
26
|
+
version:
|
27
|
+
description: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails. ZenTest scans your target and unit-test code and writes your missing code based on simple naming rules, enabling XP at a much quicker pace. ZenTest only works with Ruby and Test::Unit. unit_diff is a command-line filter to diff expected results from actual results and allow you to quickly see exactly what is wrong. autotest is a continous testing facility meant to be used during development. As soon as you save a file, autotest will run the corresponding dependent tests. multiruby runs anything you want on multiple versions of ruby. Great for compatibility checking! Use multiruby_setup to manage your installed versions. Test::Rails helps you build industrial-strength Rails code."
|
28
|
+
email:
|
29
|
+
- ryand-ruby@zenspider.com
|
30
|
+
- drbrain@segment7.net
|
31
|
+
- dray@izea.com
|
32
|
+
executables: []
|
33
|
+
|
34
|
+
extensions: []
|
35
|
+
|
36
|
+
extra_rdoc_files:
|
37
|
+
- History.txt
|
38
|
+
- Manifest.txt
|
39
|
+
- README.txt
|
40
|
+
files:
|
41
|
+
- History.txt
|
42
|
+
- Manifest.txt
|
43
|
+
- README.txt
|
44
|
+
- Rakefile
|
45
|
+
- lib/test/rails.rb
|
46
|
+
- lib/test/rails/controller_test_case.rb
|
47
|
+
- lib/test/rails/functional_test_case.rb
|
48
|
+
- lib/test/rails/helper_test_case.rb
|
49
|
+
- lib/test/rails/ivar_proxy.rb
|
50
|
+
- lib/test/rails/pp_html_document.rb
|
51
|
+
- lib/test/rails/rake_tasks.rb
|
52
|
+
- lib/test/rails/render_tree.rb
|
53
|
+
- lib/test/rails/test_case.rb
|
54
|
+
- lib/test/rails/version.rb
|
55
|
+
- lib/test/rails/view_test_case.rb
|
56
|
+
- lib/test/zentest_assertions.rb
|
57
|
+
- test/test_help.rb
|
58
|
+
- test/test_rails_controller_test_case.rb
|
59
|
+
- test/test_rails_helper_test_case.rb
|
60
|
+
- test/test_rails_view_test_case.rb
|
61
|
+
- test/test_zentest_assertions.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://www.zenspider.com/ZSS/Products/ZenTest/
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options:
|
66
|
+
- --main
|
67
|
+
- README.txt
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: "0"
|
75
|
+
version:
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: "0"
|
81
|
+
version:
|
82
|
+
requirements: []
|
83
|
+
|
84
|
+
rubyforge_project: test_rails
|
85
|
+
rubygems_version: 1.2.0
|
86
|
+
signing_key:
|
87
|
+
specification_version: 2
|
88
|
+
summary: "ZenTest provides 4 different tools and 1 library: zentest, unit_diff, autotest, multiruby, and Test::Rails"
|
89
|
+
test_files:
|
90
|
+
- test/test_help.rb
|
91
|
+
- test/test_rails_controller_test_case.rb
|
92
|
+
- test/test_rails_helper_test_case.rb
|
93
|
+
- test/test_rails_view_test_case.rb
|
94
|
+
- test/test_zentest_assertions.rb
|