capybara 0.3.0 → 0.3.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.
Files changed (60) hide show
  1. data/Manifest.txt +4 -0
  2. data/README.rdoc +45 -5
  3. data/lib/capybara.rb +11 -4
  4. data/lib/capybara/driver/base.rb +3 -0
  5. data/lib/capybara/driver/celerity_driver.rb +44 -9
  6. data/lib/capybara/driver/rack_test_driver.rb +80 -16
  7. data/lib/capybara/driver/selenium_driver.rb +41 -9
  8. data/lib/capybara/dsl.rb +4 -10
  9. data/lib/capybara/node.rb +8 -0
  10. data/lib/capybara/rails.rb +8 -2
  11. data/lib/capybara/save_and_open_page.rb +5 -1
  12. data/lib/capybara/searchable.rb +17 -9
  13. data/lib/capybara/server.rb +35 -23
  14. data/lib/capybara/session.rb +91 -22
  15. data/lib/capybara/xpath.rb +66 -27
  16. data/spec/driver/celerity_driver_spec.rb +2 -2
  17. data/spec/driver/culerity_driver_spec.rb +1 -2
  18. data/spec/driver/rack_test_driver_spec.rb +0 -1
  19. data/spec/driver/remote_culerity_driver_spec.rb +9 -5
  20. data/spec/driver/selenium_driver_spec.rb +0 -1
  21. data/spec/drivers_spec.rb +24 -32
  22. data/spec/dsl/all_spec.rb +56 -25
  23. data/spec/dsl/attach_file_spec.rb +49 -51
  24. data/spec/dsl/check_spec.rb +12 -1
  25. data/spec/dsl/choose_spec.rb +19 -21
  26. data/spec/dsl/click_button_spec.rb +140 -87
  27. data/spec/dsl/click_link_spec.rb +88 -68
  28. data/spec/dsl/click_spec.rb +20 -22
  29. data/spec/dsl/current_url_spec.rb +6 -8
  30. data/spec/dsl/fill_in_spec.rb +75 -67
  31. data/spec/dsl/find_button_spec.rb +12 -14
  32. data/spec/dsl/find_by_id_spec.rb +16 -0
  33. data/spec/dsl/find_field_spec.rb +17 -19
  34. data/spec/dsl/find_link_spec.rb +13 -15
  35. data/spec/dsl/find_spec.rb +44 -23
  36. data/spec/dsl/has_button_spec.rb +32 -0
  37. data/spec/dsl/has_content_spec.rb +79 -81
  38. data/spec/dsl/has_css_spec.rb +81 -83
  39. data/spec/dsl/has_field_spec.rb +96 -0
  40. data/spec/dsl/has_link_spec.rb +33 -0
  41. data/spec/dsl/has_xpath_spec.rb +97 -89
  42. data/spec/dsl/locate_spec.rb +47 -26
  43. data/spec/dsl/select_spec.rb +61 -17
  44. data/spec/dsl/uncheck_spec.rb +17 -25
  45. data/spec/dsl/within_spec.rb +112 -104
  46. data/spec/public/test.js +3 -0
  47. data/spec/searchable_spec.rb +1 -1
  48. data/spec/server_spec.rb +7 -7
  49. data/spec/session/celerity_session_spec.rb +2 -2
  50. data/spec/session/culerity_session_spec.rb +1 -1
  51. data/spec/session_spec.rb +7 -0
  52. data/spec/session_with_javascript_support_spec.rb +139 -120
  53. data/spec/spec_helper.rb +7 -2
  54. data/spec/test_app.rb +8 -4
  55. data/spec/views/form.erb +50 -2
  56. data/spec/views/tables.erb +61 -1
  57. data/spec/views/with_html.erb +8 -2
  58. data/spec/views/with_js.erb +4 -0
  59. data/spec/xpath_spec.rb +17 -0
  60. metadata +6 -2
@@ -2,7 +2,7 @@ require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  if RUBY_PLATFORM =~ /java/
4
4
  describe Capybara::Driver::Celerity do
5
- before do
5
+ before(:all) do
6
6
  @driver = Capybara::Driver::Celerity.new(TestApp)
7
7
  end
8
8
 
