capybara 2.0.0.beta2 → 2.0.0.beta4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. data/History.txt +30 -1
  2. data/README.md +52 -31
  3. data/lib/capybara.rb +1 -0
  4. data/lib/capybara/driver/base.rb +1 -1
  5. data/lib/capybara/driver/node.rb +1 -0
  6. data/lib/capybara/dsl.rb +12 -5
  7. data/lib/capybara/helpers.rb +33 -0
  8. data/lib/capybara/node/actions.rb +4 -2
  9. data/lib/capybara/node/base.rb +52 -1
  10. data/lib/capybara/node/element.rb +0 -12
  11. data/lib/capybara/node/finders.rb +1 -1
  12. data/lib/capybara/node/matchers.rb +57 -47
  13. data/lib/capybara/node/simple.rb +4 -0
  14. data/lib/capybara/query.rb +11 -11
  15. data/lib/capybara/rack_test/browser.rb +14 -15
  16. data/lib/capybara/rack_test/driver.rb +2 -2
  17. data/lib/capybara/rack_test/node.rb +15 -2
  18. data/lib/capybara/result.rb +7 -19
  19. data/lib/capybara/rspec.rb +7 -4
  20. data/lib/capybara/rspec/features.rb +4 -1
  21. data/lib/capybara/rspec/matchers.rb +8 -3
  22. data/lib/capybara/selector.rb +1 -2
  23. data/lib/capybara/selenium/driver.rb +2 -2
  24. data/lib/capybara/selenium/node.rb +9 -7
  25. data/lib/capybara/session.rb +47 -31
  26. data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
  27. data/lib/capybara/spec/public/test.js +1 -1
  28. data/lib/capybara/spec/session/all_spec.rb +60 -62
  29. data/lib/capybara/spec/session/assert_selector.rb +123 -0
  30. data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
  31. data/lib/capybara/spec/session/body_spec.rb +21 -0
  32. data/lib/capybara/spec/session/check_spec.rb +67 -50
  33. data/lib/capybara/spec/session/choose_spec.rb +32 -21
  34. data/lib/capybara/spec/session/click_button_spec.rb +261 -221
  35. data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
  36. data/lib/capybara/spec/session/click_link_spec.rb +95 -81
  37. data/lib/capybara/spec/session/current_url_spec.rb +70 -60
  38. data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
  39. data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
  40. data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
  41. data/lib/capybara/spec/session/find_button_spec.rb +16 -14
  42. data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
  43. data/lib/capybara/spec/session/find_field_spec.rb +23 -21
  44. data/lib/capybara/spec/session/find_link_spec.rb +15 -14
  45. data/lib/capybara/spec/session/find_spec.rb +96 -91
  46. data/lib/capybara/spec/session/first_spec.rb +53 -55
  47. data/lib/capybara/spec/session/has_button_spec.rb +22 -24
  48. data/lib/capybara/spec/session/has_css_spec.rb +190 -205
  49. data/lib/capybara/spec/session/has_field_spec.rb +167 -169
  50. data/lib/capybara/spec/session/has_link_spec.rb +26 -29
  51. data/lib/capybara/spec/session/has_select_spec.rb +175 -176
  52. data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
  53. data/lib/capybara/spec/session/has_table_spec.rb +22 -26
  54. data/lib/capybara/spec/session/has_text_spec.rb +159 -132
  55. data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
  56. data/lib/capybara/spec/session/headers.rb +4 -17
  57. data/lib/capybara/spec/session/html_spec.rb +15 -0
  58. data/lib/capybara/spec/session/node_spec.rb +172 -82
  59. data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
  60. data/lib/capybara/spec/session/response_code.rb +4 -17
  61. data/lib/capybara/spec/session/save_page_spec.rb +46 -0
  62. data/lib/capybara/spec/session/screenshot.rb +8 -24
  63. data/lib/capybara/spec/session/select_spec.rb +100 -89
  64. data/lib/capybara/spec/session/source_spec.rb +12 -0
  65. data/lib/capybara/spec/session/text_spec.rb +15 -17
  66. data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
  67. data/lib/capybara/spec/session/unselect_spec.rb +57 -52
  68. data/lib/capybara/spec/session/visit_spec.rb +58 -60
  69. data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
  70. data/lib/capybara/spec/session/within_spec.rb +119 -121
  71. data/lib/capybara/spec/session/within_window_spec.rb +29 -31
  72. data/lib/capybara/spec/spec_helper.rb +84 -0
  73. data/lib/capybara/spec/test_app.rb +5 -3
  74. data/lib/capybara/spec/views/form.erb +1 -0
  75. data/lib/capybara/spec/views/with_html.erb +6 -1
  76. data/lib/capybara/spec/views/with_js.erb +1 -0
  77. data/lib/capybara/version.rb +1 -1
  78. data/spec/basic_node_spec.rb +2 -2
  79. data/spec/capybara_spec.rb +9 -0
  80. data/spec/dsl_spec.rb +22 -10
  81. data/spec/rack_test_spec.rb +28 -23
  82. data/spec/result_spec.rb +51 -0
  83. data/spec/rspec/features_spec.rb +19 -0
  84. data/spec/rspec/matchers_spec.rb +6 -0
  85. data/spec/rspec_spec.rb +1 -1
  86. data/spec/selenium_spec.rb +11 -25
  87. data/spec/server_spec.rb +2 -2
  88. data/spec/spec_helper.rb +1 -46
  89. metadata +41 -98
  90. data/lib/capybara/spec/session.rb +0 -183
  91. data/lib/capybara/spec/session/javascript.rb +0 -290
  92. data/lib/capybara/util/save_and_open_page.rb +0 -45
  93. data/spec/save_and_open_page_spec.rb +0 -155
