steam 0.0.4 → 0.0.5
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/Gemfile +2 -0
- data/lib/core_ext/ruby/string/camelize.rb +1 -1
- data/lib/core_ext/ruby/string/underscore.rb +8 -1
- data/lib/steam/browser/html_unit.rb +9 -5
- data/lib/steam/browser/html_unit/client.rb +14 -2
- data/lib/steam/browser/html_unit/connection.rb +10 -10
- data/lib/steam/browser/html_unit/web_response.rb +0 -1
- data/lib/steam/connection/net_http.rb +4 -4
- data/lib/steam/java.rb +7 -6
- data/lib/steam/request.rb +88 -35
- data/lib/steam/session/rails.rb +1 -1
- data/lib/steam/version.rb +1 -1
- metadata +23 -50
- data/Rakefile +0 -23
- data/test/all.rb +0 -3
- data/test/browser/html_unit/actions_test.rb +0 -183
- data/test/browser/html_unit/javascript_test.rb +0 -60
- data/test/browser/html_unit/rails_actions_test.rb +0 -150
- data/test/browser/html_unit_test.rb +0 -98
- data/test/connection/cascade_test.rb +0 -42
- data/test/connection/mock_test.rb +0 -58
- data/test/connection/rails_test.rb +0 -16
- data/test/connection/static_test.rb +0 -14
- data/test/example/webrat_compat_steps_test.rb +0 -307
- data/test/fixtures/html_fakes.rb +0 -191
- data/test/java_test.rb +0 -29
- data/test/playground/connection.rb +0 -19
- data/test/playground/dragdrop_behavior.rb +0 -60
- data/test/playground/drb.rb +0 -55
- data/test/playground/java_signature.rb +0 -22
- data/test/playground/nokogiri.rb +0 -15
- data/test/playground/put_headers.rb +0 -83
- data/test/playground/rack.rb +0 -11
- data/test/playground/rjb_bind.rb +0 -42
- data/test/playground/stack_level_problem.rb +0 -129
- data/test/playground/thread_problem.rb +0 -57
- data/test/playground/web_response_data.rb +0 -21
- data/test/playground/webrat.rb +0 -48
- data/test/playground/xhr_accept_headers.rb +0 -61
- data/test/process_test.rb +0 -55
- data/test/session_test.rb +0 -40
- data/test/test_helper.rb +0 -80
@@ -1,42 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
require 'rack/cascade'
|
3
|
-
|
4
|
-
class ConnectionCascadeTest < Test::Unit::TestCase
|
5
|
-
include Steam
|
6
|
-
|
7
|
-
def setup
|
8
|
-
connections = []
|
9
|
-
@urls = []
|
10
|
-
@bodies = []
|
11
|
-
|
12
|
-
@root = File.expand_path(File.dirname(__FILE__) + '/../fixtures')
|
13
|
-
connections << Connection::Static.new(:root => @root)
|
14
|
-
@urls << 'http://localhost:3000/javascripts/foo.js'
|
15
|
-
@bodies << File.read(@root + '/javascripts/foo.js')
|
16
|
-
|
17
|
-
@mock_url = 'http://localhost:3000/mock'
|
18
|
-
mock = Connection::Mock.new
|
19
|
-
mock.mock :get, @mock_url, 'mock body'
|
20
|
-
connections << mock
|
21
|
-
@urls << @mock_url
|
22
|
-
@bodies << 'mock body'
|
23
|
-
|
24
|
-
if Gem.available?('patron')
|
25
|
-
patron = Connection::Patron.new
|
26
|
-
patron_body = 'patron body'
|
27
|
-
patron.stubs(:handle_request).returns(patron_response(patron_body)) # FIXME .with(...)
|
28
|
-
connections << patron
|
29
|
-
@urls << 'http://localhost:3000/patron'
|
30
|
-
@bodies << patron_body
|
31
|
-
end
|
32
|
-
|
33
|
-
@connection = Rack::Cascade.new(connections)
|
34
|
-
end
|
35
|
-
|
36
|
-
def test_cascade
|
37
|
-
@urls.each_with_index do |url, index|
|
38
|
-
status, headers, response = @connection.call(Request.env_for(url))
|
39
|
-
assert_equal @bodies[index], response.body.join
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class ConnectionMockTest < Test::Unit::TestCase
|
4
|
-
include Steam
|
5
|
-
|
6
|
-
def setup
|
7
|
-
@connection = Connection::Mock.new
|
8
|
-
@url = 'http://localhost:3000/'
|
9
|
-
@body = <<-body
|
10
|
-
<html>
|
11
|
-
<head>
|
12
|
-
<script src="/javascripts/script.js" type="text/javascript"></script>
|
13
|
-
</head>
|
14
|
-
</html>
|
15
|
-
body
|
16
|
-
end
|
17
|
-
|
18
|
-
def test_call
|
19
|
-
@connection.mock(:get, @url, @body)
|
20
|
-
status, headers, response = @connection.call(Request.env_for(@url))
|
21
|
-
assert_equal [@body], response.body
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_mock_with_response
|
25
|
-
@connection.mock(:get, @url, Rack::Response.new(@body, 200, { 'Content-Type' => 'text/css' }))
|
26
|
-
assert_response('Content-Type' => 'text/css')
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_mock_with_string
|
30
|
-
@connection.mock(:get, @url, @body)
|
31
|
-
assert_response
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_mock_with_array_without_content_type
|
35
|
-
@connection.mock(:get, @url, [@body, 201, { 'foo' => 'bar' }])
|
36
|
-
assert_response(201, 'foo' => 'bar')
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_mock_with_array_with_content_type
|
40
|
-
@connection.mock(:get, @url, [@body, 201, { 'Content-Type' => 'text/css' }])
|
41
|
-
assert_response(201, 'Content-Type' => 'text/css')
|
42
|
-
end
|
43
|
-
|
44
|
-
protected
|
45
|
-
|
46
|
-
def assert_response(*args)
|
47
|
-
headers = args.last.is_a?(Hash) ? args.pop : {}
|
48
|
-
headers = { 'Content-Type' => 'text/html' }.merge(headers)
|
49
|
-
status = args.pop || 200
|
50
|
-
|
51
|
-
response = @connection.response('GET', @url)
|
52
|
-
|
53
|
-
assert response.is_a?(Rack::Response)
|
54
|
-
assert_equal [@body], response.body
|
55
|
-
assert_equal status, response.status
|
56
|
-
assert_equal headers['Content-Type'], response.header['Content-Type']
|
57
|
-
end
|
58
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
# require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
#
|
3
|
-
# class ConnectionRailsTest < Test::Unit::TestCase
|
4
|
-
# include Steam
|
5
|
-
#
|
6
|
-
# def test_rails
|
7
|
-
# rails_root = File.expand_path(File.dirname(__FILE__) + '/../fixtures/rails')
|
8
|
-
# require rails_root + '/config/environment.rb'
|
9
|
-
#
|
10
|
-
# url = 'http://localhost:3000/users'
|
11
|
-
# connection = Connection::Rails.new
|
12
|
-
#
|
13
|
-
# status, headers, response = connection.call(Request.env_for(url))
|
14
|
-
# # assert !response.body.empty?
|
15
|
-
# end
|
16
|
-
# end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../test_helper')
|
2
|
-
|
3
|
-
class ConnectionStaticTest < Test::Unit::TestCase
|
4
|
-
include Steam
|
5
|
-
|
6
|
-
def test_static
|
7
|
-
url = 'http://localhost:3000/javascripts/foo.js'
|
8
|
-
root = File.expand_path(File.dirname(__FILE__) + '/../fixtures')
|
9
|
-
connection = Connection::Static.new(:root => root)
|
10
|
-
|
11
|
-
status, headers, response = connection.call(Request.env_for(url))
|
12
|
-
assert_equal File.read(root + '/javascripts/foo.js'), response.body.join
|
13
|
-
end
|
14
|
-
end
|
@@ -1,307 +0,0 @@
|
|
1
|
-
require File.expand_path('../../test_helper', __FILE__)
|
2
|
-
# $: << File.expand_path("../../../lib", __FILE__)
|
3
|
-
|
4
|
-
require 'cucumber'
|
5
|
-
require 'steam'
|
6
|
-
|
7
|
-
module PathTo
|
8
|
-
def path_to(page_name)
|
9
|
-
"http://localhost:3000/#{page_name}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
include PathTo
|
13
|
-
|
14
|
-
connection = Steam::Connection::Mock.new
|
15
|
-
$browser = Steam::Browser.create(connection)
|
16
|
-
|
17
|
-
$step_mother = Cucumber::StepMother.new
|
18
|
-
$step_mother.log = Logger.new(File.open('/dev/null', 'w'))
|
19
|
-
steps_file = File.expand_path('../../../example/cucumber/webrat_compatible_steps.rb', __FILE__)
|
20
|
-
$step_mother.load_code_file(steps_file)
|
21
|
-
|
22
|
-
ruby = $step_mother.load_programming_language('rb')
|
23
|
-
ruby.build_rb_world_factory([PathTo], lambda { Steam::Session.new($browser) })
|
24
|
-
ruby.send(:create_world)
|
25
|
-
ruby.send(:extend_world)
|
26
|
-
|
27
|
-
class WebratCompatStepsTest < Test::Unit::TestCase
|
28
|
-
def setup
|
29
|
-
@browser = $browser
|
30
|
-
end
|
31
|
-
|
32
|
-
def invoke(step)
|
33
|
-
$step_mother.invoke(step)
|
34
|
-
end
|
35
|
-
|
36
|
-
def response
|
37
|
-
$browser.response
|
38
|
-
end
|
39
|
-
|
40
|
-
def title
|
41
|
-
$browser.page.getTitleText
|
42
|
-
end
|
43
|
-
|
44
|
-
def locate(*args)
|
45
|
-
$browser.locate(*args)
|
46
|
-
end
|
47
|
-
|
48
|
-
test 'I go to page' do
|
49
|
-
mock :get, path_to('foo'), 'FOO'
|
50
|
-
invoke 'I go to foo'
|
51
|
-
assert_match 'FOO', response.body
|
52
|
-
end
|
53
|
-
|
54
|
-
test 'I press "button"' do
|
55
|
-
perform :get, path_to('foo'), %(<input type="button" id="button" onclick="document.title='OK'">)
|
56
|
-
invoke 'I press "button"'
|
57
|
-
assert_match 'OK', title
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'I click on "button"' do
|
61
|
-
perform :get, path_to('foo'), %(<input type="button" id="button" onclick="document.title='OK'">)
|
62
|
-
invoke 'I click on "button"'
|
63
|
-
assert_match 'OK', title
|
64
|
-
end
|
65
|
-
|
66
|
-
test 'I follow "link"' do
|
67
|
-
perform :get, path_to('foo'), %(<a href="javascript:document.title='OK'">link</a>)
|
68
|
-
invoke 'I follow "link"'
|
69
|
-
assert_match 'OK', title
|
70
|
-
end
|
71
|
-
|
72
|
-
test 'I follow "link" within "foo"' do
|
73
|
-
perform :get, path_to('foo'), %(<a>link</a><div id="foo"><a href="javascript:document.title='OK'">link</a></div>)
|
74
|
-
invoke 'I follow "link" within "#foo"'
|
75
|
-
assert_match 'OK', title
|
76
|
-
end
|
77
|
-
|
78
|
-
test 'I fill in "foo" with "OK"' do
|
79
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="bar">)
|
80
|
-
invoke 'I fill in "foo" with "OK"'
|
81
|
-
assert_match 'OK', locate(:input).attribute('value')
|
82
|
-
end
|
83
|
-
|
84
|
-
test 'I fill in "foo" for "OK"' do
|
85
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="bar">)
|
86
|
-
invoke 'I fill in "OK" for "foo"'
|
87
|
-
assert_match 'OK', locate(:input).attribute('value')
|
88
|
-
end
|
89
|
-
|
90
|
-
# TODO
|
91
|
-
# When /^(?:|I )fill in the following:$/ do |fields|
|
92
|
-
# fields.rows_hash.each do |name, value|
|
93
|
-
# When %{I fill in "#{name}" with "#{value}"}
|
94
|
-
# end
|
95
|
-
# end
|
96
|
-
|
97
|
-
test 'I select "OK" from "foo"' do
|
98
|
-
perform :get, path_to('foo'), %(<select name="foo"><option>bar</option><option>OK</option></select>)
|
99
|
-
invoke 'I select "OK" from "foo"'
|
100
|
-
assert_equal 'OK', locate(:select).value
|
101
|
-
end
|
102
|
-
|
103
|
-
# TODO
|
104
|
-
# # When I select "December 25, 2008 10:00" as the date and time
|
105
|
-
# When /^(?:|I )select "([^\"]*)" as the date and time$/ do |time|
|
106
|
-
# select_datetime(time)
|
107
|
-
# end
|
108
|
-
#
|
109
|
-
# When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date and time$/ do |datetime, select|
|
110
|
-
# select_datetime(datetime, :from => select)
|
111
|
-
# end
|
112
|
-
#
|
113
|
-
# # Note: Rail's default time helper provides 24-hour time-- not 12 hour time. Webrat
|
114
|
-
# # will convert the 2:20PM to 14:20 and then select it.
|
115
|
-
# When /^(?:|I )select "([^\"]*)" as the time$/ do |time|
|
116
|
-
# select_time(time)
|
117
|
-
# end
|
118
|
-
#
|
119
|
-
# # When I select "7:30AM" as the "Gym" time
|
120
|
-
# When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" time$/ do |time, time_label|
|
121
|
-
# select_time(time, :from => time_label)
|
122
|
-
# end
|
123
|
-
#
|
124
|
-
# # When I select "February 20, 1981" as the date
|
125
|
-
# When /^(?:|I )select "([^\"]*)" as the date$/ do |date|
|
126
|
-
# # reformat_date!(date)
|
127
|
-
# select_date(date)
|
128
|
-
# end
|
129
|
-
#
|
130
|
-
# # When I select "April 26, 1982" as the "Date of Birth" date
|
131
|
-
# When /^(?:|I )select "([^\"]*)" as the "([^\"]*)" date$/ do |date, date_label|
|
132
|
-
# # reformat_date!(date)
|
133
|
-
# select_date(date, :from => date_label)
|
134
|
-
# end
|
135
|
-
|
136
|
-
test 'I check "foo"' do
|
137
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo">)
|
138
|
-
invoke 'I check "foo"'
|
139
|
-
assert_equal 'checked', locate(:input, :type => 'checkbox').checked
|
140
|
-
end
|
141
|
-
|
142
|
-
test 'I uncheck "foo"' do
|
143
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo" checked="checked">)
|
144
|
-
invoke 'I uncheck "foo"'
|
145
|
-
assert_nil locate(:check_box).checked
|
146
|
-
end
|
147
|
-
|
148
|
-
test 'I choose "foo"' do
|
149
|
-
perform :get, path_to('foo'), %(<input type="radio" name="foo">)
|
150
|
-
invoke 'I choose "foo"'
|
151
|
-
assert_equal 'checked', locate(:radio_button).checked
|
152
|
-
end
|
153
|
-
|
154
|
-
test 'I attach the file at "path" to "foo"' do
|
155
|
-
perform :get, path_to('foo'), %(<input type="file" name="foo">)
|
156
|
-
invoke 'I attach the file at "path" to "foo"'
|
157
|
-
assert_equal 'path', locate(:file).value
|
158
|
-
end
|
159
|
-
|
160
|
-
# I should see
|
161
|
-
|
162
|
-
test 'I should see "foo" (passes)' do
|
163
|
-
perform :get, path_to('foo'), %(foo)
|
164
|
-
assert_passes { invoke 'I should see "foo"' }
|
165
|
-
end
|
166
|
-
|
167
|
-
test 'I should see "foo" (fails)' do
|
168
|
-
perform :get, path_to('foo'), %(bar)
|
169
|
-
assert_fails { invoke 'I should see "foo"' }
|
170
|
-
end
|
171
|
-
|
172
|
-
test 'I should see /foo/ (passes)' do
|
173
|
-
perform :get, path_to('foo'), %(foo)
|
174
|
-
assert_passes { invoke 'I should see /foo/' }
|
175
|
-
end
|
176
|
-
|
177
|
-
test 'I should see /foo/ (fails)' do
|
178
|
-
perform :get, path_to('foo'), %(bar)
|
179
|
-
assert_fails { invoke 'I should see /foo/' }
|
180
|
-
end
|
181
|
-
|
182
|
-
# I should not see
|
183
|
-
|
184
|
-
test 'I should not see "foo" (passes)' do
|
185
|
-
perform :get, path_to('foo'), %(bar)
|
186
|
-
assert_passes { invoke 'I should not see "foo"' }
|
187
|
-
end
|
188
|
-
|
189
|
-
test 'I should not see "foo" (fails)' do
|
190
|
-
perform :get, path_to('foo'), %(foo)
|
191
|
-
assert_fails { invoke 'I should not see "foo"' }
|
192
|
-
end
|
193
|
-
|
194
|
-
test 'I should not see /foo/ (passes)' do
|
195
|
-
perform :get, path_to('foo'), %(bar)
|
196
|
-
assert_passes { invoke 'I should not see /foo/' }
|
197
|
-
end
|
198
|
-
|
199
|
-
test 'I should not see /foo/ (fails)' do
|
200
|
-
perform :get, path_to('foo'), %(foo)
|
201
|
-
assert_fails { invoke 'I should not see /foo/' }
|
202
|
-
end
|
203
|
-
|
204
|
-
# I should see within
|
205
|
-
|
206
|
-
test 'I should see "bar" within "foo" (passes)' do
|
207
|
-
perform :get, path_to('foo'), %(<div id="foo"><span>bar</span></div>)
|
208
|
-
assert_passes { invoke 'I should see "bar" within "#foo"' }
|
209
|
-
end
|
210
|
-
|
211
|
-
test 'I should see "bar" within "foo" (fails)' do
|
212
|
-
perform :get, path_to('foo'), %(<div id="foo"></div><span>bar</span>)
|
213
|
-
assert_fails { invoke 'I should see "bar" within "#foo"' }
|
214
|
-
end
|
215
|
-
|
216
|
-
test 'I should see /bar/ within "foo" (passes)' do
|
217
|
-
perform :get, path_to('foo'), %(<div id="foo"><span>foobar</span></div>)
|
218
|
-
assert_passes { invoke 'I should see /bar/ within "#foo"' }
|
219
|
-
end
|
220
|
-
|
221
|
-
test 'I should see /bar/ within "foo" (fails)' do
|
222
|
-
perform :get, path_to('foo'), %(<div id="foo"></div><span>foobar</span>)
|
223
|
-
assert_fails { invoke 'I should see /bar/ within "#foo"' }
|
224
|
-
end
|
225
|
-
|
226
|
-
# I should not see within
|
227
|
-
|
228
|
-
test 'I should not see "bar" within "foo" (passes)' do
|
229
|
-
perform :get, path_to('foo'), %(<div id="foo"></div><span>bar</span>)
|
230
|
-
assert_passes { invoke 'I should not see "bar" within "#foo"' }
|
231
|
-
end
|
232
|
-
|
233
|
-
test 'I should not see "bar" within "foo" (fails)' do
|
234
|
-
perform :get, path_to('foo'), %(<div id="foo"><span>bar</span></div>)
|
235
|
-
assert_fails { invoke 'I should not see "bar" within "#foo"' }
|
236
|
-
end
|
237
|
-
|
238
|
-
test 'I should not see /bar/ within "foo" (passes)' do
|
239
|
-
perform :get, path_to('foo'), %(<div id="foo"></div><span>bar</span>)
|
240
|
-
assert_passes { invoke 'I should not see /bar/ within "#foo"' }
|
241
|
-
end
|
242
|
-
|
243
|
-
test 'I should not see /bar/ within "foo" (fails)' do
|
244
|
-
perform :get, path_to('foo'), %(<div id="foo"><span>foobar</span></div>)
|
245
|
-
assert_fails { invoke 'I should not see /bar/ within "#foo"' }
|
246
|
-
end
|
247
|
-
|
248
|
-
# field should contain
|
249
|
-
|
250
|
-
test 'the "foo" field should contain "bar" (passes)' do
|
251
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="bar">)
|
252
|
-
assert_passes { invoke 'the "foo" field should contain "bar"' }
|
253
|
-
end
|
254
|
-
|
255
|
-
test 'the "foo" field should contain "bar" (fails)' do
|
256
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="foo">)
|
257
|
-
assert_fails { invoke 'the "foo" field should contain "bar"' }
|
258
|
-
end
|
259
|
-
|
260
|
-
# field should not contain
|
261
|
-
|
262
|
-
test 'the "foo" field should not contain "bar" (passes)' do
|
263
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="foo">)
|
264
|
-
assert_passes { invoke 'the "foo" field should not contain "bar"' }
|
265
|
-
end
|
266
|
-
|
267
|
-
test 'the "foo" field should not contain "bar" (fails)' do
|
268
|
-
perform :get, path_to('foo'), %(<input type="text" name="foo" value="bar">)
|
269
|
-
assert_fails { invoke 'the "foo" field should not contain "bar"' }
|
270
|
-
end
|
271
|
-
|
272
|
-
# checkbox should be checked
|
273
|
-
|
274
|
-
test 'the "foo" checkbox should be checked (passes)' do
|
275
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo" checked="checked">)
|
276
|
-
assert_passes { invoke 'the "foo" checkbox should be checked' }
|
277
|
-
end
|
278
|
-
|
279
|
-
test 'the "foo" checkbox should be checked (fails)' do
|
280
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo">)
|
281
|
-
assert_fails { invoke 'the "foo" checkbox should be checked' }
|
282
|
-
end
|
283
|
-
|
284
|
-
# checkbox should not be checked
|
285
|
-
|
286
|
-
test 'the "foo" checkbox should not be checked (passes)' do
|
287
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo">)
|
288
|
-
assert_passes { invoke 'the "foo" checkbox should not be checked' }
|
289
|
-
end
|
290
|
-
|
291
|
-
test 'the "foo" checkbox should not be checked (fails)' do
|
292
|
-
perform :get, path_to('foo'), %(<input type="checkbox" name="foo" checked="checked">)
|
293
|
-
assert_fails { invoke 'the "foo" checkbox should not be checked' }
|
294
|
-
end
|
295
|
-
|
296
|
-
# I should be on
|
297
|
-
|
298
|
-
test 'I should be on foo (passes)' do
|
299
|
-
perform :get, path_to('foo'), ''
|
300
|
-
assert_passes { invoke 'I should be on foo' }
|
301
|
-
end
|
302
|
-
|
303
|
-
test 'I should be on foo (fails)' do
|
304
|
-
perform :get, path_to('bar'), ''
|
305
|
-
assert_fails { invoke 'I should be on foo' }
|
306
|
-
end
|
307
|
-
end
|
data/test/fixtures/html_fakes.rb
DELETED
@@ -1,191 +0,0 @@
|
|
1
|
-
module HtmlFakes
|
2
|
-
def html(options = {})
|
3
|
-
fields = Array(options[:fields]).map { |field| self.send(field) }
|
4
|
-
scripts = Array(options[:scripts]).map { |script| self.send(script) }
|
5
|
-
ERB.new(layout).result(binding)
|
6
|
-
end
|
7
|
-
|
8
|
-
def text
|
9
|
-
<<-html
|
10
|
-
<label for="field">Label for field</label>
|
11
|
-
<input type="text" id="field" name="field" />
|
12
|
-
html
|
13
|
-
end
|
14
|
-
|
15
|
-
def textarea
|
16
|
-
<<-html
|
17
|
-
<label for="textarea">Label for textarea</label>
|
18
|
-
<textarea id="textarea" name="textarea"></textarea>
|
19
|
-
html
|
20
|
-
end
|
21
|
-
|
22
|
-
def checkbox
|
23
|
-
<<-html
|
24
|
-
<label for="checkbox">Label for checkbox</label>
|
25
|
-
<input id="checkbox" type="checkbox" name="checkbox" value="1" />
|
26
|
-
html
|
27
|
-
end
|
28
|
-
|
29
|
-
def radio
|
30
|
-
<<-html
|
31
|
-
<label for="radio1">Label for radio</label>
|
32
|
-
<input id="radio1" type="radio" name="radio" value="radio" />
|
33
|
-
<label for="radio2">Label for tv</label>
|
34
|
-
<input id="radio2" type="radio" name="radio" value="tv" />
|
35
|
-
html
|
36
|
-
end
|
37
|
-
|
38
|
-
def select
|
39
|
-
<<-html
|
40
|
-
<label for="select">Label for select</label>
|
41
|
-
<select id="select" name="select">
|
42
|
-
<option value=""></option>
|
43
|
-
<option value="foo">foo</option>
|
44
|
-
</select>
|
45
|
-
html
|
46
|
-
end
|
47
|
-
|
48
|
-
def hidden
|
49
|
-
<<-html
|
50
|
-
<input id="hidden" type="hidden" name="hidden" value="bar" />
|
51
|
-
html
|
52
|
-
end
|
53
|
-
|
54
|
-
def file
|
55
|
-
<<-html
|
56
|
-
<label for="file">Label for file</label><input id="file" type="file" name="file" />
|
57
|
-
html
|
58
|
-
end
|
59
|
-
|
60
|
-
def date
|
61
|
-
<<-html
|
62
|
-
<label for="event_date">Date</label>
|
63
|
-
<select id="event_date_1i" name="event_date(1i)">
|
64
|
-
<option value="2008">2008</option>
|
65
|
-
<option value="2009">2009</option>
|
66
|
-
<option value="2010">2010</option>
|
67
|
-
</select>
|
68
|
-
<select id="event_date_2i" name="event_date(2i)">
|
69
|
-
<option value="10">October</option>
|
70
|
-
<option value="11">November</option>
|
71
|
-
<option value="12">December</option>
|
72
|
-
</select>
|
73
|
-
<select id="event_date_3i" name="event_date(3i)">
|
74
|
-
<option value="6">6</option>
|
75
|
-
<option value="7">7</option>
|
76
|
-
<option value="8">8</option>
|
77
|
-
</select>
|
78
|
-
html
|
79
|
-
end
|
80
|
-
|
81
|
-
def datetime
|
82
|
-
<<-html
|
83
|
-
<label for="event_datetime">Datetime</label>
|
84
|
-
<select id="event_datetime_1i" name="event_datetime(1i)">
|
85
|
-
<option value="2008">2008</option>
|
86
|
-
<option value="2009">2009</option>
|
87
|
-
<option value="2010">2010</option>
|
88
|
-
</select>
|
89
|
-
<select id="event_datetime_2i" name="event_datetime(2i)">
|
90
|
-
<option value="10">October</option>
|
91
|
-
<option value="11">November</option>
|
92
|
-
<option value="12">December</option>
|
93
|
-
</select>
|
94
|
-
<select id="event_datetime_3i" name="event_datetime(3i)">
|
95
|
-
<option value="6">6</option>
|
96
|
-
<option value="7">7</option>
|
97
|
-
<option value="8">8</option>
|
98
|
-
</select> :
|
99
|
-
<select id="event_datetime_4i" name="event_datetime(4i)">
|
100
|
-
<option value="18">18</option>
|
101
|
-
<option value="19">19</option>
|
102
|
-
<option value="20">20</option>
|
103
|
-
</select>
|
104
|
-
<select id="event_datetime_5i" name="event_datetime(5i)">
|
105
|
-
<option value="0">00</option>
|
106
|
-
<option value="1">01</option>
|
107
|
-
<option value="2">02</option>
|
108
|
-
</select>
|
109
|
-
html
|
110
|
-
end
|
111
|
-
|
112
|
-
def time
|
113
|
-
<<-html
|
114
|
-
<label for="event_time">Time</label>
|
115
|
-
<select id="event_time_4i" name="event_time(4i)">
|
116
|
-
<option value="18">18</option>
|
117
|
-
<option value="19">19</option>
|
118
|
-
<option value="20">20</option>
|
119
|
-
</select>
|
120
|
-
<select id="event_time_5i" name="event_time(5i)">
|
121
|
-
<option value="0">00</option>
|
122
|
-
<option value="1">01</option>
|
123
|
-
<option value="2">02</option>
|
124
|
-
</select>
|
125
|
-
html
|
126
|
-
end
|
127
|
-
|
128
|
-
def jquery
|
129
|
-
<<-html
|
130
|
-
<script src="/javascripts/jquery.js" type="text/javascript"></script>
|
131
|
-
html
|
132
|
-
end
|
133
|
-
|
134
|
-
def jquery_ui
|
135
|
-
<<-html
|
136
|
-
<script src="/javascripts/jquery-ui.js" type="text/javascript"></script>
|
137
|
-
html
|
138
|
-
end
|
139
|
-
|
140
|
-
def foo
|
141
|
-
<<-html
|
142
|
-
<script src="/javascripts/foo.js" type="text/javascript"></script>
|
143
|
-
html
|
144
|
-
end
|
145
|
-
|
146
|
-
def hover
|
147
|
-
<<-html
|
148
|
-
<script src="/javascripts/hover.js" type="text/javascript"></script>
|
149
|
-
html
|
150
|
-
end
|
151
|
-
|
152
|
-
def blur
|
153
|
-
<<-html
|
154
|
-
<script src="/javascripts/blur.js" type="text/javascript"></script>
|
155
|
-
html
|
156
|
-
end
|
157
|
-
|
158
|
-
def focus
|
159
|
-
<<-html
|
160
|
-
<script src="/javascripts/focus.js" type="text/javascript"></script>
|
161
|
-
html
|
162
|
-
end
|
163
|
-
|
164
|
-
def double_click
|
165
|
-
<<-html
|
166
|
-
<script src="/javascripts/double_click.js" type="text/javascript"></script>
|
167
|
-
html
|
168
|
-
end
|
169
|
-
|
170
|
-
def drag
|
171
|
-
<<-html
|
172
|
-
<script src="/javascripts/drag.js" type="text/javascript"></script>
|
173
|
-
html
|
174
|
-
end
|
175
|
-
|
176
|
-
def layout
|
177
|
-
<<-erb
|
178
|
-
<html>
|
179
|
-
<head><%= scripts %></head>
|
180
|
-
<body>
|
181
|
-
<p id="paragraph"></p>
|
182
|
-
<p><a href="/link" id="link">link</a></p>
|
183
|
-
<form action="/form" method="get" id="form" enctype="multipart/form-data">
|
184
|
-
<%= fields %>
|
185
|
-
<input type="submit" value="button" />
|
186
|
-
</form>
|
187
|
-
</body>
|
188
|
-
</html>
|
189
|
-
erb
|
190
|
-
end
|
191
|
-
end
|