webrat 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/Gemfile +0 -6
  2. data/History.txt +17 -0
  3. data/Rakefile +7 -9
  4. data/lib/webrat.rb +1 -1
  5. data/lib/webrat/adapters/mechanize.rb +22 -6
  6. data/lib/webrat/adapters/rack.rb +4 -0
  7. data/lib/webrat/adapters/rails.rb +4 -0
  8. data/lib/webrat/core/configuration.rb +16 -1
  9. data/lib/webrat/core/elements/field.rb +40 -89
  10. data/lib/webrat/core/elements/form.rb +55 -31
  11. data/lib/webrat/core/locators/form_locator.rb +1 -1
  12. data/lib/webrat/core/matchers/have_xpath.rb +4 -2
  13. data/lib/webrat/core/methods.rb +1 -1
  14. data/lib/webrat/core/mime.rb +2 -2
  15. data/lib/webrat/core/scope.rb +1 -0
  16. data/lib/webrat/core/session.rb +4 -3
  17. data/lib/webrat/core_extensions/{nil_to_param.rb → nil_to_query_string.rb} +1 -1
  18. data/lib/webrat/selenium/location_strategy_javascript/label.js +9 -3
  19. data/lib/webrat/selenium/selenium_rc_server.rb +4 -1
  20. data/lib/webrat/selenium/selenium_session.rb +9 -4
  21. data/spec/fakes/test_adapter.rb +1 -1
  22. data/spec/integration/mechanize/sample_app.rb +16 -1
  23. data/spec/integration/mechanize/spec/mechanize_spec.rb +9 -1
  24. data/spec/integration/rack/app.rb +2 -2
  25. data/spec/integration/rack/test/helper.rb +0 -1
  26. data/spec/integration/rack/test/webrat_rack_test.rb +3 -2
  27. data/spec/integration/sinatra/classic_app.rb +0 -1
  28. data/spec/integration/sinatra/modular_app.rb +0 -1
  29. data/spec/integration/sinatra/test/classic_app_test.rb +1 -0
  30. data/spec/integration/sinatra/test/test_helper.rb +0 -1
  31. data/spec/private/core/field_spec.rb +1 -1
  32. data/spec/private/core/form_spec.rb +51 -0
  33. data/spec/private/core/session_spec.rb +5 -18
  34. data/spec/private/mechanize/mechanize_adapter_spec.rb +24 -1
  35. data/spec/private/rails/attaches_file_spec.rb +33 -0
  36. data/spec/public/matchers/have_xpath_spec.rb +6 -0
  37. data/spec/public/submit_form_spec.rb +52 -1
  38. data/spec/spec_helper.rb +0 -1
  39. data/webrat.gemspec +6 -4
  40. metadata +38 -18
@@ -106,24 +106,6 @@ describe Webrat::Session do
106
106
  webrat_session = Webrat::Session.new
107
107
  end
108
108
 
109
- it "should return true if the last response was a redirect and Fixnum#/ returns a Rational" do
110
- # This happens if the ruby-units gem has been required
111
- Fixnum.class_eval do
112
- alias_method :original_divide, "/".to_sym
113
-
114
- def /(other)
115
- Rational(self, other)
116
- end
117
- end
118
-
119
- webrat_session.stub!(:response_code => 301)
120
- webrat_session.redirect?.should be_true
121
-
122
- Fixnum.class_eval do
123
- alias_method "/".to_sym, :original_divide
124
- end
125
- end
126
-
127
109
  it "should return true if the last response was a redirect" do
128
110
  webrat_session.stub!(:response_code => 301)
129
111
  webrat_session.redirect?.should be_true
@@ -133,6 +115,11 @@ describe Webrat::Session do
133
115
  webrat_session.stub!(:response_code => 200)
134
116
  webrat_session.redirect?.should be_false
135
117
  end
118
+
119
+ it "should return false if the last response was a 304 Not Modified" do
120
+ webrat_session.stub!(:response_code => 304)
121
+ webrat_session.redirect?.should be_false
122
+ end
136
123
  end
137
124
 
138
125
  describe "#internal_redirect?" do
@@ -1,6 +1,9 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
2
 
3
3
  describe Webrat::MechanizeAdapter do
