mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
Specs at spec/decorators prime the view context
This commit is contained in:
parent
78b200a84f
commit
a5a3c38770
3 changed files with 24 additions and 2 deletions
|
@ -6,5 +6,6 @@ require 'draper/model_support'
|
||||||
require 'draper/helper_support'
|
require 'draper/helper_support'
|
||||||
require 'draper/view_context'
|
require 'draper/view_context'
|
||||||
require 'draper/decorated_enumerable_proxy'
|
require 'draper/decorated_enumerable_proxy'
|
||||||
|
require 'draper/rspec_integration' if defined?(RSpec)
|
||||||
|
|
||||||
Draper::System.setup
|
Draper::System.setup
|
||||||
|
|
22
lib/draper/rspec_integration.rb
Normal file
22
lib/draper/rspec_integration.rb
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
module Draper
|
||||||
|
module DecoratorExampleGroup
|
||||||
|
extend ActiveSupport::Concern
|
||||||
|
included { metadata[:type] = :decorator }
|
||||||
|
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/
|
||||||
|
}
|
||||||
|
|
||||||
|
# Specs tagged type: :decorator set the Draper view context
|
||||||
|
config.around do |example|
|
||||||
|
if :decorator == example.metadata[:type]
|
||||||
|
ApplicationController.new.set_current_view_context
|
||||||
|
end
|
||||||
|
example.call
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe ApplicationDecorator do
|
describe ApplicationDecorator do
|
||||||
before { ApplicationController.new.set_current_view_context }
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue