From 57c8678e8cb48cb81c13f8fb655566e2d7f5de50 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Wed, 9 May 2012 14:29:32 -0400 Subject: [PATCH] Adding capybara integration. Fixes #156 --- lib/draper/rspec_integration.rb | 37 ++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/lib/draper/rspec_integration.rb b/lib/draper/rspec_integration.rb index 4031e1d3..dd944fa5 100755 --- a/lib/draper/rspec_integration.rb +++ b/lib/draper/rspec_integration.rb @@ -3,22 +3,31 @@ module DecoratorExampleGroup extend ActiveSupport::Concern included { metadata[:type] = :decorator } end +end - RSpec.configure do |config| - # Automatically tag specs in specs/decorators as type: :decorator - config.include Draper::DecoratorExampleGroup, :type => :decorator, :example_group => { - :file_path => /spec[\\\/]decorators/ - } +RSpec.configure do |config| + # Automatically tag specs in specs/decorators as type: :decorator + config.include Draper::DecoratorExampleGroup, :type => :decorator, :example_group => { + :file_path => /spec[\\\/]decorators/ + } - # Specs tagged type: :decorator set the Draper view context - config.around do |example| - if :decorator == example.metadata[:type] - ApplicationController.new.set_current_view_context - Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new - Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request - Draper::ViewContext.current.params ||= {} - end - example.call + # Specs tagged type: :decorator set the Draper view context + config.around do |example| + if :decorator == example.metadata[:type] + ApplicationController.new.set_current_view_context + Draper::ViewContext.current.controller.request ||= ActionController::TestRequest.new + Draper::ViewContext.current.request ||= Draper::ViewContext.current.controller.request + Draper::ViewContext.current.params ||= {} end + example.call + end +end + +if defined?(Capybara) + require 'capybara/rspec/matchers' + + RSpec.configure do |config| + config.include Capybara::RSpecMatchers, :type => :decorator end end +