public
Description: Webrat - Ruby Acceptance Testing for Web applications
Homepage: http://gitrdoc.com/brynary/webrat/tree/master/
Clone URL: git://github.com/brynary/webrat.git
Sets the Webrat mode with Configuration#mode= in the config block
gaffo (author)
Thu Dec 25 20:04:41 -0800 2008
brynary (committer)
Thu Dec 25 20:07:10 -0800 2008
commit  22c7834512190c5991cd0ff9e27c750037be0405
tree    473e024ebfb283d48fb42e3663fba2fcd4db6b2c
parent  6d7fc04f71c170c889e6d758d5de9d98401f72dd
...
19
20
21
 
22
23
24
...
19
20
21
22
23
24
25
0
@@ -19,6 +19,7 @@
0
 
0
   * Maximize the browser window after initializing Selenium (Luke Melia)
0
   * Better inspect output for Webrat elements
0
+  * Sets the Webrat mode with Configuration#mode= in the config block [#85] (Mike Gaffney)
0
   * Detect if the document is XML or HTML using the Content-Type when in Rails mode
0
   * Expose #selenium method for direct access to Selenium client
0
   * Check nokogiri gem version before requiring nokogiri
...
61
62
63
64
 
 
 
 
 
65
66
67
...
61
62
63
 
64
65
66
67
68
69
70
71
0
@@ -61,7 +61,11 @@ To install the latest code as a plugin: (_Note:_ This may be less stable than us
0
 
0
 In your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber) add:
0
 
0
-  require "webrat/rails"
0
+  require "webrat"
0
+  
0
+  Webrat.configure do |config|
0
+    config.mode = :rails
0
+  end
0
   
0
 == Install with Merb
0
 
...
17
18
19
 
20
21
22
...
39
40
41
 
 
 
 
 
 
 
42
43
44
45
...
17
18
19
20
21
22
23
...
40
41
42
43
44
45
46
47
48
49
50
51
52
53
0
@@ -17,6 +17,7 @@ module Webrat
0
   #     config.parse_with_nokogiri = false
0
   #   end
0
   class Configuration
0
+    
0
     # Should XHTML be parsed with Nokogiri? Defaults to true, except on JRuby. When false, Hpricot and REXML are used
0
     attr_writer :parse_with_nokogiri
0
     
0
@@ -39,6 +40,13 @@ module Webrat
0
       @open_error_files ? true : false
0
     end
0
     
0
+    # Allows setting of webrat's mode, valid modes are:
0
+    # :rails, :selenium, :rack, :sinatra, :mechanize, :merb
0
+    def mode=(mode)
0
+      @mode = mode
0
+      require("webrat/#{mode}")
0
+    end
0
+    
0
   end
0
   
0
 end
0
\ No newline at end of file
...
72
73
74
75
76
77
...
72
73
74
 
 
75
0
@@ -72,5 +72,3 @@ module Webrat #:nodoc:
0
       end
0
   end
0
 end
0
-
0
-Webrat.configuration.mode = :mechanize
0
\ No newline at end of file
...
72
73
74
75
76
77
...
72
73
74
 
 
 
0
@@ -72,6 +72,3 @@ class Merb::Test::RspecStory #:nodoc:
0
     @browser ||= Webrat::MerbSession.new
0
   end
0
 end
0
-
0
-Webrat.configuration.mode = :merb
0
-
...
22
23
24
25
26
27
...
22
23
24
 
 
25
0
@@ -22,5 +22,3 @@ module Webrat
0
     end
0
   end
0
 end
0
-
0
-Webrat.configuration.mode = :rack
0
\ No newline at end of file
...
86
87
88
89
90
91
92
93
94
95
96
97
...
86
87
88
 
89
90
91
92
93
 
 
94
0
@@ -86,11 +86,8 @@ module ActionController #:nodoc:
0
       end
0
     end
0
   end
0
-  
0
   IntegrationTest.class_eval do
0
     include Webrat::Methods
0
     include Webrat::Matchers
0
   end
0
 end
0
-
0
-Webrat.configuration.mode = :rails
0
\ No newline at end of file
...
4
5
6
7
8
9
10
11
...
4
5
6
 
 
7
8
9
0
@@ -4,8 +4,6 @@ require "selenium/client"
0
 require "webrat/selenium/selenium_session"
0
 require "webrat/selenium/matchers"
0
 
0
-Webrat.configuration.mode = :selenium
0
-
0
 module Webrat
0
   
0
   def self.with_selenium_server #:nodoc:
...
17
18
19
20
21
22
...
17
18
19
 
 
20
0
@@ -17,5 +17,3 @@ module Webrat
0
     
0
   end
0
 end
0
-
0
-Webrat.configuration.mode = :sinatra
0
\ No newline at end of file
...
38
39
40
 
 
 
 
 
 
41
42
...
38
39
40
41
42
43
44
45
46
47
48
0
@@ -38,4 +38,10 @@ module Webrat
0
   def self.reset_for_test
0
     @@configuration = @@previous_config if @@previous_config
0
   end
0
+  
0
+  class Configuration
0
+    def mode_for_test= (mode)
0
+      @mode = mode
0
+    end
0
+  end
0
 end
0
\ No newline at end of file
...
3
4
5
6
 
7
8
9
...
41
42
43
 
 
 
 
 
 
 
 
 
 
 
 
 
44
45
...
3
4
5
 
6
7
8
9
...
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
0
@@ -3,7 +3,7 @@ require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
0
 describe Webrat::Configuration do
0
   predicate_matchers[:parse_with_nokogiri]  = :parse_with_nokogiri?
0
   predicate_matchers[:open_error_files]     = :open_error_files?
0
-  
0
+
0
   before do
0
     Webrat.cache_config_for_test
0
   end
0
@@ -41,4 +41,17 @@ describe Webrat::Configuration do
0
     config = Webrat.configuration
0
     config.should_not open_error_files
0
   end
0
+  
0
+  [:rails, 
0
+   :selenium,
0
+   :rack,
0
+   :sinatra,
0
+   :merb,
0
+   :mechanize].each do |mode|
0
+    it "should require correct lib when in #{mode} mode" do
0
+      config = Webrat::Configuration.new
0
+      config.should_receive(:require).with("webrat/#{mode}")
0
+      config.mode = mode
0
+    end
0
+  end
0
 end
0
\ No newline at end of file
...
3
4
5
6
 
7
8
9
10
11
12
 
13
14
15
...
3
4
5
 
6
7
8
9
10
11
 
12
13
14
15
0
@@ -3,13 +3,13 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
0
 describe "Webrat::MechanizeSession" do
0
   before :all do
0
     Webrat.cache_config_for_test
0
-    require "webrat/mechanize"
0
+    Webrat.configuration.mode = :mechanize
0
   end
0
   
0
   after :all do
0
     Webrat.reset_for_test
0
   end
0
-  
0
+
0
   before(:each) do
0
     @mech = Webrat::MechanizeSession.new
0
   end
...
7
8
9
 
...
7
8
9
10
0
@@ -7,3 +7,4 @@ silence_warnings do
0
 end
0
 
0
 require "webrat/rails"
0
+Webrat.configuration.mode_for_test = :rails

Comments