Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

updated from master

  • Loading branch information...
commit 449edf4a10578844792ddd62919187a291d25065 1 parent fbcd509
Mike Gaffney authored December 27, 2008
1  .gitignore
@@ -10,3 +10,4 @@ log
10 10
 .loadpath
11 11
 *.swp
12 12
 results
  13
+test_apps
22  History.txt
@@ -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/rails"
  11
+    require "webrat"
  12
+    
  13
+    Webrat.configure do |config|
  14
+      config.mode = :rails
  15
+    end
12 16
   
13 17
 * Major enhancements
14 18
 
@@ -16,7 +20,10 @@
16 20
   * Use Hpricot and REXML when not parsing with Nokogiri (on JRuby, for example)
17 21
 
18 22
 * Minor enhancements
19  
-  * Now sets the mode with configuration.mode in the block (Mike Gaffney, Ticket #85)
  23
+  * Added assert_contain, assert_not_contain [#86] (Mike Gaffney)
  24
+  * Maximize the browser window after initializing Selenium (Luke Melia)
  25
+  * Better inspect output for Webrat elements
  26
+  * Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
20 27
   * Detect if the document is XML or HTML using the Content-Type when in Rails mode
21 28
   * Expose #selenium method for direct access to Selenium client
22 29
   * Check nokogiri gem version before requiring nokogiri
@@ -50,6 +57,8 @@
50 57
   * Raise Webrat::PageLoadError when a failure occurs so that application exceptions
51 58
     can be more accurately tested (Ryan Briones)
52 59
   * Helpful error message for missing option in select box. [#40] (Ben Mabey)
  60
+  * Extracted save_and_open page to make it usable in Selenium mode (Luke Melia)
  61
+  * Added save_and_open_screengrab for Selenium mode (Luke Melia)
53 62
 
54 63
 * Bug fixes
55 64
   
@@ -66,6 +75,13 @@
66 75
   * Extend Rails' ActionController::IntegrationTest instead of
67 76
     ActionController::Integration::Session (Fixes using Webrat's #select method and 
68 77
     avoids usage of method_missing)
  78
+  * Ensure that Webrat::MechanizeSession.request_page always uses an absolute 
  79
+    URL. (Graham Ashton)
  80
+  * Strip anchor tags from URIs before passing to Rails integration session
  81
+    (Noah Davis)
  82
+  * Treat text and regexp when matching Selenium buttons (Ross Kaffenberger)
  83
+  * Allow SeleniumSession's click_button to be called without an argument without
  84
+    blowing up (Luke Melia)
69 85
     
70 86
 == 0.3.2 / 2008-11-08
71 87
 
5  README.rdoc
Source Rendered
@@ -59,11 +59,12 @@ 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, spec_helper.rb, or env.rb (for Cucumber) add:
  62
+In your test_helper.rb or env.rb (for Cucumber) add:
63 63
 
64 64
   require "webrat"
  65
+  
65 66
   Webrat.configure do |config|
66  
-    config.mode = Webrat::Configuration::RAILS_MODE
  67
+    config.mode = :rails
67 68
   end
68 69
   
69 70
 == Install with Merb
2  lib/webrat.rb
@@ -7,7 +7,7 @@ module Webrat
7 7
   class WebratError < StandardError
8 8
   end
9 9
 
10  
-  VERSION = '0.3.2.1'
  10
+  VERSION = '0.3.2.2'
11 11
 
12 12
   def self.require_xml
13 13
     gem "nokogiri", ">= 1.0.6"
1  lib/webrat/core.rb
@@ -11,3 +11,4 @@
11 11
 require "webrat/core/session"
12 12
 require "webrat/core/methods"
13 13
 require "webrat/core/matchers"
  14
+require "webrat/core/save_and_open_page"
4  lib/webrat/core/elements/element.rb
@@ -24,6 +24,10 @@ def path
24 24
       Webrat::XML.xpath_to(@element)
25 25
     end
26 26
     
  27
+    def inspect
  28
+      "#<#{self.class} @element=#{element.inspect}>"
  29
+    end
  30
+    
27 31
   end
28 32
   
29 33
 end
50  lib/webrat/core/save_and_open_page.rb
... ...
@@ -0,0 +1,50 @@
  1
+module Webrat
  2
+  module SaveAndOpenPage
  3
+    # Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
  4
+    # web browser if on OS X. Useful for debugging.
  5
+    # 
  6
+    # Example:
  7
+    #   save_and_open_page
  8
+    def save_and_open_page
  9
+      return unless File.exist?(saved_page_dir)
  10
+
  11
+      filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
  12
+      
  13
+      File.open(filename, "w") do |f|
  14
+        f.write rewrite_css_and_image_references(response_body)
  15
+      end
  16
+
  17
+      open_in_browser(filename)
  18
+    end
  19
+    
  20
+    def open_in_browser(path) # :nodoc
  21
+      platform = ruby_platform
  22
+      if platform =~ /cygwin/ || platform =~ /win32/
  23
+        `rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
  24
+      elsif platform =~ /darwin/
  25
+        `open #{path}`
  26
+      end
  27
+    end
  28
+    
  29
+    def rewrite_css_and_image_references(response_html) # :nodoc:
  30
+      return response_html unless doc_root
  31
+      response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
  32
+    end
  33
+    
  34
+    def saved_page_dir #:nodoc:
  35
+      File.expand_path(".")
  36
+    end
  37
+    
  38
+    def doc_root #:nodoc:
  39
+      nil
  40
+    end
  41
+  
  42
+  private
  43
+
  44
+    # accessor for testing
  45
+    def ruby_platform
  46
+      RUBY_PLATFORM
  47
+    end
  48
+    
  49
+  end
  50
+end
41  lib/webrat/core/session.rb
@@ -2,6 +2,7 @@
2 2
 require "ostruct"
3 3
 
4 4
 require "webrat/core/mime"
  5
+require "webrat/core/save_and_open_page"
5 6
 
6 7
 module Webrat
7 8
   # A page load or form submission returned an unsuccessful response code (500-599)
@@ -30,6 +31,7 @@ def self.session_class
30 31
   class Session
31 32
     extend Forwardable
32 33
     include Logging
  34
+    include SaveAndOpenPage
33 35
     
34 36
     attr_reader :current_url
35 37
     attr_reader :elements
@@ -43,23 +45,6 @@ def initialize(context = nil) #:nodoc:
43 45
       
44 46
       reset
45 47
     end
46  
-
47  
-    # Saves the page out to RAILS_ROOT/tmp/ and opens it in the default
48  
-    # web browser if on OS X. Useful for debugging.
49  
-    # 
50  
-    # Example:
51  
-    #   save_and_open_page
52  
-    def save_and_open_page
53  
-      return unless File.exist?(saved_page_dir)
54  
-
55  
-      filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html"
56  
-      
57  
-      File.open(filename, "w") do |f|
58  
-        f.write rewrite_css_and_image_references(response_body)
59  
-      end
60  
-
61  
-      open_in_browser(filename)
62  
-    end
63 48
     
64 49
     def current_dom #:nodoc:
65 50
       current_scope.dom
@@ -78,10 +63,6 @@ def doc_root #:nodoc:
78 63
       nil
79 64
     end
80 65
     
81  
-    def saved_page_dir #:nodoc:
82  
-      File.expand_path(".")
83  
-    end
84  
-
85 66
     def header(key, value)
86 67
       @custom_headers[key] = value
87 68
     end
@@ -172,20 +153,6 @@ def visit(url = nil, http_method = :get, data = {})
172 153
     end
173 154
     
174 155
     webrat_deprecate :visits, :visit
175  
-    
176  
-    def open_in_browser(path) # :nodoc
177  
-      platform = ruby_platform
178  
-      if platform =~ /cygwin/ || platform =~ /win32/
179  
-        `rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
180  
-      elsif platform =~ /darwin/
181  
-        `open #{path}`
182  
-      end
183  
-    end
184  
-    
185  
-    def rewrite_css_and_image_references(response_html) # :nodoc:
186  
-      return response_html unless doc_root
187  
-      response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1')
188  
-    end
189 156
 
190 157
     # Subclasses can override this to show error messages without html
191 158
     def formatted_error #:nodoc:
@@ -247,9 +214,5 @@ def reset
247 214
       @_page_scope  = nil
248 215
     end
249 216
     
250  
-    # accessor for testing
251  
-    def ruby_platform
252  
-      RUBY_PLATFORM
253  
-    end
254 217
   end
255 218
 end
33  lib/webrat/mechanize.rb
@@ -6,6 +6,10 @@ class MechanizeSession < Session #: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,6 +40,35 @@ def mechanize
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
17  lib/webrat/rails.rb
... ...
@@ -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
@@ -48,15 +50,18 @@ def integration_session
48 50
     
49 51
     def do_request(http_method, url, data, headers) #:nodoc:
50 52
       update_protocol(url)
51  
-      integration_session.request_via_redirect(http_method, remove_protocol(url), data, headers)
  53
+      url = normalize_url(url)
  54
+      integration_session.request_via_redirect(http_method, url, data, headers)
52 55
     end
53 56
   
54  
-    def remove_protocol(href) #:nodoc:
55  
-      if href =~ %r{^https?://www.example.com(/.*)}
56  
-        $LAST_MATCH_INFO.captures.first
57  
-      else
58  
-        href
  57
+    # remove protocol, host and anchor
  58
+    def normalize_url(href) #:nodoc:
  59
+      uri = URI.parse(href)
  60
+      normalized_url = uri.path
  61
+      if uri.query
  62
+        normalized_url += "?" + uri.query
59 63
       end
  64
+      normalized_url
60 65
     end
61 66
     
62 67
     def update_protocol(href) #:nodoc:
43  lib/webrat/selenium.rb
@@ -38,14 +38,10 @@ def self.stop_app_server #:nodoc:
38 38
   # To use Webrat's Selenium support, you'll need the selenium-client gem installed.
39 39
   # Activate it with (for example, in your <tt>env.rb</tt>):
40 40
   #
41  
-  #   require "webrat/selenium"
42  
-  # 
43  
-  # Then, if you're using Cucumber, configure it to use a 
44  
-  # <tt>Webrat::Selenium::Rails::World</tt> as the scenario context by adding
45  
-  # the following to <tt>env.rb</tt>:
46  
-  #
47  
-  #   World do
48  
-  #     Webrat::Selenium::Rails::World.new
  41
+  #   require "webrat"
  42
+  #   
  43
+  #   Webrat.configure do |config|
  44
+  #     config.mode = :selenium
49 45
   #   end
50 46
   #
51 47
   # == Dropping down to the selenium-client API
@@ -72,31 +68,26 @@ def self.stop_app_server #:nodoc:
72 68
   # your Webrat::Selenium tests ignoring the concurrency issues that can plague in-browser
73 69
   # testing, so long as you're using the Webrat API.
74 70
   module Selenium
75  
-    
76  
-    module Rails #:nodoc:
77  
-      class World < ::ActionController::IntegrationTest
78  
-        include Webrat::Selenium::Matchers
79  
-        
80  
-        def initialize #:nodoc:
81  
-          @_result = Test::Unit::TestResult.new
82  
-        end
83  
-        
84  
-        def response
85  
-          webrat_session.response
86  
-        end
87  
-        
88  
-        def wait_for(*args, &block)
89  
-          webrat_session.wait_for(*args, &block)
90  
-        end
91  
-        
  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
  79
+
  80
+      def save_and_open_screengrab
  81
+        webrat_session.save_and_open_screengrab
92 82
       end
93 83
     end
94 84
   end
95  
-    
96 85
 end
97 86
 
98 87
 module ActionController #:nodoc:
99 88
   IntegrationTest.class_eval do
100 89
     include Webrat::Methods
  90
+    include Webrat::Selenium::Methods
  91
+    include Webrat::Selenium::Matchers
101 92
   end
102 93
 end
22  lib/webrat/selenium/selenium_session.rb
... ...
@@ -1,3 +1,5 @@
  1
+require "webrat/core/save_and_open_page"
  2
+
1 3
 module Webrat
2 4
   class TimeoutError < WebratError
3 5
   end
@@ -17,6 +19,7 @@ def selenium
17 19
   end
18 20
   
19 21
   class SeleniumSession
  22
+    include Webrat::SaveAndOpenPage
20 23
     
21 24
     def initialize(*args) # :nodoc:
22 25
     end
@@ -53,7 +56,7 @@ def response_body #:nodoc:
53 56
     def click_button(button_text_or_regexp = nil, options = {})
54 57
       if button_text_or_regexp.is_a?(Hash) && options == {}
55 58
         pattern, options = nil, button_text_or_regexp
56  
-      else
  59
+      elsif button_text_or_regexp
57 60
         pattern = adjust_if_regexp(button_text_or_regexp)
58 61
       end
59 62
       pattern ||= '*'
@@ -160,6 +163,20 @@ def selenium
160 163
     
161 164
     webrat_deprecate :browser, :selenium
162 165
     
  166
+    
  167
+    def save_and_open_screengrab
  168
+      return unless File.exist?(saved_page_dir)
  169
+      
  170
+      filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.png"
  171
+         
  172
+      if $browser.chrome_backend?
  173
+        $browser.capture_entire_page_screenshot(filename, '')
  174
+      else
  175
+        $browser.capture_screenshot(filename)
  176
+      end
  177
+        open_in_browser(filename)
  178
+    end
  179
+    
163 180
   protected
164 181
     
165 182
     def setup #:nodoc:
@@ -175,6 +192,7 @@ def setup #:nodoc:
175 192
       
176 193
       extend_selenium
177 194
       define_location_strategies
  195
+      $browser.window_maximize
178 196
     end
179 197
     
180 198
     def teardown_at_exit #:nodoc:
@@ -191,7 +209,7 @@ def adjust_if_regexp(text_or_regexp) #:nodoc:
191 209
       if text_or_regexp.is_a?(Regexp)
192 210
         "evalregex:#{text_or_regexp.inspect}"
193 211
       else
194  
-        text_or_regexp
  212
+        "evalregex:/#{text_or_regexp}/"
195 213
       end 
196 214
     end
197 215
     
8  spec/api/click_button_spec.rb
@@ -330,7 +330,7 @@
330 330
   end
331 331
   
332 332
   it "should properly handle HTML entities in textarea default values" do
333  
-    pending "needs bug fix" do
  333
+    spec = lambda do
334 334
       with_html <<-HTML
335 335
         <html>
336 336
         <form method="post" action="/posts">
@@ -342,6 +342,12 @@
342 342
       webrat_session.should_receive(:post).with("/posts", "post" => {"body" => "Peanut butter & jelly"})
343 343
       click_button
344 344
     end
  345
+    
  346
+    if Webrat.on_java?
  347
+      spec.call
  348
+    else
  349
+      pending("needs bug fix", &spec)
  350
+    end
345 351
   end
346 352
   
347 353
   it "should send default selected option value from select" do
16  spec/api/select_spec.rb
@@ -201,7 +201,7 @@
201 201
   end
202 202
   
203 203
   it "should properly handle submitting HTML entities in select values" do
204  
-    pending "needs bug fix" do
  204
+    spec = lambda do
205 205
       with_html <<-HTML
206 206
         <html>
207 207
         <form method="post" action="/login">
@@ -213,10 +213,16 @@
213 213
       webrat_session.should_receive(:post).with("/login", "month" => "Peanut butter & jelly")
214 214
       click_button
215 215
     end
  216
+    
  217
+    if Webrat.on_java?
  218
+      spec.call
  219
+    else
  220
+      pending("needs bug fix", &spec)
  221
+    end
216 222
   end
217 223
   
218 224
   it "should properly handle locating with HTML entities in select values" do
219  
-    pending "needs bug fix" do
  225
+    spec = lambda do
220 226
       with_html <<-HTML
221 227
         <html>
222 228
         <form method="post" action="/login">
@@ -230,5 +236,11 @@
230 236
         select "Peanut butter & jelly"
231 237
       }.should_not raise_error(Webrat::NotFoundError)
232 238
     end
  239
+    
  240
+    if Webrat.on_java?
  241
+      spec.call
  242
+    else
  243
+      pending("needs bug fix", &spec)
  244
+    end
233 245
   end
234 246
 end
22  spec/api/within_spec.rb
@@ -58,6 +58,28 @@
58 58
     end
59 59
   end
60 60
   
  61
+  it "should work when the scope is inside the form" do
  62
+    pending "needs bug fix" do
  63
+      with_html <<-HTML
  64
+        <html>
  65
+          <form id="form2" action="/form2">
  66
+            <div class="important">
  67
+              <label>Email: <input type="text" class="email2" name="email" /></label>
  68
+            </div>
  69
+            <input type="submit" value="Add" />
  70
+          </form>
  71
+        </html>
  72
+      HTML
  73
+    
  74
+      webrat_session.should_receive(:get).with("/form2", "email" => "test@example.com")
  75
+      within ".important" do
  76
+        fill_in "Email", :with => "test@example.com"
  77
+      end
  78
+    
  79
+      submit_form "form2"
  80
+    end
  81
+  end
  82
+  
61 83
   it "should not find buttons outside of the scope" do
62 84
     with_html <<-HTML
63 85
       <html>
40  spec/spec_helper.rb
@@ -7,15 +7,24 @@
7 7
 webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
8 8
 $LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
9 9
 
10  
-require "merb-core"
11  
-require "webrat/merb"
12  
-
13 10
 require "webrat"
14 11
 require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session")
15 12
 
  13
+module Webrat
  14
+  @@previous_config = nil
  15
+
  16
+  def self.cache_config_for_test
  17
+    @@previous_config = Webrat.configuration.clone
  18
+  end
  19
+
  20
+  def self.reset_for_test
  21
+    @@configuration = @@previous_config if @@previous_config
  22
+  end
  23
+end
  24
+
16 25
 Spec::Runner.configure do |config|
17 26
   include Webrat::Methods
18  
-
  27
+  
19 28
   def with_html(html)
20 29
     raise "This doesn't look like HTML. Wrap it in a <html> tag" unless html =~ /^\s*<[^Hh>]*html/i
21 30
     webrat_session.response_body = html
@@ -26,22 +35,15 @@ def with_xml(xml)
26 35
     webrat_session.response_body = xml
27 36
   end
28 37
   
29  
-end
30  
-
31  
-module Webrat
32  
-  @@previous_config = nil
33  
-
34  
-  def self.cache_config_for_test
35  
-    @@previous_config = Webrat.configuration.clone
36  
-  end
37  
-
38  
-  def self.reset_for_test
39  
-    @@configuration = @@previous_config if @@previous_config
  38
+  config.before :each do
  39
+    Webrat.cache_config_for_test
40 40
   end
41 41
   
42  
-  class Configuration
43  
-    def mode_for_test= (mode)
44  
-      @mode = mode
45  
-    end
  42
+  config.after :each do
  43
+    Webrat.reset_for_test
46 44
   end
  45
+end
  46
+
  47
+Webrat.configure do |config|
  48
+  config.mode = :merb
47 49
 end
8  spec/webrat/core/configuration_spec.rb
@@ -4,14 +4,6 @@
4 4
   predicate_matchers[:parse_with_nokogiri]  = :parse_with_nokogiri?
5 5
   predicate_matchers[:open_error_files]     = :open_error_files?
6 6
 
7  
-  before do
8  
-    Webrat.cache_config_for_test
9  
-  end
10  
-  
11  
-  after do
12  
-    Webrat.reset_for_test
13  
-  end
14  
-
15 7
   it "should have a mode" do
16 8
     Webrat.configuration.should respond_to(:mode)
17 9
   end
14  spec/webrat/core/field_spec.rb
... ...
@@ -1,6 +1,20 @@
1 1
 require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2 2
 
3 3
 module Webrat
  4
+  describe Field do
  5
+    it "should have nice inspect output" do
  6
+      html = <<-HTML
  7
+        <html>
  8
+        <input type='checkbox' checked='checked' />
  9
+        </html>
  10
+      HTML
  11
+      
  12
+      element = Webrat::XML.css_search(Webrat::XML.document(html), "input").first
  13
+      checkbox = CheckboxField.new(nil, element)
  14
+      checkbox.inspect.should =~ /#<Webrat::CheckboxField @element=<input type=['"]checkbox['"] checked(=['"]checked['"])?\/?>>/
  15
+    end
  16
+  end
  17
+  
4 18
   describe CheckboxField do
5 19
     it "should say it is checked if it is" do
6 20
       html = <<-HTML
4  spec/webrat/core/session_spec.rb
@@ -87,12 +87,8 @@ def session.response_body
87 87
 
88 88
   describe "#request_page" do
89 89
     before(:each) do
90  
-      Webrat.cache_config_for_test
91 90
       webrat_session = Webrat::Session.new
92 91
     end
93  
-    after(:each) do
94  
-      Webrat.reset_for_test
95  
-    end
96 92
   
97 93
     it "should raise an error if the request is not a success" do
98 94
       webrat_session.stub!(:get)
49  spec/webrat/mechanize/mechanize_session_spec.rb
... ...
@@ -1,9 +1,13 @@
1 1
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2  
-require "mechanize"
  2
+
3 3
 require "webrat/mechanize"
4 4
 
5 5
 describe Webrat::MechanizeSession do
6  
-  
  6
+
  7
+  before :each do
  8
+    Webrat.configuration.mode = :mechanize
  9
+  end
  10
+
7 11
   before(:each) do
8 12
     @mech = Webrat::MechanizeSession.new
9 13
   end
@@ -34,4 +38,45 @@ def flattened_data
34 38
       Webrat::MechanizeSession.new.post(url, data)
35 39
     end
36 40
   end
  41
+  
  42
+  describe "#absolute_url" do
  43
+    before(:each) do
  44
+      @session = Webrat::MechanizeSession.new
  45
+      @session.stub!(:current_url).and_return(absolute_url)
  46
+    end
  47
+    
  48
+    def absolute_url
  49
+      'http://test.host/users/fred/cabbages'
  50
+    end
  51
+    
  52
+    def rooted_url
  53
+      '/users/fred/cabbages'
  54
+    end
  55
+    
  56
+    def relative_url
  57
+      '../../wilma'
  58
+    end
  59
+    
  60
+    it "should return unmodified url if prefixed with scheme" do
  61
+      @session.absolute_url(absolute_url).should == absolute_url
  62
+    end
  63
+    
  64
+    it "should prefix scheme and hostname if url begins with /" do
  65
+      @session.absolute_url(rooted_url).should == absolute_url
  66
+    end
  67
+    
  68
+    it "should resolve sibling URLs relative to current path" do
  69
+      @session.absolute_url(relative_url).should == 'http://test.host/users/wilma'
  70
+    end
  71
+    
  72
+    it "should cope with sibling URLs from root of site" do
  73
+      @session.stub!(:current_url).and_return('http://test.host')
  74
+      @session.absolute_url(relative_url).should == 'http://test.host/wilma'
  75
+    end
  76
+    
  77
+    it "should cope with https" do
  78
+      @session.stub!(:current_url).and_return('https://test.host')
  79
+      @session.absolute_url(relative_url).should == 'https://test.host/wilma'
  80
+    end
  81
+  end
37 82
 end
1  spec/webrat/merb/indifferent_access_spec.rb
... ...
@@ -1,5 +1,4 @@
1 1
 require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
2  
-require File.expand_path(File.dirname(__FILE__) + "/helper")
3 2
 
4 3
 describe HashWithIndifferentAccess do
5 4
   it "should not update constructor when not a hash" do
42  spec/webrat/merb/merb_session_spec.rb
... ...
@@ -0,0 +1,42 @@
  1
+require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
  2
+
  3
+require "webrat/merb"
  4
+
  5
+describe Webrat::MerbSession do
  6
+  it "should not pass empty params if data is and empty hash" do
  7
+    session = Webrat::MerbSession.new
  8
+    response = OpenStruct.new
  9
+    response.status = 200
  10
+    session.should_receive(:request).with('url', {:params=> nil, :method=>"GET", :headers=>nil}).and_return(response)
  11
+    session.get('url', {}, nil)
  12
+  end
  13
+  
  14
+  %w{post put delete}.each do |request_method|
  15
+    it "should call do request with method #{request_method.upcase} for a #{request_method} call" do
  16
+      session = Webrat::MerbSession.new
  17
+      response = OpenStruct.new
  18
+      response.status = 200
  19
+      
  20
+      session.should_receive(:request).with('url', {:params=>nil, :method=>request_method.upcase, :headers=>nil}).and_return(response)
  21
+      session.send(request_method, 'url', {}, nil)
  22
+    end
  23
+  end
  24
+
  25
+  context "a session with a response" do
  26
+    setup do
  27
+      @session = Webrat::MerbSession.new
  28
+      @response = OpenStruct.new
  29
+      @response.status = 200
  30
+      @response.body = 'test response'
  31
+      @session.instance_variable_set(:@response, @response)
  32
+    end
  33
+    
  34
+    it "should return body of a request as a response_body" do
  35
+      @session.response_body.should == @response.body
  36
+    end
  37
+    
  38
+    it "should return status of a request as a response_code" do
  39
+      @session.response_code.should == @response.status
  40
+    end
  41
+  end
  42
+end
3  spec/webrat/rails/attaches_file_spec.rb
... ...
@@ -1,7 +1,8 @@
1  
-require File.expand_path(File.dirname(__FILE__) + '/helper')
  1
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2 2
 
3 3
 describe "attach_file" do
4 4
   before do
  5
+    Webrat.configuration.mode = :rails
5 6
     @filename = __FILE__
6 7
     @uploaded_file = mock("uploaded file")
7 8
     ActionController::TestUploadedFile.stub!(:new => @uploaded_file)
17  spec/webrat/rails/rails_session_spec.rb
... ...
@@ -1,6 +1,12 @@
1  
-require File.expand_path(File.dirname(__FILE__) + '/helper')
  1
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
  2
+
  3
+require "webrat/rails"
2 4
 
3 5
 describe Webrat::RailsSession do
  6
+  before do
  7
+    Webrat.configuration.mode = :rails
  8
+  end
  9
+  
4 10
   it "should delegate response_body to the session response body" do
5 11
     response = mock("response", :body => "<html>")
6 12
     integration_session = mock("integration session", :response => response)
@@ -69,6 +75,15 @@
69 75
     end
70 76
   end
71 77
   
  78
+  context "the URL include an anchor" do
  79
+    it "should strip out the anchor" do
  80
+      integration_session = mock("integration session", :https! => false)
  81
+      rails_session = Webrat::RailsSession.new(integration_session)
  82
+      integration_session.should_receive(:request_via_redirect).with(:get, "/url", "data", "headers")
  83
+      rails_session.get("http://www.example.com/url#foo", "data", "headers")
  84
+    end
  85
+  end
  86
+  
72 87
   it "should provide a saved_page_dir" do
73 88
     Webrat::RailsSession.new(mock("integration session")).should respond_to(:saved_page_dir)
74 89
   end
6  webrat.gemspec
... ...
@@ -1,14 +1,14 @@
1 1
 Gem::Specification.new do |s|
2 2
   s.name = %q{webrat}
3  
-  s.version = "0.3.2.1"
  3
+  s.version = "0.3.2.2"
4 4
 
5 5
   s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6 6
   s.authors = ["Bryan Helmkamp"]
7  
-  s.date = %q{2008-11-30}
  7
+  s.date = %q{2008-12-25}
8 8
   s.description = %q{Webrat. Ruby Acceptance Testing for Web applications}
9 9
   s.email = %q{bryan@brynary.com}
10 10
   s.extra_rdoc_files = ["README.rdoc", "MIT-LICENSE.txt"]
11  
-  s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails", "lib/webrat/rails/redirect_actions.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"]
  11
+  s.files = ["History.txt", "install.rb", "MIT-LICENSE.txt", "README.rdoc", "Rakefile", "lib/webrat", "lib/webrat/core", "lib/webrat/core/configuration.rb", "lib/webrat/core/elements", "lib/webrat/core/elements/area.rb", "lib/webrat/core/elements/element.rb", "lib/webrat/core/elements/field.rb", "lib/webrat/core/elements/form.rb", "lib/webrat/core/elements/label.rb", "lib/webrat/core/elements/link.rb", "lib/webrat/core/elements/select_option.rb", "lib/webrat/core/locators", "lib/webrat/core/locators/area_locator.rb", "lib/webrat/core/locators/button_locator.rb", "lib/webrat/core/locators/field_by_id_locator.rb", "lib/webrat/core/locators/field_labeled_locator.rb", "lib/webrat/core/locators/field_locator.rb", "lib/webrat/core/locators/field_named_locator.rb", "lib/webrat/core/locators/form_locator.rb", "lib/webrat/core/locators/label_locator.rb", "lib/webrat/core/locators/link_locator.rb", "lib/webrat/core/locators/locator.rb", "lib/webrat/core/locators/select_option_locator.rb", "lib/webrat/core/locators.rb", "lib/webrat/core/logging.rb", "lib/webrat/core/matchers", "lib/webrat/core/matchers/have_content.rb", "lib/webrat/core/matchers/have_selector.rb", "lib/webrat/core/matchers/have_tag.rb", "lib/webrat/core/matchers/have_xpath.rb", "lib/webrat/core/matchers.rb", "lib/webrat/core/methods.rb", "lib/webrat/core/mime.rb", "lib/webrat/core/save_and_open_page.rb", "lib/webrat/core/scope.rb", "lib/webrat/core/session.rb", "lib/webrat/core/xml", "lib/webrat/core/xml/hpricot.rb", "lib/webrat/core/xml/nokogiri.rb", "lib/webrat/core/xml/rexml.rb", "lib/webrat/core/xml.rb", "lib/webrat/core.rb", "lib/webrat/core_extensions", "lib/webrat/core_extensions/blank.rb", "lib/webrat/core_extensions/deprecate.rb", "lib/webrat/core_extensions/detect_mapped.rb", "lib/webrat/core_extensions/hash_with_indifferent_access.rb", "lib/webrat/core_extensions/meta_class.rb", "lib/webrat/core_extensions/nil_to_param.rb", "lib/webrat/mechanize.rb", "lib/webrat/merb.rb", "lib/webrat/rack.rb", "lib/webrat/rails", "lib/webrat/rails/redirect_actions.rb", "lib/webrat/rails.rb", "lib/webrat/rspec-rails.rb", "lib/webrat/selenium", "lib/webrat/selenium/location_strategy_javascript", "lib/webrat/selenium/location_strategy_javascript/button.js", "lib/webrat/selenium/location_strategy_javascript/label.js", "lib/webrat/selenium/location_strategy_javascript/webrat.js", "lib/webrat/selenium/location_strategy_javascript/webratlink.js", "lib/webrat/selenium/location_strategy_javascript/webratlinkwithin.js", "lib/webrat/selenium/location_strategy_javascript/webratselectwithoption.js", "lib/webrat/selenium/matchers.rb", "lib/webrat/selenium/selenium_extensions.js", "lib/webrat/selenium/selenium_session.rb", "lib/webrat/selenium.rb", "lib/webrat/sinatra.rb", "lib/webrat.rb", "vendor/selenium-server.jar"]
12 12
   s.has_rdoc = true
13 13
   s.homepage = %q{http://github.com/brynary/webrat}
14 14
   s.require_paths = ["lib"]

0 notes on commit 449edf4

Please sign in to comment.
Something went wrong with that request. Please try again.