rspec-rails 3.0.2 → 7.1.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 (105) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +1 -1
  4. data/.yardopts +3 -1
  5. data/Capybara.md +6 -55
  6. data/Changelog.md +805 -47
  7. data/{License.txt → LICENSE.md} +5 -3
  8. data/README.md +278 -444
  9. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  10. data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
  11. data/lib/generators/rspec/controller/controller_generator.rb +24 -7
  12. data/lib/generators/rspec/controller/templates/controller_spec.rb +3 -3
  13. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  14. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  15. data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
  16. data/lib/generators/rspec/feature/feature_generator.rb +15 -2
  17. data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
  18. data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
  19. data/lib/generators/rspec/generator/generator_generator.rb +24 -0
  20. data/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
  21. data/lib/generators/rspec/helper/helper_generator.rb +2 -2
  22. data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
  23. data/lib/generators/rspec/install/install_generator.rb +41 -7
  24. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +63 -22
  25. data/lib/generators/rspec/job/job_generator.rb +13 -0
  26. data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  27. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  28. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  29. data/lib/generators/rspec/mailer/mailer_generator.rb +12 -3
  30. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  31. data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
  32. data/lib/generators/rspec/model/model_generator.rb +20 -6
  33. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  34. data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
  35. data/lib/generators/rspec/request/request_generator.rb +17 -0
  36. data/lib/generators/rspec/request/templates/request_spec.rb +10 -0
  37. data/lib/generators/rspec/scaffold/scaffold_generator.rb +90 -113
  38. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  39. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  40. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +46 -64
  41. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +11 -7
  42. data/lib/generators/rspec/scaffold/templates/index_spec.rb +4 -3
  43. data/lib/generators/rspec/scaffold/templates/new_spec.rb +4 -4
  44. data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
  45. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +18 -11
  46. data/lib/generators/rspec/scaffold/templates/show_spec.rb +3 -3
  47. data/lib/generators/rspec/system/system_generator.rb +24 -0
  48. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  49. data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
  50. data/lib/generators/rspec/view/view_generator.rb +4 -4
  51. data/lib/generators/rspec.rb +30 -11
  52. data/lib/rspec/rails/active_record.rb +25 -0
  53. data/lib/rspec/rails/adapters.rb +46 -29
  54. data/lib/rspec/rails/configuration.rb +165 -41
  55. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  56. data/lib/rspec/rails/example/controller_example_group.rb +185 -149
  57. data/lib/rspec/rails/example/feature_example_group.rb +43 -23
  58. data/lib/rspec/rails/example/helper_example_group.rb +28 -25
  59. data/lib/rspec/rails/example/job_example_group.rb +23 -0
  60. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  61. data/lib/rspec/rails/example/mailer_example_group.rb +27 -22
  62. data/lib/rspec/rails/example/model_example_group.rb +9 -6
  63. data/lib/rspec/rails/example/rails_example_group.rb +9 -2
  64. data/lib/rspec/rails/example/request_example_group.rb +21 -17
  65. data/lib/rspec/rails/example/routing_example_group.rb +47 -39
  66. data/lib/rspec/rails/example/system_example_group.rb +180 -0
  67. data/lib/rspec/rails/example/view_example_group.rb +179 -134
  68. data/lib/rspec/rails/example.rb +4 -0
  69. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -11
  70. data/lib/rspec/rails/feature_check.rb +51 -0
  71. data/lib/rspec/rails/file_fixture_support.rb +18 -0
  72. data/lib/rspec/rails/fixture_file_upload_support.rb +45 -0
  73. data/lib/rspec/rails/fixture_support.rb +70 -14
  74. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +180 -0
  75. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  76. data/lib/rspec/rails/matchers/action_cable.rb +70 -0
  77. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  78. data/lib/rspec/rails/matchers/active_job.rb +526 -0
  79. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  80. data/lib/rspec/rails/matchers/be_a_new.rb +70 -64
  81. data/lib/rspec/rails/matchers/be_new_record.rb +25 -20
  82. data/lib/rspec/rails/matchers/be_valid.rb +39 -34
  83. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +259 -0
  84. data/lib/rspec/rails/matchers/have_http_status.rb +359 -333
  85. data/lib/rspec/rails/matchers/have_rendered.rb +55 -32
  86. data/lib/rspec/rails/matchers/redirect_to.rb +30 -27
  87. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  88. data/lib/rspec/rails/matchers/routing_matchers.rb +107 -101
  89. data/lib/rspec/rails/matchers/send_email.rb +122 -0
  90. data/lib/rspec/rails/matchers.rb +21 -12
  91. data/lib/rspec/rails/tasks/rspec.rake +9 -17
  92. data/lib/rspec/rails/vendor/capybara.rb +10 -11
  93. data/lib/rspec/rails/version.rb +1 -1
  94. data/lib/rspec/rails/view_assigns.rb +1 -20
  95. data/lib/rspec/rails/view_path_builder.rb +29 -0
  96. data/lib/rspec/rails/view_rendering.rb +89 -27
  97. data/lib/rspec/rails/view_spec_methods.rb +56 -0
  98. data/lib/rspec/rails.rb +9 -1
  99. data/lib/rspec-rails.rb +83 -3
  100. data.tar.gz.sig +0 -0
  101. metadata +108 -78
  102. metadata.gz.sig +3 -2
  103. data/lib/generators/rspec/integration/integration_generator.rb +0 -17
  104. data/lib/generators/rspec/integration/templates/request_spec.rb +0 -10
  105. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -1,8 +1,11 @@
