Skip to content

Commit

Permalink
centralize Capybara config
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed May 4, 2011
1 parent d0e790e commit ec15a2f
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 36 deletions.
19 changes: 16 additions & 3 deletions lib/rspec/rails.rb
Expand Up @@ -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
9 changes: 5 additions & 4 deletions lib/rspec/rails/browser_simulators.rb
@@ -1,3 +1,8 @@
begin
require 'webrat'
rescue LoadError
end

module RSpec
module Rails
module BrowserSimulators
Expand All @@ -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

Expand Down
9 changes: 0 additions & 9 deletions lib/rspec/rails/example/controller_example_group.rb
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/rspec/rails/example/helper_example_group.rb
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/rspec/rails/example/mailer_example_group.rb
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/rspec/rails/example/request_example_group.rb
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions lib/rspec/rails/example/view_example_group.rb
Expand Up @@ -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
Expand Down

0 comments on commit ec15a2f

Please sign in to comment.