webrat 0.5.3 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/Gemfile +19 -0
- data/History.txt +29 -0
- data/Rakefile +27 -63
- data/Thorfile +117 -0
- data/lib/webrat.rb +11 -3
- data/lib/webrat/{mechanize.rb → adapters/mechanize.rb} +0 -0
- data/lib/webrat/adapters/merb.rb +11 -0
- data/lib/webrat/{rack.rb → adapters/rack.rb} +0 -0
- data/lib/webrat/{rails.rb → adapters/rails.rb} +2 -23
- data/lib/webrat/{sinatra.rb → adapters/sinatra.rb} +0 -2
- data/lib/webrat/core.rb +0 -1
- data/lib/webrat/core/configuration.rb +6 -16
- data/lib/webrat/core/elements/area.rb +2 -2
- data/lib/webrat/core/elements/element.rb +3 -3
- data/lib/webrat/core/elements/field.rb +106 -30
- data/lib/webrat/core/elements/form.rb +4 -4
- data/lib/webrat/core/elements/label.rb +4 -4
- data/lib/webrat/core/elements/link.rb +6 -6
- data/lib/webrat/core/elements/select_option.rb +15 -2
- data/lib/webrat/core/locators.rb +1 -1
- data/lib/webrat/core/locators/area_locator.rb +3 -3
- data/lib/webrat/core/locators/button_locator.rb +6 -6
- data/lib/webrat/core/locators/field_by_id_locator.rb +3 -3
- data/lib/webrat/core/locators/field_labeled_locator.rb +2 -2
- data/lib/webrat/core/locators/field_named_locator.rb +3 -3
- data/lib/webrat/core/locators/form_locator.rb +1 -1
- data/lib/webrat/core/locators/label_locator.rb +2 -2
- data/lib/webrat/core/locators/link_locator.rb +7 -7
- data/lib/webrat/core/locators/select_option_locator.rb +5 -5
- data/lib/webrat/core/logging.rb +4 -5
- data/lib/webrat/core/matchers/have_content.rb +2 -7
- data/lib/webrat/core/matchers/have_xpath.rb +3 -28
- data/lib/webrat/core/methods.rb +1 -0
- data/lib/webrat/core/scope.rb +17 -2
- data/lib/webrat/core/session.rb +2 -1
- data/lib/webrat/core/xml.rb +41 -84
- data/lib/webrat/integrations/merb.rb +10 -0
- data/lib/webrat/integrations/rails.rb +25 -0
- data/lib/webrat/integrations/rspec-rails.rb +11 -0
- data/lib/webrat/integrations/selenium.rb +11 -0
- data/lib/webrat/rspec-rails.rb +2 -10
- data/lib/webrat/selenium.rb +0 -10
- data/lib/webrat/selenium/application_servers.rb +1 -1
- data/lib/webrat/selenium/application_servers/external.rb +1 -1
- data/lib/webrat/selenium/location_strategy_javascript/label.js +29 -3
- data/lib/webrat/selenium/location_strategy_javascript/webrat.js +1 -0
- data/lib/webrat/selenium/location_strategy_javascript/webratlink.js +24 -4
- data/lib/webrat/selenium/selenium_rc_server.rb +2 -2
- data/lib/webrat/selenium/selenium_session.rb +21 -2
- data/lib/webrat/selenium/silence_stream.rb +1 -1
- data/spec/integration/mechanize/spec/spec_helper.rb +3 -1
- data/spec/integration/rails/app/controllers/{application.rb → application_controller.rb} +0 -0
- data/spec/integration/rails/app/controllers/webrat_controller.rb +3 -0
- data/spec/integration/rails/app/views/buttons/show.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/buttons.html.erb +0 -2
- data/spec/integration/rails/app/views/webrat/within.html.erb +3 -0
- data/spec/integration/rails/config/environment.rb +1 -1
- data/spec/integration/rails/config/routes.rb +1 -0
- data/spec/integration/rails/test/integration/button_click_test.rb +12 -26
- data/spec/integration/rails/test/integration/fill_in_test.rb +1 -1
- data/spec/integration/rails/test/integration/link_click_test.rb +1 -1
- data/spec/integration/rails/test/integration/webrat_test.rb +35 -9
- data/spec/integration/rails/test/test_helper.rb +1 -0
- data/spec/private/core/configuration_spec.rb +2 -31
- data/spec/private/core/field_spec.rb +14 -16
- data/spec/private/mechanize/mechanize_adapter_spec.rb +0 -2
- data/spec/private/nokogiri_spec.rb +2 -2
- data/spec/private/rails/rails_adapter_spec.rb +0 -27
- data/spec/public/basic_auth_spec.rb +13 -2
- data/spec/public/click_button_spec.rb +10 -12
- data/spec/public/click_link_spec.rb +21 -0
- data/spec/public/fill_in_spec.rb +15 -0
- data/spec/public/matchers/have_selector_spec.rb +4 -0
- data/spec/public/select_spec.rb +232 -26
- data/spec/spec_helper.rb +2 -0
- data/webrat.gemspec +305 -313
- metadata +21 -25
- data/VERSION +0 -1
- data/lib/webrat/core/xml/hpricot.rb +0 -19
- data/lib/webrat/core/xml/nokogiri.rb +0 -76
- data/lib/webrat/core/xml/rexml.rb +0 -24
- data/lib/webrat/merb_adapter.rb +0 -82
- data/lib/webrat/merb_multipart_support.rb +0 -27
- data/spec/private/core/logging_spec.rb +0 -10
- data/spec/private/merb/attaches_file_spec.rb +0 -93
- data/spec/private/merb/merb_adapter_spec.rb +0 -61
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-11-28 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -45,19 +45,25 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
|
47
47
|
extra_rdoc_files:
|
48
|
-
- History.txt
|
49
|
-
- MIT-LICENSE.txt
|
50
48
|
- README.rdoc
|
49
|
+
- MIT-LICENSE.txt
|
50
|
+
- History.txt
|
51
51
|
files:
|
52
52
|
- .document
|
53
53
|
- .gitignore
|
54
|
+
- Gemfile
|
54
55
|
- History.txt
|
55
56
|
- MIT-LICENSE.txt
|
56
57
|
- README.rdoc
|
57
58
|
- Rakefile
|
58
|
-
-
|
59
|
+
- Thorfile
|
59
60
|
- install.rb
|
60
61
|
- lib/webrat.rb
|
62
|
+
- lib/webrat/adapters/mechanize.rb
|
63
|
+
- lib/webrat/adapters/merb.rb
|
64
|
+
- lib/webrat/adapters/rack.rb
|
65
|
+
- lib/webrat/adapters/rails.rb
|
66
|
+
- lib/webrat/adapters/sinatra.rb
|
61
67
|
- lib/webrat/core.rb
|
62
68
|
- lib/webrat/core/configuration.rb
|
63
69
|
- lib/webrat/core/elements/area.rb
|
@@ -91,21 +97,17 @@ files:
|
|
91
97
|
- lib/webrat/core/scope.rb
|
92
98
|
- lib/webrat/core/session.rb
|
93
99
|
- lib/webrat/core/xml.rb
|
94
|
-
- lib/webrat/core/xml/hpricot.rb
|
95
|
-
- lib/webrat/core/xml/nokogiri.rb
|
96
|
-
- lib/webrat/core/xml/rexml.rb
|
97
100
|
- lib/webrat/core_extensions/blank.rb
|
98
101
|
- lib/webrat/core_extensions/deprecate.rb
|
99
102
|
- lib/webrat/core_extensions/detect_mapped.rb
|
100
103
|
- lib/webrat/core_extensions/meta_class.rb
|
101
104
|
- lib/webrat/core_extensions/nil_to_param.rb
|
102
105
|
- lib/webrat/core_extensions/tcp_socket.rb
|
103
|
-
- lib/webrat/
|
106
|
+
- lib/webrat/integrations/merb.rb
|
107
|
+
- lib/webrat/integrations/rails.rb
|
108
|
+
- lib/webrat/integrations/rspec-rails.rb
|
109
|
+
- lib/webrat/integrations/selenium.rb
|
104
110
|
- lib/webrat/merb.rb
|
105
|
-
- lib/webrat/merb_adapter.rb
|
106
|
-
- lib/webrat/merb_multipart_support.rb
|
107
|
-
- lib/webrat/rack.rb
|
108
|
-
- lib/webrat/rails.rb
|
109
111
|
- lib/webrat/rspec-rails.rb
|
110
112
|
- lib/webrat/selenium.rb
|
111
113
|
- lib/webrat/selenium/application_server_factory.rb
|
@@ -130,7 +132,6 @@ files:
|
|
130
132
|
- lib/webrat/selenium/selenium_rc_server.rb
|
131
133
|
- lib/webrat/selenium/selenium_session.rb
|
132
134
|
- lib/webrat/selenium/silence_stream.rb
|
133
|
-
- lib/webrat/sinatra.rb
|
134
135
|
- spec/fakes/test_adapter.rb
|
135
136
|
- spec/integration/mechanize/Rakefile
|
136
137
|
- spec/integration/mechanize/config.ru
|
@@ -168,7 +169,7 @@ files:
|
|
168
169
|
- spec/integration/rack/test/webrat_rack_test.rb
|
169
170
|
- spec/integration/rails/.gitignore
|
170
171
|
- spec/integration/rails/Rakefile
|
171
|
-
- spec/integration/rails/app/controllers/
|
172
|
+
- spec/integration/rails/app/controllers/application_controller.rb
|
172
173
|
- spec/integration/rails/app/controllers/buttons_controller.rb
|
173
174
|
- spec/integration/rails/app/controllers/fields_controller.rb
|
174
175
|
- spec/integration/rails/app/controllers/links_controller.rb
|
@@ -182,6 +183,7 @@ files:
|
|
182
183
|
- spec/integration/rails/app/views/webrat/before_redirect_form.html.erb
|
183
184
|
- spec/integration/rails/app/views/webrat/buttons.html.erb
|
184
185
|
- spec/integration/rails/app/views/webrat/form.html.erb
|
186
|
+
- spec/integration/rails/app/views/webrat/within.html.erb
|
185
187
|
- spec/integration/rails/config/boot.rb
|
186
188
|
- spec/integration/rails/config/environment.rb
|
187
189
|
- spec/integration/rails/config/environments/development.rb
|
@@ -223,11 +225,8 @@ files:
|
|
223
225
|
- spec/private/core/configuration_spec.rb
|
224
226
|
- spec/private/core/field_spec.rb
|
225
227
|
- spec/private/core/link_spec.rb
|
226
|
-
- spec/private/core/logging_spec.rb
|
227
228
|
- spec/private/core/session_spec.rb
|
228
229
|
- spec/private/mechanize/mechanize_adapter_spec.rb
|
229
|
-
- spec/private/merb/attaches_file_spec.rb
|
230
|
-
- spec/private/merb/merb_adapter_spec.rb
|
231
230
|
- spec/private/nokogiri_spec.rb
|
232
231
|
- spec/private/rails/attaches_file_spec.rb
|
233
232
|
- spec/private/rails/rails_adapter_spec.rb
|
@@ -269,8 +268,8 @@ homepage: http://github.com/brynary/webrat
|
|
269
268
|
licenses: []
|
270
269
|
|
271
270
|
post_install_message:
|
272
|
-
rdoc_options:
|
273
|
-
|
271
|
+
rdoc_options: []
|
272
|
+
|
274
273
|
require_paths:
|
275
274
|
- lib
|
276
275
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -288,7 +287,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
288
287
|
requirements: []
|
289
288
|
|
290
289
|
rubyforge_project: webrat
|
291
|
-
rubygems_version: 1.3.
|
290
|
+
rubygems_version: 1.3.5
|
292
291
|
signing_key:
|
293
292
|
specification_version: 3
|
294
293
|
summary: Ruby Acceptance Testing for Web applications
|
@@ -316,7 +315,7 @@ test_files:
|
|
316
315
|
- spec/integration/rack/app.rb
|
317
316
|
- spec/integration/rack/test/helper.rb
|
318
317
|
- spec/integration/rack/test/webrat_rack_test.rb
|
319
|
-
- spec/integration/rails/app/controllers/
|
318
|
+
- spec/integration/rails/app/controllers/application_controller.rb
|
320
319
|
- spec/integration/rails/app/controllers/buttons_controller.rb
|
321
320
|
- spec/integration/rails/app/controllers/fields_controller.rb
|
322
321
|
- spec/integration/rails/app/controllers/links_controller.rb
|
@@ -346,11 +345,8 @@ test_files:
|
|
346
345
|
- spec/private/core/configuration_spec.rb
|
347
346
|
- spec/private/core/field_spec.rb
|
348
347
|
- spec/private/core/link_spec.rb
|
349
|
-
- spec/private/core/logging_spec.rb
|
350
348
|
- spec/private/core/session_spec.rb
|
351
349
|
- spec/private/mechanize/mechanize_adapter_spec.rb
|
352
|
-
- spec/private/merb/attaches_file_spec.rb
|
353
|
-
- spec/private/merb/merb_adapter_spec.rb
|
354
350
|
- spec/private/nokogiri_spec.rb
|
355
351
|
- spec/private/rails/attaches_file_spec.rb
|
356
352
|
- spec/private/rails/rails_adapter_spec.rb
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.5.3
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Webrat
|
2
|
-
|
3
|
-
def self.hpricot_document(stringlike)
|
4
|
-
return stringlike.dom if stringlike.respond_to?(:dom)
|
5
|
-
|
6
|
-
if Hpricot::Doc === stringlike
|
7
|
-
stringlike
|
8
|
-
elsif Hpricot::Elements === stringlike
|
9
|
-
stringlike
|
10
|
-
elsif StringIO === stringlike
|
11
|
-
Hpricot(stringlike.string)
|
12
|
-
elsif stringlike.respond_to?(:body)
|
13
|
-
Hpricot(stringlike.body.to_s)
|
14
|
-
else
|
15
|
-
Hpricot(stringlike.to_s)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
require "webrat/core_extensions/meta_class"
|
2
|
-
|
3
|
-
module Webrat
|
4
|
-
|
5
|
-
def self.nokogiri_document(stringlike) #:nodoc:
|
6
|
-
return stringlike.dom if stringlike.respond_to?(:dom)
|
7
|
-
|
8
|
-
if Nokogiri::HTML::Document === stringlike
|
9
|
-
stringlike
|
10
|
-
elsif Nokogiri::XML::NodeSet === stringlike
|
11
|
-
stringlike
|
12
|
-
elsif StringIO === stringlike
|
13
|
-
Nokogiri::HTML(stringlike.string)
|
14
|
-
elsif stringlike.respond_to?(:body)
|
15
|
-
Nokogiri::HTML(stringlike.body.to_s)
|
16
|
-
else
|
17
|
-
Nokogiri::HTML(stringlike.to_s)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.html_nokogiri_document(stringlike) #:nodoc:
|
22
|
-
return stringlike.dom if stringlike.respond_to?(:dom)
|
23
|
-
|
24
|
-
if Nokogiri::HTML::Document === stringlike
|
25
|
-
stringlike
|
26
|
-
elsif Nokogiri::XML::NodeSet === stringlike
|
27
|
-
stringlike
|
28
|
-
elsif StringIO === stringlike
|
29
|
-
Nokogiri::HTML(stringlike.string)
|
30
|
-
elsif stringlike.respond_to?(:body)
|
31
|
-
Nokogiri::HTML(stringlike.body.to_s)
|
32
|
-
else
|
33
|
-
Nokogiri::HTML(stringlike.to_s)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.xml_nokogiri_document(stringlike) #:nodoc:
|
38
|
-
return stringlike.dom if stringlike.respond_to?(:dom)
|
39
|
-
|
40
|
-
if Nokogiri::HTML::Document === stringlike
|
41
|
-
stringlike
|
42
|
-
elsif Nokogiri::XML::NodeSet === stringlike
|
43
|
-
stringlike
|
44
|
-
elsif StringIO === stringlike
|
45
|
-
Nokogiri::XML(stringlike.string)
|
46
|
-
elsif stringlike.respond_to?(:body)
|
47
|
-
Nokogiri::XML(stringlike.body.to_s)
|
48
|
-
else
|
49
|
-
Nokogiri::XML(stringlike.to_s)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.define_dom_method(object, dom) #:nodoc:
|
54
|
-
object.meta_class.send(:define_method, :dom) do
|
55
|
-
dom
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
module Nokogiri #:nodoc:
|
63
|
-
module CSS #:nodoc:
|
64
|
-
class XPathVisitor #:nodoc:
|
65
|
-
|
66
|
-
def visit_pseudo_class_text(node) #:nodoc:
|
67
|
-
"@type='text'"
|
68
|
-
end
|
69
|
-
|
70
|
-
def visit_pseudo_class_password(node) #:nodoc:
|
71
|
-
"@type='password'"
|
72
|
-
end
|
73
|
-
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
module Webrat
|
2
|
-
|
3
|
-
def self.rexml_document(stringlike)
|
4
|
-
stringlike = stringlike.body.to_s if stringlike.respond_to?(:body)
|
5
|
-
|
6
|
-
case stringlike
|
7
|
-
when REXML::Document
|
8
|
-
stringlike.root
|
9
|
-
when REXML::Node, Array
|
10
|
-
stringlike
|
11
|
-
else
|
12
|
-
begin
|
13
|
-
REXML::Document.new(stringlike.to_s).root
|
14
|
-
rescue REXML::ParseException => e
|
15
|
-
if e.message.include?("second root element")
|
16
|
-
REXML::Document.new("<fake-root-element>#{stringlike}</fake-root-element>").root
|
17
|
-
else
|
18
|
-
raise e
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
data/lib/webrat/merb_adapter.rb
DELETED
@@ -1,82 +0,0 @@
|
|
1
|
-
require "webrat"
|
2
|
-
require "merb-core"
|
3
|
-
require "webrat/merb_multipart_support"
|
4
|
-
|
5
|
-
module Webrat
|
6
|
-
class MerbAdapter #:nodoc:
|
7
|
-
include Merb::Test::MakeRequest
|
8
|
-
|
9
|
-
# Include Webrat's own version of multipart_post/put because the officially
|
10
|
-
# supported methods in Merb don't perform the request correctly.
|
11
|
-
include MerbMultipartSupport
|
12
|
-
|
13
|
-
attr_accessor :response
|
14
|
-
|
15
|
-
def initialize(context=nil); end
|
16
|
-
|
17
|
-
def get(url, data, headers = nil)
|
18
|
-
do_request(url, data, headers, "GET")
|
19
|
-
end
|
20
|
-
|
21
|
-
def post(url, data, headers = nil)
|
22
|
-
do_request(url, data, headers, "POST")
|
23
|
-
end
|
24
|
-
|
25
|
-
def put(url, data, headers = nil)
|
26
|
-
do_request(url, data, headers, "PUT")
|
27
|
-
end
|
28
|
-
|
29
|
-
def delete(url, data, headers = nil)
|
30
|
-
do_request(url, data, headers, "DELETE")
|
31
|
-
end
|
32
|
-
|
33
|
-
def response_body
|
34
|
-
@response.body.to_s
|
35
|
-
end
|
36
|
-
|
37
|
-
def response_code
|
38
|
-
@response.status
|
39
|
-
end
|
40
|
-
|
41
|
-
def do_request(url, data, headers, method)
|
42
|
-
if method == "POST" && has_file?(data)
|
43
|
-
@response = multipart_post(url, data, :headers => headers)
|
44
|
-
|
45
|
-
elsif method == "PUT" && has_file?(data)
|
46
|
-
@response = multipart_put(url, data, :headers => headers)
|
47
|
-
|
48
|
-
else
|
49
|
-
@response = request(url,
|
50
|
-
:params => (data && data.any?) ? data : nil,
|
51
|
-
:headers => headers,
|
52
|
-
:method => method)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
protected
|
57
|
-
|
58
|
-
# Recursively search the data for a file attachment.
|
59
|
-
def has_file?(data)
|
60
|
-
data.each do |key, value|
|
61
|
-
if value.is_a?(Hash)
|
62
|
-
return has_file?(value)
|
63
|
-
else
|
64
|
-
return true if value.is_a?(File)
|
65
|
-
end
|
66
|
-
end
|
67
|
-
return false
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
module Merb #:nodoc:
|
74
|
-
module Test #:nodoc:
|
75
|
-
module RequestHelper #:nodoc:
|
76
|
-
def request(uri, env = {})
|
77
|
-
@_webrat_session ||= Webrat::MerbAdapter.new
|
78
|
-
@_webrat_session.response = @_webrat_session.request(uri, env)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Webrat
|
2
|
-
|
3
|
-
# These methods are copied from merb-core/two-oh.rb which defines new
|
4
|
-
# multipart_post and multipart_put methods for Merb::Test::MultipartRequestHelper.
|
5
|
-
# We can't require two-oh.rb because it alters Merb's own behavior, causing
|
6
|
-
# failing specs in Merb when Webrat is required.
|
7
|
-
module MerbMultipartSupport
|
8
|
-
def multipart_request(path, params = {}, env = {})
|
9
|
-
multipart = Merb::Test::MultipartRequestHelper::Post.new(params)
|
10
|
-
body, head = multipart.to_multipart
|
11
|
-
env["CONTENT_TYPE"] = head
|
12
|
-
env["CONTENT_LENGTH"] = body.size
|
13
|
-
env[:input] = StringIO.new(body)
|
14
|
-
request(path, env)
|
15
|
-
end
|
16
|
-
|
17
|
-
def multipart_post(path, params = {}, env = {})
|
18
|
-
env[:method] = "POST"
|
19
|
-
multipart_request(path, params, env)
|
20
|
-
end
|
21
|
-
|
22
|
-
def multipart_put(path, params = {}, env = {}, &block)
|
23
|
-
env[:method] = "PUT"
|
24
|
-
multipart_request(path, params, env)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
-
|
3
|
-
describe "attach_file with merb" do
|
4
|
-
before do
|
5
|
-
Webrat.configuration.mode = :merb
|
6
|
-
@filename = __FILE__
|
7
|
-
end
|
8
|
-
|
9
|
-
it "should fail if no file field found" do
|
10
|
-
with_html <<-HTML
|
11
|
-
<html>
|
12
|
-
<form method="post" action="/widgets">
|
13
|
-
</form>
|
14
|
-
</html>
|
15
|
-
HTML
|
16
|
-
lambda { attach_file("Doc", "/some/path") }.should raise_error(Webrat::NotFoundError)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should submit empty strings for blank file fields" do
|
20
|
-
with_html <<-HTML
|
21
|
-
<html>
|
22
|
-
<form method="post" action="/widgets">
|
23
|
-
<input type="file" id="widget_file" name="widget[file]" />
|
24
|
-
<input type="submit" />
|
25
|
-
</form>
|
26
|
-
</html>
|
27
|
-
HTML
|
28
|
-
webrat_session.should_receive(:post).with("/widgets", { "widget" => { "file" => "" } })
|
29
|
-
click_button
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should submit the attached file" do
|
33
|
-
with_html <<-HTML
|
34
|
-
<html>
|
35
|
-
<form method="post" action="/widgets">
|
36
|
-
<label for="widget_file">Document</label>
|
37
|
-
<input type="file" id="widget_file" name="widget[file]" />
|
38
|
-
<input type="submit" />
|
39
|
-
</form>
|
40
|
-
</html>
|
41
|
-
HTML
|
42
|
-
webrat_session.should_receive(:post).with { |path, params|
|
43
|
-
path.should == "/widgets"
|
44
|
-
params.should have_key("widget")
|
45
|
-
params["widget"].should have_key("file")
|
46
|
-
params["widget"]["file"].should be_an_instance_of(File)
|
47
|
-
params["widget"]["file"].path.should == @filename
|
48
|
-
}
|
49
|
-
attach_file "Document", @filename
|
50
|
-
click_button
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should support collections" do
|
54
|
-
with_html <<-HTML
|
55
|
-
<html>
|
56
|
-
<form method="post" action="/widgets">
|
57
|
-
<label for="widget_file1">Document</label>
|
58
|
-
<input type="file" id="widget_file1" name="widget[files][]" />
|
59
|
-
<label for="widget_file2">Spreadsheet</label>
|
60
|
-
<input type="file" id="widget_file2" name="widget[files][]" />
|
61
|
-
<input type="submit" />
|
62
|
-
</form>
|
63
|
-
</html>
|
64
|
-
HTML
|
65
|
-
webrat_session.should_receive(:post).with { |path, params|
|
66
|
-
path.should == "/widgets"
|
67
|
-
params.should have_key("widget")
|
68
|
-
params["widget"].should have_key("files")
|
69
|
-
params["widget"]["files"][0].should be_an_instance_of(File)
|
70
|
-
params["widget"]["files"][0].path.should == @filename
|
71
|
-
params["widget"]["files"][1].should be_an_instance_of(File)
|
72
|
-
params["widget"]["files"][1].path.should == @filename
|
73
|
-
}
|
74
|
-
attach_file "Document", @filename
|
75
|
-
attach_file "Spreadsheet", @filename
|
76
|
-
click_button
|
77
|
-
end
|
78
|
-
|
79
|
-
xit "should allow the content type to be specified" do
|
80
|
-
with_html <<-HTML
|
81
|
-
<html>
|
82
|
-
<form method="post" action="/widgets">
|
83
|
-
<label for="person_picture">Picture</label>
|
84
|
-
<input type="file" id="person_picture" name="person[picture]" />
|
85
|
-
<input type="submit" />
|
86
|
-
</form>
|
87
|
-
</html>
|
88
|
-
HTML
|
89
|
-
ActionController::TestUploadedFile.should_receive(:new).with(@filename, "image/png").any_number_of_times
|
90
|
-
attach_file "Picture", @filename, "image/png"
|
91
|
-
click_button
|
92
|
-
end
|
93
|
-
end
|