Skip to content

Commit

Permalink
Adding capybara integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
steveklabnik committed May 9, 2012
1 parent 8b0b50e commit 57c8678
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions lib/draper/rspec_integration.rb
Expand Up @@ -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

0 comments on commit 57c8678

Please sign in to comment.