Skip to content

Commit ec15a2f

Browse files
committed
centralize Capybara config
1 parent d0e790e commit ec15a2f

7 files changed

+21
-36
lines changed

lib/rspec/rails.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,20 @@
2525
rescue LoadError
2626
end
2727

28-
begin
29-
require 'webrat'
30-
rescue LoadError
28+
RSpec.configure do |c|
29+
if defined?(Capybara::RSpecMatchers)
30+
c.include Capybara::RSpecMatchers, :type => :view
31+
c.include Capybara::RSpecMatchers, :type => :helper
32+
c.include Capybara::RSpecMatchers, :type => :mailer
33+
c.include Capybara::RSpecMatchers, :type => :controller
34+
end
35+
36+
if defined?(Capybara::DSL)
37+
c.include Capybara::DSL, :type => :controller
38+
end
39+
40+
unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
41+
c.include Capybara, :type => :request
42+
c.include Capybara, :type => :controller
43+
end
3144
end

lib/rspec/rails/browser_simulators.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
begin
2+
require 'webrat'
3+
rescue LoadError
4+
end
5+
16
module RSpec
27
module Rails
38
module BrowserSimulators
@@ -8,10 +13,6 @@ def self.included(mod)
813
def webrat(&block)
914
block.call if defined?(Webrat)
1015
end
11-
12-
def capybara(&block)
13-
block.call if defined?(Capybara)
14-
end
1516
end
1617
end
1718

lib/rspec/rails/example/controller_example_group.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,6 @@ module ControllerExampleGroup
8989
include Webrat::Methods
9090
end
9191

92-
capybara do
93-
begin
94-
include Capybara::DSL
95-
include Capybara::RSpecMatchers
96-
rescue
97-
include Capybara
98-
end
99-
end
100-
10192
module ClassMethods
10293
def controller_class
10394
describes

lib/rspec/rails/example/helper_example_group.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ module HelperExampleGroup
3636
include Webrat::Matchers
3737
end
3838

39-
capybara do
40-
include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
41-
end
42-
4339
module ClassMethods
4440
def determine_default_helper_class(ignore)
4541
describes

lib/rspec/rails/example/mailer_example_group.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ module MailerExampleGroup
1010
include Webrat::Matchers
1111
end
1212

13-
capybara do
14-
begin
15-
include Capybara::RSpecMatchers
16-
rescue
17-
include Capybara
18-
end
19-
end
20-
2113
included do
2214
metadata[:type] = :mailer
2315
include ::Rails.application.routes.url_helpers

lib/rspec/rails/example/request_example_group.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ def last_response
3636
end
3737
end
3838

39-
capybara do
40-
include Capybara unless defined?(Capybara::DSL)
41-
end
42-
4339
include RSpec::Rails::Matchers::RedirectTo
4440
include RSpec::Rails::Matchers::RenderTemplate
4541
include ActionController::TemplateAssertions

lib/rspec/rails/example/view_example_group.rb

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ module ViewExampleGroup
2929
include Webrat::Matchers
3030
end
3131

32-
capybara do
33-
include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
34-
end
35-
3632
module ClassMethods
3733
def _default_helper
3834
base = metadata[:example_group][:description].split('/').first

0 commit comments

Comments
 (0)