@@ -1,123 +1,127 @@
1
- shared_examples_for "has_xpath" do
2
- describe '#has_xpath?' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#has_xpath?' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should be true if the given selector is on the page" do
7
+ @session.should have_xpath("//p")
8
+ @session.should have_xpath("//p//a[@id='foo']")
9
+ @session.should have_xpath("//p[contains(.,'est')]")
10
+ end
6
11
 
7
- it "should be true if the given selector is on the page" do
8
- @session.should have_xpath("//p")
9
- @session.should have_xpath("//p//a[@id='foo']")
10
- @session.should have_xpath("//p[contains(.,'est')]")
12
+ it "should be false if the given selector is not on the page" do
13
+ @session.should_not have_xpath("//abbr")
14
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
15
+ @session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
16
+ end
17
+
18
+ it "should use xpath even if default selector is CSS" do
19
+ Capybara.default_selector = :css
20
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']")
21
+ end
22
+
23
+ it "should respect scopes" do
24
+ @session.within "//p[@id='first']" do
25
+ @session.should have_xpath(".//a[@id='foo']")
26
+ @session.should_not have_xpath(".//a[@id='red']")
11
27
  end
28
+ end
29
+
30
+ it "should wait for content to appear", :requires => [:js] do
31
+ @session.visit('/with_js')
32
+ @session.click_link('Click me')
33
+ @session.should have_xpath("//input[@type='submit' and @value='New Here']")
34
+ end
12
35
 
13
- it "should be false if the given selector is not on the page" do
14
- @session.should_not have_xpath("//abbr")
15
- @session.should_not have_xpath("//p//a[@id='doesnotexist']")
16
- @session.should_not have_xpath("//p[contains(.,'thisstringisnotonpage')]")
36
+ context "with count" do
37
+ it "should be true if the content occurs the given number of times" do
38
+ @session.should have_xpath("//p", :count => 3)
39
+ @session.should have_xpath("//p//a[@id='foo']", :count => 1)
40
+ @session.should have_xpath("//p[contains(.,'est')]", :count => 1)
41
+ @session.should have_xpath("//p//a[@id='doesnotexist']", :count => 0)
17
42
  end
18
43
 
