mini-quick-sys 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/mini-quick-sys.gemspec +12 -0
  3. data/rspec-rails-8.0.4/Capybara.md +28 -0
  4. data/rspec-rails-8.0.4/Changelog.md +1408 -0
  5. data/rspec-rails-8.0.4/LICENSE.md +25 -0
  6. data/rspec-rails-8.0.4/README.md +386 -0
  7. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/authentication_generator.rb +25 -0
  8. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/templates/user_spec.rb +5 -0
  9. data/rspec-rails-8.0.4/lib/generators/rspec/authentication/templates/users.yml +11 -0
  10. data/rspec-rails-8.0.4/lib/generators/rspec/channel/channel_generator.rb +12 -0
  11. data/rspec-rails-8.0.4/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
  12. data/rspec-rails-8.0.4/lib/generators/rspec/controller/controller_generator.rb +51 -0
  13. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/controller_spec.rb +16 -0
  14. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  15. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  16. data/rspec-rails-8.0.4/lib/generators/rspec/controller/templates/view_spec.rb +5 -0
  17. data/rspec-rails-8.0.4/lib/generators/rspec/feature/feature_generator.rb +29 -0
  18. data/rspec-rails-8.0.4/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
  19. data/rspec-rails-8.0.4/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  20. data/rspec-rails-8.0.4/lib/generators/rspec/generator/generator_generator.rb +24 -0
  21. data/rspec-rails-8.0.4/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
  22. data/rspec-rails-8.0.4/lib/generators/rspec/helper/helper_generator.rb +16 -0
  23. data/rspec-rails-8.0.4/lib/generators/rspec/helper/templates/helper_spec.rb +17 -0
  24. data/rspec-rails-8.0.4/lib/generators/rspec/install/install_generator.rb +80 -0
  25. data/rspec-rails-8.0.4/lib/generators/rspec/install/templates/spec/rails_helper.rb +91 -0
  26. data/rspec-rails-8.0.4/lib/generators/rspec/job/job_generator.rb +13 -0
  27. data/rspec-rails-8.0.4/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  28. data/rspec-rails-8.0.4/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  29. data/rspec-rails-8.0.4/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  30. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/mailer_generator.rb +30 -0
  31. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/fixture +3 -0
  32. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/mailer_spec.rb +25 -0
  33. data/rspec-rails-8.0.4/lib/generators/rspec/mailer/templates/preview.rb +13 -0
  34. data/rspec-rails-8.0.4/lib/generators/rspec/model/model_generator.rb +37 -0
  35. data/rspec-rails-8.0.4/lib/generators/rspec/model/templates/fixtures.yml +19 -0
  36. data/rspec-rails-8.0.4/lib/generators/rspec/model/templates/model_spec.rb +7 -0
  37. data/rspec-rails-8.0.4/lib/generators/rspec/request/request_generator.rb +17 -0
  38. data/rspec-rails-8.0.4/lib/generators/rspec/request/templates/request_spec.rb +10 -0
  39. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/scaffold_generator.rb +136 -0
  40. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  41. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  42. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/controller_spec.rb +145 -0
  43. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/edit_spec.rb +27 -0
  44. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/index_spec.rb +26 -0
  45. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/new_spec.rb +22 -0
  46. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
  47. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/routing_spec.rb +46 -0
  48. data/rspec-rails-8.0.4/lib/generators/rspec/scaffold/templates/show_spec.rb +21 -0
  49. data/rspec-rails-8.0.4/lib/generators/rspec/system/system_generator.rb +24 -0
  50. data/rspec-rails-8.0.4/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  51. data/rspec-rails-8.0.4/lib/generators/rspec/view/templates/view_spec.rb +5 -0
  52. data/rspec-rails-8.0.4/lib/generators/rspec/view/view_generator.rb +22 -0
  53. data/rspec-rails-8.0.4/lib/generators/rspec.rb +56 -0
  54. data/rspec-rails-8.0.4/lib/rspec/rails/active_record.rb +25 -0
  55. data/rspec-rails-8.0.4/lib/rspec/rails/adapters.rb +196 -0
  56. data/rspec-rails-8.0.4/lib/rspec/rails/configuration.rb +158 -0
  57. data/rspec-rails-8.0.4/lib/rspec/rails/example/channel_example_group.rb +93 -0
  58. data/rspec-rails-8.0.4/lib/rspec/rails/example/controller_example_group.rb +217 -0
  59. data/rspec-rails-8.0.4/lib/rspec/rails/example/feature_example_group.rb +53 -0
  60. data/rspec-rails-8.0.4/lib/rspec/rails/example/helper_example_group.rb +42 -0
  61. data/rspec-rails-8.0.4/lib/rspec/rails/example/job_example_group.rb +23 -0
  62. data/rspec-rails-8.0.4/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  63. data/rspec-rails-8.0.4/lib/rspec/rails/example/mailer_example_group.rb +38 -0
  64. data/rspec-rails-8.0.4/lib/rspec/rails/example/model_example_group.rb +11 -0
  65. data/rspec-rails-8.0.4/lib/rspec/rails/example/rails_example_group.rb +23 -0
  66. data/rspec-rails-8.0.4/lib/rspec/rails/example/request_example_group.rb +27 -0
  67. data/rspec-rails-8.0.4/lib/rspec/rails/example/routing_example_group.rb +61 -0
  68. data/rspec-rails-8.0.4/lib/rspec/rails/example/system_example_group.rb +177 -0
  69. data/rspec-rails-8.0.4/lib/rspec/rails/example/view_example_group.rb +214 -0
  70. data/rspec-rails-8.0.4/lib/rspec/rails/example.rb +13 -0
  71. data/rspec-rails-8.0.4/lib/rspec/rails/extensions/active_record/proxy.rb +11 -0
  72. data/rspec-rails-8.0.4/lib/rspec/rails/extensions.rb +1 -0
  73. data/rspec-rails-8.0.4/lib/rspec/rails/feature_check.rb +51 -0
  74. data/rspec-rails-8.0.4/lib/rspec/rails/file_fixture_support.rb +18 -0
  75. data/rspec-rails-8.0.4/lib/rspec/rails/fixture_file_upload_support.rb +39 -0
  76. data/rspec-rails-8.0.4/lib/rspec/rails/fixture_support.rb +58 -0
  77. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +180 -0
  78. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  79. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_cable.rb +70 -0
  80. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  81. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/active_job.rb +534 -0
  82. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  83. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_a_new.rb +83 -0
  84. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_new_record.rb +30 -0
  85. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/be_valid.rb +49 -0
  86. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_enqueued_mail.rb +259 -0
  87. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_http_status.rb +381 -0
  88. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/have_rendered.rb +64 -0
  89. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/redirect_to.rb +38 -0
  90. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/relation_match_array.rb +3 -0
  91. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/routing_matchers.rb +125 -0
  92. data/rspec-rails-8.0.4/lib/rspec/rails/matchers/send_email.rb +122 -0
  93. data/rspec-rails-8.0.4/lib/rspec/rails/matchers.rb +36 -0
  94. data/rspec-rails-8.0.4/lib/rspec/rails/tasks/rspec.rake +49 -0
  95. data/rspec-rails-8.0.4/lib/rspec/rails/vendor/capybara.rb +32 -0
  96. data/rspec-rails-8.0.4/lib/rspec/rails/version.rb +9 -0
  97. data/rspec-rails-8.0.4/lib/rspec/rails/view_assigns.rb +27 -0
  98. data/rspec-rails-8.0.4/lib/rspec/rails/view_path_builder.rb +29 -0
  99. data/rspec-rails-8.0.4/lib/rspec/rails/view_rendering.rb +166 -0
  100. data/rspec-rails-8.0.4/lib/rspec/rails/view_spec_methods.rb +56 -0
  101. data/rspec-rails-8.0.4/lib/rspec/rails.rb +18 -0
  102. data/rspec-rails-8.0.4/lib/rspec-rails.rb +91 -0
  103. metadata +142 -0
