File: helper_example_group.rb

package info (click to toggle)
ruby-rspec-rails 8.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 1,820 kB
  • sloc: ruby: 10,902; sh: 199; makefile: 6
file content (42 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
        def determine_constant_from_test_name(_ignore)
          described_class if yield(described_class)
        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