19
- it "should use xpath even if default selector is CSS" do
20
- Capybara.default_selector = :css
21
- @session.should_not have_xpath("//p//a[@id='doesnotexist']")
44
+ it "should be false if the content occurs a different number of times than the given" do
45
+ @session.should_not have_xpath("//p", :count => 6)
46
+ @session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
47
+ @session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
48
+ @session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
22
49
  end
50
+ end
23
51
 
24
- it "should respect scopes" do
25
- @session.within "//p[@id='first']" do
26
- @session.should have_xpath(".//a[@id='foo']")
27
- @session.should_not have_xpath(".//a[@id='red']")
28
- end
52
+ context "with text" do
53
+ it "should discard all matches where the given string is not contained" do
54
+ @session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
55
+ @session.should_not have_xpath("//p", :text => "Doesnotexist")
29
56
  end
30
57
 
31
- context "with count" do
32
- it "should be true if the content is on the page the given number of times" do
33
- @session.should have_xpath("//p", :count => 3)
34
- @session.should have_xpath("//p//a[@id='foo']", :count => 1)
35
- @session.should have_xpath("//p[contains(.,'est')]", :count => 1)
36
- end
37
-
38
- it "should be false if the content is on the page the given number of times" do
39
- @session.should_not have_xpath("//p", :count => 6)
40
- @session.should_not have_xpath("//p//a[@id='foo']", :count => 2)
41
- @session.should_not have_xpath("//p[contains(.,'est')]", :count => 5)
42
- end
43
-
44
- it "should be false if the content isn't on the page at all" do
45
- @session.should_not have_xpath("//abbr", :count => 2)
46
- @session.should_not have_xpath("//p//a[@id='doesnotexist']", :count => 1)
47
- end
58
+ it "should discard all matches where the given regexp is not matched" do
59
+ @session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
60
+ @session.should_not have_xpath("//p//a", :text => /Red$/)
48
61
  end
62
+ end
63
+ end
49
64
 
50
- context "with text" do
51
- it "should discard all matches where the given string is not contained" do
52
- @session.should have_xpath("//p//a", :text => "Redirect", :count => 1)
53
- @session.should_not have_xpath("//p", :text => "Doesnotexist")
54
- end
65
+ Capybara::SpecHelper.spec '#has_no_xpath?' do
66
+ before do
67
+ @session.visit('/with_html')
68
+ end
55
69
 
56
- it "should discard all matches where the given regexp is not matched" do
57
- @session.should have_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
58
- @session.should_not have_xpath("//p//a", :text => /Red$/)
59
- end
60
- end
70
+ it "should be false if the given selector is on the page" do
71
+ @session.should_not have_no_xpath("//p")
72
+ @session.should_not have_no_xpath("//p//a[@id='foo']")
73
+ @session.should_not have_no_xpath("//p[contains(.,'est')]")
61
74
  end
62
75
 
63
- describe '#has_no_xpath?' do
64
- before do
65
- @session.visit('/with_html')
66
- end
76
+ it "should be true if the given selector is not on the page" do
77
+ @session.should have_no_xpath("//abbr")
78
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
79
+ @session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
80
+ end
67
81
 
68
- it "should be false if the given selector is on the page" do
69
- @session.should_not have_no_xpath("//p")
70
- @session.should_not have_no_xpath("//p//a[@id='foo']")
71
- @session.should_not have_no_xpath("//p[contains(.,'est')]")
72
- end
82
+ it "should use xpath even if default selector is CSS" do
83
+ Capybara.default_selector = :css
84
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']")
85
+ end
73
86
 
74
- it "should be true if the given selector is not on the page" do
75
- @session.should have_no_xpath("//abbr")
76
- @session.should have_no_xpath("//p//a[@id='doesnotexist']")
77
- @session.should have_no_xpath("//p[contains(.,'thisstringisnotonpage')]")
87
+ it "should respect scopes" do
88
+ @session.within "//p[@id='first']" do
89
+ @session.should_not have_no_xpath(".//a[@id='foo']")
90
+ @session.should have_no_xpath(".//a[@id='red']")
78
91
  end
92
+ end
79
93
 
