Sha256: f9085873ad2209fd8406603eb70a460f0fa1c5b5e4d361895b19d33ab302e1e8

Contents?: true

Size: 1.32 KB

Versions: 21

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

21 entries across 21 versions & 2 rubygems

Version Path
rspec-rails-3.9.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.8.3 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.9.0 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.8.2 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.8.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.8.0 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.7.2 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.7.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.7.0 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.6.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.6.0 lib/rspec/rails/example/helper_example_group.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/rspec-rails-3.5.2/lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.6.0.beta2 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.6.0.beta1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.2 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.1 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.0 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.0.beta4 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.0.beta3 lib/rspec/rails/example/helper_example_group.rb
rspec-rails-3.5.0.beta2 lib/rspec/rails/example/helper_example_group.rb