Permalink
Browse files

centralize Capybara config

  • Loading branch information...
1 parent d0e790e commit ec15a2fa21ec3421ecac9215e37c4df5c93d9eab @dchelimsky dchelimsky committed May 4, 2011
View
19 lib/rspec/rails.rb
@@ -25,7 +25,20 @@
rescue LoadError
end
-begin
- require 'webrat'
-rescue LoadError
+RSpec.configure do |c|
+ if defined?(Capybara::RSpecMatchers)
+ c.include Capybara::RSpecMatchers, :type => :view
+ c.include Capybara::RSpecMatchers, :type => :helper
+ c.include Capybara::RSpecMatchers, :type => :mailer
+ c.include Capybara::RSpecMatchers, :type => :controller
+ end
+
+ if defined?(Capybara::DSL)
+ c.include Capybara::DSL, :type => :controller
+ end
+
+ unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
+ c.include Capybara, :type => :request
+ c.include Capybara, :type => :controller
+ end
end
View
9 lib/rspec/rails/browser_simulators.rb
@@ -1,3 +1,8 @@
+begin
+ require 'webrat'
+rescue LoadError
+end
+
module RSpec
module Rails
module BrowserSimulators
@@ -8,10 +13,6 @@ def self.included(mod)
def webrat(&block)
block.call if defined?(Webrat)
end
-
- def capybara(&block)
- block.call if defined?(Capybara)
- end
end
end
View
9 lib/rspec/rails/example/controller_example_group.rb
@@ -89,15 +89,6 @@ module ControllerExampleGroup
include Webrat::Methods
end
- capybara do
- begin
- include Capybara::DSL
- include Capybara::RSpecMatchers
- rescue
- include Capybara
- end
- end
-
module ClassMethods
def controller_class
describes
View
4 lib/rspec/rails/example/helper_example_group.rb
@@ -36,10 +36,6 @@ module HelperExampleGroup
include Webrat::Matchers
end
- capybara do
- include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
- end
-
module ClassMethods
def determine_default_helper_class(ignore)
describes
View
8 lib/rspec/rails/example/mailer_example_group.rb
@@ -10,14 +10,6 @@ module MailerExampleGroup
include Webrat::Matchers
end
- capybara do
- begin
- include Capybara::RSpecMatchers
- rescue
- include Capybara
- end
- end
-
included do
metadata[:type] = :mailer
include ::Rails.application.routes.url_helpers
View
4 lib/rspec/rails/example/request_example_group.rb
@@ -36,10 +36,6 @@ def last_response
end
end
- capybara do
- include Capybara unless defined?(Capybara::DSL)
- end
-
include RSpec::Rails::Matchers::RedirectTo
include RSpec::Rails::Matchers::RenderTemplate
include ActionController::TemplateAssertions
View
4 lib/rspec/rails/example/view_example_group.rb
@@ -29,10 +29,6 @@ module ViewExampleGroup
include Webrat::Matchers
end
- capybara do
- include Capybara::RSpecMatchers if defined?(Capybara::RSpecMatchers)
- end
-
module ClassMethods
def _default_helper
base = metadata[:example_group][:description].split('/').first

0 comments on commit ec15a2f

Please sign in to comment.