honkster-webrat 0.6.0.10 → 0.7.1.1

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.
Files changed (53) hide show
  1. data/Gemfile +0 -6
  2. data/History.txt +34 -0
  3. data/Rakefile +7 -8
  4. data/Thorfile +1 -0
  5. data/honkster-webrat.gemspec +9 -5
  6. data/lib/webrat.rb +1 -1
  7. data/lib/webrat/adapters/mechanize.rb +22 -6
  8. data/lib/webrat/adapters/rack.rb +4 -0
  9. data/lib/webrat/adapters/rails.rb +4 -8
  10. data/lib/webrat/core/configuration.rb +23 -4
  11. data/lib/webrat/core/elements/field.rb +40 -89
  12. data/lib/webrat/core/elements/form.rb +55 -31
  13. data/lib/webrat/core/locators/form_locator.rb +1 -1
  14. data/lib/webrat/core/locators/select_option_locator.rb +1 -1
  15. data/lib/webrat/core/matchers/have_content.rb +1 -1
  16. data/lib/webrat/core/matchers/have_xpath.rb +4 -2
  17. data/lib/webrat/core/methods.rb +1 -1
  18. data/lib/webrat/core/mime.rb +2 -2
  19. data/lib/webrat/core/save_and_open_page.rb +3 -23
  20. data/lib/webrat/core/scope.rb +1 -0
  21. data/lib/webrat/core/session.rb +4 -7
  22. data/lib/webrat/core_extensions/{nil_to_param.rb → nil_to_query_string.rb} +1 -1
  23. data/lib/webrat/selenium/location_strategy_javascript/label.js +8 -2
  24. data/lib/webrat/selenium/matchers/have_content.rb +22 -10
  25. data/lib/webrat/selenium/matchers/have_selector.rb +8 -0
  26. data/lib/webrat/selenium/matchers/have_xpath.rb +8 -0
  27. data/lib/webrat/selenium/selenium_rc_server.rb +5 -2
  28. data/lib/webrat/selenium/selenium_session.rb +12 -12
  29. data/spec/fakes/test_adapter.rb +1 -5
  30. data/spec/integration/mechanize/sample_app.rb +16 -1
  31. data/spec/integration/mechanize/spec/mechanize_spec.rb +9 -1
  32. data/spec/integration/rack/app.rb +2 -2
  33. data/spec/integration/rack/test/helper.rb +0 -1
  34. data/spec/integration/rack/test/webrat_rack_test.rb +3 -2
  35. data/spec/integration/sinatra/classic_app.rb +0 -1
  36. data/spec/integration/sinatra/modular_app.rb +0 -1
  37. data/spec/integration/sinatra/test/classic_app_test.rb +1 -0
  38. data/spec/integration/sinatra/test/test_helper.rb +0 -1
  39. data/spec/private/core/field_spec.rb +1 -1
  40. data/spec/private/core/form_spec.rb +51 -0
  41. data/spec/private/core/session_spec.rb +5 -23
  42. data/spec/private/mechanize/mechanize_adapter_spec.rb +24 -1
  43. data/spec/private/rails/attaches_file_spec.rb +33 -0
  44. data/spec/private/rails/rails_adapter_spec.rb +0 -7
  45. data/spec/public/matchers/contain_spec.rb +8 -15
  46. data/spec/public/matchers/have_xpath_spec.rb +6 -0
  47. data/spec/public/save_and_open_spec.rb +4 -25
  48. data/spec/public/select_spec.rb +19 -0
  49. data/spec/public/submit_form_spec.rb +52 -1
  50. data/spec/spec_helper.rb +0 -1
  51. data/vendor/selenium-server.jar +0 -0
  52. metadata +56 -15
  53. data/pkg/honkster-webrat-0.6.0.9.gem +0 -0
@@ -10,16 +10,12 @@ module Webrat #:nodoc:
10
10
  def initialize(*args)
11
11
  end
12
12
 
