aslakhellesoy-webrat 0.3.2.1 → 0.3.2.2
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.txt +19 -3
- data/README.rdoc +6 -2
- data/Rakefile +43 -8
- data/lib/webrat/core/configuration.rb +16 -0
- data/lib/webrat/core/matchers/have_content.rb +14 -0
- data/lib/webrat/core/matchers/have_selector.rb +15 -0
- data/lib/webrat/core/matchers/have_tag.rb +14 -0
- data/lib/webrat/core/matchers/have_xpath.rb +10 -0
- data/lib/webrat/core/methods.rb +1 -0
- data/lib/webrat/core/session.rb +61 -32
- data/lib/webrat/mechanize.rb +33 -2
- data/lib/webrat/merb.rb +0 -12
- data/lib/webrat/rack.rb +0 -2
- data/lib/webrat/rails.rb +18 -28
- data/lib/webrat/selenium/matchers.rb +108 -0
- data/lib/webrat/selenium.rb +18 -32
- data/lib/webrat/sinatra.rb +13 -5
- data/lib/webrat.rb +1 -1
- metadata +4 -5
- data/lib/webrat/rails/redirect_actions.rb +0 -18
data/History.txt
CHANGED
@@ -6,9 +6,13 @@
|
|
6
6
|
* Removed auto-require of webrat/rails when requiring webrat when RAILS_ENV is
|
7
7
|
defined
|
8
8
|
|
9
|
-
In your env.rb file, ensure you have:
|
9
|
+
In your env.rb or test_helper.rb file, ensure you have something like:
|
10
10
|
|
11
|
-
require "webrat
|
11
|
+
require "webrat"
|
12
|
+
|
13
|
+
Webrat.configure do |config|
|
14
|
+
config.mode = :rails
|
15
|
+
end
|
12
16
|
|
13
17
|
* Major enhancements
|
14
18
|
|
@@ -16,8 +20,11 @@
|
|
16
20
|
* Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
|
17
21
|
|
18
22
|
* Minor enhancements
|
19
|
-
|
23
|
+
* Added assert_contain, assert_not_contain [#86] (Mike Gaffney, Amos King)
|
24
|
+
* Add configuration options for the Selenium environment and port (Kieran Pilkington)
|
25
|
+
* Maximize the browser window after initializing Selenium (Luke Melia)
|
20
26
|
* Better inspect output for Webrat elements
|
27
|
+
* Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
|
21
28
|
* Detect if the document is XML or HTML using the Content-Type when in Rails mode
|
22
29
|
* Expose #selenium method for direct access to Selenium client
|
23
30
|
* Check nokogiri gem version before requiring nokogiri
|
@@ -51,6 +58,8 @@
|
|
51
58
|
* Raise Webrat::PageLoadError when a failure occurs so that application exceptions
|
52
59
|
can be more accurately tested (Ryan Briones)
|
53
60
|
* Helpful error message for missing option in select box. [#40] (Ben Mabey)
|
61
|
+
* Extracted save_and_open page to make it usable in Selenium mode (Luke Melia)
|
62
|
+
* Added save_and_open_screengrab for Selenium mode (Luke Melia)
|
54
63
|
|
55
64
|
* Bug fixes
|
56
65
|
|
@@ -67,6 +76,13 @@
|
|
67
76
|
* Extend Rails' ActionController::IntegrationTest instead of
|
68
77
|
ActionController::Integration::Session (Fixes using Webrat's #select method and
|
69
78
|
avoids usage of method_missing)
|
79
|
+
* Ensure that Webrat::MechanizeSession.request_page always uses an absolute
|
80
|
+
URL. (Graham Ashton)
|
81
|
+
* Strip anchor tags from URIs before passing to Rails integration session
|
82
|
+
(Noah Davis)
|
83
|
+
* Treat text and regexp when matching Selenium buttons (Ross Kaffenberger)
|
84
|
+
* Allow SeleniumSession's click_button to be called without an argument without
|
85
|
+
blowing up (Luke Melia)
|
70
86
|
|
71
87
|
== 0.3.2 / 2008-11-08
|
72
88
|
|
data/README.rdoc
CHANGED
@@ -59,9 +59,13 @@ To install the latest code as a plugin: (_Note:_ This may be less stable than us
|
|
59
59
|
|
60
60
|
script/plugin install git://github.com/brynary/webrat.git
|
61
61
|
|
62
|
-
In your test_helper.rb
|
62
|
+
In your test_helper.rb or env.rb (for Cucumber) add:
|
63
63
|
|
64
|
-
require "webrat
|
64
|
+
require "webrat"
|
65
|
+
|
66
|
+
Webrat.configure do |config|
|
67
|
+
config.mode = :rails
|
68
|
+
end
|
65
69
|
|
66
70
|
== Install with Merb
|
67
71
|
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'rubygems'
|
1
|
+
# require 'rubygems'
|
2
2
|
require "rake/gempackagetask"
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
require "rake/clean"
|
@@ -28,8 +28,8 @@ spec = Gem::Specification.new do |s|
|
|
28
28
|
s.extra_rdoc_files = %w(README.rdoc MIT-LICENSE.txt)
|
29
29
|
|
30
30
|
# Dependencies
|
31
|
-
s.add_dependency "nokogiri", ">= 1.0
|
32
|
-
|
31
|
+
s.add_dependency "nokogiri", ">= 1.1.0"
|
32
|
+
|
33
33
|
s.rubyforge_project = "webrat"
|
34
34
|
end
|
35
35
|
|
@@ -52,13 +52,13 @@ end
|
|
52
52
|
desc "Run API and Core specs"
|
53
53
|
Spec::Rake::SpecTask.new do |t|
|
54
54
|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
55
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
55
|
+
t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
|
56
56
|
end
|
57
57
|
|
58
58
|
desc "Run all specs in spec directory with RCov"
|
59
59
|
Spec::Rake::SpecTask.new(:rcov) do |t|
|
60
60
|
t.spec_opts = ['--options', "\"#{File.dirname(__FILE__)}/spec/spec.opts\""]
|
61
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
61
|
+
t.spec_files = FileList['spec/public/**/*_spec.rb'] + FileList['spec/private/**/*_spec.rb']
|
62
62
|
t.rcov = true
|
63
63
|
t.rcov_opts = lambda do
|
64
64
|
IO.readlines(File.dirname(__FILE__) + "/spec/rcov.opts").map {|l| l.chomp.split " "}.flatten
|
@@ -71,8 +71,8 @@ end
|
|
71
71
|
|
72
72
|
desc 'Install the package as a gem.'
|
73
73
|
task :install_gem => [:clean, :package] do
|
74
|
-
|
75
|
-
sh "sudo gem install --local #{
|
74
|
+
gem_filename = Dir['pkg/*.gem'].first
|
75
|
+
sh "sudo gem install --local #{gem_filename}"
|
76
76
|
end
|
77
77
|
|
78
78
|
desc "Delete generated RDoc"
|
@@ -99,6 +99,41 @@ task :spec_deps do
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
+
task :prepare do
|
103
|
+
system "ln -s ../../../../.. ./spec/integration/rails/vendor/plugins/webrat"
|
104
|
+
end
|
105
|
+
|
106
|
+
namespace :spec do
|
107
|
+
desc "Run the integration specs"
|
108
|
+
task :integration => ["integration:rails", "integration:merb", "integration:sinatra"]
|
109
|
+
|
110
|
+
namespace :integration do
|
111
|
+
desc "Run the Rails integration specs"
|
112
|
+
task :rails do
|
113
|
+
Dir.chdir "spec/integration/rails" do
|
114
|
+
result = system "rake test:integration"
|
115
|
+
raise "Rails integration tests failed" unless result
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
desc "Run the Merb integration specs"
|
120
|
+
task :merb do
|
121
|
+
Dir.chdir "spec/integration/merb" do
|
122
|
+
result = system "rake spec"
|
123
|
+
raise "Merb integration tests failed" unless result
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
desc "Run the Sinatra integration specs"
|
128
|
+
task :sinatra do
|
129
|
+
Dir.chdir "spec/integration/sinatra" do
|
130
|
+
result = system "rake test"
|
131
|
+
raise "Sinatra tntegration tests failed" unless result
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
102
137
|
task :default => :spec
|
103
138
|
|
104
|
-
task :precommit => ["spec", "spec:jruby"]
|
139
|
+
task :precommit => ["spec", "spec:jruby", "spec:integration"]
|
@@ -17,6 +17,7 @@ module Webrat
|
|
17
17
|
# config.parse_with_nokogiri = false
|
18
18
|
# end
|
19
19
|
class Configuration
|
20
|
+
|
20
21
|
# Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
|
21
22
|
attr_writer :parse_with_nokogiri
|
22
23
|
|
@@ -26,9 +27,17 @@ module Webrat
|
|
26
27
|
# Save and open pages with error status codes (500-599) in a browser? Defualts to true.
|
27
28
|
attr_writer :open_error_files
|
28
29
|
|
30
|
+
# Which environment should the selenium tests be run in? Defaults to selenium.
|
31
|
+
attr_accessor :selenium_environment
|
32
|
+
|
33
|
+
# Which port should the selenium tests be run on? Defaults to 3001.
|
34
|
+
attr_accessor :selenium_port
|
35
|
+
|
29
36
|
def initialize # :nodoc:
|
30
37
|
self.open_error_files = true
|
31
38
|
self.parse_with_nokogiri = !Webrat.on_java?
|
39
|
+
self.selenium_environment = :selenium
|
40
|
+
self.selenium_port = 3001
|
32
41
|
end
|
33
42
|
|
34
43
|
def parse_with_nokogiri? #:nodoc:
|
@@ -39,6 +48,13 @@ module Webrat
|
|
39
48
|
@open_error_files ? true : false
|
40
49
|
end
|
41
50
|
|
51
|
+
# Allows setting of webrat's mode, valid modes are:
|
52
|
+
# :rails, :selenium, :rack, :sinatra, :mechanize, :merb
|
53
|
+
def mode=(mode)
|
54
|
+
@mode = mode
|
55
|
+
require("webrat/#{mode}")
|
56
|
+
end
|
57
|
+
|
42
58
|
end
|
43
59
|
|
44
60
|
end
|
@@ -51,5 +51,19 @@ module Webrat
|
|
51
51
|
HasContent.new(content)
|
52
52
|
end
|
53
53
|
|
54
|
+
# Asserts that the body of the response contain
|
55
|
+
# the supplied string or regexp
|
56
|
+
def assert_contain(content)
|
57
|
+
hc = HasContent.new(content)
|
58
|
+
raise Test::Unit::AssertionFailedError.new(hc.failure_message) unless hc.matches?(response_body)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Asserts that the body of the response
|
62
|
+
# does not contain the supplied string or regepx
|
63
|
+
def assert_not_contain(content)
|
64
|
+
hc = HasContent.new(content)
|
65
|
+
raise Test::Unit::AssertionFailedError.new(hc.negative_failure_message) if hc.matches?(response_body)
|
66
|
+
end
|
67
|
+
|
54
68
|
end
|
55
69
|
end
|
@@ -33,5 +33,20 @@ module Webrat
|
|
33
33
|
end
|
34
34
|
alias_method :match_selector, :have_selector
|
35
35
|
|
36
|
+
|
37
|
+
# Asserts that the body of the response contains
|
38
|
+
# the supplied selector
|
39
|
+
def assert_have_selector(expected)
|
40
|
+
hs = HaveSelector.new(expected)
|
41
|
+
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Asserts that the body of the response
|
45
|
+
# does not contain the supplied string or regepx
|
46
|
+
def assert_have_no_selector(expected)
|
47
|
+
hs = HaveSelector.new(expected)
|
48
|
+
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
|
49
|
+
end
|
50
|
+
|
36
51
|
end
|
37
52
|
end
|
@@ -52,6 +52,20 @@ module Webrat
|
|
52
52
|
end
|
53
53
|
|
54
54
|
alias_method :match_tag, :have_tag
|
55
|
+
|
56
|
+
# Asserts that the body of the response contains
|
57
|
+
# the supplied tag with the associated selectors
|
58
|
+
def assert_have_tag(name, attributes = {})
|
59
|
+
ht = HaveTag.new([name, attributes])
|
60
|
+
raise Test::Unit::AssertionFailedError.new(ht.failure_message) unless ht.matches?(response_body)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Asserts that the body of the response
|
64
|
+
# does not contain the supplied string or regepx
|
65
|
+
def assert_have_no_tag(name, attributes = {})
|
66
|
+
ht = HaveTag.new([name, attributes])
|
67
|
+
raise Test::Unit::AssertionFailedError.new(ht.negative_failure_message) if ht.matches?(response_body)
|
68
|
+
end
|
55
69
|
|
56
70
|
end
|
57
71
|
end
|
@@ -79,5 +79,15 @@ module Webrat
|
|
79
79
|
end
|
80
80
|
alias_method :match_xpath, :have_xpath
|
81
81
|
|
82
|
+
def assert_have_xpath(expected, &block)
|
83
|
+
hs = HaveXpath.new(expected, &block)
|
84
|
+
raise Test::Unit::AssertionFailedError.new(hs.failure_message) unless hs.matches?(response_body)
|
85
|
+
end
|
86
|
+
|
87
|
+
def assert_have_no_xpath(expected, &block)
|
88
|
+
hs = HaveXpath.new(expected, &block)
|
89
|
+
raise Test::Unit::AssertionFailedError.new(hs.negative_failure_message) if hs.matches?(response_body)
|
90
|
+
end
|
91
|
+
|
82
92
|
end
|
83
93
|
end
|
data/lib/webrat/core/methods.rb
CHANGED
data/lib/webrat/core/session.rb
CHANGED
@@ -8,7 +8,7 @@ module Webrat
|
|
8
8
|
# A page load or form submission returned an unsuccessful response code (500-599)
|
9
9
|
class PageLoadError < WebratError
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
def self.session_class
|
13
13
|
case Webrat.configuration.mode
|
14
14
|
when :rails
|
@@ -24,32 +24,41 @@ module Webrat
|
|
24
24
|
when :mechanize
|
25
25
|
MechanizeSession
|
26
26
|
else
|
27
|
-
raise WebratError.new(
|
27
|
+
raise WebratError.new(<<-STR)
|
28
|
+
Unknown Webrat mode: #{Webrat.configuration.mode.inspect}
|
29
|
+
|
30
|
+
Please ensure you have a Webrat configuration block that specifies a mode
|
31
|
+
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).
|
32
|
+
For example:
|
33
|
+
|
34
|
+
Webrat.configure do |config|
|
35
|
+
config.mode = :rails
|
36
|
+
end
|
37
|
+
STR
|
28
38
|
end
|
29
39
|
end
|
30
|
-
|
40
|
+
|
31
41
|
class Session
|
32
42
|
extend Forwardable
|
33
43
|
include Logging
|
34
44
|
include SaveAndOpenPage
|
35
|
-
|
36
45
|
attr_reader :current_url
|
37
46
|
attr_reader :elements
|
38
|
-
|
47
|
+
|
39
48
|
def initialize(context = nil) #:nodoc:
|
40
49
|
@http_method = :get
|
41
50
|
@data = {}
|
42
51
|
@default_headers = {}
|
43
52
|
@custom_headers = {}
|
44
53
|
@context = context
|
45
|
-
|
54
|
+
|
46
55
|
reset
|
47
56
|
end
|
48
|
-
|
57
|
+
|
49
58
|
def current_dom #:nodoc:
|
50
59
|
current_scope.dom
|
51
60
|
end
|
52
|
-
|
61
|
+
|
53
62
|
# For backwards compatibility -- removing in 1.0
|
54
63
|
def current_page #:nodoc:
|
55
64
|
page = OpenStruct.new
|
@@ -58,7 +67,7 @@ module Webrat
|
|
58
67
|
page.data = @data
|
59
68
|
page
|
60
69
|
end
|
61
|
-
|
70
|
+
|
62
71
|
def doc_root #:nodoc:
|
63
72
|
nil
|
64
73
|
end
|
@@ -70,7 +79,7 @@ module Webrat
|
|
70
79
|
def http_accept(mime_type)
|
71
80
|
header('Accept', Webrat::MIME.mime_type(mime_type))
|
72
81
|
end
|
73
|
-
|
82
|
+
|
74
83
|
def basic_auth(user, pass)
|
75
84
|
encoded_login = ["#{user}:#{pass}"].pack("m*")
|
76
85
|
header('HTTP_AUTHORIZATION', "Basic #{encoded_login}")
|
@@ -93,28 +102,38 @@ module Webrat
|
|
93
102
|
|
94
103
|
save_and_open_page if exception_caught? && Webrat.configuration.open_error_files?
|
95
104
|
raise PageLoadError.new("Page load was not successful (Code: #{response_code.inspect}):\n#{formatted_error}") unless success_code?
|
96
|
-
|
105
|
+
|
97
106
|
reset
|
98
|
-
|
107
|
+
|
99
108
|
@current_url = url
|
100
109
|
@http_method = http_method
|
101
110
|
@data = data
|
102
|
-
|
111
|
+
|
112
|
+
request_page(response_location, :get, data) if internal_redirect?
|
113
|
+
|
103
114
|
return response
|
104
115
|
end
|
105
|
-
|
116
|
+
|
106
117
|
def success_code? #:nodoc:
|
107
118
|
(200..499).include?(response_code)
|
108
119
|
end
|
109
|
-
|
120
|
+
|
121
|
+
def redirect? #:nodoc:
|
122
|
+
response_code / 100 == 3
|
123
|
+
end
|
124
|
+
|
125
|
+
def internal_redirect? #:nodoc:
|
126
|
+
redirect? && current_host == response_location_host
|
127
|
+
end
|
128
|
+
|
110
129
|
def exception_caught? #:nodoc:
|
111
130
|
response_body =~ /Exception caught/
|
112
131
|
end
|
113
|
-
|
132
|
+
|
114
133
|
def current_scope #:nodoc:
|
115
134
|
scopes.last || page_scope
|
116
135
|
end
|
117
|
-
|
136
|
+
|
118
137
|
# Reloads the last page requested. Note that this will resubmit forms
|
119
138
|
# and their data.
|
120
139
|
def reloads
|
@@ -122,10 +141,10 @@ module Webrat
|
|
122
141
|
end
|
123
142
|
|
124
143
|
webrat_deprecate :reload, :reloads
|
125
|
-
|
126
|
-
|
144
|
+
|
145
|
+
|
127
146
|
# Works like click_link, but only looks for the link text within a given selector
|
128
|
-
#
|
147
|
+
#
|
129
148
|
# Example:
|
130
149
|
# click_link_within "#user_12", "Vote"
|
131
150
|
def click_link_within(selector, link_text)
|
@@ -135,14 +154,14 @@ module Webrat
|
|
135
154
|
end
|
136
155
|
|
137
156
|
webrat_deprecate :clicks_link_within, :click_link_within
|
138
|
-
|
157
|
+
|
139
158
|
def within(selector)
|
140
159
|
scopes.push(Scope.from_scope(self, current_scope, selector))
|
141
160
|
ret = yield(current_scope)
|
142
161
|
scopes.pop
|
143
162
|
return ret
|
144
163
|
end
|
145
|
-
|
164
|
+
|
146
165
|
# Issues a GET request for a page, follows any redirects, and verifies the final page
|
147
166
|
# load was successful.
|
148
167
|
#
|
@@ -151,7 +170,7 @@ module Webrat
|
|
151
170
|
def visit(url = nil, http_method = :get, data = {})
|
152
171
|
request_page(url, http_method, data)
|
153
172
|
end
|
154
|
-
|
173
|
+
|
155
174
|
webrat_deprecate :visits, :visit
|
156
175
|
|
157
176
|
# Subclasses can override this to show error messages without html
|
@@ -166,25 +185,25 @@ module Webrat
|
|
166
185
|
def page_scope #:nodoc:
|
167
186
|
@_page_scope ||= Scope.from_page(self, response, response_body)
|
168
187
|
end
|
169
|
-
|
188
|
+
|
170
189
|
def dom
|
171
190
|
page_scope.dom
|
172
191
|
end
|
173
|
-
|
192
|
+
|
174
193
|
def xml_content_type?
|
175
194
|
false
|
176
195
|
end
|
177
|
-
|
196
|
+
|
178
197
|
def simulate
|
179
198
|
return if Webrat.configuration.mode == :selenium
|
180
199
|
yield
|
181
200
|
end
|
182
|
-
|
201
|
+
|
183
202
|
def automate
|
184
203
|
return unless Webrat.configuration.mode == :selenium
|
185
204
|
yield
|
186
205
|
end
|
187
|
-
|
206
|
+
|
188
207
|
def_delegators :current_scope, :fill_in, :fills_in
|
189
208
|
def_delegators :current_scope, :set_hidden_field
|
190
209
|
def_delegators :current_scope, :submit_form
|
@@ -199,15 +218,25 @@ module Webrat
|
|
199
218
|
def_delegators :current_scope, :click_area, :clicks_area
|
200
219
|
def_delegators :current_scope, :click_link, :clicks_link
|
201
220
|
def_delegators :current_scope, :click_button, :clicks_button
|
202
|
-
def_delegators :current_scope, :should_see
|
203
|
-
def_delegators :current_scope, :should_not_see
|
204
221
|
def_delegators :current_scope, :field_labeled
|
205
222
|
def_delegators :current_scope, :field_by_xpath
|
206
223
|
def_delegators :current_scope, :field_with_id
|
207
224
|
def_delegators :current_scope, :select_option
|
208
|
-
|
225
|
+
|
209
226
|
private
|
210
|
-
|
227
|
+
|
228
|
+
def response_location
|
229
|
+
response.headers["Location"]
|
230
|
+
end
|
231
|
+
|
232
|
+
def current_host
|
233
|
+
URI.parse(current_url).host || "www.example.com"
|
234
|
+
end
|
235
|
+
|
236
|
+
def response_location_host
|
237
|
+
URI.parse(response_location).host || "www.example.com"
|
238
|
+
end
|
239
|
+
|
211
240
|
def reset
|
212
241
|
@elements = {}
|
213
242
|
@_scopes = nil
|
data/lib/webrat/mechanize.rb
CHANGED
@@ -6,6 +6,10 @@ module Webrat #:nodoc:
|
|
6
6
|
attr_accessor :response
|
7
7
|
alias :page :response
|
8
8
|
|
9
|
+
def request_page(url, http_method, data) #:nodoc:
|
10
|
+
super(absolute_url(url), http_method, data)
|
11
|
+
end
|
12
|
+
|
9
13
|
def get(url, data, headers_argument_not_used = nil)
|
10
14
|
@response = mechanize.get(url, data)
|
11
15
|
end
|
@@ -36,8 +40,35 @@ module Webrat #:nodoc:
|
|
36
40
|
end
|
37
41
|
|
38
42
|
def_delegators :mechanize, :basic_auth
|
43
|
+
|
44
|
+
def absolute_url(url) #:nodoc:
|
45
|
+
current_host, current_path = split_current_url
|
46
|
+
if url =~ Regexp.new('^https?://')
|
47
|
+
url
|
48
|
+
elsif url =~ Regexp.new('^/')
|
49
|
+
current_host + url
|
50
|
+
elsif url =~ Regexp.new('^\.')
|
51
|
+
current_host + absolute_path(current_path, url)
|
52
|
+
else
|
53
|
+
url
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
def split_current_url
|
59
|
+
current_url =~ Regexp.new('^(https?://[^/]+)(/.*)?')
|
60
|
+
[Regexp.last_match(1), Regexp.last_match(2)]
|
61
|
+
end
|
39
62
|
|
63
|
+
def absolute_path(current_path, url)
|
64
|
+
levels_up = url.split('/').find_all { |x| x == '..' }.size
|
65
|
+
ancestor = if current_path.nil?
|
66
|
+
""
|
67
|
+
else
|
68
|
+
current_path.split("/")[0..(-1 - levels_up)].join("/")
|
69
|
+
end
|
70
|
+
descendent = url.split("/")[levels_up..-1]
|
71
|
+
"#{ancestor}/#{descendent}"
|
72
|
+
end
|
40
73
|
end
|
41
74
|
end
|
42
|
-
|
43
|
-
Webrat.configuration.mode = :mechanize
|
data/lib/webrat/merb.rb
CHANGED
@@ -42,11 +42,6 @@ module Webrat
|
|
42
42
|
:params => (data && data.any?) ? data : nil,
|
43
43
|
:headers => headers,
|
44
44
|
:method => method)
|
45
|
-
follow_redirect
|
46
|
-
end
|
47
|
-
|
48
|
-
def follow_redirect
|
49
|
-
self.get(@response.headers['Location'], nil, @response.headers) if @response.status == 302
|
50
45
|
end
|
51
46
|
|
52
47
|
end
|
@@ -59,10 +54,6 @@ module Merb #:nodoc:
|
|
59
54
|
@_webrat_session ||= Webrat::MerbSession.new
|
60
55
|
@_webrat_session.response = @_webrat_session.request(uri, env)
|
61
56
|
end
|
62
|
-
|
63
|
-
def follow_redirect
|
64
|
-
@_webrat_session.follow_redirect
|
65
|
-
end
|
66
57
|
end
|
67
58
|
end
|
68
59
|
end
|
@@ -72,6 +63,3 @@ class Merb::Test::RspecStory #:nodoc:
|
|
72
63
|
@browser ||= Webrat::MerbSession.new
|
73
64
|
end
|
74
65
|
end
|
75
|
-
|
76
|
-
Webrat.configuration.mode = :merb
|
77
|
-
|
data/lib/webrat/rack.rb
CHANGED
data/lib/webrat/rails.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require "webrat"
|
2
|
+
|
3
|
+
require "action_controller"
|
2
4
|
require "action_controller/integration"
|
3
5
|
|
4
6
|
module Webrat
|
@@ -7,51 +9,50 @@ module Webrat
|
|
7
9
|
def doc_root
|
8
10
|
File.expand_path(File.join(RAILS_ROOT, 'public'))
|
9
11
|
end
|
10
|
-
|
12
|
+
|
11
13
|
def saved_page_dir
|
12
14
|
File.expand_path(File.join(RAILS_ROOT, "tmp"))
|
13
15
|
end
|
14
|
-
|
16
|
+
|
15
17
|
def get(url, data, headers = nil)
|
16
18
|
do_request(:get, url, data, headers)
|
17
19
|
end
|
18
|
-
|
20
|
+
|
19
21
|
def post(url, data, headers = nil)
|
20
22
|
do_request(:post, url, data, headers)
|
21
23
|
end
|
22
|
-
|
24
|
+
|
23
25
|
def put(url, data, headers = nil)
|
24
26
|
do_request(:put, url, data, headers)
|
25
27
|
end
|
26
|
-
|
28
|
+
|
27
29
|
def delete(url, data, headers = nil)
|
28
30
|
do_request(:delete, url, data, headers)
|
29
31
|
end
|
30
|
-
|
32
|
+
|
31
33
|
def response_body
|
32
34
|
response.body
|
33
35
|
end
|
34
|
-
|
36
|
+
|
35
37
|
def response_code
|
36
38
|
response.code.to_i
|
37
39
|
end
|
38
|
-
|
40
|
+
|
39
41
|
def xml_content_type?
|
40
42
|
response.headers["Content-Type"].to_s =~ /xml/
|
41
43
|
end
|
42
|
-
|
44
|
+
|
43
45
|
protected
|
44
|
-
|
46
|
+
|
45
47
|
def integration_session
|
46
48
|
@context
|
47
49
|
end
|
48
|
-
|
50
|
+
|
49
51
|
def do_request(http_method, url, data, headers) #:nodoc:
|
50
52
|
update_protocol(url)
|
51
|
-
|
52
|
-
integration_session.request_via_redirect(http_method, url, data, headers)
|
53
|
+
integration_session.send(http_method, normalize_url(url), data, headers)
|
53
54
|
end
|
54
|
-
|
55
|
+
|
55
56
|
# remove protocol, host and anchor
|
56
57
|
def normalize_url(href) #:nodoc:
|
57
58
|
uri = URI.parse(href)
|
@@ -61,7 +62,7 @@ module Webrat
|
|
61
62
|
end
|
62
63
|
normalized_url
|
63
64
|
end
|
64
|
-
|
65
|
+
|
65
66
|
def update_protocol(href) #:nodoc:
|
66
67
|
if href =~ /^https:/
|
67
68
|
integration_session.https!(true)
|
@@ -69,28 +70,17 @@ module Webrat
|
|
69
70
|
integration_session.https!(false)
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
|
+
|
73
74
|
def response #:nodoc:
|
74
75
|
integration_session.response
|
75
76
|
end
|
76
|
-
|
77
|
+
|
77
78
|
end
|
78
79
|
end
|
79
80
|
|
80
81
|
module ActionController #:nodoc:
|
81
|
-
module Integration #:nodoc:
|
82
|
-
Session.class_eval do
|
83
|
-
unless instance_methods.include?("put_via_redirect")
|
84
|
-
require "webrat/rails/redirect_actions"
|
85
|
-
include Webrat::RedirectActions
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
82
|
IntegrationTest.class_eval do
|
91
83
|
include Webrat::Methods
|
92
84
|
include Webrat::Matchers
|
93
85
|
end
|
94
86
|
end
|
95
|
-
|
96
|
-
Webrat.configuration.mode = :rails
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module Webrat
|
2
|
+
module Selenium
|
3
|
+
module Matchers
|
4
|
+
|
5
|
+
class HaveXpath
|
6
|
+
def initialize(expected)
|
7
|
+
@expected = expected
|
8
|
+
end
|
9
|
+
|
10
|
+
def matches?(response)
|
11
|
+
response.session.wait_for do
|
12
|
+
response.selenium.is_element_present("xpath=#{@expected}")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# ==== Returns
|
17
|
+
# String:: The failure message.
|
18
|
+
def failure_message
|
19
|
+
"expected following text to match xpath #{@expected}:\n#{@document}"
|
20
|
+
end
|
21
|
+
|
22
|
+
# ==== Returns
|
23
|
+
# String:: The failure message to be displayed in negative matches.
|
24
|
+
def negative_failure_message
|
25
|
+
"expected following text to not match xpath #{@expected}:\n#{@document}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def have_xpath(xpath)
|
30
|
+
HaveXpath.new(xpath)
|
31
|
+
end
|
32
|
+
|
33
|
+
class HaveSelector
|
34
|
+
def initialize(expected)
|
35
|
+
@expected = expected
|
36
|
+
end
|
37
|
+
|
38
|
+
def matches?(response)
|
39
|
+
response.session.wait_for do
|
40
|
+
response.selenium.is_element_present("css=#{@expected}")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# ==== Returns
|
45
|
+
# String:: The failure message.
|
46
|
+
def failure_message
|
47
|
+
"expected following text to match selector #{@expected}:\n#{@document}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# ==== Returns
|
51
|
+
# String:: The failure message to be displayed in negative matches.
|
52
|
+
def negative_failure_message
|
53
|
+
"expected following text to not match selector #{@expected}:\n#{@document}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def have_selector(content)
|
58
|
+
HaveSelector.new(content)
|
59
|
+
end
|
60
|
+
|
61
|
+
class HasContent #:nodoc:
|
62
|
+
def initialize(content)
|
63
|
+
@content = content
|
64
|
+
end
|
65
|
+
|
66
|
+
def matches?(response)
|
67
|
+
if @content.is_a?(Regexp)
|
68
|
+
text_finder = "regexp:#{@content.source}"
|
69
|
+
else
|
70
|
+
text_finder = @content
|
71
|
+
end
|
72
|
+
|
73
|
+
response.session.wait_for do
|
74
|
+
response.selenium.is_text_present(text_finder)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# ==== Returns
|
79
|
+
# String:: The failure message.
|
80
|
+
def failure_message
|
81
|
+
"expected the following element's content to #{content_message}:\n#{@element}"
|
82
|
+
end
|
83
|
+
|
84
|
+
# ==== Returns
|
85
|
+
# String:: The failure message to be displayed in negative matches.
|
86
|
+
def negative_failure_message
|
87
|
+
"expected the following element's content to not #{content_message}:\n#{@element}"
|
88
|
+
end
|
89
|
+
|
90
|
+
def content_message
|
91
|
+
case @content
|
92
|
+
when String
|
93
|
+
"include \"#{@content}\""
|
94
|
+
when Regexp
|
95
|
+
"match #{@content.inspect}"
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# Matches the contents of an HTML document with
|
101
|
+
# whatever string is supplied
|
102
|
+
def contain(content)
|
103
|
+
HasContent.new(content)
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
data/lib/webrat/selenium.rb
CHANGED
@@ -4,8 +4,6 @@ require "selenium/client"
|
|
4
4
|
require "webrat/selenium/selenium_session"
|
5
5
|
require "webrat/selenium/matchers"
|
6
6
|
|
7
|
-
Webrat.configuration.mode = :selenium
|
8
|
-
|
9
7
|
module Webrat
|
10
8
|
|
11
9
|
def self.with_selenium_server #:nodoc:
|
@@ -28,8 +26,8 @@ module Webrat
|
|
28
26
|
|
29
27
|
def self.start_app_server #:nodoc:
|
30
28
|
pid_file = File.expand_path(RAILS_ROOT + "/tmp/pids/mongrel_selenium.pid")
|
31
|
-
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port
|
32
|
-
TCPSocket.wait_for_service :host => "0.0.0.0", :port =>
|
29
|
+
system("mongrel_rails start -d --chdir=#{RAILS_ROOT} --port=#{Webrat.configuration.selenium_port} --environment=#{Webrat.configuration.selenium_environment} --pid #{pid_file} &")
|
30
|
+
TCPSocket.wait_for_service :host => "0.0.0.0", :port => Webrat.configuration.selenium_port.to_i
|
33
31
|
end
|
34
32
|
|
35
33
|
def self.stop_app_server #:nodoc:
|
@@ -40,14 +38,10 @@ module Webrat
|
|
40
38
|
# To use Webrat's Selenium support, you'll need the selenium-client gem installed.
|
41
39
|
# Activate it with (for example, in your <tt>env.rb</tt>):
|
42
40
|
#
|
43
|
-
# require "webrat
|
44
|
-
#
|
45
|
-
#
|
46
|
-
#
|
47
|
-
# the following to <tt>env.rb</tt>:
|
48
|
-
#
|
49
|
-
# World do
|
50
|
-
# Webrat::Selenium::Rails::World.new
|
41
|
+
# require "webrat"
|
42
|
+
#
|
43
|
+
# Webrat.configure do |config|
|
44
|
+
# config.mode = :selenium
|
51
45
|
# end
|
52
46
|
#
|
53
47
|
# == Dropping down to the selenium-client API
|
@@ -74,34 +68,26 @@ module Webrat
|
|
74
68
|
# your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
|
75
69
|
# testing, so long as you're using the Webrat API.
|
76
70
|
module Selenium
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
def response
|
87
|
-
webrat_session.response
|
88
|
-
end
|
89
|
-
|
90
|
-
def wait_for(*args, &block)
|
91
|
-
webrat_session.wait_for(*args, &block)
|
92
|
-
end
|
71
|
+
module Methods
|
72
|
+
def response
|
73
|
+
webrat_session.response
|
74
|
+
end
|
75
|
+
|
76
|
+
def wait_for(*args, &block)
|
77
|
+
webrat_session.wait_for(*args, &block)
|
78
|
+
end
|
93
79
|
|
94
|
-
|
95
|
-
|
96
|
-
end
|
80
|
+
def save_and_open_screengrab
|
81
|
+
webrat_session.save_and_open_screengrab
|
97
82
|
end
|
98
83
|
end
|
99
84
|
end
|
100
|
-
|
101
85
|
end
|
102
86
|
|
103
87
|
module ActionController #:nodoc:
|
104
88
|
IntegrationTest.class_eval do
|
105
89
|
include Webrat::Methods
|
90
|
+
include Webrat::Selenium::Methods
|
91
|
+
include Webrat::Selenium::Matchers
|
106
92
|
end
|
107
93
|
end
|
data/lib/webrat/sinatra.rb
CHANGED
@@ -2,20 +2,28 @@ require 'webrat/rack'
|
|
2
2
|
require 'sinatra'
|
3
3
|
require 'sinatra/test/methods'
|
4
4
|
|
5
|
+
class Sinatra::Application
|
6
|
+
# Override this to prevent Sinatra from barfing on the options passed from RSpec
|
7
|
+
def self.load_default_options_from_command_line!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
disable :run
|
12
|
+
disable :reload
|
13
|
+
|
5
14
|
module Webrat
|
6
15
|
class SinatraSession < RackSession #:nodoc:
|
7
16
|
include Sinatra::Test::Methods
|
8
17
|
|
18
|
+
attr_reader :request, :response
|
19
|
+
|
9
20
|
%w(get head post put delete).each do |verb|
|
10
21
|
define_method(verb) do |*args| # (path, data, headers = nil)
|
11
22
|
path, data, headers = *args
|
12
|
-
|
23
|
+
data = data.inject({}) {|data, (key,value)| data[key] = Rack::Utils.unescape(value); data }
|
24
|
+
params = data.merge(:env => headers || {})
|
13
25
|
self.__send__("#{verb}_it", path, params)
|
14
|
-
follow! while @response.redirect?
|
15
26
|
end
|
16
27
|
end
|
17
|
-
|
18
28
|
end
|
19
29
|
end
|
20
|
-
|
21
|
-
Webrat.configuration.mode = :sinatra
|
data/lib/webrat.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aslakhellesoy-webrat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.2.
|
4
|
+
version: 0.3.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bryan Helmkamp
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-12-
|
12
|
+
date: 2008-12-29 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,7 +19,7 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 1.0
|
22
|
+
version: 1.1.0
|
23
23
|
version:
|
24
24
|
description: Webrat. Ruby Acceptance Testing for Web applications
|
25
25
|
email: bryan@brynary.com
|
@@ -88,8 +88,6 @@ files:
|
|
88
88
|
- lib/webrat/mechanize.rb
|
89
89
|
- lib/webrat/merb.rb
|
90
90
|
- lib/webrat/rack.rb
|
91
|
-
- lib/webrat/rails
|
92
|
-
- lib/webrat/rails/redirect_actions.rb
|
93
91
|
- lib/webrat/rails.rb
|
94
92
|
- lib/webrat/rspec-rails.rb
|
95
93
|
- lib/webrat/selenium
|
@@ -100,6 +98,7 @@ files:
|
|
100
98
|
- lib/webrat/selenium/location_strategy_javascript/webratlink.js
|
101
99
|
- lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js
|
102
100
|
- lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js
|
101
|
+
- lib/webrat/selenium/matchers.rb
|
103
102
|
- lib/webrat/selenium/selenium_extensions.js
|
104
103
|
- lib/webrat/selenium/selenium_session.rb
|
105
104
|
- lib/webrat/selenium.rb
|
@@ -1,18 +0,0 @@
|
|
1
|
-
# For Rails before http://dev.rubyonrails.org/ticket/10497 was committed
|
2
|
-
module Webrat
|
3
|
-
module RedirectActions #:nodoc:
|
4
|
-
|
5
|
-
def put_via_redirect(path, parameters = {}, headers = {})
|
6
|
-
put path, parameters, headers
|
7
|
-
follow_redirect! while redirect?
|
8
|
-
status
|
9
|
-
end
|
10
|
-
|
11
|
-
def delete_via_redirect(path, parameters = {}, headers = {})
|
12
|
-
delete path, parameters, headers
|
13
|
-
follow_redirect! while redirect?
|
14
|
-
status
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|