@@ -0,0 +1,122 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RSpec
4
+ module Rails
5
+ module Matchers
6
+ # @api private
7
+ #
8
+ # Matcher class for `send_email`. Should not be instantiated directly.
9
+ #
10
+ # @see RSpec::Rails::Matchers#send_email
11
+ class SendEmail < RSpec::Rails::Matchers::BaseMatcher
12
+ # @api private
13
+ # Define the email attributes that should be included in the inspection output.
14
+ INSPECT_EMAIL_ATTRIBUTES = %i[subject from to cc bcc].freeze
15
+
16
+ def initialize(criteria)
17
+ @criteria = criteria
18
+ end
19
+
20
+ # @api private
21
+ def supports_value_expectations?
22
+ false
23
+ end
24
+
25
+ # @api private
26
+ def supports_block_expectations?
27
+ true
28
+ end
29
+
30
+ def matches?(block)
31
+ define_matched_emails(block)
32
+
33
+ @matched_emails.one?
34
+ end
35
+
36
+ # @api private
37
+ # @return [String]
38
+ def failure_message
39
+ result =
40
+ if multiple_match?
41
+ "More than 1 matching emails were sent."
42
+ else
43
+ "No matching emails were sent."
44
+ end
45
+ "#{result}#{sent_emails_message}"
46
+ end
47
+
48
+ # @api private
49
+ # @return [String]
50
+ def failure_message_when_negated
51
+ "Expected not to send an email but it was sent."
52
+ end
53
+
54
+ private
55
+
56
+ def diffable?
57
+ true
58
+ end
59
+
60
+ def deliveries
61
+ ActionMailer::Base.deliveries
62
+ end
63
+
64
+ def define_matched_emails(block)
65
+ before = deliveries.dup
66
+
67
+ block.call
68
+
69
+ after = deliveries
70
+
71
+ @diff = after - before
72
+ @matched_emails = @diff.select(&method(:matched_email?))
73
+ end
74
+
75
+ def matched_email?(email)
76
+ @criteria.all? do |attr, value|
77
+ expected =
78
+ case attr
79
+ when :to, :from, :cc, :bcc then Array(value)
80
+ else
81
+ value
82
+ end
83
+
84
+ values_match?(expected, email.public_send(attr))
85
+ end
86
+ end
87
+
88
+ def multiple_match?
89
+ @matched_emails.many?
90
+ end
91
+
92
+ def sent_emails_message
93
+ if @diff.empty?
94
+ "\n\nThere were no emails sent inside the expectation block."
95
+ else
96
+ sent_emails =
97
+ @diff.map do |email|
98
+ inspected = INSPECT_EMAIL_ATTRIBUTES.map { |attr| "#{attr}: #{email.public_send(attr)}" }.join(", ")
99
+ "- #{inspected}"
100
+ end.join("\n")
101
+ "\n\nThe following emails were sent:\n#{sent_emails}"
102
+ end
103
+ end
104
+ end
105
+
106
+ # @api public
107
+ # Check email sending with specific parameters.
108
+ #
109
+ # @example Positive expectation
110
+ # expect { action }.to send_email
111
+ #
112
+ # @example Negative expectations
113
+ # expect { action }.not_to send_email
114
+ #
115
+ # @example More precise expectation with attributes to match
116
+ # expect { action }.to send_email(to: 'test@example.com', subject: 'Confirm email')
117
+ def send_email(criteria = {})
118
+ SendEmail.new(criteria)
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,36 @@
1
+ require 'rspec/core/warnings'
2
+ require 'rspec/expectations'
3
+ require 'rspec/rails/feature_check'
4
+
5
+ module RSpec
6
+ module Rails
7
+ # @api public
8
+ # Container module for Rails specific matchers.
9
+ module Matchers
10
+ end
11
+ end
12
+ end
13
+
14
+ require 'rspec/rails/matchers/base_matcher'
15
+ require 'rspec/rails/matchers/have_rendered'
16
+ require 'rspec/rails/matchers/redirect_to'
17
+ require 'rspec/rails/matchers/routing_matchers'
18
+ require 'rspec/rails/matchers/be_new_record'
19
+ require 'rspec/rails/matchers/be_a_new'
20
+ require 'rspec/rails/matchers/relation_match_array'
21
+ require 'rspec/rails/matchers/be_valid'
22
+ require 'rspec/rails/matchers/have_http_status'
23
+ require 'rspec/rails/matchers/send_email'
24
+
25
+ if RSpec::Rails::FeatureCheck.has_active_job?
26
+ require 'rspec/rails/matchers/active_job'
27
+ require 'rspec/rails/matchers/have_enqueued_mail'
28
+ end
29
+
30
+ if RSpec::Rails::FeatureCheck.has_action_cable_testing?
31
+ require 'rspec/rails/matchers/action_cable'
32
+ end
33
+
34
+ if RSpec::Rails::FeatureCheck.has_action_mailbox?
35
+ require 'rspec/rails/matchers/action_mailbox'
36
+ end
@@ -0,0 +1,49 @@
1
+ require 'rspec/core/rake_task'
2
+ if default = Rake.application.instance_variable_get('@tasks')['default']
3
+ default.prerequisites.delete('test')
4
+ end
5
+
6
+ task default: :spec
7
+
8
+ if ::Rails::VERSION::STRING < "8.0.0"
9
+ task stats: "spec:statsetup"
10
+ end
11
+
12
+ desc "Run all specs in spec directory (excluding plugin specs)"
13
+ RSpec::Core::RakeTask.new(spec: "spec:prepare")
14
+
15
+ namespace :spec do
16
+ types = begin
17
+ dirs = Dir['./spec/**/*_spec.rb']
18
+ .map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
19
+ .uniq
20
+ .select { |f| File.directory?(f) }
21
+ Hash[dirs.map { |d| [d.split('/').last, d] }]
22
+ end
23
+
24
+ task :prepare do
25
+ ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
26
+ if Rails.configuration.generators.options[:rails][:orm] == :active_record
27
+ if Rake::Task.task_defined?("test:prepare")
28
+ Rake::Task["test:prepare"].invoke
29
+ end
30
+ end
31
+ end
32
+
33
+ types.each do |type, dir|
34
+ desc "Run the code examples in #{dir}"
35
+ RSpec::Core::RakeTask.new(type => "spec:prepare") do |t|
36
+ t.pattern = "./#{dir}/**/*_spec.rb"
37
+ end
38
+ end
39
+
40
+ task :statsetup do
41
+ require 'rails/code_statistics'
42
+ types.each do |type, dir|
43
+ name = type.singularize.capitalize
44
+
45
+ ::STATS_DIRECTORIES << ["#{name} specs", dir]
46
+ ::CodeStatistics::TEST_TYPES << "#{name} specs"
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'capybara/rspec'
3
+ rescue LoadError
4
+ end
5
+
6
+ begin
7
+ require 'capybara/rails'
8
+ rescue LoadError
9
+ end
10
+
11
+ if defined?(Capybara)
12
+ RSpec.configure do |c|
13
+ if defined?(Capybara::DSL)
14
+ c.include Capybara::DSL, type: :feature
15
+ c.include Capybara::DSL, type: :system
16
+ end
17
+
18
+ if defined?(Capybara::RSpecMatchers)
19
+ c.include Capybara::RSpecMatchers, type: :view
20
+ c.include Capybara::RSpecMatchers, type: :helper
21
+ c.include Capybara::RSpecMatchers, type: :mailer
22
+ c.include Capybara::RSpecMatchers, type: :controller
23
+ c.include Capybara::RSpecMatchers, type: :feature
24
+ c.include Capybara::RSpecMatchers, type: :system
25
+ end
26
+
27
+ unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL)
28
+ c.include Capybara, type: :request
29
+ c.include Capybara, type: :controller
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module Rails
3
+ # Version information for RSpec Rails.
4
+ module Version
5
+ # Current version of RSpec Rails, in semantic versioning format.
6
+ STRING = '8.0.4'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ module RSpec
2
+ module Rails
3
+ # Helpers for making instance variables available to views.
4
+ module ViewAssigns
5
+ # Assigns a value to an instance variable in the scope of the
6
+ # view being rendered.
7
+ #
8
+ # @example
9
+ #
10
+ # assign(:widget, stub_model(Widget))
11
+ def assign(key, value)
12
+ _encapsulated_assigns[key] = value
13
+ end
14
+
15
+ # Compat-shim for AbstractController::Rendering#view_assigns
16
+ def view_assigns
17
+ super.merge(_encapsulated_assigns)
18
+ end
19
+
20
+ private
21
+
22
+ def _encapsulated_assigns
23
+ @_encapsulated_assigns ||= {}
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,29 @@
1
+ module RSpec
2
+ module Rails
3
+ # Builds paths for view specs using a particular route set.
4
+ class ViewPathBuilder
5
+ def initialize(route_set)
6
+ self.class.send(:include, route_set.url_helpers)
7
+ end
8
+
9
+ # Given a hash of parameters, build a view path, if possible.
10
+ # Returns nil if no path can be built from the given params.
11
+ #
12
+ # @example
13
+ # # path can be built because all required params are present in the hash
14
+ # view_path_builder = ViewPathBuilder.new(::Rails.application.routes)
15
+ # view_path_builder.path_for({ :controller => 'posts', :action => 'show', :id => '54' })
16
+ # # => "/post/54"
17
+ #
18
+ # @example
19
+ # # path cannot be built because the params are missing a required element (:id)
20
+ # view_path_builder.path_for({ :controller => 'posts', :action => 'delete' })
21
+ # # => ActionController::UrlGenerationError: No route matches {:action=>"delete", :controller=>"posts"}
22
+ def path_for(path_params)
23
+ url_for(path_params.merge(only_path: true))
24
+ rescue => e
25
+ e.message
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,166 @@
1
+ require 'action_view/testing/resolvers'
2
+
3
+ module RSpec
4
+ module Rails
5
+ # @api public
6
+ # Helpers for optionally rendering views in controller specs.
7
+ module ViewRendering
8
+ extend ActiveSupport::Concern
9
+
10
+ # @!attribute [r]
11
+ # Returns the controller object instance under test.
12
+ attr_reader :controller
13
+
14
+ # @private
15
+ attr_writer :controller
16
+ private :controller=
17
+
18
+ # DSL methods
19
+ module ClassMethods
20
+ # @see RSpec::Rails::ControllerExampleGroup
21
+ def render_views(true_or_false = true)
22
+ @render_views = true_or_false
23
+ end
24
+
25
+ # @api private
26
+ def render_views?
27
+ return @render_views if defined?(@render_views)
28
+
29
+ if superclass.respond_to?(:render_views?)
30
+ superclass.render_views?
31
+ else
32
+ RSpec.configuration.render_views?
33
+ end
34
+ end
35
+ end
36
+
37
+ # @api private
38
+ def render_views?
39
+ self.class.render_views? || !controller.class.respond_to?(:view_paths)
40
+ end
41
+
42
+ # @private
43
+ class EmptyTemplateResolver
44
+ def self.build(path)
45
+ if path.is_a?(::ActionView::Resolver)
46
+ ResolverDecorator.new(path)
47
+ else
48
+ FileSystemResolver.new(path)
49
+ end
50
+ end
51
+
52
+ def self.nullify_template_rendering(templates)
53
+ templates.map do |template|
54
+ ::ActionView::Template.new(
55
+ "",
56
+ template.identifier,
57
+ EmptyTemplateHandler,
58
+ virtual_path: template.virtual_path,
59
+ format: template_format(template),
60
+ locals: []
61
+ )
62
+ end
63
+ end
64
+
65
+ def self.template_format(template)
66
+ template.format
67
+ end
68
+
69
+ # Delegates all methods to the submitted resolver and for all methods
70
+ # that return a collection of `ActionView::Template` instances, return
71
+ # templates with modified source
72
+ #
73
+ # @private
74
+ class ResolverDecorator < ::ActionView::Resolver
75
+ (::ActionView::Resolver.instance_methods - Object.instance_methods).each do |method|
76
+ undef_method method
77
+ end
78
+
79
+ (::ActionView::Resolver.methods - Object.methods).each do |method|
80
+ singleton_class.undef_method method
81
+ end
82
+
83
+ def initialize(resolver)
84
+ @resolver = resolver
85
+ end
86
+
87
+ def method_missing(name, *args, &block)
88
+ result = @resolver.send(name, *args, &block)
89
+ nullify_templates(result)
90
+ end
91
+
92
+ private
93
+
94
+ def nullify_templates(collection)
95
+ return collection unless collection.is_a?(Enumerable)
96
+ return collection unless collection.all? { |element| element.is_a?(::ActionView::Template) }
97
+
98
+ EmptyTemplateResolver.nullify_template_rendering(collection)
99
+ end
100
+ end
101
+
102
+ # Delegates find_templates to the submitted path set and then returns
103
+ # templates with modified source
104
+ #
105
+ # @private
106
+ class FileSystemResolver < ::ActionView::FileSystemResolver
107
+ private
108
+
109
+ def find_templates(*args)
110
+ templates = super
111
+ EmptyTemplateResolver.nullify_template_rendering(templates)
112
+ end
113
+ end
114
+ end
115
+
116
+ # @private
117
+ class EmptyTemplateHandler
118
+ def self.call(_template, _source = nil)
119
+ ::Rails.logger.info(" Template rendering was prevented by rspec-rails. Use `render_views` to verify rendered view contents if necessary.")
120
+
121
+ %("")
122
+ end
123
+ end
124
+
125
+ # Used to null out view rendering in controller specs.
126
+ #
127
+ # @private
128
+ module EmptyTemplates
129
+ def prepend_view_path(new_path)
130
+ super(_path_decorator(*new_path))
131
+ end
132
+
133
+ def append_view_path(new_path)
134
+ super(_path_decorator(*new_path))
135
+ end
136
+
137
+ private
138
+
139
+ def _path_decorator(*paths)
140
+ paths.map { |path| EmptyTemplateResolver.build(path) }
141
+ end
142
+ end
143
+
144
+ # @private
145
+ RESOLVER_CACHE = Hash.new do |hash, path|
146
+ hash[path] = EmptyTemplateResolver.build(path)
147
+ end
148
+
149
+ included do
150
+ before do
151
+ unless render_views?
152
+ @_original_path_set = controller.class.view_paths
153
+ path_set = @_original_path_set.map { |resolver| RESOLVER_CACHE[resolver] }
154
+
155
+ controller.class.view_paths = path_set
156
+ controller.extend(EmptyTemplates)
157
+ end
158
+ end
159
+
160
+ after do
161
+ controller.class.view_paths = @_original_path_set unless render_views?
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
@@ -0,0 +1,56 @@
1
+ module RSpec
2
+ module Rails
3
+ # Adds methods (generally to ActionView::TestCase::TestController).
4
+ # Intended for use in view specs.
5
+ module ViewSpecMethods
6
+ module_function
7
+
8
+ # Adds methods `extra_params=` and `extra_params` to the indicated class.
9
+ # When class is `::ActionView::TestCase::TestController`, these methods
10
+ # are exposed in view specs on the `controller` object.
11
+ def add_to(klass)
12
+ return if klass.method_defined?(:extra_params) && klass.method_defined?(:extra_params=)
13
+
14
+ klass.module_exec do
15
+ # Set any extra parameters that rendering a URL for this view
16
+ # would require.
17
+ #
18
+ # @example
19
+ #
20
+ # # In "spec/views/widgets/show.html.erb_spec.rb":
21
+ # before do
22
+ # widget = Widget.create!(:name => "slicer")
23
+ # controller.extra_params = { :id => widget.id }
24
+ # end
25
+ def extra_params=(hash)
26
+ @extra_params = hash
27
+ request.path =
28
+ ViewPathBuilder.new(::Rails.application.routes).path_for(
29
+ extra_params.merge(request.path_parameters)
30
+ )
31
+ end
32
+
33
+ # Use to read extra parameters that are set in the view spec.
34
+ #
35
+ # @example
36
+ #
37
+ # # After the before in the above example:
38
+ # controller.extra_params
39
+ # # => { :id => 4 }
40
+ def extra_params
41
+ @extra_params ||= {}
42
+ @extra_params.dup.freeze
43
+ end
44
+ end
45
+ end
46
+
47
+ # Removes methods `extra_params=` and `extra_params` from the indicated class.
48
+ def remove_from(klass)
49
+ klass.module_exec do
50
+ undef extra_params= if klass.method_defined?(:extra_params=)
51
+ undef extra_params if klass.method_defined?(:extra_params)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ require 'rspec/core'
2
+ require 'rails/version'
3
+
4
+ # Load any of our adapters and extensions early in the process
5
+ require 'rspec/rails/adapters'
6
+ require 'rspec/rails/extensions'
7
+
8
+ # Load the rspec-rails parts
9
+ require 'rspec/rails/view_rendering'
10
+ require 'rspec/rails/matchers'
11
+ require 'rspec/rails/fixture_support'
12
+ require 'rspec/rails/file_fixture_support'
13
+ require 'rspec/rails/fixture_file_upload_support'
14
+ require 'rspec/rails/example'
15
+ require 'rspec/rails/vendor/capybara'
16
+ require 'rspec/rails/configuration'
17
+ require 'rspec/rails/active_record'
18
+ require 'rspec/rails/feature_check'
@@ -0,0 +1,91 @@
1
+ require 'rspec/rails/feature_check'
2
+
3
+ # Namespace for all core RSpec projects.
4
+ module RSpec
5
+ # Namespace for rspec-rails code.
6
+ module Rails
7
+ # Railtie to hook into Rails.
8
+ class Railtie < ::Rails::Railtie
9
+ # As of Rails 5.1.0 you can register directories to work with `rake notes`
10
+ require 'rails/source_annotation_extractor'
11
+ ::Rails::SourceAnnotationExtractor::Annotation.register_directories("spec")
12
+
13
+ # As of Rails 8.0.0 you can register directories to work with `rails stats`
14
+ if ::Rails::VERSION::STRING >= "8.0.0"
15
+ initializer "rspec_rails.code_statistics" do
16
+ require 'rails/code_statistics'
17
+
18
+ root = ::Rails.root
19
+ dirs = Dir[root.join('spec', '**', '*_spec.rb').to_s]
20
+ .map { |f| f.sub(%r{^#{Regexp.escape(root.to_s)}/(spec/\w+)/.*}, '\\1') }
21
+ .uniq
22
+ .select { |f| File.directory?(root.join(f)) }
23
+
24
+ Hash[dirs.map { |d| [d.split('/').last, d] }].each do |type, dir|
25
+ name = type.singularize.capitalize
26
+ ::Rails::CodeStatistics.register_directory "#{name} specs", root.join(dir).to_s, test_directory: true
27
+ end
28
+ end
29
+ end
30
+
31
+ generators = config.app_generators
32
+ generators.integration_tool :rspec
33
+ generators.test_framework :rspec
34
+
35
+ generators do
36
+ ::Rails::Generators.hidden_namespaces.reject! { |namespace| namespace.to_s.start_with?("rspec") }
37
+ end
38
+
39
+ rake_tasks do
40
+ load "rspec/rails/tasks/rspec.rake"
41
+ end
42
+
43
+ # This is called after the environment has been loaded but before Rails
44
+ # sets the default for the `preview_path`
45
+ initializer "rspec_rails.action_mailer",
46
+ before: "action_mailer.set_configs" do |app|
47
+ setup_preview_path(app)
48
+ end
49
+
50
+ private
51
+
52
+ def setup_preview_path(app)
53
+ return unless supports_action_mailer_previews?(app.config)
54
+
55
+ options = app.config.action_mailer
56
+ config_default_preview_path(options) if config_preview_path?(options)
57
+ end
58
+
59
+ def config_preview_path?(options)
60
+ # We cannot use `respond_to?(:show_previews)` here as it will always
61
+ # return `true`.
62
+ if options.show_previews.nil?
63
+ options.show_previews = ::Rails.env.development?
64
+ else
65
+ options.show_previews
66
+ end
67
+ end
68
+
69
+ def config_default_preview_path(options)
70
+ return unless options.preview_paths.empty?
71
+
72
+ options.preview_paths << "#{::Rails.root}/spec/mailers/previews"
73
+ end
74
+
75
+ def supports_action_mailer_previews?(config)
76
+ # These checks avoid loading `ActionMailer`. Using `defined?` has the
77
+ # side-effect of the class getting loaded if it is available. This is
78
+ # problematic because loading `ActionMailer::Base` will cause it to
79
+ # read the config settings; this is the only time the config is read.
80
+ # If the config is loaded now, any settings declared in a config block
81
+ # in an initializer will be ignored.
82
+ #
83
+ # If the action mailer railtie has not been loaded then `config` will
84
+ # not respond to the method. However, we cannot use
85
+ # `config.action_mailer.respond_to?(:preview_path)` here as it will
86
+ # always return `true`.
87
+ config.respond_to?(:action_mailer)
88
+ end
89
+ end
90
+ end
91
+ end