@@ -14,4 +14,4 @@ if RUBY_PLATFORM =~ /java/
14
14
  end
15
15
  else
16
16
  puts "#{File.basename(__FILE__)} requires JRuby; skipping.."
17
- end
17
+ end
@@ -1,13 +1,12 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Capybara::Driver::Culerity do
4
- before do
4
+ before(:all) do
5
5
  @driver = Capybara::Driver::Culerity.new(TestApp)
6
6
  end
7
7
 
8
8
  it_should_behave_like "driver"
9
9
  it_should_behave_like "driver with javascript support"
10
10
  it_should_behave_like "driver with header support"
11
- it_should_behave_like "driver with node path support"
12
11
 
13
12
  end
@@ -7,6 +7,5 @@ describe Capybara::Driver::RackTest do
7
7
 
8
8
  it_should_behave_like "driver"
9
9
  it_should_behave_like "driver with header support"
10
- it_should_behave_like "driver with node path support"
11
10
 
12
11
  end
@@ -1,19 +1,23 @@
1
1
  require File.expand_path('../spec_helper', File.dirname(__FILE__))
2
2
 
3
3
  describe Capybara::Driver::Culerity do
4
- before do
5
- @driver = Capybara::Driver::Culerity.new(TestApp)
6
- end
7
-
8
4
  before(:all) do
9
5
  Capybara.app_host = "http://capybara-testapp.heroku.com"
6
+ Capybara.run_server = false
7
+ @driver = Capybara::Driver::Culerity.new(TestApp)
10
8
  end
11
9
 
12
10
  after(:all) do
13
11
  Capybara.app_host = nil
12
+ Capybara.run_server = true
13
+ end
14
+
15
+ it "should navigate to a fully qualified remote page" do
16
+ @driver.visit('http://elabs.se/contact')
17
+ @driver.body.should include('Edithouse eLabs AB')
14
18
  end
15
19
 
16
20
  it_should_behave_like "driver"
17
21
  it_should_behave_like "driver with javascript support"
18
22
  it_should_behave_like "driver with header support"
19
- end
23
+ end
@@ -7,6 +7,5 @@ describe Capybara::Driver::Selenium do
7
7
 
8
8
  it_should_behave_like "driver"
9
9
  it_should_behave_like "driver with javascript support"
10
- it_should_behave_like "driver without node path support"
11
10
 
12
11
  end
@@ -47,6 +47,10 @@ shared_examples_for 'driver' do
47
47
  @driver.find('//a')[1][:rel].should be_nil
48
48
  end
49
49
 
50
+ it "should extract boolean node attributes" do
51
+ @driver.find('//input[@id="checked_field"]')[0][:checked].should be_true
52
+ end
53
+
50
54
  it "should allow assignment of field value" do
51
55
  @driver.find('//input').first.value.should == 'monkey'
52
56
  @driver.find('//input').first.set('gorilla')
@@ -68,6 +72,26 @@ shared_examples_for 'driver' do
68
72
  end
69
73
  end
70
74
 
75
+ describe "node relative searching" do
76
+ before do
77
+ @driver.visit('/tables')
78
+ @node = @driver.find('//body').first
79
+ end
80
+
81
+ it "should be able to navigate/search child node" do
82
+ @node.all('//table').size.should == 5
83
+ @node.find('//form').all('.//table').size.should == 1
84
+ @node.find('//form').find('.//table//caption').text.should == 'Agent'
85
+ if @driver.class == Capybara::Driver::Selenium
86
+ pending("Selenium gets this wrong, see http://code.google.com/p/selenium/issues/detail?id=403") do
87
+ @node.find('//form').all('//table').size.should == 5
88
+ end
89
+ else
90
+ @node.find('//form').all('//table').size.should == 5
91
+ end
92
+ end
93
+ end
94
+
71
95
  end
72
96
 
73
97
  shared_examples_for "driver with javascript support" do
@@ -93,7 +117,6 @@ shared_examples_for "driver with javascript support" do
93
117
  @driver.evaluate_script('1+1').should == 2
94
118
  end
95
119
  end
96
-
97
120
  end
98
121
 
99
122
  shared_examples_for "driver with header support" do
@@ -102,34 +125,3 @@ shared_examples_for "driver with header support" do
102
125
  @driver.response_headers['Content-Type'].should == 'text/html'
103
126
  end
104
127
  end
105
-
106
- shared_examples_for "driver with node path support" do
107
- describe "node relative searching" do
108
- before do
109
- @driver.visit('/tables')
110
- @node = @driver.find('//body').first
111
- end
112
-
113
- it "should be able to navigate/search child nodes" do
114
- @node.all('//table').size.should == 3
115
- @node.find('//form').all('//table').size.should == 1
116
- @node.find('//form').find('//table//caption').text.should == 'Agent'
117
- end
118
- end
119
- end
120
-
121
- shared_examples_for "driver without node path support" do
122
- describe "node relative searching" do
123
- before do
124
- @driver.visit('/tables')
125
- @node = @driver.find('//body').first
126
- end
127
-
128
- it "should get NotSupportedByDriverError" do
129
- running do
130
- @node.all('//form')
131
- end.should raise_error(Capybara::NotSupportedByDriverError)
132
- end
133
-
134
- end
135
- end
@@ -1,38 +1,69 @@
1
- module AllSpec
2
- shared_examples_for "all" do
3
- describe '#all' do
4
- before do
5
- @session.visit('/with_html')
1
+ shared_examples_for "all" do
2
+ describe '#all' do
3
+ before do
4
+ @session.visit('/with_html')
5
+ end
6
+
7
+ it "should find all elements using the given locator" do
8
+ @session.all('//p').should have(3).elements
9
+ @session.all('//h1').first.text.should == 'This is a test'
10
+ @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
11
+ end
12
+
13
+ it "should return an empty array when nothing was found" do
14
+ @session.all('//div[@id="nosuchthing"]').should be_empty
15
+ end
16
+
17
+ it "should accept an XPath instance" do
18
+ @session.visit('/form')
19
+ @xpath = Capybara::XPath.text_field('Name')
20
+ @result = @session.all(@xpath).map { |r| r.value }
21
+ @result.should include('Smith', 'John', 'John Smith')
22
+ end
23
+
24
+ context "with css selectors" do
25
+ it "should find the first element using the given locator" do
26
+ @session.all(:css, 'h1').first.text.should == 'This is a test'
27
+ @session.all(:css, "input[id='test_field']").first[:value].should == 'monkey'
6
28
  end
29
+ end
7
30
 
8
- it "should find all elements using the given locator" do
9
- @session.all('//p').should have(3).elements
10
- @session.all('//h1').first.text.should == 'This is a test'
11
- @session.all("//input[@id='test_field']").first[:value].should == 'monkey'
31
+ context "with xpath selectors" do
32
+ it "should find the first element using the given locator" do
33
+ @session.all(:xpath, '//h1').first.text.should == 'This is a test'
34
+ @session.all(:xpath, "//input[@id='test_field']").first[:value].should == 'monkey'
12
35
  end
36
+ end
13
37
 
14
- it "should return an empty array when nothing was found" do
15
- @session.all('//div[@id="nosuchthing"]').should be_empty
38
+ context "with css as default selector" do
39
+ before { Capybara.default_selector = :css }
40
+ it "should find the first element using the given locator" do
41
+ @session.all('h1').first.text.should == 'This is a test'
42
+ @session.all("input[id='test_field']").first[:value].should == 'monkey'
16
43
  end
44
+ after { Capybara.default_selector = :xpath }
45
+ end
17
46
 
18
- it "should accept an XPath instance" do
19
- @session.visit('/form')
20
- @xpath = Capybara::XPath.text_field('Name')
21
- @result = @session.all(@xpath).map { |r| r.value }
22
- @result.should include('Smith', 'John', 'John Smith')
47
+ context "with visible filter" do
48
+ after { Capybara.ignore_hidden_elements = false }
49
+ it "should only find visible nodes" do
50
+ @session.all("//a[@title='awesome title']").should have(2).elements
51
+ @session.all("//a[@title='awesome title']", :visible => true).should have(1).elements
52
+ Capybara.ignore_hidden_elements = true
53
+ @session.all("//a[@title='awesome title']").should have(1).elements
23
54
  end
