capybara 2.4.4 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +32 -5
  3. data/README.md +69 -8
  4. data/lib/capybara.rb +50 -29
  5. data/lib/capybara/driver/base.rb +4 -0
  6. data/lib/capybara/driver/node.rb +4 -0
  7. data/lib/capybara/helpers.rb +17 -5
  8. data/lib/capybara/node/actions.rb +16 -11
  9. data/lib/capybara/node/base.rb +7 -7
  10. data/lib/capybara/node/document_matchers.rb +1 -1
  11. data/lib/capybara/node/element.rb +82 -7
  12. data/lib/capybara/node/finders.rb +62 -22
  13. data/lib/capybara/node/matchers.rb +3 -3
  14. data/lib/capybara/node/simple.rb +6 -1
  15. data/lib/capybara/queries/base_query.rb +1 -1
  16. data/lib/capybara/queries/current_path_query.rb +58 -0
  17. data/lib/capybara/queries/text_query.rb +2 -11
  18. data/lib/capybara/rack_test/browser.rb +7 -2
  19. data/lib/capybara/rack_test/driver.rb +4 -0
  20. data/lib/capybara/rack_test/form.rb +2 -1
  21. data/lib/capybara/rack_test/node.rb +1 -0
  22. data/lib/capybara/result.rb +2 -2
  23. data/lib/capybara/rspec.rb +1 -0
  24. data/lib/capybara/rspec/features.rb +1 -1
  25. data/lib/capybara/rspec/matchers.rb +42 -3
  26. data/lib/capybara/selector.rb +7 -2
  27. data/lib/capybara/selenium/driver.rb +26 -12
  28. data/lib/capybara/selenium/node.rb +42 -6
  29. data/lib/capybara/server.rb +1 -1
  30. data/lib/capybara/session.rb +78 -50
  31. data/lib/capybara/session/matchers.rb +69 -0
  32. data/lib/capybara/spec/public/test.js +8 -0
  33. data/lib/capybara/spec/session/all_spec.rb +5 -0
  34. data/lib/capybara/spec/session/assert_current_path.rb +59 -0
  35. data/lib/capybara/spec/session/assert_text.rb +1 -1
  36. data/lib/capybara/spec/session/attach_file_spec.rb +2 -2
  37. data/lib/capybara/spec/session/body_spec.rb +2 -0
  38. data/lib/capybara/spec/session/click_button_spec.rb +17 -8
  39. data/lib/capybara/spec/session/click_link_spec.rb +32 -1
  40. data/lib/capybara/spec/session/current_url_spec.rb +5 -0
  41. data/lib/capybara/spec/session/fill_in_spec.rb +1 -1
  42. data/lib/capybara/spec/session/find_field_spec.rb +17 -0
  43. data/lib/capybara/spec/session/find_spec.rb +14 -5
  44. data/lib/capybara/spec/session/first_spec.rb +24 -0
  45. data/lib/capybara/spec/session/has_current_path_spec.rb +68 -0
  46. data/lib/capybara/spec/session/has_link_spec.rb +3 -0
  47. data/lib/capybara/spec/session/has_text_spec.rb +7 -0
  48. data/lib/capybara/spec/session/node_spec.rb +45 -6
  49. data/lib/capybara/spec/session/reset_session_spec.rb +18 -1
  50. data/lib/capybara/spec/session/save_and_open_page_spec.rb +19 -0
  51. data/lib/capybara/spec/session/save_page_spec.rb +12 -3
  52. data/lib/capybara/spec/session/save_screenshot_spec.rb +23 -0
  53. data/lib/capybara/spec/session/select_spec.rb +12 -0
  54. data/lib/capybara/spec/session/title_spec.rb +2 -2
  55. data/lib/capybara/spec/session/window/become_closed_spec.rb +4 -4
  56. data/lib/capybara/spec/session/window/switch_to_window_spec.rb +8 -0
  57. data/lib/capybara/spec/session/window/window_opened_by_spec.rb +14 -8
  58. data/lib/capybara/spec/session/window/window_spec.rb +24 -4
  59. data/lib/capybara/spec/spec_helper.rb +3 -1
  60. data/lib/capybara/spec/test_app.rb +10 -1
  61. data/lib/capybara/spec/views/form.erb +7 -1
  62. data/lib/capybara/spec/views/path.erb +12 -0
  63. data/lib/capybara/spec/views/with_html.erb +2 -0
  64. data/lib/capybara/spec/views/with_js.erb +9 -1
  65. data/lib/capybara/spec/views/with_title.erb +4 -1
  66. data/lib/capybara/spec/views/with_windows.erb +2 -2
  67. data/lib/capybara/version.rb +1 -1
  68. data/spec/basic_node_spec.rb +1 -0
  69. data/spec/capybara_spec.rb +12 -3
  70. data/spec/dsl_spec.rb +18 -6
  71. data/spec/rack_test_spec.rb +6 -5
  72. data/spec/rspec/matchers_spec.rb +62 -16
  73. data/spec/rspec/views_spec.rb +7 -0
  74. data/spec/selenium_spec.rb +38 -3
  75. data/spec/selenium_spec_chrome.rb +3 -7
  76. metadata +13 -4
