capybara 2.0.0.beta2 → 2.0.0.beta4

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 (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,18 +1,20 @@
1
- shared_examples_for "find_button" do
2
- describe '#find_button' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#find_button' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
5
+
6
+ it "should find any button" do
7
+ @session.find_button('med')[:id].should == "mediocre"
8
+ @session.find_button('crap321').value.should == "crappy"
9
+ end
6
10
 
7
- it "should find any field" do
8
- @session.find_button('med')[:id].should == "mediocre"
9
- @session.find_button('crap321').value.should == "crappy"
10
- end
11
+ it "casts to string" do
12
+ @session.find_button(:'med')[:id].should == "mediocre"
13
+ end
11
14
 
12
- it "should raise error if the field doesn't exist" do
13
- running do
14
- @session.find_button('Does not exist')
15
- end.should raise_error(Capybara::ElementNotFound)
16
- end
15
+ it "should raise error if the button doesn't exist" do
16
+ expect do
17
+ @session.find_button('Does not exist')
18
+ end.to raise_error(Capybara::ElementNotFound)
17
19
  end
18
20
  end
@@ -1,18 +1,20 @@
1
- shared_examples_for "find_by_id" do
2
- describe '#find_by_id' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#find_by_id' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
5
+
6
+ it "should find any element by id" do
7
+ @session.find_by_id('red').tag_name.should == 'a'
8
+ @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
9
+ end
6
10
 
7
- it "should find any element by id" do
8
- @session.find_by_id('red').tag_name.should == 'a'
9
- @session.find_by_id('hidden_via_ancestor').tag_name.should == 'div'
10
- end
11
+ it "casts to string" do
12
+ @session.find_by_id(:'red').tag_name.should == 'a'
13
+ end
11
14
 
12
- it "should raise error if no element with id is found" do
13
- running do
14
- @session.find_by_id('nothing_with_this_id')
15
- end.should raise_error(Capybara::ElementNotFound)
16
- end
15
+ it "should raise error if no element with id is found" do
16
+ expect do
17
+ @session.find_by_id('nothing_with_this_id')
18
+ end.to raise_error(Capybara::ElementNotFound)
17
19
  end
18
20
  end
@@ -1,26 +1,28 @@
1
- shared_examples_for "find_field" do
2
- describe '#find_field' do
3
- before do
4
- @session.visit('/form')
5
- end
1
+ Capybara::SpecHelper.spec '#find_field' do
2
+ before do
3
+ @session.visit('/form')
4
+ end
6
5
 
7
- it "should find any field" do
8
- @session.find_field('Dog').value.should == 'dog'
9
- @session.find_field('form_description').text.should == 'Descriptive text goes here'
10
- @session.find_field('Region')[:name].should == 'form[region]'
11
- end
6
+ it "should find any field" do
7
+ @session.find_field('Dog').value.should == 'dog'
8
+ @session.find_field('form_description').text.should == 'Descriptive text goes here'
9
+ @session.find_field('Region')[:name].should == 'form[region]'
10
+ end
12
11
 
13
- it "should raise error if the field doesn't exist" do
14
- running do
15
- @session.find_field('Does not exist')
16
- end.should raise_error(Capybara::ElementNotFound)
17
- end
12
+ it "casts to string" do
13
+ @session.find_field(:'Dog').value.should == 'dog'
14
+ end
15
+
16
+ it "should raise error if the field doesn't exist" do
17
+ expect do
18
+ @session.find_field('Does not exist')
19
+ end.to raise_error(Capybara::ElementNotFound)
20
+ end
18
21
 
19
- it "should be aliased as 'field_labeled' for webrat compatibility" do
20
- @session.field_labeled('Dog').value.should == 'dog'
21
- running do
22
- @session.field_labeled('Does not exist')
23
- end.should raise_error(Capybara::ElementNotFound)
24
- end
22
+ it "should be aliased as 'field_labeled' for webrat compatibility" do
23
+ @session.field_labeled('Dog').value.should == 'dog'
24
+ expect do
25
+ @session.field_labeled('Does not exist')
26
+ end.to raise_error(Capybara::ElementNotFound)
25
27
  end
26
28
  end
@@ -1,19 +1,20 @@
1
- shared_examples_for "find_link" do
1
+ Capybara::SpecHelper.spec '#find_link' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
2
5
 
3
- describe '#find_link' do
4
- before do
5
- @session.visit('/with_html')
6
- end
6
+ it "should find any field" do
7
+ @session.find_link('foo').text.should == "ullamco"
8
+ @session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
9
+ end
7
10
 
8
- it "should find any field" do
9
- @session.find_link('foo').text.should == "ullamco"
10
- @session.find_link('labore')[:href].should =~ %r(/with_simple_html$)
11
- end
11
+ it "casts to string" do
12
+ @session.find_link(:'foo').text.should == "ullamco"
13
+ end
12
14
 
13
- it "should raise error if the field doesn't exist" do
14
- running do
15
- @session.find_link('Does not exist')
16
- end.should raise_error(Capybara::ElementNotFound)
17
- end
15
+ it "should raise error if the field doesn't exist" do
16
+ expect do
17
+ @session.find_link('Does not exist')
18
+ end.to raise_error(Capybara::ElementNotFound)
18
19
  end
19
20
  end
@@ -1,121 +1,126 @@
1
- shared_examples_for "find" do
2
- describe '#find' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#find' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- after do
8
- Capybara::Selector.remove(:monkey)
9
- end
6
+ after do
7
+ Capybara::Selector.remove(:monkey)
8
+ end
10
9
 
11
- it "should find the first element using the given locator" do
12
- @session.find('//h1').text.should == 'This is a test'
13
- @session.find("//input[@id='test_field']")[:value].should == 'monkey'
14
- end
10
+ it "should find the first element using the given locator" do
11
+ @session.find('//h1').text.should == 'This is a test'
12
+ @session.find("//input[@id='test_field']")[:value].should == 'monkey'
13
+ end
15
14
 
16
- it "should find the first element using the given locator and options" do
17
- @session.find('//a', :text => 'Redirect')[:id].should == 'red'
18
- @session.find(:css, 'a', :text => 'A link came first')[:title].should == 'twas a fine link'
19
- end
15
+ it "should find the first element using the given locator and options" do
16
+ @session.find('//a', :text => 'Redirect')[:id].should == 'red'
17
+ @session.find(:css, 'a', :text => 'A link came first')[:title].should == 'twas a fine link'
18
+ end
20
19
 
21
- it "should raise an error if there are multiple matches" do
22
- expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
23
- end
20
+ it "should raise an error if there are multiple matches" do
21
+ expect { @session.find('//a') }.to raise_error(Capybara::Ambiguous)
22
+ end
24
23
 
25
- context "with css selectors" do
26
- it "should find the first element using the given locator" do
27
- @session.find(:css, 'h1').text.should == 'This is a test'
28
- @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
29
- end
30
- end
24
+ it "should wait for asynchronous load", :requires => [:js] do
25
+ @session.visit('/with_js')
26
+ @session.click_link('Click me')
27
+ @session.find(:css, "a#has-been-clicked").text.should include('Has been clicked')
28
+ end
31
29
 
32
- context "with id selectors" do
33
- it "should find the first element using the given locator" do
34
- @session.find(:id, 'john_monkey').text.should == 'Monkey John'
35
- @session.find(:id, 'red').text.should == 'Redirect'
36
- @session.find(:red).text.should == 'Redirect'
37
- end
30
+ context "with frozen time", :requires => [:js] do
31
+ it "raises an error suggesting that Capybara is stuck in time" do
32
+ @session.visit('/with_js')
33
+ now = Time.now
34
+ Time.stub(:now).and_return(now)
35
+ expect { @session.find('//isnotthere') }.to raise_error(Capybara::FrozenInTime)
38
36
  end
37
+ end
39
38
 
40
- context "with xpath selectors" do
41
- it "should find the first element using the given locator" do
42
- @session.find(:xpath, '//h1').text.should == 'This is a test'
43
- @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
44
- end
39
+ context "with css selectors" do
40
+ it "should find the first element using the given locator" do
41
+ @session.find(:css, 'h1').text.should == 'This is a test'
42
+ @session.find(:css, "input[id='test_field']")[:value].should == 'monkey'
45
43
  end
44
+ end
46
45
 
47
- context "with custom selector" do
48
- it "should use the custom selector" do
49
- Capybara.add_selector(:monkey) do
50
- xpath { |name| ".//*[@id='#{name}_monkey']" }
51
- end
52
- @session.find(:monkey, 'john').text.should == 'Monkey John'
53
- @session.find(:monkey, 'paul').text.should == 'Monkey Paul'
54
- end
46
+ context "with xpath selectors" do
47
+ it "should find the first element using the given locator" do
48
+ @session.find(:xpath, '//h1').text.should == 'This is a test'
49
+ @session.find(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
55
50
  end
51
+ end
56
52
 
57
- context "with custom selector with :for option" do
58
- it "should use the selector when it matches the :for option" do
59
- Capybara.add_selector(:monkey) do
60
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
61
- match { |value| value.is_a?(Fixnum) }
62
- end
63
- @session.find(:monkey, '2').text.should == 'Monkey Paul'
64
- @session.find(1).text.should == 'Monkey John'
65
- @session.find(2).text.should == 'Monkey Paul'
66
- @session.find('//h1').text.should == 'This is a test'
53
+ context "with custom selector" do
54
+ it "should use the custom selector" do
55
+ Capybara.add_selector(:monkey) do
56
+ xpath { |name| ".//*[@id='#{name}_monkey']" }
67
57
  end
58
+ @session.find(:monkey, 'john').text.should == 'Monkey John'
59
+ @session.find(:monkey, 'paul').text.should == 'Monkey Paul'
68
60
  end
61
+ end
69
62
 
70
- context "with custom selector with custom filter" do
71
- before do
72
- Capybara.add_selector(:monkey) do
73
- xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
74
- filter(:name) { |node, name| node.text == name }
75
- end
76
- end
77
-
78
- it "should find elements that match the filter" do
79
- @session.find(:monkey, '1', :name => 'Monkey John').text.should == 'Monkey John'
80
- @session.find(:monkey, '2', :name => 'Monkey Paul').text.should == 'Monkey Paul'
63
+ context "with custom selector with :for option" do
64
+ it "should use the selector when it matches the :for option" do
65
+ Capybara.add_selector(:monkey) do
66
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
67
+ match { |value| value.is_a?(Fixnum) }
81
68
  end
69
+ @session.find(:monkey, '2').text.should == 'Monkey Paul'
70
+ @session.find(1).text.should == 'Monkey John'
71
+ @session.find(2).text.should == 'Monkey Paul'
72
+ @session.find('//h1').text.should == 'This is a test'
73
+ end
74
+ end
82
75
 
83
- it "should not find elements that don't match the filter" do
84
- expect { @session.find(:monkey, '2', :name => 'Monkey John') }.to raise_error(Capybara::ElementNotFound)
85
- expect { @session.find(:monkey, '1', :name => 'Monkey Paul') }.to raise_error(Capybara::ElementNotFound)
76
+ context "with custom selector with custom filter" do
77
+ before do
78
+ Capybara.add_selector(:monkey) do
79
+ xpath { |num| ".//*[contains(@id, 'monkey')][#{num}]" }
80
+ filter(:name) { |node, name| node.text == name }
86
81
  end
87
82
  end
88
83
 
89
- context "with css as default selector" do
90
- before { Capybara.default_selector = :css }
91
- it "should find the first element using the given locator" do
92
- @session.find('h1').text.should == 'This is a test'
93
- @session.find("input[id='test_field']")[:value].should == 'monkey'
94
- end
95
- after { Capybara.default_selector = :xpath }
84
+ it "should find elements that match the filter" do
85
+ @session.find(:monkey, '1', :name => 'Monkey John').text.should == 'Monkey John'
86
+ @session.find(:monkey, '2', :name => 'Monkey Paul').text.should == 'Monkey Paul'
96
87
  end
97
88
 
98
- it "should raise ElementNotFound with a useful default message if nothing was found" do
99
- running do
100
- @session.find(:xpath, '//div[@id="nosuchthing"]').should be_nil
101
- end.should raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
89
+ it "should not find elements that don't match the filter" do
90
+ expect { @session.find(:monkey, '2', :name => 'Monkey John') }.to raise_error(Capybara::ElementNotFound)
91
+ expect { @session.find(:monkey, '1', :name => 'Monkey Paul') }.to raise_error(Capybara::ElementNotFound)
102
92
  end
93
+ end
103
94
 
104
- it "should accept an XPath instance" do
105
- @session.visit('/form')
106
- @xpath = XPath::HTML.fillable_field('First Name')
107
- @session.find(@xpath).value.should == 'John'
95
+ context "with css as default selector" do
96
+ before { Capybara.default_selector = :css }
97
+ it "should find the first element using the given locator" do
98
+ @session.find('h1').text.should == 'This is a test'
99
+ @session.find("input[id='test_field']")[:value].should == 'monkey'
108
100
  end
101
+ after { Capybara.default_selector = :xpath }
102
+ end
109
103
 
110
- context "within a scope" do
111
- before do
112
- @session.visit('/with_scope')
113
- end
104
+ it "should raise ElementNotFound with a useful default message if nothing was found" do
105
+ expect do
106
+ @session.find(:xpath, '//div[@id="nosuchthing"]').to be_nil
107
+ end.to raise_error(Capybara::ElementNotFound, "Unable to find xpath \"//div[@id=\\\"nosuchthing\\\"]\"")
108
+ end
109
+
110
+ it "should accept an XPath instance" do
111
+ @session.visit('/form')
112
+ @xpath = XPath::HTML.fillable_field('First Name')
113
+ @session.find(@xpath).value.should == 'John'
114
+ end
115
+
116
+ context "within a scope" do
117
+ before do
118
+ @session.visit('/with_scope')
119
+ end
114
120
 
115
- it "should find the an element using the given locator" do
116
- @session.within(:xpath, "//div[@id='for_bar']") do
117
- @session.find('.//li[1]').text.should =~ /With Simple HTML/
118
- end
121
+ it "should find the an element using the given locator" do
122
+ @session.within(:xpath, "//div[@id='for_bar']") do
123
+ @session.find('.//li[1]').text.should =~ /With Simple HTML/
119
124
  end
120
125
  end
121
126
  end
@@ -1,72 +1,70 @@
1
- shared_examples_for "first" do
2
- describe '#first' do
3
- before do
4
- @session.visit('/with_html')
5
- end
1
+ Capybara::SpecHelper.spec '#first' do
2
+ before do
3
+ @session.visit('/with_html')
4
+ end
6
5
 
7
- it "should find the first element using the given locator" do
8
- @session.first('//h1').text.should == 'This is a test'
9
- @session.first("//input[@id='test_field']")[:value].should == 'monkey'
10
- end
6
+ it "should find the first element using the given locator" do
7
+ @session.first('//h1').text.should == 'This is a test'
8
+ @session.first("//input[@id='test_field']")[:value].should == 'monkey'
9
+ end
11
10
 
12
- it "should return nil when nothing was found" do
13
- @session.first('//div[@id="nosuchthing"]').should be_nil
14
- end
11
+ it "should return nil when nothing was found" do
12
+ @session.first('//div[@id="nosuchthing"]').should be_nil
13
+ end
15
14
 
16
- it "should accept an XPath instance" do
17
- @session.visit('/form')
18
- @xpath = XPath::HTML.fillable_field('First Name')
19
- @session.first(@xpath).value.should == 'John'
20
- end
15
+ it "should accept an XPath instance" do
16
+ @session.visit('/form')
17
+ @xpath = XPath::HTML.fillable_field('First Name')
18
+ @session.first(@xpath).value.should == 'John'
19
+ end
21
20
 
22
- context "with css selectors" do
23
- it "should find the first element using the given selector" do
24
- @session.first(:css, 'h1').text.should == 'This is a test'
25
- @session.first(:css, "input[id='test_field']")[:value].should == 'monkey'
26
- end
21
+ context "with css selectors" do
22
+ it "should find the first element using the given selector" do
23
+ @session.first(:css, 'h1').text.should == 'This is a test'
24
+ @session.first(:css, "input[id='test_field']")[:value].should == 'monkey'
27
25
  end
26
+ end
28
27
 
29
- context "with xpath selectors" do
30
- it "should find the first element using the given locator" do
31
- @session.first(:xpath, '//h1').text.should == 'This is a test'
32
- @session.first(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
33
- end
28
+ context "with xpath selectors" do
29
+ it "should find the first element using the given locator" do
30
+ @session.first(:xpath, '//h1').text.should == 'This is a test'
31
+ @session.first(:xpath, "//input[@id='test_field']")[:value].should == 'monkey'
34
32
  end
33
+ end
35
34
 
36
- context "with css as default selector" do
37
- before { Capybara.default_selector = :css }
38
- it "should find the first element using the given locator" do
39
- @session.first('h1').text.should == 'This is a test'
40
- @session.first("input[id='test_field']")[:value].should == 'monkey'
41
- end
42
- after { Capybara.default_selector = :xpath }
35
+ context "with css as default selector" do
36
+ before { Capybara.default_selector = :css }
37
+ it "should find the first element using the given locator" do
38
+ @session.first('h1').text.should == 'This is a test'
39
+ @session.first("input[id='test_field']")[:value].should == 'monkey'
43
40
  end
41
+ after { Capybara.default_selector = :xpath }
42
+ end
44
43
 
45
- context "with visible filter" do
46
- after { Capybara.ignore_hidden_elements = false }
47
- it "should only find visible nodes if true given" do
48
- @session.first(:css, "a#invisible").should_not be_nil
49
- @session.first(:css, "a#invisible", :visible => true).should be_nil
50
- Capybara.ignore_hidden_elements = true
51
- @session.first(:css, "a#invisible").should be_nil
52
- end
44
+ context "with visible filter" do
45
+ after { Capybara.ignore_hidden_elements = false }
46
+ it "should only find visible nodes if true given" do
47
+ @session.first(:css, "a#invisible").should_not be_nil
48
+ @session.first(:css, "a#invisible", :visible => true).should be_nil
49
+ Capybara.ignore_hidden_elements = true
50
+ @session.first(:css, "a#invisible").should be_nil
51
+ end
53
52
 
54
- it "should include invisible nodes if false given" do
55
- Capybara.ignore_hidden_elements = true
56
- @session.first(:css, "a#invisible", :visible => false).should_not be_nil
57
- @session.first(:css, "a#invisible").should be_nil
58
- end
53
+ it "should include invisible nodes if false given" do
54
+ Capybara.ignore_hidden_elements = true
55
+ @session.first(:css, "a#invisible", :visible => false).should_not be_nil
56
+ @session.first(:css, "a#invisible").should be_nil
59
57
  end
58
+ end
60
59
 
61
- context "within a scope" do
62
- before do
63
- @session.visit('/with_scope')
64
- end
60
+ context "within a scope" do
61
+ before do
62
+ @session.visit('/with_scope')
63
+ end
65
64
 
66
- it "should find the first element using the given locator" do
67
- @session.within(:xpath, "//div[@id='for_bar']") do
68
- @session.first('.//form').should_not be_nil
69
- end
65
+ it "should find the first element using the given locator" do
66
+ @session.within(:xpath, "//div[@id='for_bar']") do
67
+ @session.first('.//form').should_not be_nil
70
68
  end
71
69
  end
72
70
  end