1
- module RSpec::Rails
2
- # Container class for model spec functionality. Does not provide anything
3
- # special over the common RailsExampleGroup currently.
4
- module ModelExampleGroup
5
- extend ActiveSupport::Concern
6
- include RSpec::Rails::RailsExampleGroup
1
+ module RSpec
2
+ module Rails
3
+ # @api public
4
+ # Container class for model spec functionality. Does not provide anything
5
+ # special over the common RailsExampleGroup currently.
6
+ module ModelExampleGroup
7
+ extend ActiveSupport::Concern
8
+ include RSpec::Rails::RailsExampleGroup
9
+ end
7
10
  end
8
11
  end
@@ -2,15 +2,22 @@
2
2
  # suite and ammeter.
3
3
  require 'rspec/rails/matchers'
4
4
 
5
+ require 'active_support/current_attributes/test_helper'
6
+ require 'active_support/execution_context/test_helper'
7
+
5
8
  module RSpec
6
9
  module Rails
10
+ # @api public
7
11
  # Common rails example functionality.
8
12
  module RailsExampleGroup
9
13
  extend ActiveSupport::Concern
10
14
  include RSpec::Rails::SetupAndTeardownAdapter
11
- include RSpec::Rails::MinitestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
15
+ include RSpec::Rails::MinitestLifecycleAdapter
12
16
  include RSpec::Rails::MinitestAssertionAdapter
13
- include RSpec::Rails::Matchers
17
+ include RSpec::Rails::FixtureSupport
18
+ include RSpec::Rails::TaggedLoggingAdapter
19
+ include ActiveSupport::CurrentAttributes::TestHelper
20
+ include ActiveSupport::ExecutionContext::TestHelper
14
21
  end
15
22
  end
16
23
  end
@@ -1,22 +1,26 @@
1
- module RSpec::Rails
2
- # Container class for request spec functionality.
3
- module RequestExampleGroup
4
- extend ActiveSupport::Concern
5
- include RSpec::Rails::RailsExampleGroup
6
- include ActionDispatch::Integration::Runner
7
- include ActionDispatch::Assertions
8
- include RSpec::Rails::Matchers::RedirectTo
9
- include RSpec::Rails::Matchers::RenderTemplate
10
- include ActionController::TemplateAssertions
1
+ module RSpec
2
+ module Rails
3
+ # @api public
4
+ # Container class for request spec functionality.
5
+ module RequestExampleGroup
6
+ extend ActiveSupport::Concern
7
+ include RSpec::Rails::RailsExampleGroup
8
+ include ActionDispatch::Integration::Runner
9
+ include ActionDispatch::Assertions
10
+ include RSpec::Rails::Matchers::RedirectTo
11
+ include RSpec::Rails::Matchers::RenderTemplate
12
+ include ActionController::TemplateAssertions
13
+ include ActionDispatch::IntegrationTest::Behavior
11
14
 
12
- # Delegates to `Rails.application`.
13
- def app
14
- ::Rails.application
15
- end
15
+ # Delegates to `Rails.application`.
16
+ def app
17
+ ::Rails.application
18
+ end
16
19
 
17
- included do
18
- before do
19
- @routes = ::Rails.application.routes
20
+ included do
21
+ before do
22
+ @routes = ::Rails.application.routes
23
+ end
20
24
  end
21
25
  end
22
26
  end
