rspec-rails 1.3.2 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (269) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data/.document +4 -6
  4. data/.yardopts +11 -0
  5. data/Capybara.md +28 -0
  6. data/Changelog.md +1286 -0
  7. data/LICENSE.md +25 -0
  8. data/README.md +381 -0
  9. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  10. data/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
  11. data/lib/generators/rspec/controller/controller_generator.rb +51 -0
  12. data/lib/generators/rspec/controller/templates/controller_spec.rb +16 -0
  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 +5 -0
  16. data/lib/generators/rspec/feature/feature_generator.rb +29 -0
  17. data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
  18. data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  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 +16 -0
  22. data/lib/generators/rspec/helper/templates/helper_spec.rb +17 -0
  23. data/lib/generators/rspec/install/install_generator.rb +80 -0
  24. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +84 -0
  25. data/lib/generators/rspec/integration/integration_generator.rb +29 -0
  26. data/lib/generators/rspec/job/job_generator.rb +13 -0
  27. data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  28. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  29. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  30. data/lib/generators/rspec/mailer/mailer_generator.rb +30 -0
  31. data/lib/generators/rspec/mailer/templates/fixture +3 -0
  32. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +25 -0
  33. data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
  34. data/lib/generators/rspec/model/model_generator.rb +37 -0
  35. data/lib/generators/rspec/model/templates/fixtures.yml +19 -0
  36. data/lib/generators/rspec/model/templates/model_spec.rb +7 -0
  37. data/lib/generators/rspec/request/request_generator.rb +17 -0
  38. data/lib/generators/rspec/request/templates/request_spec.rb +10 -0
  39. data/lib/generators/rspec/scaffold/scaffold_generator.rb +136 -0
  40. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
  41. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  42. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +160 -0
  43. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +27 -0
  44. data/lib/generators/rspec/scaffold/templates/index_spec.rb +26 -0
  45. data/lib/generators/rspec/scaffold/templates/new_spec.rb +22 -0
  46. data/lib/generators/rspec/scaffold/templates/request_spec.rb +153 -0
  47. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +46 -0
  48. data/lib/generators/rspec/scaffold/templates/show_spec.rb +21 -0
  49. data/lib/generators/rspec/system/system_generator.rb +24 -0
  50. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  51. data/lib/generators/rspec/view/templates/view_spec.rb +5 -0
  52. data/lib/generators/rspec/view/view_generator.rb +22 -0
  53. data/lib/generators/rspec.rb +56 -0
  54. data/lib/rspec/rails/active_record.rb +25 -0
  55. data/lib/rspec/rails/adapters.rb +196 -0
  56. data/lib/rspec/rails/configuration.rb +222 -0
  57. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  58. data/lib/rspec/rails/example/controller_example_group.rb +217 -0
  59. data/lib/rspec/rails/example/feature_example_group.rb +53 -0
  60. data/lib/rspec/rails/example/helper_example_group.rb +42 -0
  61. data/lib/rspec/rails/example/job_example_group.rb +23 -0
  62. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  63. data/lib/rspec/rails/example/mailer_example_group.rb +38 -0
  64. data/lib/rspec/rails/example/model_example_group.rb +11 -0
  65. data/lib/rspec/rails/example/rails_example_group.rb +25 -0
  66. data/lib/rspec/rails/example/request_example_group.rb +27 -0
  67. data/lib/rspec/rails/example/routing_example_group.rb +61 -0
  68. data/lib/rspec/rails/example/system_example_group.rb +172 -0
  69. data/lib/rspec/rails/example/view_example_group.rb +214 -0
  70. data/lib/rspec/rails/example.rb +13 -0
  71. data/lib/rspec/rails/extensions/active_record/proxy.rb +11 -0
  72. data/lib/rspec/rails/extensions.rb +1 -0
  73. data/lib/rspec/rails/feature_check.rb +51 -0
  74. data/lib/rspec/rails/file_fixture_support.rb +18 -0
  75. data/lib/rspec/rails/fixture_file_upload_support.rb +45 -0
  76. data/lib/rspec/rails/fixture_support.rb +89 -0
  77. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +173 -0
  78. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  79. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  80. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  81. data/lib/rspec/rails/matchers/active_job.rb +465 -0
  82. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  83. data/lib/rspec/rails/matchers/be_a_new.rb +83 -0
  84. data/lib/rspec/rails/matchers/be_new_record.rb +30 -0
  85. data/lib/rspec/rails/matchers/be_valid.rb +49 -0
  86. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +227 -0
  87. data/lib/rspec/rails/matchers/have_http_status.rb +385 -0
  88. data/lib/rspec/rails/matchers/have_rendered.rb +64 -0
  89. data/lib/rspec/rails/matchers/redirect_to.rb +38 -0
  90. data/lib/rspec/rails/matchers/relation_match_array.rb +3 -0
  91. data/lib/rspec/rails/matchers/routing_matchers.rb +125 -0
  92. data/lib/rspec/rails/matchers/send_email.rb +122 -0
  93. data/lib/rspec/rails/matchers.rb +36 -0
  94. data/lib/rspec/rails/tasks/rspec.rake +47 -0
  95. data/lib/rspec/rails/vendor/capybara.rb +32 -0
  96. data/lib/rspec/rails/version.rb +9 -0
  97. data/lib/rspec/rails/view_assigns.rb +27 -0
  98. data/lib/rspec/rails/view_path_builder.rb +29 -0
  99. data/lib/rspec/rails/view_rendering.rb +166 -0
  100. data/lib/rspec/rails/view_spec_methods.rb +56 -0
  101. data/lib/rspec/rails.rb +18 -0
  102. data/lib/rspec-rails.rb +80 -0
  103. data.tar.gz.sig +2 -0
  104. metadata +308 -261
  105. metadata.gz.sig +0 -0
  106. data/Contribute.rdoc +0 -4
  107. data/History.rdoc +0 -302
  108. data/License.txt +0 -33
  109. data/Manifest.txt +0 -165
  110. data/README.rdoc +0 -45
  111. data/Rakefile +0 -72
  112. data/TODO.txt +0 -17
  113. data/Upgrade.rdoc +0 -148
  114. data/generators/integration_spec/integration_spec_generator.rb +0 -10
  115. data/generators/integration_spec/templates/integration_spec.rb +0 -4
  116. data/generators/rspec/CHANGES +0 -1
  117. data/generators/rspec/rspec_generator.rb +0 -72
  118. data/generators/rspec/templates/previous_failures.txt +0 -0
  119. data/generators/rspec/templates/rcov.opts +0 -2
  120. data/generators/rspec/templates/rspec.rake +0 -144
  121. data/generators/rspec/templates/script/autospec +0 -6
  122. data/generators/rspec/templates/script/spec +0 -10
  123. data/generators/rspec/templates/spec.opts +0 -4
  124. data/generators/rspec/templates/spec_helper.rb +0 -54
  125. data/generators/rspec_controller/USAGE +0 -33
  126. data/generators/rspec_controller/rspec_controller_generator.rb +0 -47
  127. data/generators/rspec_controller/templates/controller_spec.rb +0 -25
  128. data/generators/rspec_controller/templates/helper_spec.rb +0 -11
  129. data/generators/rspec_controller/templates/view_spec.rb +0 -12
  130. data/generators/rspec_default_values.rb +0 -28
  131. data/generators/rspec_model/USAGE +0 -18
  132. data/generators/rspec_model/rspec_model_generator.rb +0 -35
  133. data/generators/rspec_model/templates/model_spec.rb +0 -13
  134. data/generators/rspec_scaffold/rspec_scaffold_generator.rb +0 -154
  135. data/generators/rspec_scaffold/templates/controller_spec.rb +0 -131
  136. data/generators/rspec_scaffold/templates/edit_erb_spec.rb +0 -25
  137. data/generators/rspec_scaffold/templates/helper_spec.rb +0 -11
  138. data/generators/rspec_scaffold/templates/index_erb_spec.rb +0 -27
  139. data/generators/rspec_scaffold/templates/new_erb_spec.rb +0 -25
  140. data/generators/rspec_scaffold/templates/routing_spec.rb +0 -33
  141. data/generators/rspec_scaffold/templates/show_erb_spec.rb +0 -22
  142. data/init.rb +0 -9
  143. data/lib/autotest/discover.rb +0 -5
  144. data/lib/autotest/rails_rspec.rb +0 -76
  145. data/lib/spec/rails/example/assigns_hash_proxy.rb +0 -39
  146. data/lib/spec/rails/example/controller_example_group.rb +0 -285
  147. data/lib/spec/rails/example/cookies_proxy.rb +0 -29
  148. data/lib/spec/rails/example/functional_example_group.rb +0 -106
  149. data/lib/spec/rails/example/helper_example_group.rb +0 -153
  150. data/lib/spec/rails/example/integration_example_group.rb +0 -16
  151. data/lib/spec/rails/example/model_example_group.rb +0 -15
  152. data/lib/spec/rails/example/render_observer.rb +0 -80
  153. data/lib/spec/rails/example/routing_example_group.rb +0 -13
  154. data/lib/spec/rails/example/routing_helpers.rb +0 -66
  155. data/lib/spec/rails/example/view_example_group.rb +0 -199
  156. data/lib/spec/rails/example.rb +0 -48
  157. data/lib/spec/rails/extensions/action_controller/rescue.rb +0 -42
  158. data/lib/spec/rails/extensions/action_controller/test_case.rb +0 -16
  159. data/lib/spec/rails/extensions/action_controller/test_response.rb +0 -21
  160. data/lib/spec/rails/extensions/action_view/base.rb +0 -33
  161. data/lib/spec/rails/extensions/active_record/base.rb +0 -45
  162. data/lib/spec/rails/extensions/active_support/test_case.rb +0 -7
  163. data/lib/spec/rails/extensions/spec/matchers/have.rb +0 -23
  164. data/lib/spec/rails/extensions/spec/runner/configuration.rb +0 -44
  165. data/lib/spec/rails/extensions.rb +0 -11
  166. data/lib/spec/rails/interop/testcase.rb +0 -14
  167. data/lib/spec/rails/matchers/ar_be_valid.rb +0 -27
  168. data/lib/spec/rails/matchers/assert_select.rb +0 -180
  169. data/lib/spec/rails/matchers/change.rb +0 -13
  170. data/lib/spec/rails/matchers/have_text.rb +0 -57
  171. data/lib/spec/rails/matchers/include_text.rb +0 -54
  172. data/lib/spec/rails/matchers/redirect_to.rb +0 -126
  173. data/lib/spec/rails/matchers/render_template.rb +0 -129
  174. data/lib/spec/rails/matchers/route_to.rb +0 -149
  175. data/lib/spec/rails/matchers.rb +0 -32
  176. data/lib/spec/rails/mocks.rb +0 -136
  177. data/lib/spec/rails/version.rb +0 -16
  178. data/lib/spec/rails.rb +0 -26
  179. data/spec/autotest/mappings_spec.rb +0 -86
  180. data/spec/rails_suite.rb +0 -7
  181. data/spec/resources/controllers/action_view_base_spec_controller.rb +0 -2
  182. data/spec/resources/controllers/application.rb +0 -9
  183. data/spec/resources/controllers/controller_spec_controller.rb +0 -127
  184. data/spec/resources/controllers/example.txt +0 -1
  185. data/spec/resources/controllers/redirect_spec_controller.rb +0 -70
  186. data/spec/resources/controllers/render_spec_controller.rb +0 -34
  187. data/spec/resources/controllers/rjs_spec_controller.rb +0 -58
  188. data/spec/resources/helpers/addition_helper.rb +0 -5
  189. data/spec/resources/helpers/explicit_helper.rb +0 -46
  190. data/spec/resources/helpers/more_explicit_helper.rb +0 -5
  191. data/spec/resources/helpers/plugin_application_helper.rb +0 -6
  192. data/spec/resources/helpers/view_spec_helper.rb +0 -13
  193. data/spec/resources/models/animal.rb +0 -4
  194. data/spec/resources/models/person.rb +0 -18
  195. data/spec/resources/models/thing.rb +0 -3
  196. data/spec/resources/views/controller_spec/_partial.html.erb +0 -0
  197. data/spec/resources/views/controller_spec/action_setting_flash_after_session_reset.html.erb +0 -1
  198. data/spec/resources/views/controller_spec/action_setting_flash_before_session_reset.html.erb +0 -1
  199. data/spec/resources/views/controller_spec/action_setting_the_assigns_hash.html.erb +0 -0
  200. data/spec/resources/views/controller_spec/action_with_errors_in_template.html.erb +0 -1
  201. data/spec/resources/views/controller_spec/action_with_template.html.erb +0 -1
  202. data/spec/resources/views/layouts/application.html.erb +0 -0
  203. data/spec/resources/views/layouts/simple.html.erb +0 -0
  204. data/spec/resources/views/objects/_object.html.erb +0 -1
  205. data/spec/resources/views/render_spec/_a_partial.html.erb +0 -0
  206. data/spec/resources/views/render_spec/action_with_alternate_layout.html.erb +0 -0
  207. data/spec/resources/views/render_spec/some_action.html.erb +0 -0
  208. data/spec/resources/views/render_spec/some_action.js.rjs +0 -1
  209. data/spec/resources/views/rjs_spec/_replacement_partial.html.erb +0 -1
  210. data/spec/resources/views/rjs_spec/hide_div.js.rjs +0 -1
  211. data/spec/resources/views/rjs_spec/hide_page_element.js.rjs +0 -1
  212. data/spec/resources/views/rjs_spec/insert_html.js.rjs +0 -1
  213. data/spec/resources/views/rjs_spec/replace.js.rjs +0 -1
  214. data/spec/resources/views/rjs_spec/replace_html.js.rjs +0 -1
  215. data/spec/resources/views/rjs_spec/replace_html_with_partial.js.rjs +0 -1
  216. data/spec/resources/views/rjs_spec/visual_effect.js.rjs +0 -1
  217. data/spec/resources/views/rjs_spec/visual_toggle_effect.js.rjs +0 -1
  218. data/spec/resources/views/tag_spec/no_tags.html.erb +0 -1
  219. data/spec/resources/views/tag_spec/single_div_with_no_attributes.html.erb +0 -1
  220. data/spec/resources/views/tag_spec/single_div_with_one_attribute.html.erb +0 -1
  221. data/spec/resources/views/view_spec/_partial.html.erb +0 -2
  222. data/spec/resources/views/view_spec/_partial_used_twice.html.erb +0 -0
  223. data/spec/resources/views/view_spec/_partial_with_local_variable.html.erb +0 -1
  224. data/spec/resources/views/view_spec/_partial_with_sub_partial.html.erb +0 -1
  225. data/spec/resources/views/view_spec/_spacer.html.erb +0 -1
  226. data/spec/resources/views/view_spec/accessor.html.erb +0 -6
  227. data/spec/resources/views/view_spec/block_helper.html.erb +0 -3
  228. data/spec/resources/views/view_spec/entry_form.html.erb +0 -2
  229. data/spec/resources/views/view_spec/explicit_helper.html.erb +0 -2
  230. data/spec/resources/views/view_spec/foo/show.html.erb +0 -1
  231. data/spec/resources/views/view_spec/implicit_helper.html.erb +0 -2
  232. data/spec/resources/views/view_spec/multiple_helpers.html.erb +0 -3
  233. data/spec/resources/views/view_spec/path_params.html.erb +0 -1
  234. data/spec/resources/views/view_spec/should_not_receive.html.erb +0 -3
  235. data/spec/resources/views/view_spec/template_with_partial.html.erb +0 -5
  236. data/spec/resources/views/view_spec/template_with_partial_using_collection.html.erb +0 -3
  237. data/spec/resources/views/view_spec/template_with_partial_with_array.html.erb +0 -1
  238. data/spec/resources/views/view_spec/view_helpers.html.erb +0 -1
  239. data/spec/spec/rails/example/assigns_hash_proxy_spec.rb +0 -109
  240. data/spec/spec/rails/example/configuration_spec.rb +0 -65
  241. data/spec/spec/rails/example/controller_example_group_spec.rb +0 -307
  242. data/spec/spec/rails/example/controller_isolation_spec.rb +0 -75
  243. data/spec/spec/rails/example/cookies_proxy_spec.rb +0 -87
  244. data/spec/spec/rails/example/error_handling_spec.rb +0 -90
  245. data/spec/spec/rails/example/example_group_factory_spec.rb +0 -112
  246. data/spec/spec/rails/example/helper_example_group_spec.rb +0 -233
  247. data/spec/spec/rails/example/model_example_group_spec.rb +0 -32
  248. data/spec/spec/rails/example/routing_example_group_spec.rb +0 -10
  249. data/spec/spec/rails/example/shared_routing_example_group_examples.rb +0 -237
  250. data/spec/spec/rails/example/test_unit_assertion_accessibility_spec.rb +0 -33
  251. data/spec/spec/rails/example/view_example_group_spec.rb +0 -346
  252. data/spec/spec/rails/extensions/action_view_base_spec.rb +0 -74
  253. data/spec/spec/rails/extensions/active_record_spec.rb +0 -14
  254. data/spec/spec/rails/interop/testcase_spec.rb +0 -70
  255. data/spec/spec/rails/matchers/ar_be_valid_spec.rb +0 -19
  256. data/spec/spec/rails/matchers/assert_select_spec.rb +0 -835
  257. data/spec/spec/rails/matchers/errors_on_spec.rb +0 -37
  258. data/spec/spec/rails/matchers/have_text_spec.rb +0 -69
  259. data/spec/spec/rails/matchers/include_text_spec.rb +0 -62
  260. data/spec/spec/rails/matchers/redirect_to_spec.rb +0 -253
  261. data/spec/spec/rails/matchers/render_template_spec.rb +0 -208
  262. data/spec/spec/rails/matchers/should_change_spec.rb +0 -15
  263. data/spec/spec/rails/mocks/ar_classes.rb +0 -10
  264. data/spec/spec/rails/mocks/mock_model_spec.rb +0 -109
  265. data/spec/spec/rails/mocks/stub_model_spec.rb +0 -80
  266. data/spec/spec/rails/sample_modified_fixture.rb +0 -8
  267. data/spec/spec/rails/sample_spec.rb +0 -8
  268. data/spec/spec/rails/spec_spec.rb +0 -11
  269. data/spec/spec_helper.rb +0 -78
