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
Cleanup the way the tests switch Webrat modes
brynary (author)
Thu Dec 25 20:25:27 -0800 2008
commit  0eaad5276871b4f98da56ae560fa11f4dc8ee6b1
tree    0f4a90e5dd6d0e080fb17ef5c3cef8243f55eebf
parent  22c7834512190c5991cd0ff9e27c750037be0405
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 require "webrat"
0
+
0
+require "action_controller"
0
 require "action_controller/integration"
0
 
0
 module Webrat
...
7
8
9
10
11
12
13
14
15
 
 
 
 
 
 
 
 
 
 
 
 
16
17
18
 
19
20
21
...
26
27
28
29
30
31
32
33
34
35
36
37
38
39
 
 
40
41
42
43
44
45
 
 
46
47
48
 
 
 
 
 
...
7
8
9
 
 
 
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
27
28
29
30
...
35
36
37
 
 
 
 
 
 
 
 
 
 
 
38
39
40
41
 
 
 
 
42
43
44
 
45
46
47
48
49
50
0
@@ -7,15 +7,24 @@ begin require "redgreen" unless ENV['TM_CURRENT_LINE']; rescue LoadError; end
0
 webrat_path = File.expand_path(File.dirname(__FILE__) + "/../lib/")
0
 $LOAD_PATH.unshift(webrat_path) unless $LOAD_PATH.include?(webrat_path)
0
 
0
-require "merb-core"
0
-require "webrat/merb"
0
-
0
 require "webrat"
0
 require File.expand_path(File.dirname(__FILE__) + "/fakes/test_session")
0
 
0
+module Webrat
0
+  @@previous_config = nil
0
+
0
+  def self.cache_config_for_test
0
+    @@previous_config = Webrat.configuration.clone
0
+  end
0
+
0
+  def self.reset_for_test
0
+    @@configuration = @@previous_config if @@previous_config
0
+  end
0
+end
0
+
0
 Spec::Runner.configure do |config|
0
   include Webrat::Methods
0
-
0
+  
0
   def with_html(html)
0
     raise "This doesn't look like HTML. Wrap it in a <html> tag" unless html =~ /^\s*<[^Hh>]*html/i
0
     webrat_session.response_body = html
0
@@ -26,22 +35,15 @@ Spec::Runner.configure do |config|
0
     webrat_session.response_body = xml
0
   end
0
   
0
-end
0
-
0
-module Webrat
0
-  @@previous_config = nil
0
-
0
-  def self.cache_config_for_test
0
-    @@previous_config = Webrat.configuration.clone
0
-  end
0
-
0
-  def self.reset_for_test
0
-    @@configuration = @@previous_config if @@previous_config
0
+  config.before :each do
0
+    Webrat.cache_config_for_test
0
   end
0
   
0
-  class Configuration
0
-    def mode_for_test= (mode)
0
-      @mode = mode
0
-    end
0
+  config.after :each do
0
+    Webrat.reset_for_test
0
   end
0
-end
0
\ No newline at end of file
0
+end
0
+
0
+Webrat.configure do |config|
0
+  config.mode = :merb
0
+end
...
4
5
6
7
8
9
10
11
12
13
14
15
16
17
...
4
5
6
 
 
 
 
 
 
 
 
7
8
9
0
@@ -4,14 +4,6 @@ describe Webrat::Configuration do
0
   predicate_matchers[:parse_with_nokogiri]  = :parse_with_nokogiri?
0
   predicate_matchers[:open_error_files]     = :open_error_files?
0
 
0
-  before do
0
-    Webrat.cache_config_for_test
0
-  end
0
-  
0
-  after do
0
-    Webrat.reset_for_test
0
-  end
0
-
0
   it "should have a mode" do
0
     Webrat.configuration.should respond_to(:mode)
0
   end
...
87
88
89
90
91
92
93
94
95
96
97
98
...
87
88
89
 
90
91
 
 
 
92
93
94
0
@@ -87,12 +87,8 @@ describe Webrat::Session do
0
 
0
   describe "#request_page" do
0
     before(:each) do
0
-      Webrat.cache_config_for_test
0
       webrat_session = Webrat::Session.new
0
     end
0
-    after(:each) do
0
-      Webrat.reset_for_test
0
-    end
0
   
0
     it "should raise an error if the request is not a success" do
0
       webrat_session.stub!(:get)
...
1
2
3
4
5
 
 
 
 
6
7
8
9
10
11
12
13
14
...
1
2
 
 
 
3
4
5
6
7
8
 
 
 
 
9
10
11
0
@@ -1,14 +1,11 @@
0
 require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
0
 
0
-describe "Webrat::MechanizeSession" do
0
-  before :all do
0
-    Webrat.cache_config_for_test
0
+require "webrat/mechanize"
0
+
0
+describe Webrat::MechanizeSession do
0
+  before :each do
0
     Webrat.configuration.mode = :mechanize
0
   end
0
-  
0
-  after :all do
0
-    Webrat.reset_for_test
0
-  end
0
 
0
   before(:each) do
0
     @mech = Webrat::MechanizeSession.new
...
1
2
3
4
5
...
1
 
2
3
4
0
@@ -1,5 +1,4 @@
0
 require File.expand_path(File.dirname(__FILE__) + "/../../spec_helper")
0
-require File.expand_path(File.dirname(__FILE__) + "/helper")
0
 
0
 describe HashWithIndifferentAccess do
0
   it "should not update constructor when not a hash" do
...
1
 
2
3
4
 
5
6
7
...
 
1
2
3
4
5
6
7
8
0
@@ -1,7 +1,8 @@
0
-require File.expand_path(File.dirname(__FILE__) + '/helper')
0
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
0
 
0
 describe "attach_file" do
0
   before do
0
+    Webrat.configuration.mode = :rails
0
     @filename = __FILE__
0
     @uploaded_file = mock("uploaded file")
0
     ActionController::TestUploadedFile.stub!(:new => @uploaded_file)
...
1
 
 
 
2
3
 
 
 
 
4
5
6
...
 
1
2
3
4
5
6
7
8
9
10
11
12
0
@@ -1,6 +1,12 @@
0
-require File.expand_path(File.dirname(__FILE__) + '/helper')
0
+require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
0
+
0
+require "webrat/rails"
0
 
0
 describe Webrat::RailsSession do
0
+  before do
0
+    Webrat.configuration.mode = :rails
0
+  end
0
+  
0
   it "should delegate response_body to the session response body" do
0
     response = mock("response", :body => "<html>")
0
     integration_session = mock("integration session", :response => response)

Comments