@@ -1,3 +1,5 @@
1
+ require 'capybara/session/matchers'
2
+
1
3
  module Capybara
2
4
 
3
5
  ##
@@ -24,10 +26,12 @@ module Capybara
24
26
  # When using capybara/dsl, the Session is initialized automatically for you.
25
27
  #
26
28
  class Session
29
+ include Capybara::SessionMatchers
30
+
27
31
  NODE_METHODS = [
28
32
  :all, :first, :attach_file, :text, :check, :choose,
29
33
  :click_link_or_button, :click_button, :click_link, :field_labeled,
30
- :fill_in, :find, :find_button, :find_by_id, :find_field, :find_link,
34
+ :fill_in, :find, :find_all, :find_button, :find_by_id, :find_field, :find_link,
31
35
  :has_content?, :has_text?, :has_css?, :has_no_content?, :has_no_text?,
32
36
  :has_no_css?, :has_no_xpath?, :resolve, :has_xpath?, :select, :uncheck,
33
37
  :has_link?, :has_no_link?, :has_button?, :has_no_button?, :has_field?,
@@ -48,7 +52,8 @@ module Capybara
48
52
  :windows, :open_new_window, :switch_to_window, :within_window, :window_opened_by,
49
53
  :save_page, :save_and_open_page, :save_screenshot,
50
54
  :save_and_open_screenshot, :reset_session!, :response_headers,
51
- :status_code, :current_scope
55
+ :status_code, :current_scope,
56
+ :assert_current_path, :assert_no_current_path, :has_current_path?, :has_no_current_path?
52
57
  ] + DOCUMENT_METHODS