55
+ end
24
56
 
25
- context "within a scope" do
26
- before do
27
- @session.visit('/with_scope')
28
- end
57
+ context "within a scope" do
58
+ before do
59
+ @session.visit('/with_scope')
60
+ end
29
61
 
30
- it "should find any element using the given locator" do
31
- @session.within(:xpath, "//div[@id='for_bar']") do
32
- @session.all('//li').should have(2).elements
33
- end
62
+ it "should find any element using the given locator" do
63
+ @session.within(:xpath, "//div[@id='for_bar']") do
64
+ @session.all('//li').should have(2).elements
34
65
  end
35
66
  end
36
67
  end
37
68
  end
38
- end
69
+ end
@@ -1,66 +1,64 @@
1
- module AttachFileSpec
2
- shared_examples_for "attach_file" do
1
+ shared_examples_for "attach_file" do
3
2
 
4
- describe "#attach_file" do
5
- before do
6
- @session.visit('/form')
7
- end
3
+ describe "#attach_file" do
4
+ before do
5
+ @session.visit('/form')
6
+ end
8
7
 
9
- context "with normal form" do
10
- it "should set a file path by id" do
11
- @session.attach_file "form_image", __FILE__
12
- @session.click_button('awesome')
13
- extract_results(@session)['image'].should == File.basename(__FILE__)
14
- end
8
+ context "with normal form" do
9
+ it "should set a file path by id" do
10
+ @session.attach_file "form_image", __FILE__
11
+ @session.click_button('awesome')
12
+ extract_results(@session)['image'].should == File.basename(__FILE__)
13
+ end
15
14
 
16
- it "should set a file path by label" do
17
- @session.attach_file "Image", __FILE__
18
- @session.click_button('awesome')
19
- extract_results(@session)['image'].should == File.basename(__FILE__)
20
- end
15
+ it "should set a file path by label" do
16
+ @session.attach_file "Image", __FILE__
17
+ @session.click_button('awesome')
18
+ extract_results(@session)['image'].should == File.basename(__FILE__)
21
19
  end
20
+ end
22
21
 
23
- context "with multipart form" do
24
- before do
25
- @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
26
- @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
27
- end
22
+ context "with multipart form" do
23
+ before do
24
+ @test_file_path = File.expand_path('../fixtures/test_file.txt', File.dirname(__FILE__))
25
+ @test_jpg_file_path = File.expand_path('../fixtures/capybara.jpg', File.dirname(__FILE__))
26
+ end
28
27
 
29
- it "should set a file path by id" do
30
- @session.attach_file "form_document", @test_file_path
31
- @session.click_button('Upload')
32
- @session.body.should include(File.read(@test_file_path))
33
- end
28
+ it "should set a file path by id" do
29
+ @session.attach_file "form_document", @test_file_path
30
+ @session.click_button('Upload')
31
+ @session.body.should include(File.read(@test_file_path))
32
+ end
34
33
 
35
- it "should set a file path by label" do
36
- @session.attach_file "Document", @test_file_path
37
- @session.click_button('Upload')
38
- @session.body.should include(File.read(@test_file_path))
39
- end
34
+ it "should set a file path by label" do
35
+ @session.attach_file "Document", @test_file_path
36
+ @session.click_button('Upload')
37
+ @session.body.should include(File.read(@test_file_path))
38
+ end
40
39
 
41
- it "should not break if no file is submitted" do
42
- @session.click_button('Upload')
43
- @session.body.should include('No file uploaded')
44
- end
40
+ it "should not break if no file is submitted" do
41
+ @session.click_button('Upload')
42
+ @session.body.should include('No file uploaded')
43
+ end
45
44
 
46
- it "should send content type text/plain when uploading a text file" do
47
- @session.attach_file "Document", @test_file_path
48
- @session.click_button 'Upload'
49
- @session.body.should include('text/plain')
50
- end
45
+ it "should send content type text/plain when uploading a text file" do
46
+ @session.attach_file "Document", @test_file_path
47
+ @session.click_button 'Upload'
48
+ @session.body.should include('text/plain')
49
+ end
51
50
 