80
- it "should use xpath even if default selector is CSS" do
81
- Capybara.default_selector = :css
82
- @session.should have_no_xpath("//p//a[@id='doesnotexist']")
83
- end
94
+ it "should wait for content to disappear", :requires => [:js] do
95
+ @session.visit('/with_js')
96
+ @session.click_link('Click me')
97
+ @session.should have_no_xpath("//p[@id='change']")
98
+ end
84
99
 
85
- it "should respect scopes" do
86
- @session.within "//p[@id='first']" do
87
- @session.should_not have_no_xpath(".//a[@id='foo']")
88
- @session.should have_no_xpath(".//a[@id='red']")
89
- end
100
+ context "with count" do
101
+ it "should be false if the content occurs the given number of times" do
102
+ @session.should_not have_no_xpath("//p", :count => 3)
103
+ @session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
104
+ @session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
105
+ @session.should_not have_no_xpath("//p//a[@id='doesnotexist']", :count => 0)
90
106
  end
91
107
 
92
- context "with count" do
93
- it "should be false if the content is on the page the given number of times" do
94
- @session.should_not have_no_xpath("//p", :count => 3)
95
- @session.should_not have_no_xpath("//p//a[@id='foo']", :count => 1)
96
- @session.should_not have_no_xpath("//p[contains(.,'est')]", :count => 1)
97
- end
98
-
99
- it "should be true if the content is on the page the wrong number of times" do
100
- @session.should have_no_xpath("//p", :count => 6)
101
- @session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
102
- @session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
103
- end
104
-
105
- it "should be true if the content isn't on the page at all" do
106
- @session.should have_no_xpath("//abbr", :count => 2)
107
- @session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
108
- end
108
+ it "should be true if the content occurs a different number of times than the given" do
109
+ @session.should have_no_xpath("//p", :count => 6)
110
+ @session.should have_no_xpath("//p//a[@id='foo']", :count => 2)
111
+ @session.should have_no_xpath("//p[contains(.,'est')]", :count => 5)
112
+ @session.should have_no_xpath("//p//a[@id='doesnotexist']", :count => 1)
109
113
  end
114
+ end
110
115
 
111
- context "with text" do
112
- it "should discard all matches where the given string is contained" do
113
- @session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
114
- @session.should have_no_xpath("//p", :text => "Doesnotexist")
115
- end
116
+ context "with text" do
117
+ it "should discard all matches where the given string is contained" do
118
+ @session.should_not have_no_xpath("//p//a", :text => "Redirect", :count => 1)
119
+ @session.should have_no_xpath("//p", :text => "Doesnotexist")
120
+ end
116
121
 
117
- it "should discard all matches where the given regexp is matched" do
118
- @session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
119
- @session.should have_no_xpath("//p//a", :text => /Red$/)
120
- end
122
+ it "should discard all matches where the given regexp is matched" do
123
+ @session.should_not have_no_xpath("//p//a", :text => /re[dab]i/i, :count => 1)
124
+ @session.should have_no_xpath("//p//a", :text => /Red$/)
121
125
  end
122
126
  end
123
127
  end
@@ -1,19 +1,6 @@
1
- shared_examples_for "session with headers support" do
2
- describe '#response_headers' do
3
- it "should return response headers" do
4
- @session.visit('/with_simple_html')
5
- @session.response_headers['Content-Type'].should =~ %r(text/html)
6
- end
7
- end
8
- end
9
-
10
- shared_examples_for "session without headers support" do
11
- describe "#response_headers" do
12
- before{ @session.visit('/with_simple_html') }
13
- it "should raise an error" do
14
- running {
15
- @session.response_headers
16
- }.should raise_error(Capybara::NotSupportedByDriverError)
17
- end
1
+ Capybara::SpecHelper.spec '#response_headers' do
2
+ it "should return response headers", :requires => [:response_headers] do
3
+ @session.visit('/with_simple_html')
4
+ @session.response_headers['Content-Type'].should =~ %r(text/html)
18
5
  end
19
6
  end
