forked from rspec/rspec-rails
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_example_group.rb
42 lines (36 loc) · 1.07 KB
/
helper_example_group.rb
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