@@ -1,53 +1,61 @@
1
- require "action_dispatch/testing/assertions/routing"
1
+ module RSpec
2
+ module Rails
3
+ # @private
4
+ RoutingAssertionDelegator = RSpec::Rails::AssertionDelegator.new(
5
+ ActionDispatch::Assertions::RoutingAssertions
6
+ )
2
7
 
3
- module RSpec::Rails
4
- # Container module for routing spec functionality.
5
- module RoutingExampleGroup
6
- extend ActiveSupport::Concern
7
- include RSpec::Rails::RailsExampleGroup
8
- include RSpec::Rails::Matchers::RoutingMatchers
9
- include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
10
- include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
8
+ # @api public
9
+ # Container module for routing spec functionality.
10
+ module RoutingExampleGroup
11
+ extend ActiveSupport::Concern
12
+ include RSpec::Rails::RailsExampleGroup
13
+ include RSpec::Rails::Matchers::RoutingMatchers
14
+ include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
15
+ include RSpec::Rails::RoutingAssertionDelegator
11
16
 
12
- # Class-level DSL for route specs.
13
- module ClassMethods
14
- # Specifies the routeset that will be used for the example group. This
15
- # is most useful when testing Rails engines.
16
- #
17
- # @example
18
- # describe MyEngine::PostsController do
19
- # routes { MyEngine::Engine.routes }
20
- #
21
- # it "routes posts#index" do
22
- # expect(:get => "/posts").to
23
- # route_to(:controller => "my_engine/posts", :action => "index")
24
- # end
25
- # end
26
- def routes(&blk)
27
- before do
28
- self.routes = blk.call
17
+ # Class-level DSL for route specs.
18
+ module ClassMethods
19
+ # Specifies the routeset that will be used for the example group. This
20
+ # is most useful when testing Rails engines.
21
+ #
22
+ # @example
23
+ # describe MyEngine::PostsController do
24
+ # routes { MyEngine::Engine.routes }
25
+ #
26
+ # it "routes posts#index" do
27
+ # expect(:get => "/posts").to
28
+ # route_to(:controller => "my_engine/posts", :action => "index")
29
+ # end
30
+ # end
31
+ def routes
32
+ before do
33
+ self.routes = yield
34
+ end
29
35
  end
30
36
  end
31
- end
32
37
 
33
- included do
34
- before do
35
- self.routes = ::Rails.application.routes
38
+ included do
39
+ before do
40
+ self.routes = ::Rails.application.routes
41
+ end
36
42
  end
37
- end
38
43
 
39
- attr_reader :routes
44
+ # @!attribute [r]
45
+ # @private
46
+ attr_reader :routes
40
47
 
41
- # @private
42
- def routes=(routes)
43
- @routes = routes
44
- assertion_instance.instance_variable_set(:@routes, routes)
45
- end
48
+ # @private
49
+ def routes=(routes)
50
+ @routes = routes
51
+ assertion_instance.instance_variable_set(:@routes, routes)
52
+ end
46
53
 
47
54
  private
48
55
 
49
- def method_missing(m, *args, &block)
50
- routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
56
+ def method_missing(m, *args, &block)
57
+ routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
58
+ end
51
59
  end
52
60
  end
53
61
  end