13
- def doc_root
14
- File.expand_path(File.join(".", "public"))
15
- end
16
-
17
13
  def response
18
14
  @response ||= Object.new
19
15
  end
20
16
 
21
17
  def response_code
22
- @response_code || 200
18
+ @response_code ||= 200
23
19
  end
24
20
 
25
21
  def get(url, data, headers = nil)
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "sinatra/base"
3
2
 
4
3
  class SampleApp < Sinatra::Default
@@ -17,4 +16,20 @@ class SampleApp < Sinatra::Default
17
16
  get "/redirected" do
18
17
  "Redirected"
19
18
  end
19
+
20
+ get "/form" do
21
+ <<-EOS
22
+ <html>
23
+ <form action="/form" method="post">
24
+ <input type="hidden" name="_method" value="put" />
25
+ <label for="email">Email:</label> <input type="text" id="email" name="email" /></label>
26
+ <input type="submit" value="Add" />
27
+ </form>
28
+ </html>
29
+ EOS
30
+ end
31
+
32
+ put "/form" do
33
+ "Welcome #{params[:email]}"
34
+ end
20
35
  end
@@ -12,7 +12,15 @@ describe "Webrat's Mechanize mode" do
12
12
  end
13
13
 
14
14
  it "should follow links"
15
- it "should submit forms"
15
+
16
+ it "should submit forms" do
17
+ visit "http://localhost:9292/form"
18
+ fill_in "Email", :with => "albert@example.com"
19
+ response = click_button "Add"
20
+
21
+ response.should contain("Welcome albert@example.com")
22
+ end
23
+
16
24
  it "should not follow external redirects" do
17
25
  pending do
18
26
  response = visit("http://localhost:9292/external_redirect")
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "sinatra/base"
3
2
 
4
3
  class RackApp < Sinatra::Base
@@ -39,7 +38,8 @@ class RackApp < Sinatra::Base
39
38
  end
40
39
 
41
40
  post "/upload" do
42
- params[:uploaded_file].to_yaml
41
+ uploaded_file = params[:uploaded_file]
42
+ Marshal.dump(:tempfile => uploaded_file[:tempfile].read, :type => uploaded_file[:type], :filename => uploaded_file[:filename])
43
43
  end
44
44
  end
45
45
 
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "test/unit"
3
2
  require "rack/test"
4
3
  # require "redgreen"
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require File.dirname(__FILE__) + "/helper"
2
3
 
3
4
  class WebratRackTest < Test::Unit::TestCase
@@ -52,10 +53,10 @@ class WebratRackTest < Test::Unit::TestCase
52
53
  attach_file "File", __FILE__, "text/ruby"
53
54
  click_button "Upload"
54
55
 
55
- upload = YAML.load(response_body)
56
+ upload = Marshal.load(response_body)
56
57
  assert_equal "text/ruby", upload[:type]
57
58
  assert_equal "webrat_rack_test.rb", upload[:filename]
58
- assert upload[:tempfile].respond_to?(:read)
59
+ assert_equal File.read(__FILE__), upload[:tempfile]
59
60
  end
60
61
  end
61
62
 
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "sinatra"
3
2
 
4
3
  use_in_file_templates!
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "sinatra/base"
3
2
 
4
3
  class MyModularApp < Sinatra::Default
@@ -1,3 +1,4 @@
1
+ require "rubygems"
1
2
  require File.dirname(__FILE__) + "/test_helper"
2
3
  require File.dirname(__FILE__) + "/../classic_app"
3
4
 
@@ -1,4 +1,3 @@
1
- require "rubygems"
2
1
  require "test/unit"
3
2
  # require "redgreen"
4
3
 
@@ -77,7 +77,7 @@ module Webrat
77
77
 
78
78
  element = Webrat::XML.document(html).css('input').first
79
79
  text_field = TextField.new(nil, element)
80
- text_field.to_param.should == { 'email' => 'user@example.com' }
80
+ text_field.to_query_string.should == 'email=user@example.com'
81
81
  end