@@ -0,0 +1,15 @@
1
+ Capybara::SpecHelper.spec '#html' do
2
+ it "should return the unmodified page body" do
3
+ # html and body should be aliased, but we can't just check for
4
+ # method(:html) == method(:body) because these shared examples get run
5
+ # against the DSL, which uses forwarding methods. So we test behavior.
6
+ @session.visit('/')
7
+ @session.html.should include('Hello world!')
8
+ end
9
+
10
+ it "should return the current state of the page", :requires => [:js] do
11
+ @session.visit('/with_js')
12
+ @session.html.should include('I changed it')
13
+ @session.html.should_not include('This is text')
14
+ end
15
+ end
@@ -1,115 +1,205 @@
1
- shared_examples_for "node" do
2
- describe "node" do
3
- before do
4
- @session.visit('/with_html')
1
+ Capybara::SpecHelper.spec "node" do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should act like a session object" do
7
+ @session.visit('/form')
8
+ @form = @session.find(:css, '#get-form')
9
+ @form.should have_field('Middle Name')
10
+ @form.should have_no_field('Languages')
11
+ @form.fill_in('Middle Name', :with => 'Monkey')
12
+ @form.click_button('med')
13
+ extract_results(@session)['middle_name'].should == 'Monkey'
14
+ end
15
+
16
+ it "should scope CSS selectors" do
17
+ @session.find(:css, '#second').should have_no_css('h1')
18
+ end
19
+
20
+ describe "#parent" do
21
+ it "should have a reference to its parent if there is one" do
22
+ @node = @session.find(:css, '#first')
23
+ @node.parent.should == @node.session.document
24
+ @node.find(:css, '#foo').parent.should == @node
5
25
  end
26
+ end
6
27
 
7
- it "should act like a session object" do
8
- @session.visit('/form')
9
- @form = @session.find(:css, '#get-form')
10
- @form.should have_field('Middle Name')
11
- @form.should have_no_field('Languages')
12
- @form.fill_in('Middle Name', :with => 'Monkey')
13
- @form.click_button('med')
14
- extract_results(@session)['middle_name'].should == 'Monkey'
28
+ describe "#text" do
29
+ it "should extract node texts" do
30
+ @session.all('//a')[0].text.should == 'labore'
31
+ @session.all('//a')[1].text.should == 'ullamco'
15
32
  end
16
33
 
17
- it "should scope CSS selectors" do
18
- @session.find(:css, '#second').should have_no_css('h1')
34
+ it "should return document text on /html selector" do
35
+ @session.visit('/with_simple_html')
36
+ @session.all('/html')[0].text.should == 'Bar'
19
37
  end
38
+ end
20
39
 
21
- describe "#parent" do
22
- it "should have a reference to its parent if there is one" do
23
- @node = @session.find(:css, '#first')
24
- @node.parent.should == @node.session.document
25
- @node.find(:css, '#foo').parent.should == @node
26
- end
40
+ describe "#[]" do
41
+ it "should extract node attributes" do
42
+ @session.all('//a')[0][:class].should == 'simple'
43
+ @session.all('//a')[1][:id].should == 'foo'
44
+ @session.all('//input')[0][:type].should == 'text'
27
45
  end
28
46
 
29
- describe "#text" do
30
- it "should extract node texts" do
31
- @session.all('//a')[0].text.should == 'labore'
32
- @session.all('//a')[1].text.should == 'ullamco'
33
- end
47
+ it "should extract boolean node attributes" do
48
+ @session.find('//input[@id="checked_field"]')[:checked].should be_true
49
+ end
50
+ end
34
51
 
35
- it "should return document text on /html selector" do
36
- @session.visit('/with_simple_html')
37
- @session.all('/html')[0].text.should == 'Bar'
38
- end
52
+ describe "#value" do
53
+ it "should allow retrieval of the value" do
54
+ @session.find('//textarea[@id="normal"]').value.should == 'banana'
39
55
  end
40
56
 
41
- describe "#[]" do
42
- it "should extract node attributes" do
43
- @session.all('//a')[0][:class].should == 'simple'
44
- @session.all('//a')[1][:id].should == 'foo'
45
- @session.all('//input')[0][:type].should == 'text'
46
- end
57
+ it "should not swallow extra newlines in textarea" do
58
+ @session.find('//textarea[@id="additional_newline"]').value.should == "\nbanana"
59
+ end
60
+ end
47
61
 