53
58
  MODAL_METHODS = [
54
59
  :accept_alert, :accept_confirm, :dismiss_confirm, :accept_prompt,
@@ -101,7 +106,7 @@ module Capybara
101
106
  def reset!
102
107
  if @touched
103
108
  driver.reset!
104
- assert_no_selector :xpath, "/html/body/*"
109
+ assert_no_selector :xpath, "/html/body/*" if driver.browser_initialized?
105
110
  @touched = false
106
111
  end
107
112
  raise_server_error!
@@ -380,7 +385,11 @@ module Capybara
380
385
  # `within_frame` or `within_window` methods
381
386
  # @raise [ArgumentError] if both or neither arguments were provided
382
387
  #
383
- def switch_to_window(window = nil)
388
+ def switch_to_window(window = nil, options= {})
389
+ if window.is_a? Hash
390
+ options = window
391
+ window = nil
392
+ end
384
393
  block_given = block_given?
385
394
  if window && block_given
386
395
  raise ArgumentError, "`switch_to_window` can take either a block or a window, not both"
@@ -395,20 +404,23 @@ module Capybara
395
404
  driver.switch_to_window(window.handle)
396
405
  window
397
406
  else
398
- original_window_handle = driver.current_window_handle
399
- begin
400
- driver.window_handles.each do |handle|
401
- driver.switch_to_window handle
402
- if yield
403
- return Window.new(self, handle)
407
+ wait_time = Capybara::Query.new(options).wait
408
+ document.synchronize(wait_time, errors: [Capybara::WindowError]) do
409
+ original_window_handle = driver.current_window_handle
410
+ begin
411
+ driver.window_handles.each do |handle|
412
+ driver.switch_to_window handle
413
+ if yield
414
+ return Window.new(self, handle)
415
+ end
404
416
  end
417
+ rescue => e
418
+ driver.switch_to_window(original_window_handle)
419
+ raise e
420
+ else
421
+ driver.switch_to_window(original_window_handle)
422
+ raise Capybara::WindowError, "Could not find a window matching block/lambda"
405
423
  end
406
- rescue => e
407
- driver.switch_to_window(original_window_handle)
408
- raise e
409
- else
410
- driver.switch_to_window(original_window_handle)
411
- raise Capybara::WindowError, "Could not find a window matching block/lambda"
412
424
  end
413
425
  end
414
426
  end
@@ -480,7 +492,7 @@ module Capybara
480
492
  # {https://dvcs.w3.org/hg/webdriver/raw-file/default/webdriver-spec.html#h_note_10 as order of windows isn't defined in some drivers}
481
493
  #
482
494
  # @param options [Hash]
483
- # @option options [Numeric] :wait (Capybara.default_wait_time) wait time
495
+ # @option options [Numeric] :wait (Capybara.default_max_wait_time) maximum wait time
484
496
  # @return [Capybara::Window] the window that has been opened within a block
485
497
  # @raise [Capybara::WindowError] if block passed to window hasn't opened window
486
498
  # or opened more than one window
@@ -561,7 +573,7 @@ module Capybara
561
573
  else
562
574
  options[:text]=text_or_options
563
575
  end
564
-
576
+
565
577
  driver.accept_modal(:confirm, options, &blk)
566
578
  end
567
579
 
@@ -577,7 +589,7 @@ module Capybara
577
589
  else
578
590
  options[:text]=text_or_options
579
591
  end
580
-
592
+
581
593
  driver.dismiss_modal(:confirm, options, &blk)
582
594
  end
583
595
 
@@ -594,7 +606,7 @@ module Capybara
594
606
  else
595
607
  options[:text]=text_or_options
596
608
  end
597
-
609
+
598
610
  driver.accept_modal(:prompt, options, &blk)
599
611
  end
600
612
 
@@ -610,60 +622,70 @@ module Capybara
610
622
  else
611
623
  options[:text]=text_or_options
612
624
  end
613
-
625
+
614
626
  driver.dismiss_modal(:prompt, options, &blk)
615
627
  end
616
628
 
617
629
  ##
618
630
  #
619
- # Save a snapshot of the page.
631
+ # Save a snapshot of the page. If `Capybara.asset_host` is set it will inject `base` tag
632
+ # pointing to `asset_host`.
620
633
  #
621
- # @param [String] path The path to where it should be saved [optional]
634
+ # If invoked without arguments it will save file to `Capybara.save_and_open_page_path`
635
+ # and file will be given randomly generated filename.
622
636
  #
623
- def save_page(path=nil)
624
- path ||= default_path('html')
625
-
626
- FileUtils.mkdir_p(File.dirname(path))
627
-
628
- File.open(path,'wb') { |f| f.write(Capybara::Helpers.inject_asset_host(body)) }
637
+ # @param [String] path the path to where it should be saved
638
+ # @return [String] the path to which the file was saved
639
+ #
640
+ def save_page(path = nil)
641
+ path = prepare_path(path, 'html')
642
+ File.write(path, Capybara::Helpers.inject_asset_host(body), mode: 'wb')
629
643
  path
630
644
  end
631
645
 
632
646
  ##
633
647
  #
634
- # Save a snapshot of the page and open it in a browser for inspection
648
+ # Save a snapshot of the page and open it in a browser for inspection.
649
+ #
650
+ # If invoked without arguments it will save file to `Capybara.save_and_open_page_path`
651
+ # and file will be given randomly generated filename.
635
652
  #
636
- # @param [String] file_name The path to where it should be saved [optional]
653
+ # @param [String] path the path to where it should be saved
637
654
  #
638
- def save_and_open_page(file_name=nil)
639
- file_name = save_page(file_name)
640
- open_file(file_name)
655
+ def save_and_open_page(path = nil)
656
+ path = save_page(path)
657
+ open_file(path)
641
658
  end
642
659
 
643
660
  ##
644
661
  #
645
- # Save a screenshot of page
662
+ # Save a screenshot of page.
646
663
  #
647
- # @param [String] path A string of image path
648
- # @option [Hash] options Options for saving screenshot
649
- def save_screenshot(path, options={})
650
- path ||= default_path('png')
651
-
652
- FileUtils.mkdir_p(File.dirname(path))
653
-
664
+ # If invoked without `path` argument it will save file to `Capybara.save_and_open_page_path`
665
+ # and file will be given randomly generated filename.
666
+ #
667
+ # @param [String] path the path to where it should be saved
668
+ # @param [Hash] options a customizable set of options
669
+ # @return [String] the path to which the file was saved
670
+ def save_screenshot(path = nil, options = {})
671
+ path = prepare_path(path, 'png')
654
672
  driver.save_screenshot(path, options)
655
673
  path
656
674
  end
657
675
 
658
676
  ##
659
677
  #
660
- # Save a screenshot of the page and open it for inspection
678
+ # Save a screenshot of the page and open it for inspection.
661
679
  #
662
- # @param [String] file_name The path to where it should be saved [optional]
680
+ # If invoked without `path` argument it will save file to `Capybara.save_and_open_page_path`
681
+ # and file will be given randomly generated filename.
663
682
  #
664
- def save_and_open_screenshot(file_name=nil)
665
- file_name = save_screenshot(file_name)
666
- open_file(file_name)
683
+ # @param [String] path the path to where it should be saved
684
+ # @param [Hash] options a customizable set of options
685
+ #
686
+ def save_and_open_screenshot(path = nil, options = {})
687
+ path = save_screenshot(path, options)
688
+ open_file(path)
667
689
  end
668
690
 
669
691
  def document
@@ -693,16 +715,22 @@ module Capybara
693
715
 
694
716
  private
695
717
 
696
- def open_file(file_name)
718
+ def open_file(path)
697
719
  begin
698
720
  require "launchy"
699
- Launchy.open(file_name)
721
+ Launchy.open(path)
700
722
  rescue LoadError
701
- warn "File saved to #{file_name}."
723
+ warn "File saved to #{path}."
702
724
  warn "Please install the launchy gem to open the file automatically."
703
725
  end
704
726
  end
705
727
 
728
+ def prepare_path(path, extension)
729
+ path = default_path(extension) if path.nil?
730
+ FileUtils.mkdir_p(File.dirname(path))
731
+ path
732
+ end
733
+
706
734
  def default_path(extension)
707
735
  timestamp = Time.new.strftime("%Y%m%d%H%M%S")
708
736
  path = "capybara-#{timestamp}#{rand(10**10)}.#{extension}"
@@ -0,0 +1,69 @@
1
+ module Capybara
2
+ module SessionMatchers
3
+ ##
4
+ # Asserts that the page has the given path.
5
+ # By default this will compare against the path+query portion of the full url
6
+ #
7
+ # @!macro current_path_query_params
8
+ # @overload $0(string, options = {})
9
+ # @param string [String] The string that the current 'path' should equal
10
+ # @overload $0(regexp, options = {})
11
+ # @param regexp [Regexp] The regexp that the current 'path' should match to
12
+ # @option options [Numeric] :wait (Capybara.default_max_wait_time) Maximum time that Capybara will wait for the current path to eq/match given string/regexp argument
13
+ # @option options [Boolean] :url (false) Whether the compare should be done against the full url
14
+ # @option options [Boolean] :only_path (false) Whether the compare should be done against just the path protion of the url
15
+ # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
16
+ # @return [true]
17
+ #
18
+ def assert_current_path(path, options={})
19
+ query = Capybara::Queries::CurrentPathQuery.new(path, options)
20
+ document.synchronize(query.wait) do
21
+ unless query.resolves_for?(self)
22
+ raise Capybara::ExpectationNotMet, query.failure_message
23
+ end
24
+ end
25
+ return true
26
+ end
27
+
28
+ ##
29
+ # Asserts that the page doesn't have the given path.
30
+ #
31
+ # @macro current_path_query_params
32
+ # @raise [Capybara::ExpectationNotMet] if the assertion hasn't succeeded during wait time
33
+ # @return [true]
34
+ #
35
+ def assert_no_current_path(path, options={})
36
+ query = Capybara::Queries::CurrentPathQuery.new(path, options)
37
+ document.synchronize(query.wait) do
38
+ if query.resolves_for?(self)
39
+ raise Capybara::ExpectationNotMet, query.negative_failure_message
40
+ end
41
+ end
42
+ return true
43
+ end
44
+
45
+ ##
46
+ # Checks if the page has the given path.
47
+ #
48
+ # @macro current_path_query_params
49
+ # @return [Boolean]
50
+ #
51
+ def has_current_path?(path, options={})
52
+ assert_current_path(path, options)
53
+ rescue Capybara::ExpectationNotMet
54
+ return false
55
+ end
56
+
57
+ ##
58
+ # Checks if the page doesn't have the given path.
59
+ #
60
+ # @macro current_path_query_params
61
+ # @return [Boolean]
62
+ #
63
+ def has_no_current_path?(path, options={})
64
+ assert_no_current_path(path, options)
65
+ rescue Capybara::ExpectationNotMet
66
+ return false
67
+ end
68
+ end
69
+ end
@@ -100,4 +100,12 @@ $(function() {
100
100
  $(this).attr('response', response);
101
101
  }
102
102
  });