52
- it "should send content type image/jpeg when uploading an image" do
53
- @session.attach_file "Document", @test_jpg_file_path
54
- @session.click_button 'Upload'
55
- @session.body.should include('image/jpeg')
56
- end
51
+ it "should send content type image/jpeg when uploading an image" do
52
+ @session.attach_file "Document", @test_jpg_file_path
53
+ @session.click_button 'Upload'
54
+ @session.body.should include('image/jpeg')
57
55
  end
56
+ end
58
57
 
59
- context "with a locator that doesn't exist" do
60
- it "should raise an error" do
61
- running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
62
- end
58
+ context "with a locator that doesn't exist" do
59
+ it "should raise an error" do
60
+ running { @session.attach_file('does not exist', 'foo.txt') }.should raise_error(Capybara::ElementNotFound)
63
61
  end
64
62
  end
65
63
  end
66
- end
64
+ end
@@ -5,6 +5,17 @@ module CheckSpec
5
5
  before do
6
6
  @session.visit('/form')
7
7
  end
8
+
9
+ describe "'checked' attribute" do
10
+ it "should be true if checked" do
11
+ @session.check("Terms of Use")
12
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_true
13
+ end
14
+
15
+ it "should be false if unchecked" do
16
+ @session.find(:xpath, "//input[@id='form_terms_of_use']")['checked'].should be_false
17
+ end
18
+ end
8
19
 
9
20
  it "should check a checkbox by id" do
10
21
  @session.check("form_pets_cat")
@@ -25,4 +36,4 @@ module CheckSpec
25
36
  end
26
37
  end
27
38
  end
28
- end
39
+ end
@@ -1,28 +1,26 @@
1
- module ChooseSpec
2
- shared_examples_for "choose" do
1
+ shared_examples_for "choose" do
3
2
 
4
- describe "#choose" do
5
- before do
6
- @session.visit('/form')
7
- end
3
+ describe "#choose" do
4
+ before do
5
+ @session.visit('/form')
6
+ end
8
7
 
9
- it "should choose a radio button by id" do
10
- @session.choose("gender_male")
11
- @session.click_button('awesome')
12
- extract_results(@session)['gender'].should == 'male'
13
- end
8
+ it "should choose a radio button by id" do
9
+ @session.choose("gender_male")
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['gender'].should == 'male'
12
+ end
14
13
 
15
- it "should choose a radio button by label" do
16
- @session.choose("Both")
17
- @session.click_button('awesome')
18
- extract_results(@session)['gender'].should == 'both'
19
- end
14
+ it "should choose a radio button by label" do
15
+ @session.choose("Both")
16
+ @session.click_button('awesome')
17
+ extract_results(@session)['gender'].should == 'both'
18
+ end
20
19
 
21
- context "with a locator that doesn't exist" do
22
- it "should raise an error" do
23
- running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
24
- end
20
+ context "with a locator that doesn't exist" do
21
+ it "should raise an error" do
22
+ running { @session.choose('does not exist') }.should raise_error(Capybara::ElementNotFound)
25
23
  end
26
24
  end
27
25
  end
28
- end
26
+ end
@@ -1,19 +1,46 @@
1
- module ClickButtonSpec
2
- shared_examples_for "click_button" do
3
- describe '#click_button' do
4
- before do
5
- @session.visit('/form')
1
+ shared_examples_for "click_button" do
2
+ describe '#click_button' do
3
+ before do
4
+ @session.visit('/form')
5
+ end
6
+
7
+ context "with multiple values with the same name" do
8
+ it "should use the latest given value" do
9
+ @session.check('Terms of Use')
10
+ @session.click_button('awesome')
11
+ extract_results(@session)['terms_of_use'].should == '1'
6
12
  end
13
+ end
7
14
 