82
82
  end
83
83
  end
@@ -0,0 +1,51 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Multiple nested params" do
4
+ it "should be corretly posted" do
5
+ Webrat.configuration.mode = :rails
6
+
7
+ with_html <<-HTML
8
+ <html>
9
+ <form method="post" action="/family">
10
+ <div class="couple">
11
+ <div class="parent">
12
+ <select name="user[family][parents][0][][gender]">
13
+ <option selected="selected" value="Mother">Mother</option>
14
+ <option value="Father">Father</option>
15
+ </select>
16
+ <input type="text" value="Alice" name="user[family][parents][0][][name]" />
17
+ </div>
18
+ <div class="parent">
19
+ <select name="user[family][parents][0][][gender]">
20
+ <option value="Mother">Mother</option>
21
+ <option selected="selected" value="Father">Father</option>
22
+ </select>
23
+ <input type="text" value="Michael" name="user[family][parents][0][][name]" />
24
+ </div>
25
+ </div>
26
+ <div class="couple">
27
+ <div class="parent">
28
+ <select name="user[family][parents][1][][gender]">
29
+ <option selected="selected" value="Mother">Mother</option>
30
+ <option value="Father">Father</option>
31
+ </select>
32
+ <input type="text" value="Jenny" name="user[family][parents][1][][name]" />
33
+ </div>
34
+ </div>
35
+ <input type="submit" />
36
+ </form>
37
+ </html>
38
+ HTML
39
+
40
+ params = { "user" => { "family" => { "parents" => {
41
+ "0" => [ {"name" => "Alice", "gender"=>"Mother"}, {"name" => "Michael", "gender"=>"Father"} ],
42
+ "1" => [ {"name" => "Jenny", "gender"=>"Mother"} ]
43
+ }
44
+ }
45
+ }
46
+ }
47
+
48
+ webrat_session.should_receive(:post).with("/family", params)
49
+ click_button
50
+ end
51
+ end
@@ -2,11 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2
2
 
3
3
  describe Webrat::Session do
4
4
 
5
- it "should not have a doc_root" do
6
- session = Webrat::Session.new
7
- session.doc_root.should be_nil
8
- end
9
-
10
5
  it "should expose the current_dom" do
11
6
  session = Webrat::Session.new
12
7
 
@@ -112,24 +107,6 @@ describe Webrat::Session do
112
107
  webrat_session = Webrat::Session.new
113
108
  end
114
109
 
115
- it "should return true if the last response was a redirect and Fixnum#/ returns a Rational" do
116
- # This happens if the ruby-units gem has been required
117
- Fixnum.class_eval do
118
- alias_method :original_divide, "/".to_sym
119
-
120
- def /(other)
121
- Rational(self, other)
122
- end
123
- end
124
-
125
- webrat_session.stub!(:response_code => 301)
126
- webrat_session.redirect?.should be_true
127
-
128
- Fixnum.class_eval do
129
- alias_method "/".to_sym, :original_divide
130
- end
131
- end
132
-
133
110
  it "should return true if the last response was a redirect" do
134
111
  webrat_session.stub!(:response_code => 301)
135
112
  webrat_session.redirect?.should be_true
@@ -139,6 +116,11 @@ describe Webrat::Session do
139
116
  webrat_session.stub!(:response_code => 200)
140
117
  webrat_session.redirect?.should be_false
141
118
  end
119
+
120
+ it "should return false if the last response was a 304 Not Modified" do
121
+ webrat_session.stub!(:response_code => 304)
122
+ webrat_session.redirect?.should be_false
123
+ end
142
124
  end
143
125
 
144
126
  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
@@ -76,11 +76,4 @@ describe Webrat::RailsAdapter do
76
76
  end
77
77
  end
78
78
 
79
- it "should provide a saved_page_dir" do
80
- Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:saved_page_dir)
81
- end
82
-
83
- it "should provide a doc_root" do
84
- Webrat::RailsAdapter.new(mock("integration session")).should respond_to(:doc_root)
85
- end
86
79
  end