@@ -0,0 +1,180 @@
1
+ module RSpec
2
+ module Rails
3
+ # @api public
4
+ # Container class for system tests
5
+ module SystemExampleGroup
6
+ extend ActiveSupport::Concern
7
+ include RSpec::Rails::RailsExampleGroup
8
+ include RSpec::Rails::Matchers::RedirectTo
9
+ include RSpec::Rails::Matchers::RenderTemplate
10
+ include ActionDispatch::Integration::Runner
11
+ include ActionDispatch::Assertions
12
+ include ActionController::TemplateAssertions
13
+
14
+ # Special characters to translate into underscores for #method_name
15
+ CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
16
+
17
+ # @private
18
+ module BlowAwayTeardownHooks
19
+ # @private
20
+ def before_teardown
21
+ end
22
+
23
+ # @private
24
+ def after_teardown
25
+ end
26
+ end
27
+
28
+ # for the SystemTesting Screenshot situation
29
+ def passed?
30
+ return false if RSpec.current_example.exception
31
+ return true unless defined?(::RSpec::Expectations::FailureAggregator)
32
+
33
+ failure_notifier = ::RSpec::Support.failure_notifier
34
+ return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
35
+
36
+ failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
37
+ end
38
+
39
+ # @private
40
+ def method_name
41
+ @method_name ||= [
42
+ self.class.name.underscore,
43
+ RSpec.current_example.description.underscore
44
+ ].join("_").tr(CHARS_TO_TRANSLATE.join, "_").byteslice(0...200).scrub("") + "_#{rand(1000)}"
45
+ end
46
+
47
+ if ::Rails::VERSION::STRING.to_f >= 7.1
48
+ # @private
49
+ # Allows failure screenshot to work whilst not exposing metadata
50
+ class SuppressRailsScreenshotMetadata
51
+ def initialize
52
+ @example_data = {}
53
+ end
54
+
55
+ def [](key)
56
+ if @example_data.key?(key)
57
+ @example_data[key]
58
+ else
59
+ raise_wrong_scope_error
60
+ end
61
+ end
62
+
63
+ def []=(key, value)
64
+ if key == :failure_screenshot_path
65
+ @example_data[key] = value
66
+ else
67
+ raise_wrong_scope_error
68
+ end
69
+ end
70
+
71
+ def method_missing(_name, *_args, &_block)
72
+ raise_wrong_scope_error
73
+ end
74
+
75
+ private
76
+
77
+ def raise_wrong_scope_error
78
+ raise RSpec::Core::ExampleGroup::WrongScopeError,
79
+ "`metadata` is not available from within an example " \
80
+ "(e.g. an `it` block) or from constructs that run in the " \
81
+ "scope of an example (e.g. `before`, `let`, etc). It is " \
82
+ "only available on an example group (e.g. a `describe` or "\
83
+ "`context` block)"
84
+ end
85
+ end
86
+
87
+ # @private
88
+ def metadata
89
+ @metadata ||= SuppressRailsScreenshotMetadata.new
90
+ end
91
+ end
92
+
93
+ # Delegates to `Rails.application`.
94
+ def app
95
+ ::Rails.application
96
+ end
97
+
98
+ # Default driver to assign if none specified.
99
+ DEFAULT_DRIVER =
100
+ if ::Rails::VERSION::STRING.to_f >= 7.2
101
+ :selenium_chrome_headless
102
+ else
103
+ :selenium
104
+ end
105
+
106
+ included do |other|
107
+ ActiveSupport.on_load(:action_dispatch_system_test_case) do
108
+ ActionDispatch::SystemTesting::Server.silence_puma = true
109
+ end
110
+
111
+ require 'action_dispatch/system_test_case'
112
+
113
+ begin
114
+ require 'capybara'
115
+ rescue LoadError => e
116
+ abort """
117
+ LoadError: #{e.message}
118
+ System test integration has a hard
119
+ dependency on a webserver and `capybara`, please add capybara to
120
+ your Gemfile and configure a webserver (e.g. `Capybara.server =
121
+ :puma`) before attempting to use system specs.
122
+ """.gsub(/\s+/, ' ').strip
123
+ end
124
+
125
+ original_before_teardown =
126
+ ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:before_teardown)
127
+
128
+ original_after_teardown =
129
+ ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
130
+
131
+ other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
132
+ other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
133
+ other.include BlowAwayTeardownHooks
134
+
135
+ attr_reader :driver
136
+
137
+ if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=)
138
+ ActionDispatch::SystemTesting::Server.silence_puma = true
139
+ end
140
+
141
+ def initialize(*args, &blk)
142
+ super(*args, &blk)
143
+ @driver = nil
144
+
145
+ self.class.before do
146
+ # A user may have already set the driver, so only default if driver
147
+ # is not set
148
+ driven_by(DEFAULT_DRIVER) unless @driver
149
+ end
150
+ end
151
+
152
+ def driven_by(driver, **driver_options, &blk)
153
+ @driver = ::ActionDispatch::SystemTestCase.driven_by(driver, **driver_options, &blk).tap(&:use)
154
+ end
155
+
156
+ before do
157
+ @routes = ::Rails.application.routes
158
+ end
159
+
160
+ after do
161
+ orig_stdout = $stdout
162
+ $stdout = StringIO.new
163
+ begin
164
+ original_before_teardown.bind(self).call
165
+ ensure
166
+ myio = $stdout
167
+ myio.rewind
168
+ RSpec.current_example.metadata[:extra_failure_lines] = myio.readlines
169
+ $stdout = orig_stdout
170
+ end
171
+ end
172
+
173
+ around do |example|
174
+ example.run
175
+ original_after_teardown.bind(self).call
176
+ end
177
+ end
178
+ end
179
+ end
180
+ end