8
- context "with multiple values with the same name" do
9
- it "should use the latest given value" do
10
- @session.check('Terms of Use')
11
- @session.click_button('awesome')
12
- extract_results(@session)['terms_of_use'].should == '1'
15
+ context "with value given on a submit button" do
16
+ context "on a form with HTML5 fields" do
17
+ before do
18
+ @session.click_button('html5_submit')
19
+ @results = extract_results(@session)
20
+ end
21
+
22
+ it "should serialise and submit search fields" do
23
+ @results['html5_search'].should == 'what are you looking for'
24
+ end
25
+
26
+ it "should serialise and submit email fields" do
27
+ @results['html5_email'].should == 'person@email.com'
28
+ end
29
+
30
+ it "should serialise and submit url fields" do
31
+ @results['html5_url'].should == 'http://www.example.com'
32
+ end
33
+
34
+ it "should serialise and submit tel fields" do
35
+ @results['html5_tel'].should == '911'
36
+ end
37
+
38
+ it "should serialise and submit color fields" do
39
+ @results['html5_color'].should == '#FFF'
13
40
  end
14
41
  end
15
42
 
16
- context "with value given on a submit button" do
43
+ context "on an HTML4 form" do
17
44
  before do
18
45
  @session.click_button('awesome')
19
46
  @results = extract_results(@session)
@@ -73,85 +100,72 @@ module ClickButtonSpec
73
100
  @results['tendency'].should be_nil
74
101
  end
75
102
  end
103
+ end
76
104
 
77
- context "with id given on a submit button" do
78
- it "should submit the associated form" do
79
- @session.click_button('awe123')
80
- extract_results(@session)['first_name'].should == 'John'
81
- end
82
-
83
- it "should work with partial matches" do
84
- @session.click_button('Go')
85
- @session.body.should include('You landed')
86
- end
105
+ context "with id given on a submit button" do
106
+ it "should submit the associated form" do
107
+ @session.click_button('awe123')
108
+ extract_results(@session)['first_name'].should == 'John'
87
109
  end
88
110
 
89
- context "with value given on an image button" do
90
- it "should submit the associated form" do
91
- @session.click_button('okay')
92
- extract_results(@session)['first_name'].should == 'John'
93
- end
94
-
95
- it "should work with partial matches" do
96
- @session.click_button('kay')
97
- extract_results(@session)['first_name'].should == 'John'
98
- end
111
+ it "should work with partial matches" do
112
+ @session.click_button('Go')
113
+ @session.body.should include('You landed')
114
+ end
115
+ end
116
+
117
+ context "with alt given on an image button" do
118
+ it "should submit the associated form" do
119
+ @session.click_button('oh hai thar')
120
+ extract_results(@session)['first_name'].should == 'John'
99
121
  end
100
122
 
101
- context "with id given on an image button" do
102
- it "should submit the associated form" do
103
- @session.click_button('okay556')
104
- extract_results(@session)['first_name'].should == 'John'
105
- end
123
+ it "should work with partial matches" do
124
+ @session.click_button('hai')
125
+ extract_results(@session)['first_name'].should == 'John'
106
126
  end
127
+ end
107
128
 
108
- context "with text given on a button defined by <button> tag" do
109
- it "should submit the associated form" do
110
- @session.click_button('Click me')
111
- extract_results(@session)['first_name'].should == 'John'
112
- end
129
+ context "with value given on an image button" do
130
+ it "should submit the associated form" do
131
+ @session.click_button('okay')
132
+ extract_results(@session)['first_name'].should == 'John'
133
+ end
113
134
 
114
- it "should work with partial matches" do
115
- @session.click_button('Click')
116
- extract_results(@session)['first_name'].should == 'John'
117
- end
135
+ it "should work with partial matches" do
136
+ @session.click_button('kay')
137
+ extract_results(@session)['first_name'].should == 'John'
138
+ end
139
+ end
118
140
 
119
- it "should prefer exact matches over partial matches" do
120
- @session.click_button('Just an input')
121
- extract_results(@session)['button'].should == 'button_second'
122
- end
141
+ context "with id given on an image button" do
142
+ it "should submit the associated form" do
143
+ @session.click_button('okay556')
144
+ extract_results(@session)['first_name'].should == 'John'
123
145
  end
146
+ end
124
147
 
125
- context "with id given on a button defined by <button> tag" do
126
- it "should submit the associated form" do
127
- @session.click_button('click_me_123')
128
- extract_results(@session)['first_name'].should == 'John'
129
- end
148
+ context "with text given on a button defined by <button> tag" do
149
+ it "should submit the associated form" do
150
+ @session.click_button('Click me')
151
+ extract_results(@session)['first_name'].should == 'John'
130
152
  end