4
+
5
+ Mechanize = WWW::Mechanize if defined?(WWW::Mechanize)
6
+
4
7
  before :each do
5
8
  Webrat.configuration.mode = :mechanize
6
9
  end
@@ -9,6 +12,13 @@ describe Webrat::MechanizeAdapter do
9
12
  @mech = Webrat::MechanizeAdapter.new
10
13
  end
11
14
 
15
+ describe "mechanize" do
16
+ it "should disable the following of redirects on the mechanize instance" do
17
+ mech = @mech.mechanize
18
+ mech.redirect_ok.should be_false
19
+ end
20
+ end
21
+
12
22
  describe "post" do
13
23
  def url
14
24
  'http://test.host/users'
@@ -24,7 +34,8 @@ describe Webrat::MechanizeAdapter do
24
34
 
25
35
  it "should flatten model post data" do
26
36
  mechanize = mock(:mechanize)
27
- WWW::Mechanize.stub!(:new => mechanize)
37
+ mechanize.stub!(:redirect_ok=)
38
+ Mechanize.stub!(:new => mechanize)
28
39
  mechanize.should_receive(:post).with(url, flattened_data)
29
40
  Webrat::MechanizeAdapter.new.post(url, data)
30
41
  end
@@ -70,4 +81,16 @@ describe Webrat::MechanizeAdapter do
70
81
  @session.absolute_url(relative_url).should == 'https://test.host/wilma'
71
82
  end
72
83
  end
84
+
85
+ describe "response_headers" do
86
+ it "should return the Headers object from the response" do
87
+ mech = @mech.mechanize
88
+ resp = mock('Mechanize::File')
89
+ hdr = Mechanize::Headers.new
90
+ resp.should_receive(:header).and_return(hdr)
91
+ mech.stub!(:get).and_return(resp)
92
+ @mech.get('/', nil)
93
+ @mech.response_headers.should == hdr
94
+ end
95
+ end
73
96
  end
@@ -78,4 +78,37 @@ describe "attach_file" do
78
78
  attach_file "Picture", @filename, "image/png"
79
79
  click_button
80
80
  end
81
+
82
+ it "should support nested attributes" do
83
+ with_html <<-HTML
84
+ <html>
85
+ <form method="post" action="/albums">
86
+ <label for="photo_file1">Photo</label>
87
+ <input type="file" id="photo_file1" name="album[photos_attributes][][image]" />
88
+ <input type="submit" />
89
+ </form>
90
+ </html>
91
+ HTML
92
+ webrat_session.should_receive(:post).with("/albums", { "album" => { "photos_attributes" => [{"image" => @uploaded_file}] } })
93
+ attach_file "Photo", @filename
94
+ click_button
95
+ end
96
+
97
+ it "should support nested attributes with multiple files" do
98
+ with_html <<-HTML
99
+ <html>
100
+ <form method="post" action="/albums">
101
+ <label for="photo_file1">Photo 1</label>
102
+ <input type="file" id="photo_file1" name="album[photos_attributes][][image]" />
103
+ <label for="photo_file2">Photo 2</label>
104
+ <input type="file" id="photo_file2" name="album[photos_attributes][][image]" />
105
+ <input type="submit" />
106
+ </form>
107
+ </html>
108
+ HTML
109
+ webrat_session.should_receive(:post).with("/albums", { "album" => { "photos_attributes" => [{"image" => @uploaded_file}, {"image" => @uploaded_file}] } })
110
+ attach_file "Photo 1", @filename
111
+ attach_file "Photo 2", @filename
112
+ click_button
113
+ end
81
114
  end
@@ -88,6 +88,12 @@ describe "have_xpath" do
88
88
  end
89
89
  }.should raise_error(Spec::Expectations::ExpectationNotMetError)
90
90
  end
91
+
92
+ it "should match negative expectations in the block" do
93
+ @body.should have_xpath("//div") do |node|
94
+ node.should_not have_xpath("//div[@id='main']")
95
+ end
96
+ end
91
97
 
92
98
  it "should match descendants of the matched elements in the block" do
93
99
  @body.should have_xpath("//ul") do |node|