48
- it "should extract boolean node attributes" do
49
- @session.find('//input[@id="checked_field"]')[:checked].should be_true
50
- end
62
+ describe "#set" do
63
+ it "should allow assignment of field value" do
64
+ @session.first('//input').value.should == 'monkey'
65
+ @session.first('//input').set('gorilla')
66
+ @session.first('//input').value.should == 'gorilla'
67
+ end
68
+ end
69
+
70
+ describe "#tag_name" do
71
+ it "should extract node tag name" do
72
+ @session.all('//a')[0].tag_name.should == 'a'
73
+ @session.all('//a')[1].tag_name.should == 'a'
74
+ @session.all('//p')[1].tag_name.should == 'p'
51
75
  end
76
+ end
52
77
 
53
- describe "#value" do
54
- it "should allow retrieval of the value" do
55
- @session.find('//textarea[@id="normal"]').value.should == 'banana'
56
- end
78
+ describe "#visible?" do
79
+ it "should extract node visibility" do
80
+ @session.first('//a').should be_visible
57
81
 
58
- it "should not swallow extra newlines in textarea" do
59
- @session.find('//textarea[@id="additional_newline"]').value.should == "\nbanana"
60
- end
82
+ @session.find('//div[@id="hidden"]').should_not be_visible
83
+ @session.find('//div[@id="hidden_via_ancestor"]').should_not be_visible
84
+ end
85
+ end
86
+
87
+ describe "#checked?" do
88
+ it "should extract node checked state" do
89
+ @session.visit('/form')
90
+ @session.find('//input[@id="gender_female"]').should be_checked
91
+ @session.find('//input[@id="gender_male"]').should_not be_checked
92
+ @session.first('//h1').should_not be_checked
61
93
  end
94
+ end
62
95
 
63
- describe "#set" do
64
- it "should allow assignment of field value" do
65
- @session.first('//input').value.should == 'monkey'
66
- @session.first('//input').set('gorilla')
67
- @session.first('//input').value.should == 'gorilla'
68
- end
96
+ describe "#selected?" do
97
+ it "should extract node selected state" do
98
+ @session.visit('/form')
99
+ @session.find('//option[@value="en"]').should be_selected
100
+ @session.find('//option[@value="sv"]').should_not be_selected
101
+ @session.first('//h1').should_not be_selected
69
102
  end
103
+ end
70
104
 
71
- describe "#tag_name" do
72
- it "should extract node tag name" do
73
- @session.all('//a')[0].tag_name.should == 'a'
74
- @session.all('//a')[1].tag_name.should == 'a'
75
- @session.all('//p')[1].tag_name.should == 'p'
76
- end
105
+ describe "#==" do
106
+ it "preserve object identity" do
107
+ (@session.find('//h1') == @session.find('//h1')).should be_true
108
+ (@session.find('//h1') === @session.find('//h1')).should be_true
109
+ (@session.find('//h1').eql? @session.find('//h1')).should be_false
77
110
  end
111
+ end
78
112
 
79
- describe "#visible?" do
80
- it "should extract node visibility" do
81
- @session.first('//a').should be_visible
113
+ describe "#trigger", :requires => [:js, :trigger] do
114
+ it "should allow triggering of custom JS events" do
115
+ @session.visit('/with_js')
116
+ @session.find(:css, '#with_focus_event').trigger(:focus)
117
+ @session.should have_css('#focus_event_triggered')
118
+ end
119
+ end
82
120
 
83
- @session.find('//div[@id="hidden"]').should_not be_visible
84
- @session.find('//div[@id="hidden_via_ancestor"]').should_not be_visible
85
- end
121
+ describe '#drag_to', :requires => [:js, :drag] do
122
+ it "should drag and drop an object" do
123
+ @session.visit('/with_js')
124
+ element = @session.find('//div[@id="drag"]')
125
+ target = @session.find('//div[@id="drop"]')
126
+ element.drag_to(target)
127
+ @session.find('//div[contains(., "Dropped!")]').should_not be_nil
86
128
  end
