mirror of
https://github.com/drapergem/draper
synced 2023-03-27 23:21:17 -04:00
move the test library integrations into the lib/draper/test
subdirectory
This commit is contained in:
parent
b46bb990f1
commit
f68a7da8cc
4 changed files with 51 additions and 59 deletions
|
@ -1,26 +0,0 @@
|
|||
require 'minitest/unit'
|
||||
require 'minitest/spec'
|
||||
|
||||
module MiniTest
|
||||
class DecoratorSpec < Spec
|
||||
before do
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
class MiniTest::Unit::DecoratorTestCase < MiniTest::Unit::TestCase
|
||||
add_setup_hook do
|
||||
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
|
||||
end
|
||||
|
||||
MiniTest::Spec.register_spec_type(MiniTest::DecoratorSpec) do |desc|
|
||||
desc.superclass == Draper::Base
|
||||
end
|
|
@ -1,33 +1,2 @@
|
|||
module Draper
|
||||
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/
|
||||
}
|
||||
|
||||
# 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
|
||||
|
||||
warn 'DEPRECATION WARNING -- use `require "draper/test/rspec_integration"` instead of `require "draper/rspec_integration"`'
|
||||
require 'draper/test/rspec_integration'
|
||||
|
|
17
lib/draper/test/minitest_integration.rb
Executable file
17
lib/draper/test/minitest_integration.rb
Executable file
|
@ -0,0 +1,17 @@
|
|||
require 'draper/test/view_context'
|
||||
|
||||
module MiniTest
|
||||
class Spec
|
||||
class Decorator < Spec
|
||||
before { Draper::ViewContext.infect!(self) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
class MiniTest::Unit::DecoratorTestCase < MiniTest::Unit::TestCase
|
||||
add_setup_hook { Draper::ViewContext.infect!(self) }
|
||||
end
|
||||
|
||||
MiniTest::Spec.register_spec_type(MiniTest::Spec::Decorator) do |desc|
|
||||
desc.superclass == Draper::Base
|
||||
end
|
32
lib/draper/test/rspec_integration.rb
Executable file
32
lib/draper/test/rspec_integration.rb
Executable file
|
@ -0,0 +1,32 @@
|
|||
require 'draper/test/view_context'
|
||||
|
||||
module Draper
|
||||
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/
|
||||
}
|
||||
|
||||
# Specs tagged type: :decorator set the Draper view context
|
||||
config.around do |example|
|
||||
if :decorator == example.metadata[:type]
|
||||
Draper::ViewContext.infect!(example)
|
||||
end
|
||||
example.call
|
||||
end
|
||||
end
|
||||
|
||||
if defined?(Capybara)
|
||||
require 'capybara/rspec/matchers'
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.include Capybara::RSpecMatchers, :type => :decorator
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in a new issue