131
153
 
132
- context "with value given on a button defined by <button> tag" do
133
- it "should submit the associated form" do
134
- @session.click_button('click_me')
135
- extract_results(@session)['first_name'].should == 'John'
136
- end
154
+ it "should work with partial matches" do
155
+ @session.click_button('Click')
156
+ extract_results(@session)['first_name'].should == 'John'
157
+ end
137
158
 
138
- it "should work with partial matches" do
139
- @session.click_button('ck_me')
140
- extract_results(@session)['first_name'].should == 'John'
141
- end
142
-
143
- it "should prefer exact matches over partial matches" do
144
- @session.click_button('Just a button')
145
- extract_results(@session)['button'].should == 'Just a button'
146
- end
159
+ it "should prefer exact matches over partial matches" do
160
+ @session.click_button('Just an input')
161
+ extract_results(@session)['button'].should == 'button_second'
147
162
  end
163
+ end
148
164
 
149
- context "with a locator that doesn't exist" do
150
- it "should raise an error" do
151
- running do
152
- @session.click_button('does not exist')
153
- end.should raise_error(Capybara::ElementNotFound)
154
- end
165
+ context "with id given on a button defined by <button> tag" do
166
+ it "should submit the associated form" do
167
+ @session.click_button('click_me_123')
168
+ extract_results(@session)['first_name'].should == 'John'
155
169
  end
156
170
 
157
171
  it "should serialize and send GET forms" do
@@ -161,23 +175,62 @@ module ClickButtonSpec
161
175
  @results['middle_name'].should == 'Darren'
162
176
  @results['foo'].should be_nil
163
177
  end
178
+ end
164
179
 
165
- it "should follow redirects" do
166
- @session.click_button('Go FAR')
167
- @session.body.should include('You landed')
180
+ context "with value given on a button defined by <button> tag" do
181
+ it "should submit the associated form" do
182
+ @session.click_button('click_me')
183
+ extract_results(@session)['first_name'].should == 'John'
168
184
  end
169
-
170
- it "should post pack to the same URL when no action given" do
171
- @session.visit('/postback')
172
- @session.click_button('With no action')
173
- @session.body.should include('Postback')
185
+
186
+ it "should work with partial matches" do
187
+ @session.click_button('ck_me')
188
+ extract_results(@session)['first_name'].should == 'John'
189
+ end
190
+
191
+ it "should prefer exact matches over partial matches" do
192
+ @session.click_button('Just a button')
193
+ extract_results(@session)['button'].should == 'Just a button'
174
194
  end
175
-
176
- it "should post pack to the same URL when blank action given" do
177
- @session.visit('/postback')
178
- @session.click_button('With blank action')
179
- @session.body.should include('Postback')
195
+ end
196
+
197
+ context "with a locator that doesn't exist" do
198
+ it "should raise an error" do
199
+ running do
200
+ @session.click_button('does not exist')
201
+ end.should raise_error(Capybara::ElementNotFound)
180
202
  end
181
203
  end
204
+
205
+ it "should serialize and send valueless buttons that were clicked" do
206
+ @session.click_button('No Value!')
207
+ @results = extract_results(@session)
208
+ @results['no_value'].should_not be_nil
209
+ end
210
+
211
+ it "should serialize and send GET forms" do
212
+ @session.visit('/form')
213
+ @session.click_button('med')
214
+ @results = extract_results(@session)
215
+ @results['middle_name'].should == 'Darren'
216
+ @results['foo'].should be_nil
217
+ end
218
+
219
+ it "should follow redirects" do
220
+ @session.click_button('Go FAR')
221
+ @session.body.should include('You landed')
222
+ end
223
+
224
+ it "should post pack to the same URL when no action given" do
225
+ @session.visit('/postback')
226
+ @session.click_button('With no action')
227
+ @session.body.should include('Postback')
228
+ end
229
+
230
+ it "should post pack to the same URL when blank action given" do
231
+ @session.visit('/postback')
232
+ @session.click_button('With blank action')
233
+ @session.body.should include('Postback')
234
+ end
182
235
  end
183
236
  end