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.
- data/History.txt +30 -1
- data/README.md +52 -31
- data/lib/capybara.rb +1 -0
- data/lib/capybara/driver/base.rb +1 -1
- data/lib/capybara/driver/node.rb +1 -0
- data/lib/capybara/dsl.rb +12 -5
- data/lib/capybara/helpers.rb +33 -0
- data/lib/capybara/node/actions.rb +4 -2
- data/lib/capybara/node/base.rb +52 -1
- data/lib/capybara/node/element.rb +0 -12
- data/lib/capybara/node/finders.rb +1 -1
- data/lib/capybara/node/matchers.rb +57 -47
- data/lib/capybara/node/simple.rb +4 -0
- data/lib/capybara/query.rb +11 -11
- data/lib/capybara/rack_test/browser.rb +14 -15
- data/lib/capybara/rack_test/driver.rb +2 -2
- data/lib/capybara/rack_test/node.rb +15 -2
- data/lib/capybara/result.rb +7 -19
- data/lib/capybara/rspec.rb +7 -4
- data/lib/capybara/rspec/features.rb +4 -1
- data/lib/capybara/rspec/matchers.rb +8 -3
- data/lib/capybara/selector.rb +1 -2
- data/lib/capybara/selenium/driver.rb +2 -2
- data/lib/capybara/selenium/node.rb +9 -7
- data/lib/capybara/session.rb +47 -31
- data/lib/capybara/spec/fixtures/another_test_file.txt +1 -0
- data/lib/capybara/spec/public/test.js +1 -1
- data/lib/capybara/spec/session/all_spec.rb +60 -62
- data/lib/capybara/spec/session/assert_selector.rb +123 -0
- data/lib/capybara/spec/session/attach_file_spec.rb +72 -58
- data/lib/capybara/spec/session/body_spec.rb +21 -0
- data/lib/capybara/spec/session/check_spec.rb +67 -50
- data/lib/capybara/spec/session/choose_spec.rb +32 -21
- data/lib/capybara/spec/session/click_button_spec.rb +261 -221
- data/lib/capybara/spec/session/click_link_or_button_spec.rb +40 -30
- data/lib/capybara/spec/session/click_link_spec.rb +95 -81
- data/lib/capybara/spec/session/current_url_spec.rb +70 -60
- data/lib/capybara/spec/session/evaluate_script_spec.rb +6 -0
- data/lib/capybara/spec/session/execute_script_spec.rb +7 -0
- data/lib/capybara/spec/session/fill_in_spec.rb +118 -92
- data/lib/capybara/spec/session/find_button_spec.rb +16 -14
- data/lib/capybara/spec/session/find_by_id_spec.rb +16 -14
- data/lib/capybara/spec/session/find_field_spec.rb +23 -21
- data/lib/capybara/spec/session/find_link_spec.rb +15 -14
- data/lib/capybara/spec/session/find_spec.rb +96 -91
- data/lib/capybara/spec/session/first_spec.rb +53 -55
- data/lib/capybara/spec/session/has_button_spec.rb +22 -24
- data/lib/capybara/spec/session/has_css_spec.rb +190 -205
- data/lib/capybara/spec/session/has_field_spec.rb +167 -169
- data/lib/capybara/spec/session/has_link_spec.rb +26 -29
- data/lib/capybara/spec/session/has_select_spec.rb +175 -176
- data/lib/capybara/spec/session/has_selector_spec.rb +94 -100
- data/lib/capybara/spec/session/has_table_spec.rb +22 -26
- data/lib/capybara/spec/session/has_text_spec.rb +159 -132
- data/lib/capybara/spec/session/has_xpath_spec.rb +100 -96
- data/lib/capybara/spec/session/headers.rb +4 -17
- data/lib/capybara/spec/session/html_spec.rb +15 -0
- data/lib/capybara/spec/session/node_spec.rb +172 -82
- data/lib/capybara/spec/session/reset_session_spec.rb +42 -0
- data/lib/capybara/spec/session/response_code.rb +4 -17
- data/lib/capybara/spec/session/save_page_spec.rb +46 -0
- data/lib/capybara/spec/session/screenshot.rb +8 -24
- data/lib/capybara/spec/session/select_spec.rb +100 -89
- data/lib/capybara/spec/session/source_spec.rb +12 -0
- data/lib/capybara/spec/session/text_spec.rb +15 -17
- data/lib/capybara/spec/session/uncheck_spec.rb +22 -17
- data/lib/capybara/spec/session/unselect_spec.rb +57 -52
- data/lib/capybara/spec/session/visit_spec.rb +58 -60
- data/lib/capybara/spec/session/within_frame_spec.rb +24 -26
- data/lib/capybara/spec/session/within_spec.rb +119 -121
- data/lib/capybara/spec/session/within_window_spec.rb +29 -31
- data/lib/capybara/spec/spec_helper.rb +84 -0
- data/lib/capybara/spec/test_app.rb +5 -3
- data/lib/capybara/spec/views/form.erb +1 -0
- data/lib/capybara/spec/views/with_html.erb +6 -1
- data/lib/capybara/spec/views/with_js.erb +1 -0
- data/lib/capybara/version.rb +1 -1
- data/spec/basic_node_spec.rb +2 -2
- data/spec/capybara_spec.rb +9 -0
- data/spec/dsl_spec.rb +22 -10
- data/spec/rack_test_spec.rb +28 -23
- data/spec/result_spec.rb +51 -0
- data/spec/rspec/features_spec.rb +19 -0
- data/spec/rspec/matchers_spec.rb +6 -0
- data/spec/rspec_spec.rb +1 -1
- data/spec/selenium_spec.rb +11 -25
- data/spec/server_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -46
- metadata +41 -98
- data/lib/capybara/spec/session.rb +0 -183
- data/lib/capybara/spec/session/javascript.rb +0 -290
- data/lib/capybara/util/save_and_open_page.rb +0 -45
- data/spec/save_and_open_page_spec.rb +0 -155
@@ -1,45 +0,0 @@
|
|
1
|
-
module Capybara
|
2
|
-
class << self
|
3
|
-
def save_page(html, file_name=nil)
|
4
|
-
file_name ||= "capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html"
|
5
|
-
name = File.join(*[Capybara.save_and_open_page_path, file_name].compact)
|
6
|
-
|
7
|
-
unless Capybara.save_and_open_page_path.nil? || File.directory?(Capybara.save_and_open_page_path )
|
8
|
-
FileUtils.mkdir_p(Capybara.save_and_open_page_path)
|
9
|
-
end
|
10
|
-
FileUtils.touch(name) unless File.exist?(name)
|
11
|
-
|
12
|
-
tempfile = File.new(name,'w')
|
13
|
-
tempfile.write(rewrite_css_and_image_references(html))
|
14
|
-
tempfile.close
|
15
|
-
tempfile.path
|
16
|
-
end
|
17
|
-
|
18
|
-
def save_and_open_page(html, file_name=nil)
|
19
|
-
open_in_browser save_page(html, file_name)
|
20
|
-
end
|
21
|
-
|
22
|
-
protected
|
23
|
-
|
24
|
-
def open_in_browser(path) # :nodoc
|
25
|
-
require "launchy" # could raise LoadError
|
26
|
-
raise LoadError unless Launchy::Version::MAJOR >= 2
|
27
|
-
Launchy.open(path)
|
28
|
-
rescue LoadError
|
29
|
-
warn "You need launchy >=2.0.0 to open pages with `save_and_open_page`:\n" <<
|
30
|
-
"gem 'launchy', '>= 2.0.0', :require => false, :group => :test"
|
31
|
-
end
|
32
|
-
|
33
|
-
def rewrite_css_and_image_references(response_html) # :nodoc:
|
34
|
-
root = Capybara.asset_root
|
35
|
-
return response_html unless root
|
36
|
-
directories = Dir.new(root).entries.select { |name|
|
37
|
-
(root+name).directory? and not name.to_s =~ /^\./
|
38
|
-
}
|
39
|
-
if not directories.empty?
|
40
|
-
response_html.gsub!(/("|')\/(#{directories.join('|')})/, '\1' + root.to_s + '/\2')
|
41
|
-
end
|
42
|
-
return response_html
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
require 'capybara/util/save_and_open_page'
|
4
|
-
require 'launchy'
|
5
|
-
describe Capybara do
|
6
|
-
describe ".save_page & .save_and_open_page" do
|
7
|
-
before do
|
8
|
-
@temp_file = mock("FILE")
|
9
|
-
@temp_file.stub!(:write)
|
10
|
-
@temp_file.stub!(:close)
|
11
|
-
|
12
|
-
@html = <<-HTML
|
13
|
-
<html>
|
14
|
-
<head>
|
15
|
-
<script type="text/javascript" src="/javascripts/prototype.js?123"/>
|
16
|
-
</head>
|
17
|
-
<body>
|
18
|
-
<h1>test</h1>
|
19
|
-
<p>
|
20
|
-
Some images (note differing whitespace closing tag):
|
21
|
-
<img src="/images/image1.jpeg" />
|
22
|
-
<img src="/images/image2.jpeg"/>
|
23
|
-
</p>
|
24
|
-
<p>
|
25
|
-
Some more in a non-existent directory:
|
26
|
-
<img src="/img/image3.jpeg" />
|
27
|
-
<img src="/img/image4.jpeg"/>
|
28
|
-
</p>
|
29
|
-
<p>
|
30
|
-
<a href="/not-here/foo.html">
|
31
|
-
A link to a file in a non-existent directory.
|
32
|
-
</a>
|
33
|
-
</p>
|
34
|
-
</body>
|
35
|
-
<html>
|
36
|
-
HTML
|
37
|
-
|
38
|
-
Launchy.stub(:open)
|
39
|
-
end
|
40
|
-
|
41
|
-
def default_file_expectations
|
42
|
-
@temp_file.stub!(:path).and_return('page.html')
|
43
|
-
|
44
|
-
File.should_receive(:exist?).and_return true
|
45
|
-
File.should_receive(:new).and_return @temp_file
|
46
|
-
end
|
47
|
-
|
48
|
-
describe "defaults" do
|
49
|
-
before do
|
50
|
-
default_file_expectations
|
51
|
-
end
|
52
|
-
|
53
|
-
it "should create a new temporary file" do
|
54
|
-
@temp_file.should_receive(:write).with @html
|
55
|
-
Capybara.save_page @html, 'page.html'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should open the file in the browser" do
|
59
|
-
Capybara.should_receive(:open_in_browser).with('page.html')
|
60
|
-
Capybara.save_and_open_page @html, 'page.html'
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe "custom output path" do
|
65
|
-
before do
|
66
|
-
@custom_path = File.join('tmp', 'capybara')
|
67
|
-
@custom_name = File.join(@custom_path, 'page.html')
|
68
|
-
|
69
|
-
@temp_file.stub!(:path).and_return(@custom_name)
|
70
|
-
|
71
|
-
Capybara.should_receive(:save_and_open_page_path).at_least(:once).and_return(@custom_path)
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should create a new temporary file in the custom path" do
|
75
|
-
File.should_receive(:directory?).and_return true
|
76
|
-
File.should_receive(:exist?).and_return true
|
77
|
-
File.should_receive(:new).and_return @temp_file
|
78
|
-
|
79
|
-
@temp_file.should_receive(:write).with @html
|
80
|
-
Capybara.save_page @html, 'page.html'
|
81
|
-
end
|
82
|
-
|
83
|
-
it "should open the file - in the custom path - in the browser" do
|
84
|
-
Capybara.should_receive(:open_in_browser).with(@custom_name)
|
85
|
-
Capybara.save_and_open_page @html, 'page.html'
|
86
|
-
end
|
87
|
-
|
88
|
-
it "should be possible to configure output path" do
|
89
|
-
Capybara.should respond_to(:save_and_open_page_path)
|
90
|
-
default_setting = Capybara.save_and_open_page_path
|
91
|
-
lambda {
|
92
|
-
Capybara.save_and_open_page_path = File.join('tmp', 'capybara')
|
93
|
-
Capybara.save_and_open_page_path.should == File.join('tmp', 'capybara')
|
94
|
-
}.should_not raise_error
|
95
|
-
Capybara.save_and_open_page_path = default_setting
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "rewrite_css_and_image_references" do
|
100
|
-
before do
|
101
|
-
default_file_expectations
|
102
|
-
@asset_root_dir = "/path/to/rails/public"
|
103
|
-
end
|
104
|
-
|
105
|
-
def mock_asset_root_with(directories)
|
106
|
-
@asset_root = Pathname.new(@asset_root_dir)
|
107
|
-
Capybara.should_receive(:asset_root).and_return @asset_root
|
108
|
-
|
109
|
-
dir = mock('asset_root mock dir')
|
110
|
-
Dir.should_receive(:new).with(@asset_root).and_return dir
|
111
|
-
|
112
|
-
dirents = [ '.', '..', 'file.html' ] + directories
|
113
|
-
dir.should_receive(:entries).and_return dirents
|
114
|
-
|
115
|
-
directories_regexp = directories.join('|')
|
116
|
-
FileTest.should_receive(:directory?) \
|
117
|
-
.at_least(dirents.size - 2).times \
|
118
|
-
.and_return { |dir|
|
119
|
-
dir =~ %r!#{@asset_root_dir}/(#{directories_regexp})$!
|
120
|
-
}
|
121
|
-
end
|
122
|
-
|
123
|
-
def expected_html_for_asset_root_with(directories)
|
124
|
-
mock_asset_root_with(directories)
|
125
|
-
|
126
|
-
expected_html = @html.clone
|
127
|
-
if not directories.empty?
|
128
|
-
directories_regexp = directories.join('|')
|
129
|
-
expected_html.gsub!(/"(\/(#{directories_regexp})\/)/,
|
130
|
-
'"%s\1' % @asset_root_dir)
|
131
|
-
end
|
132
|
-
|
133
|
-
return expected_html
|
134
|
-
end
|
135
|
-
|
136
|
-
def test_with_directories(directories)
|
137
|
-
@temp_file.should_receive(:write) \
|
138
|
-
.with expected_html_for_asset_root_with(directories)
|
139
|
-
Capybara.save_page @html, 'page.html'
|
140
|
-
end
|
141
|
-
|
142
|
-
context "asset_root contains some directories" do
|
143
|
-
it "should rewrite relative paths to absolute local paths" do
|
144
|
-
test_with_directories([ 'javascripts', 'images' ])
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
context "asset_root path contains no directories" do
|
149
|
-
it "should not rewrite any relative paths" do
|
150
|
-
test_with_directories([ ])
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|
154
|
-
end
|
155
|
-
end
|