capybara 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.md CHANGED
@@ -1,3 +1,24 @@
1
+ # master
2
+
3
+ ### Changed
4
+
5
+ * Move the RackTest driver override with the `:respect_data_method` option
6
+ enabled from capybara/rspec to capybara/rails, so that it is enabled in
7
+ Rails projects that don't use RSpec. [Carlos Antonio da Silva]
8
+ * Source is now an alias for `body`. RackTest no longer returns modifications
9
+ to `body`. This basically codifies the behaviour which we've had for a while
10
+ anyway, and should have minimal impact for end users. It is important to
11
+ driver authors though. [Jonas Nicklas]
12
+
13
+ ### Fixed
14
+
15
+ * Visiting relative URLs when `app_host` is set and no server is running works
16
+ as expected. [Jonas Nicklas]
17
+ * `fill_in` works properly under Selenium again when the caret is not at the
18
+ end of the field before the method is called. [Douwe Maan, Jonas Nicklas, Jari
19
+ Bakken]
20
+ * `attach_file` can once again be given a Pathname [Jake Goulding]
21
+
1
22
  # Version 2.0.0
2
23
 
3
24
  Release date: 2012-11-05
data/README.md CHANGED
@@ -88,16 +88,15 @@ Load RSpec 2.x support by adding the following line (typically to your
88
88
  require 'capybara/rspec'
89
89
  ```
90
90
 
91
- If you are using Rails, put your Capybara specs in `spec/requests` or
92
- `spec/integration`.
91
+ If you are using Rails, put your Capybara specs in `spec/features`.
93
92
 
94
93
  If you are not using Rails, tag all the example groups in which you want to use
95
- Capybara with `:type => :request`.
94
+ Capybara with `:type => :feature`.
96
95
 
97
96
  You can now write your specs like so:
98
97
 
99
98
  ```ruby
100
- describe "the signup process", :type => :request do
99
+ describe "the signup process", :type => :feature do
101
100
  before :each do
102
101
  User.make(:email => 'user@example.com', :password => 'caplin')
103
102
  end
@@ -140,7 +139,7 @@ feature "Signing up" do
140
139
  end
141
140
 
142
141
  given(:other_user) { User.make(:email => 'other@example.com', :password => 'rous') }
143
-
142
+
144
143
  scenario "Signing in as another user" do
145
144
  within("#session") do
146
145
  fill_in 'Login', :with => other_user.email
@@ -151,8 +150,9 @@ feature "Signing up" do
151
150
  end
152
151
  ```
153
152
 
154
- `feature` is in fact just an alias for `describe ..., :type => :request`,
155
- `background` is an alias for `before`, `scenario` for `it`, and `given`/`given!` aliases for `let`/`let!`, respectively.
153
+ `feature` is in fact just an alias for `describe ..., :type => :feature`,
154
+ `background` is an alias for `before`, `scenario` for `it`, and
155
+ `given`/`given!` aliases for `let`/`let!`, respectively.
156
156
 
157
157
  ## Using Capybara with Test::Unit
158
158
 
@@ -11,10 +11,6 @@ class Capybara::Driver::Base
11
11
  raise NotImplementedError
12
12
  end
13
13
 
14
- def source
15
- raise NotImplementedError
16
- end
17
-
18
14
  def html
19
15
  raise NotImplementedError
20
16
  end
@@ -70,6 +70,10 @@ module Capybara
70
70
  rescue NotSupportedByDriverError
71
71
  %(#<#{self.class} tag="#{tag_name}">)
72
72
  end
73
+
74
+ def ==(other)
75
+ raise NotSupportedByDriverError
76
+ end
73
77
  end
74
78
  end
75
79
  end
@@ -138,7 +138,7 @@ module Capybara
138
138
  # @param [String] path The path of the file that will be attached, or an array of paths
139
139
  #
140
140
  def attach_file(locator, path)
141
- (String === path ? [path] : path).each do |p|
141
+ Array(path).each do |p|
142
142
  raise Capybara::FileNotFound, "cannot attach file, #{p} does not exist" unless File.exist?(p.to_s)
143
143
  end
144
144
  find(:file_field, locator).set(path)
@@ -5,7 +5,7 @@ module Capybara
5
5
  ##
6
6
  #
7
7
  # Find an {Capybara::Element} based on the given arguments. +find+ will raise an error if the element
8
- # is not found. The error message can be customized through the +:message+ option.
8
+ # is not found.
9
9
  #
10
10
  # If the driver is capable of executing JavaScript, +find+ will wait for a set amount of time
11
11
  # and continuously retry finding the element until either the element is found or the time
@@ -19,7 +19,6 @@ module Capybara
19
19
  # page.find('li', :text => 'Quox').click_link('Delete')
20
20
  #
21
21
  # @param (see Capybara::Node::Finders#all)
22
- # @option options [String] :message An error message in case the element can't be found
23
22
  # @return [Capybara::Element] The found element
24
23
  # @raise [Capybara::ElementNotFound] If the element can't be found before time expires
25
24
  #
@@ -451,11 +451,7 @@ module Capybara
451
451
  end
452
452
 
453
453
  def ==(other)
454
- if other.respond_to?(:native)
455
- self.eql?(other) or native == other.native
456
- else
457
- self.eql?(other)
458
- end
454
+ self.eql?(other) or base == other.base
459
455
  end
460
456
 
461
457
  private
@@ -76,19 +76,15 @@ class Capybara::RackTest::Browser
76
76
  @dom = nil
77
77
  end
78
78
 
79
- def html
80
- dom.to_xml
81
- end
82
-
83
79
  def dom
84
- @dom ||= Nokogiri::HTML(source)
80
+ @dom ||= Nokogiri::HTML(html)
85
81
  end
86
82
 
87
83
  def find(selector)
88
84
  dom.xpath(selector).map { |node| Capybara::RackTest::Node.new(self, node) }
89
85
  end
90
86
 
91
- def source
87
+ def html
92
88
  last_response.body
93
89
  rescue Rack::Test::Error
94
90
  ""
@@ -70,10 +70,6 @@ class Capybara::RackTest::Driver < Capybara::Driver::Base
70
70
  browser.html
71
71
  end
72
72
 
73
- def source
74
- browser.source
75
- end
76
-
77
73
  def dom
78
74
  browser.dom
79
75
  end
@@ -97,6 +97,10 @@ class Capybara::RackTest::Node < Capybara::Driver::Node
97
97
  native.xpath(locator).map { |n| self.class.new(driver, n) }
98
98
  end
99
99
 
100
+ def ==(other)
101
+ native == other.native
102
+ end
103
+
100
104
  protected
101
105
 
102
106
  def unnormalized_text
@@ -4,7 +4,7 @@ require 'capybara/dsl'
4
4
  Capybara.app = Rack::Builder.new do
5
5
  map "/" do
6
6
  if Rails.version.to_f >= 3.0
7
- run Rails.application
7
+ run Rails.application
8
8
  else # Rails 2
9
9
  use Rails::Rack::Static
10
10
  run ActionController::Dispatcher.new
@@ -15,3 +15,7 @@ end.to_app
15
15
  Capybara.asset_root = Rails.root.join('public')
16
16
  Capybara.save_and_open_page_path = Rails.root.join('tmp/capybara')
17
17
 
18
+ # Override default rack_test driver to respect data-method attributes.
19
+ Capybara.register_driver :rack_test do |app|
20
+ Capybara::RackTest::Driver.new(app, :respect_data_method => true)
21
+ end
@@ -22,8 +22,3 @@ RSpec.configure do |config|
22
22
  end
23
23
  end
24
24
  end
25
-
26
- # Override default rack_test driver to respect data-method attributes.
27
- Capybara.register_driver :rack_test do |app|
28
- Capybara::RackTest::Driver.new(app, :respect_data_method => true)
29
- end
@@ -34,10 +34,6 @@ class Capybara::Selenium::Driver < Capybara::Driver::Base
34
34
  browser.navigate.to(path)
35
35
  end
36
36
 
37
- def source
38
- browser.page_source
39
- end
40
-
41
37
  def html
42
38
  browser.page_source
43
39
  end
@@ -32,7 +32,8 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
32
32
  path_names = value.to_s.empty? ? [] : value
33
33
  native.send_keys(*path_names)
34
34
  elsif tag_name == 'textarea' or tag_name == 'input'
35
- native.send_keys(("\b" * native[:value].size) + value.to_s)
35
+ driver.browser.execute_script "arguments[0].value = ''", native
36
+ native.send_keys(value.to_s)
36
37
  end
37
38
  end
38
39
 
@@ -75,6 +76,10 @@ class Capybara::Selenium::Node < Capybara::Driver::Node
75
76
  native.find_elements(:xpath, locator).map { |n| self.class.new(driver, n) }
76
77
  end
77
78
 
79
+ def ==(other)
80
+ native == other.native
81
+ end
82
+
78
83
  private
79
84
 
80
85
  # a reference to the select node if this is an option node
@@ -105,15 +105,8 @@ module Capybara
105
105
  def html
106
106
  driver.html
107
107
  end
108
-
109
- ##
110
- #
111
- # @return [String] HTML source of the document, before being modified by JavaScript.
112
- #
113
- def source
114
- driver.source
115
- end
116
- alias_method :body, :source
108
+ alias_method :body, :html
109
+ alias_method :source, :html
117
110
 
118
111
  ##
119
112
  #
@@ -170,10 +163,12 @@ module Capybara
170
163
  def visit(url)
171
164
  @touched = true
172
165
 
166
+ if url !~ /^http/ and Capybara.app_host
167
+ url = Capybara.app_host + url.to_s
168
+ end
169
+
173
170
  if @server
174
- unless url =~ /^http/
175
- url = (Capybara.app_host || "http://#{@server.host}:#{@server.port}") + url.to_s
176
- end
171
+ url = "http://#{@server.host}:#{@server.port}" + url.to_s unless url =~ /^http/
177
172
 
178
173
  if Capybara.always_include_port
179
174
  uri = URI.parse(url)
@@ -1,8 +1,5 @@
1
1
  Capybara::SpecHelper.spec '#html' do
2
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
3
  @session.visit('/')
7
4
  @session.html.should include('Hello world!')
8
5
  end
@@ -13,3 +10,29 @@ Capybara::SpecHelper.spec '#html' do
13
10
  @session.html.should_not include('This is text')
14
11
  end
15
12
  end
13
+
14
+ Capybara::SpecHelper.spec '#source' do
15
+ it "should return the unmodified page source" do
16
+ @session.visit('/')
17
+ @session.source.should include('Hello world!')
18
+ end
19
+
20
+ it "should return the current state of the page", :requires => [:js] do
21
+ @session.visit('/with_js')
22
+ @session.source.should include('I changed it')
23
+ @session.source.should_not include('This is text')
24
+ end
25
+ end
26
+
27
+ Capybara::SpecHelper.spec '#body' do
28
+ it "should return the unmodified page source" do
29
+ @session.visit('/')
30
+ @session.body.should include('Hello world!')
31
+ end
32
+
33
+ it "should return the current state of the page", :requires => [:js] do
34
+ @session.visit('/with_js')
35
+ @session.body.should include('I changed it')
36
+ @session.body.should_not include('This is text')
37
+ end
38
+ end
@@ -65,6 +65,12 @@ Capybara::SpecHelper.spec "node" do
65
65
  @session.first('//input').set('gorilla')
66
66
  @session.first('//input').value.should == 'gorilla'
67
67
  end
68
+
69
+ it "should fill the field even if the caret was not at the end", :requires => [:js] do
70
+ @session.execute_script("var el = document.getElementById('test_field'); el.focus(); el.setSelectionRange(0, 0);")
71
+ @session.first('//input').set('')
72
+ @session.first('//input').value.should == ''
73
+ end
68
74
  end
69
75
 
70
76
  describe "#tag_name" do
@@ -1,12 +0,0 @@
1
- Capybara::SpecHelper.spec '#source' do
2
- it "should return the unmodified page source" do
3
- @session.visit('/')
4
- @session.source.should include('Hello world!')
5
- end
6
-
7
- it "should return the original, unmodified source of the page", :requires => [:js, :source] do
8
- @session.visit('/with_js')
9
- @session.send(method).should include('This is text')
10
- @session.send(method).should_not include('I changed it')
11
- end
12
- end
@@ -43,6 +43,21 @@ Capybara::SpecHelper.spec '#visit' do
43
43
  end
44
44
  end
45
45
 
46
+ context "without a server", :requires => [:server] do
47
+ it "should respect `app_host`" do
48
+ serverless_session = Capybara::Session.new(@session.mode, nil)
49
+ Capybara.app_host = "http://#{@session.server.host}:#{@session.server.port}"
50
+ serverless_session.visit("/foo")
51
+ serverless_session.should have_content("Another World")
52
+ end
53
+
54
+ it "should visit a fully qualified URL" do
55
+ serverless_session = Capybara::Session.new(@session.mode, nil)
56
+ serverless_session.visit("http://#{@session.server.host}:#{@session.server.port}/foo")
57
+ serverless_session.should have_content("Another World")
58
+ end
59
+ end
60
+
46
61
  it "should send no referer when visiting a page" do
47
62
  @session.visit '/get_referer'
48
63
  @session.should have_content 'No referer'
@@ -1,3 +1,3 @@
1
1
  module Capybara
2
- VERSION = '2.0.0'
2
+ VERSION = '2.0.1'
3
3
  end
@@ -9,7 +9,8 @@ Capybara::SpecHelper.run_specs TestClass.new, "DSL", :skip => [
9
9
  :js,
10
10
  :screenshot,
11
11
  :frames,
12
- :windows
12
+ :windows,
13
+ :server
13
14
  ]
14
15
 
15
16
  describe Capybara::DSL do
@@ -8,7 +8,8 @@ Capybara::SpecHelper.run_specs TestSessions::RackTest, "RackTest", :skip => [
8
8
  :js,
9
9
  :screenshot,
10
10
  :frames,
11
- :windows
11
+ :windows,
12
+ :server
12
13
  ]
13
14
 
14
15
  describe Capybara::Session do
@@ -7,7 +7,6 @@ end
7
7
  Capybara::SpecHelper.run_specs TestSessions::Selenium, "selenium", :skip => [
8
8
  :response_headers,
9
9
  :status_code,
10
- :source,
11
10
  :trigger
12
11
  ]
13
12
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capybara
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-14 00:00:00.000000000 Z
12
+ date: 2012-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri