Sha256: fe93f8de0c593ea3b813f110d299a272f8a7ce90594a864421baf4cd01cef82e

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

require 'rspec/rails/view_assigns'

module RSpec
  module Rails
    # @api public
    # Container module for helper specs.
    module HelperExampleGroup
      extend ActiveSupport::Concern
      include RSpec::Rails::RailsExampleGroup
      include ActionView::TestCase::Behavior
      include RSpec::Rails::ViewAssigns

      # @private
      module ClassMethods
        if ::Rails::VERSION::MAJOR > 3
          def determine_constant_from_test_name(_ignore)
            described_class if yield(described_class)
          end
        else
          def determine_default_helper_class(_ignore)
            return unless Module === described_class && !(Class === described_class)

            described_class
          end
        end
      end

      # Returns an instance of ActionView::Base with the helper being specified
      # mixed in, along with any of the built-in rails helpers.
      def helper
        _view.tap do |v|
          v.extend(ApplicationHelper) if defined?(ApplicationHelper)
          v.assign(view_assigns)
        end
      end

    private

      def _controller_path(example)
        example.example_group.described_class.to_s.sub(/Helper/, '').underscore
      end

      included do
        before do |example|
          controller.controller_path = _controller_path(example)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-rails-4.0.0.beta3 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-4.0.0.beta2 lib/rspec/rails/example/helper_example_group.rb