@@ -3,21 +3,6 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
3
3
  describe "contain" do
4
4
  include Webrat::Matchers
5
5
 
6
- before(:each) do
7
- @body = <<-HTML
8
- <div id='main'>
9
- <div class='inner'>hello, world!</div>
10
- <h2>Welcome "Bryan"</h2>
11
- <h3>Welcome 'Bryan'</h3>
12
- <h4>Welcome 'Bryan"</h4>
13
- <ul>
14
- <li>First</li>
15
- <li>Second</li>
16
- </ul>
17
- </div>
18
- HTML
19
- end
20
-
21
6
  before(:each) do
22
7
  @body = <<-EOF
23
8
  <div id='main'>
@@ -34,6 +19,14 @@ describe "contain" do
34
19
  it "should call element#matches? when the argument is a regular expression" do
35
20
  @body.should contain(/hello, world/)
36
21
  end
22
+
23
+ it "should treat newlines as spaces" do
24
+ "<div>it takes\ndifferent strokes</div>".should contain("it takes different strokes")
25
+ end
26
+
27
+ it "should multiple spaces as a single space" do
28
+ "<div>it takes different strokes</div>".should contain("it takes different strokes")
29
+ end
37
30
  end
38
31
 
39
32
  describe "asserts for contains," do
@@ -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|
@@ -22,30 +22,13 @@ describe "save_and_open_page" do
22
22
  Launchy::Browser.stub!(:run)
23
23
 
24
24
  @file_handle = mock("file handle")
25
- File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
25
+ File.stub!(:open).and_yield(@file_handle)
26
26
  @file_handle.stub!(:write)
27
27
  end
28
28
 
29
- it "should rewrite css rules" do
30
- @file_handle.should_receive(:write) do |html|
31
- html.should =~ %r|"#{webrat_session.doc_root}/stylesheets/foo.css"|s
32
- end
33
-
34
- save_and_open_page
35
- end
36
-
37
- it "should rewrite image paths with double quotes" do
38
- @file_handle.should_receive(:write) do |html|
39
- html.should =~ %r|"#{webrat_session.doc_root}/images/bar.png"|s
40
- end
41
-
42
- save_and_open_page
43
- end
44
-
45
- it "should rewrite image paths with single quotes" do
46
- @file_handle.should_receive(:write) do |html|
47
- html.should =~ %r|'#{webrat_session.doc_root}/images/foo.png'|s
48
- end
29
+ it "should save pages to the directory configured" do
30
+ Webrat.configuration.stub!(:saved_pages_dir => "path/to/dir")
31
+ File.should_receive(:open).with("path/to/dir/webrat-1234.html", "w").and_yield(@file_handle)
49
32
 
50
33
  save_and_open_page
51
34
  end
@@ -64,8 +47,4 @@ describe "save_and_open_page" do
64
47
  end.should_not raise_error
65
48
  end
66
49
 
67
- def filename
68
- File.expand_path("./webrat-#{Time.now}.html")
69
- end
70
-
71
50
  end
@@ -362,6 +362,25 @@ describe "select" do
362
362
  click_button
363
363
  end
364
364
 
365
+ it "should allow selection of multiple fields when including from" do
366
+ with_html <<-HTML
367
+ <html>
368
+ <form method="post" action="/login">
369
+ <select name="clothes[]" multiple="multiple">
370
+ <option value="tshirt">tshirt</option>
371
+ <option value="pants">pants</option>
372
+ </select>
373
+ <input type="submit" />
374
+ </form>
375
+ </html>
376
+ HTML
377
+
378
+ webrat_session.should_receive(:post).with("/login", "clothes" => ['pants'])
379
+ select 'pants', :from => 'clothes[]'
380
+ click_button
381
+ end
382
+
383
+
365
384
  it "should not overwrite preselected multiples" do
366
385
  with_html <<-HTML
367
386
  <html>