103
+ $('#delayed-page-change').click(function() {
104
+ setTimeout(function() {
105
+ window.location.pathname = '/with_html'
106
+ }, 500)
107
+ })
108
+ $('#with-key-events').keydown(function(e){
109
+ $('#key-events-output').append('keydown:'+e.which+' ')
110
+ });
103
111
  });
@@ -149,4 +149,9 @@ Capybara::SpecHelper.spec "#all" do
149
149
  end
150
150
  end
151
151
  end
152
+
153
+ it "should have #find_all as an alias" do
154
+ expect(Capybara::Node::Finders.instance_method(:all)).to eq Capybara::Node::Finders.instance_method(:find_all)
155
+ expect(@session.find_all('//p').size).to eq(3)
156
+ end
152
157
  end
@@ -0,0 +1,59 @@
1
+ Capybara::SpecHelper.spec '#assert_current_path' do
2
+ before do
3
+ @session.visit('/with_js')
4
+ end
5
+
6
+ it "should not raise if the page has the given current path" do
7
+ expect {@session.assert_current_path('/with_js')}.not_to raise_error
8
+ end
9
+
10
+ it "should allow regexp matches" do
11
+ expect { @session.assert_current_path(/w[a-z]{3}_js/) }.not_to raise_error
12
+ end
13
+
14
+ it "should wait for current_path", :requires => [:js] do
15
+ @session.click_link("Change page")
16
+ expect { @session.assert_current_path("/with_html") }.not_to raise_error
17
+ end
18
+
19
+ it "should raise if the page has not the given current_path" do
20
+ expect{@session.assert_current_path('/with_html')}.to raise_error(Capybara::ExpectationNotMet, 'expected "/with_js" to equal "/with_html"')
21
+ end
22
+
23
+ it "should check query options" do
24
+ @session.visit('/with_js?test=test')
25
+ expect{@session.assert_current_path('/with_js?test=test')}.not_to raise_error
26
+ end
27
+
28
+ it "should compare the full url" do
29
+ expect{@session.assert_current_path(%r{\Ahttp://[^/]*/with_js\Z}, url: true)}.not_to raise_error
30
+ end
31
+
32
+ it "should ignore the query" do
33
+ @session.visit('/with_js?test=test')
34
+ expect{@session.assert_current_path('/with_js', only_path: true)}.not_to raise_error
35
+ end
36
+ end
37
+
38
+ Capybara::SpecHelper.spec '#assert_no_current_path?' do
39
+ before do
40
+ @session.visit('/with_js')
41
+ end
42
+
43
+ it "should raise if the page has the given current_path" do
44
+ expect{@session.assert_no_current_path('/with_js')}.to raise_error(Capybara::ExpectationNotMet)
45
+ end
46
+
47
+ it "should allow regexp matches" do
48
+ expect{@session.assert_no_current_path(/monkey/)}.not_to raise_error
49
+ end
50
+
51
+ it "should wait for current_path to disappear", :requires => [:js] do
52
+ @session.click_link("Change page")
53
+ expect{@session.assert_no_current_path('/with_js')}.not_to raise_error
54
+ end
55
+
56
+ it "should not raise if the page has not the given current_path" do
57
+ expect{@session.assert_no_current_path('/with_html')}.not_to raise_error
58
+ end
59
+ end
@@ -189,7 +189,7 @@ Capybara::SpecHelper.spec '#assert_no_text' do
189
189
  @session.visit('/with_js')
190
190
  @session.click_link('Click me')
191
191
  @session.find(:css, '#reload-list').click
192
- @session.find(:css, '#the-list').assert_no_text('Foo Bar', :wait => 0.4)
192
+ @session.find(:css, '#the-list').assert_no_text('Foo Bar', :wait => 0.3)
193
193
  end
194
194
  end
195
195
  end
@@ -59,8 +59,8 @@ Capybara::SpecHelper.spec "#attach_file" do
59
59
  it "should not break when using HTML5 multiple file input" do
60
60
  @session.attach_file "Multiple Documents", @test_file_path
61
61
  @session.click_button('Upload Multiple')
62
- expect(@session.body).to include("1 | ")#number of files
63
62
  expect(@session).to have_content(File.read(@test_file_path))
63
+ expect(@session.body).to include("1 | ")#number of files
64
64
  end
65
65
 
66
66
  it "should not break when using HTML5 multiple file input uploading multiple files" do
@@ -74,7 +74,7 @@ Capybara::SpecHelper.spec "#attach_file" do
74
74
 
75
75
  it "should not send anything when attaching no files to a multiple upload field" do
76
76
  @session.click_button('Upload Empty Multiple')
77
- expect(@session.body).to include("Successfully ignored empty file field")
77
+ expect(@session).to have_content("Successfully ignored empty file field")
78
78
  end
79
79
  end
80
80
 
@@ -9,11 +9,13 @@ Capybara::SpecHelper.spec '#body' do
9
9
  context "encoding of response between ascii and utf8" do
10
10
  it "should be valid with html entities" do
11
11
  @session.visit('/with_html_entities')
12
+ expect(@session).to have_content('Encoding') # wait for content to appear if visit is async
12
13
  expect { @session.body.encode!("UTF-8") }.not_to raise_error
13
14
  end
14
15
 
15
16
  it "should be valid without html entities" do
16
17
  @session.visit('/with_html')
18
+ expect(@session).to have_content('This is a test') # wait for content to appear if visit is async
17
19
  expect { @session.body.encode!("UTF-8") }.not_to raise_error
18
20
  end
19
21
  end
@@ -11,8 +11,8 @@ Capybara::SpecHelper.spec '#click_button' do
11
11
 
12
12
  it "casts to string" do
13
13
  @session.click_button(:'Relative Action')
14
- expect(@session.current_path).to eq('/relative')
15
14
  expect(extract_results(@session)['relative']).to eq('Relative Action')
15
+ expect(@session.current_path).to eq('/relative')
16
16
  end
17
17
 
18
18
  context "with multiple values with the same name" do
@@ -26,16 +26,16 @@ Capybara::SpecHelper.spec '#click_button' do
26
26
  context "with a form that has a relative url as an action" do
27
27
  it "should post to the correct url" do
28
28
  @session.click_button('Relative Action')
29
- expect(@session.current_path).to eq('/relative')
30
29
  expect(extract_results(@session)['relative']).to eq('Relative Action')
30
+ expect(@session.current_path).to eq('/relative')
31
31
  end
32
32
  end
33
33
 
34
34
  context "with a form that has no action specified" do
35
35
  it "should post to the correct url" do
36
36
  @session.click_button('No Action')
37
- expect(@session.current_path).to eq('/form')
38
37
  expect(extract_results(@session)['no_action']).to eq('No Action')
38
+ expect(@session.current_path).to eq('/form')
39
39
  end
40
40
  end
41
41
 
@@ -110,7 +110,7 @@ Capybara::SpecHelper.spec '#click_button' do
110
110
  expect(@results['pets']).to include('dog', 'hamster')
111
111
  expect(@results['pets']).not_to include('cat')
112
112
  end
113
-
113
+
114
114
  it "should default checkbox value to 'on' if none specififed" do
115
115
  expect(@results['valueless_checkbox']).to eq('on')
116
116
  end
@@ -134,11 +134,11 @@ Capybara::SpecHelper.spec '#click_button' do
134
134
  it "should not serialize a select tag without options" do
135
135
  expect(@results['tendency']).to be_nil
136
136
  end
137
-
137
+
138
138
  it "should convert lf to cr/lf in submitted textareas" do
139
139
  expect(@results['newline']).to eq("\r\nNew line after and before textarea tag\r\n")
140
140
  end
141
-
141
+
142
142
  it "should not submit disabled fields" do
143
143
  expect(@results['disabled_text_field']).to be_nil
144
144
  expect(@results['disabled_textarea']).to be_nil
@@ -254,7 +254,7 @@ Capybara::SpecHelper.spec '#click_button' do
254
254
  expect(extract_results(@session)['first_name']).to eq('John')
255
255
  end
256
256
  end
257
-
257
+
258
258
 
259
259
  context "with value given on an image button" do
260
260
  it "should submit the associated form" do
@@ -349,8 +349,17 @@ Capybara::SpecHelper.spec '#click_button' do
349
349
  context "with formaction attribute on button" do
350
350
  it "should submit to the formaction attribute" do
351
351
  @session.click_button('Formaction button')
352
+ @results = extract_results(@session)
352
353
  expect(@session.current_path).to eq '/form'
354
+ expect(@results['which_form']).to eq 'formaction form'
355
+ end
356
+ end
357
+
358
+ context "with formmethod attribute on button" do
359
+ it "should submit to the formethod attribute" do
360
+ @session.click_button('Formmethod button')
353
361
  @results = extract_results(@session)
362
+ expect(@session.current_path).to eq '/form/get'
354
363
  expect(@results['which_form']).to eq 'formaction form'
355
364
  end
356
365
  end
@@ -377,8 +386,8 @@ Capybara::SpecHelper.spec '#click_button' do
377
386
 
378
387
  it "should follow redirects" do
379
388
  @session.click_button('Go FAR')
380
- expect(@session.current_url).to match(%r{/landed$})
381
389
  expect(@session).to have_content('You landed')
390
+ expect(@session.current_url).to match(%r{/landed$})
382
391
  end
383
392
 
384
393
  it "should post pack to the same URL when no action given" do