129
+ end
87
130
 
88
- describe "#checked?" do
89
- it "should extract node checked state" do
90
- @session.visit('/form')
91
- @session.find('//input[@id="gender_female"]').should be_checked
92
- @session.find('//input[@id="gender_male"]').should_not be_checked
93
- @session.first('//h1').should_not be_checked
131
+ describe '#reload', :requires => [:js] do
132
+ context "without automatic reload" do
133
+ before { Capybara.automatic_reload = false }
134
+ it "should reload the current context of the node" do
135
+ @session.visit('/with_js')
136
+ node = @session.find(:css, '#reload-me')
137
+ @session.click_link('Reload!')
138
+ sleep(0.3)
139
+ node.reload.text.should == 'has been reloaded'
140
+ node.text.should == 'has been reloaded'
94
141
  end
95
- end
96
142
 
97
- describe "#selected?" do
98
- it "should extract node selected state" do
99
- @session.visit('/form')
100
- @session.find('//option[@value="en"]').should be_selected
101
- @session.find('//option[@value="sv"]').should_not be_selected
102
- @session.first('//h1').should_not be_selected
143
+ it "should reload a parent node" do
144
+ @session.visit('/with_js')
145
+ node = @session.find(:css, '#reload-me').find(:css, 'em')
146
+ @session.click_link('Reload!')
147
+ sleep(0.3)
148
+ node.reload.text.should == 'has been reloaded'
149
+ node.text.should == 'has been reloaded'
103
150
  end
104
- end
105
151
 
106
- describe "#==" do
107
- it "preserve object identity" do
108
- (@session.find('//h1') == @session.find('//h1')).should be_true
109
- (@session.find('//h1') === @session.find('//h1')).should be_true
110
- (@session.find('//h1').eql? @session.find('//h1')).should be_false
152
+ it "should not automatically reload" do
153
+ @session.visit('/with_js')
154
+ node = @session.find(:css, '#reload-me')
155
+ @session.click_link('Reload!')
156
+ sleep(0.3)
157
+ expect { node.text.to == 'has been reloaded' }.to raise_error
111
158
  end
159
+ after { Capybara.automatic_reload = true }
112
160
  end
113
161
 
162
+ context "with automatic reload" do
163
+ it "should reload the current context of the node automatically" do
164
+ @session.visit('/with_js')
165
+ node = @session.find(:css, '#reload-me')
166
+ @session.click_link('Reload!')
167
+ sleep(0.3)
168
+ node.text.should == 'has been reloaded'
169
+ end
170
+
171
+ it "should reload a parent node automatically" do
172
+ @session.visit('/with_js')
173
+ node = @session.find(:css, '#reload-me').find(:css, 'em')
174
+ @session.click_link('Reload!')
175
+ sleep(0.3)
176
+ node.text.should == 'has been reloaded'
177
+ end
178
+
179
+ it "should reload a node automatically when using find" do
180
+ @session.visit('/with_js')
181
+ node = @session.find(:css, '#reload-me')
182
+ @session.click_link('Reload!')
183
+ sleep(0.3)
184
+ node.find(:css, 'a').text.should == 'has been reloaded'
185
+ end
186
+
187
+ it "should not reload nodes which haven't been found" do
188
+ @session.visit('/with_js')
189
+ node = @session.all(:css, '#the-list li')[1]
190
+ @session.click_link('Fetch new list!')
191
+ sleep(0.3)
192
+ expect { node.text.to == 'Foo' }.to raise_error
193
+ expect { node.text.to == 'Bar' }.to raise_error
194
+ end
195
+
196
+ it "should reload nodes with options" do
197
+ @session.visit('/with_js')
198
+ node = @session.find(:css, 'em', :text => "reloaded")
199
+ @session.click_link('Reload!')
200
+ sleep(1)
201
+ node.text.should == 'has been reloaded'
202
+ end
203
+ end
114
204
  end
115
205
  end