diff --git a/.rubocop.yml b/.rubocop.yml index 5217bfa..6bd4a90 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -5,10 +5,12 @@ AllCops: NewCops: disable TargetRubyVersion: 3.2.2 DisplayCopNames: true + SuggestExtensions: false Exclude: # NOTE: When we run knapsack's rubocop, we don't want to check the submodule # for Hyku. We'll assume it's okay and has it's own policing policies. - "hyrax-webapp/**/*" + - "gems/**/*" Metrics/BlockLength: AllowedMethods: ['included', 'describe', 'it', 'context'] diff --git a/hyku_knapsack.gemspec b/hyku_knapsack.gemspec index ffc994a..f025202 100644 --- a/hyku_knapsack.gemspec +++ b/hyku_knapsack.gemspec @@ -25,4 +25,6 @@ Gem::Specification.new do |spec| end spec.add_dependency "rails", ">= 5.2.0" + + spec.add_development_dependency "rubocop-rake" end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 9a6340f..c93e04d 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -42,5 +42,6 @@ # TODO is this needed? config.include HykuKnapsack::Engine.routes.url_helpers config.include Capybara::DSL - config.include Fixtures::FixtureFileUpload + # Only include Fixtures::FixtureFileUpload if it's defined (from hyrax-webapp) + config.include Fixtures::FixtureFileUpload if defined?(Fixtures::FixtureFileUpload) end diff --git a/spec/support/knapsack_view_helpers.rb b/spec/support/knapsack_view_helpers.rb new file mode 100644 index 0000000..210a28a --- /dev/null +++ b/spec/support/knapsack_view_helpers.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +# This shared context ensures that view specs in the knapsack correctly +# prioritize knapsack views over hyrax-webapp views. +# +# Usage: +# RSpec.describe 'path/to/view.html.erb', type: :view do +# include_context 'with knapsack view paths' +# # ... your spec code +# end +# +RSpec.shared_context 'with knapsack view paths' do + before do + # Prepend the knapsack view paths so that views in the knapsack + # take precedence over views in hyrax-webapp. + # This mimics what happens in production via the Engine's after_initialize hook. + view.view_paths.unshift(HykuKnapsack::Engine.root.join('app', 'views')) + end +end + +# Automatically include this context for all view specs in the knapsack +RSpec.configure do |config| + config.include_context 'with knapsack view paths', type: :view +end