@@ -1,5 +1,56 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + "/../spec_helper")
2
2
 
3
3
  describe "submit_form" do
4
- it "needs specs"
4
+ it "should submit forms by ID" do
5
+ with_html <<-HTML
6
+ <html>
7
+ <form id="form1" action="/form1">
8
+ <label for="email">Email:</label> <input type="text" id="email" name="email" /></label>
9
+ <input type="submit" value="Add" />
10
+ </form>
11
+ </html>
12
+ HTML
13
+
14
+ webrat_session.should_receive(:get).with("/form1", "email" => "test@example.com")
15
+
16
+ fill_in "Email", :with => "test@example.com"
17
+ submit_form "form1"
18
+ end
19
+
20
+ it "should submit forms by CSS" do
21
+ with_html <<-HTML
22
+ <html>
23
+ <form id="form1" action="/form1">
24
+ <label for="email">Email:</label> <input id="email" type="text" name="email" />
25
+ <input type="submit" value="Add" />
26
+ </form>
27
+ </html>
28
+ HTML
29
+
30
+ webrat_session.should_receive(:get).with("/form1", "email" => "test@example.com")
31
+
32
+ fill_in "Email", :with => "test@example.com"
33
+ submit_form "form[action='/form1']"
34
+ end
35
+
36
+ it "should give priority to selecting forms by ID" do
37
+ with_html <<-HTML
38
+ <html>
39
+ <form action="/form1">
40
+ <label for="email">Email:</label> <input id="email" type="text" name="email" />
41
+ <input type="submit" value="Add" />
42
+ </form>
43
+
44
+ <form action="/form2" id="form">
45
+ <label for="email2">Another email:</label> <input id="email2" type="text" name="email" />
46
+ <input type="submit" value="Add" />
47
+ </form>
48
+ </html>
49
+ HTML
50
+
51
+ webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
52
+
53
+ fill_in "Another email", :with => "test@example.com"
54
+ submit_form "form"
55
+ end
5
56
  end
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "test/unit"
3
2
  require "spec"
4
3
 
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{webrat}
5
- s.version = "0.7.0"
5
+ s.version = "0.7.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Bryan Helmkamp"]
9
- s.date = %q{2010-01-17}
9
+ s.date = %q{2010-04-26}
10
10
  s.description = %q{Webrat lets you quickly write expressive and robust acceptance tests
11
11
  for a Ruby web application. It supports simulating a browser inside
12
12
  a Ruby process to avoid the performance hit and browser dependency of
@@ -72,7 +72,7 @@ Most Ruby web frameworks and testing frameworks are supported.}
72
72
  "lib/webrat/core_extensions/deprecate.rb",
73
73
  "lib/webrat/core_extensions/detect_mapped.rb",
74
74
  "lib/webrat/core_extensions/meta_class.rb",
75
- "lib/webrat/core_extensions/nil_to_param.rb",
75
+ "lib/webrat/core_extensions/nil_to_query_string.rb",
76
76
  "lib/webrat/core_extensions/tcp_socket.rb",
77
77
  "lib/webrat/integrations/merb.rb",
78
78
  "lib/webrat/integrations/rails.rb",
@@ -195,6 +195,7 @@ Most Ruby web frameworks and testing frameworks are supported.}
195
195
  "spec/integration/sinatra/test/test_helper.rb",
196
196
  "spec/private/core/configuration_spec.rb",
197
197
  "spec/private/core/field_spec.rb",
198
+ "spec/private/core/form_spec.rb",
198
199
  "spec/private/core/link_spec.rb",
199
200
  "spec/private/core/session_spec.rb",
200
201
  "spec/private/mechanize/mechanize_adapter_spec.rb",
@@ -238,7 +239,7 @@ Most Ruby web frameworks and testing frameworks are supported.}
238
239
  s.homepage = %q{http://github.com/brynary/webrat}
239
240
  s.require_paths = ["lib"]
240
241
  s.rubyforge_project = %q{webrat}
241
- s.rubygems_version = %q{1.3.5}
242
+ s.rubygems_version = %q{1.3.6}
242
243
  s.summary = %q{Ruby Acceptance Testing for Web applications}
243
244
  s.test_files = [
244
245
  "spec/fakes/test_adapter.rb",
@@ -293,6 +294,7 @@ Most Ruby web frameworks and testing frameworks are supported.}
293
294
  "spec/integration/sinatra/test/test_helper.rb",
294
295
  "spec/private/core/configuration_spec.rb",
295
296
  "spec/private/core/field_spec.rb",
297
+ "spec/private/core/form_spec.rb",
296
298
  "spec/private/core/link_spec.rb",
297
299
  "spec/private/core/session_spec.rb",
298
300
  "spec/private/mechanize/mechanize_adapter_spec.rb",
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webrat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 1
9
+ version: 0.7.1
5
10
  platform: ruby
6
11
  authors:
7
12
  - Bryan Helmkamp
@@ -9,39 +14,50 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-01-17 00:00:00 -05:00
17
+ date: 2010-04-26 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: nokogiri
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 0
23
31
  version: 1.2.0
24
- version:
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  - !ruby/object:Gem::Dependency
26
35
  name: rack
27
- type: :runtime
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
30
38
  requirements:
31
39
  - - ">="
32
40
  - !ruby/object:Gem::Version
41
+ segments:
42
+ - 1
43
+ - 0
33
44
  version: "1.0"
34
- version:
45
+ type: :runtime
46
+ version_requirements: *id002
35
47
  - !ruby/object:Gem::Dependency
36
48
  name: rack-test
37
- type: :runtime
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
49
+ prerelease: false
50
+ requirement: &id003 !ruby/object:Gem::Requirement
40
51
  requirements:
41
52
  - - ">="
42
53
  - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ - 5
57
+ - 3
43
58
  version: 0.5.3
44
- version:
59
+ type: :runtime
60
+ version_requirements: *id003
45
61
  description: |-
46
62
  Webrat lets you quickly write expressive and robust acceptance tests
47
63
  for a Ruby web application. It supports simulating a browser inside
@@ -111,7 +127,7 @@ files:
111
127
  - lib/webrat/core_extensions/deprecate.rb
112
128
  - lib/webrat/core_extensions/detect_mapped.rb
113
129
  - lib/webrat/core_extensions/meta_class.rb
114
- - lib/webrat/core_extensions/nil_to_param.rb
130
+ - lib/webrat/core_extensions/nil_to_query_string.rb
115
131
  - lib/webrat/core_extensions/tcp_socket.rb
116
132
  - lib/webrat/integrations/merb.rb
117
133
  - lib/webrat/integrations/rails.rb
@@ -234,6 +250,7 @@ files:
234
250
  - spec/integration/sinatra/test/test_helper.rb
235
251
  - spec/private/core/configuration_spec.rb
236
252
  - spec/private/core/field_spec.rb
253
+ - spec/private/core/form_spec.rb
237
254
  - spec/private/core/link_spec.rb
238
255
  - spec/private/core/session_spec.rb
239
256
  - spec/private/mechanize/mechanize_adapter_spec.rb
@@ -286,18 +303,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
303
  requirements:
287
304
  - - ">="
288
305
  - !ruby/object:Gem::Version
306
+ segments:
307
+ - 0
289
308
  version: "0"
290
- version:
291
309
  required_rubygems_version: !ruby/object:Gem::Requirement
292
310
  requirements:
293
311
  - - ">="
294
312
  - !ruby/object:Gem::Version
313
+ segments:
314
+ - 0
295
315
  version: "0"
296
- version:
297
316
  requirements: []
298
317
 
299
318
  rubyforge_project: webrat
300
- rubygems_version: 1.3.5
319
+ rubygems_version: 1.3.6
301
320
  signing_key:
302
321
  specification_version: 3
303
322
  summary: Ruby Acceptance Testing for Web applications
@@ -354,6 +373,7 @@ test_files:
354
373
  - spec/integration/sinatra/test/test_helper.rb
355
374
  - spec/private/core/configuration_spec.rb
356
375
  - spec/private/core/field_spec.rb
376
+ - spec/private/core/form_spec.rb
357
377
  - spec/private/core/link_spec.rb
358
378
  - spec/private/core/session_spec.rb
359
379
  - spec/private/mechanize/mechanize_adapter_spec.rb