@@ -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 any 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,47 @@
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
+ task stats: "spec:statsetup"
9
+
10
+ desc "Run all specs in spec directory (excluding plugin specs)"
11
+ RSpec::Core::RakeTask.new(spec: "spec:prepare")
12
+
13
+ namespace :spec do
14
+ types = begin
15
+ dirs = Dir['./spec/**/*_spec.rb']
16
+ .map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }
17
+ .uniq
18
+ .select { |f| File.directory?(f) }
19
+ Hash[dirs.map { |d| [d.split('/').last, d] }]
20
+ end
21
+
22
+ task :prepare do
23
+ ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
24
+ if Rails.configuration.generators.options[:rails][:orm] == :active_record
25
+ if Rake::Task.task_defined?("test:prepare")
26
+ Rake::Task["test:prepare"].invoke
27
+ end
28
+ end
29
+ end
30
+
31
+ types.each do |type, dir|
32
+ desc "Run the code examples in #{dir}"
33
+ RSpec::Core::RakeTask.new(type => "spec:prepare") do |t|
34
+ t.pattern = "./#{dir}/**/*_spec.rb"
35
+ end
36
+ end
37
+
38
+ task :statsetup do
39
+ require 'rails/code_statistics'
40
+ types.each do |type, dir|
41
+ name = type.singularize.capitalize
42
+
43
+ ::STATS_DIRECTORIES << ["#{name} specs", dir]
44
+ ::CodeStatistics::TEST_TYPES << "#{name} specs"
45
+ end
46
+ end
47
+ 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 = '6.1.2'
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,80 @@
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
+ generators = config.app_generators
13
+ generators.integration_tool :rspec
14
+ generators.test_framework :rspec
15
+
16
+ generators do
17
+ ::Rails::Generators.hidden_namespaces.reject! { |namespace| namespace.to_s.start_with?("rspec") }
18
+ end
19
+
20
+ rake_tasks do
21
+ load "rspec/rails/tasks/rspec.rake"
22
+ end
23
+
24
+ # This is called after the environment has been loaded but before Rails
25
+ # sets the default for the `preview_path`
26
+ initializer "rspec_rails.action_mailer",
27
+ before: "action_mailer.set_configs" do |app|
28
+ setup_preview_path(app)
29
+ end
30
+
31
+ private
32
+
33
+ def setup_preview_path(app)
34
+ return unless supports_action_mailer_previews?(app.config)
35
+
36
+ options = app.config.action_mailer
37
+ config_default_preview_path(options) if config_preview_path?(options)
38
+ end
39
+
40
+ def config_preview_path?(options)
41
+ # We cannot use `respond_to?(:show_previews)` here as it will always
42
+ # return `true`.
43
+ if options.show_previews.nil?
44
+ options.show_previews = ::Rails.env.development?
45
+ else
46
+ options.show_previews
47
+ end
48
+ end
49
+
50
+ if ::Rails::VERSION::STRING >= "7.1.0"
51
+ def config_default_preview_path(options)
52
+ return unless options.preview_paths.empty?
53
+
54
+ options.preview_paths << "#{::Rails.root}/spec/mailers/previews"
55
+ end
56
+ else
57
+ def config_default_preview_path(options)
58
+ return unless options.preview_path.blank?
59
+
60
+ options.preview_path = "#{::Rails.root}/spec/mailers/previews"
61
+ end
62
+ end
63
+
64
+ def supports_action_mailer_previews?(config)
65
+ # These checks avoid loading `ActionMailer`. Using `defined?` has the
66
+ # side-effect of the class getting loaded if it is available. This is
67
+ # problematic because loading `ActionMailer::Base` will cause it to
68
+ # read the config settings; this is the only time the config is read.
69
+ # If the config is loaded now, any settings declared in a config block
70
+ # in an initializer will be ignored.
71
+ #
72
+ # If the action mailer railtie has not been loaded then `config` will
73
+ # not respond to the method. However, we cannot use
74
+ # `config.action_mailer.respond_to?(:preview_path)` here as it will
75
+ # always return `true`.
76
+ config.respond_to?(:action_mailer)
77
+ end
78
+ end
79
+ end
80
+ end
data.tar.gz.sig ADDED
@@ -0,0 +1,2 @@
1
+ ��q��c��Y��PC�'{ޮSD��)5C���,���*no�G]=6��<0Ĺ���1gO�‹�'[<_�Cf'�� ��ې�h
2
+ �p�9=���}f�Ͽ��`�U�L��pi�p@y���K�Y����R�cszu-��_�cU4�>��7A�,���u=ϣ=�.zp������gg�[��Vo��dTgr�K�Tao�ȇ��Dҹ����w(�k9IwV7���p޼C/y�|��=�ȿ���J���Dh��}���� 9��R\qNa?8"�������MSm��x��"̊��br]�ӳ�``G԰ Jr?��n�*�}p[��Q#o��|HT]����ߧ�ʋc9��T4Z��G� �P=(��'r��4���1���,�8Q($���̵��҉X�����Y����%�x��]�mp��r>�=�bEַGo��k�� t-s�Ӻ�nv(�A���z����Yڽ��F�H%���eY�� l-�� z��p�G!��shY��2sKv��"�R�nK<