rspec-rails 3.6.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (89) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data/Capybara.md +5 -54
  4. data/Changelog.md +391 -68
  5. data/README.md +280 -527
  6. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  7. data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
  8. data/lib/generators/rspec/controller/controller_generator.rb +24 -7
  9. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  10. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  11. data/lib/generators/rspec/feature/feature_generator.rb +5 -5
  12. data/lib/generators/rspec/generator/generator_generator.rb +24 -0
  13. data/lib/generators/rspec/generator/templates/generator_spec.rb +6 -0
  14. data/lib/generators/rspec/helper/helper_generator.rb +2 -2
  15. data/lib/generators/rspec/install/install_generator.rb +23 -6
  16. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +25 -13
  17. data/lib/generators/rspec/integration/integration_generator.rb +13 -6
  18. data/lib/generators/rspec/job/job_generator.rb +2 -1
  19. data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
  20. data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
  21. data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
  22. data/lib/generators/rspec/mailer/mailer_generator.rb +5 -4
  23. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
  24. data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
  25. data/lib/generators/rspec/model/model_generator.rb +8 -7
  26. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  27. data/lib/generators/rspec/request/request_generator.rb +10 -3
  28. data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +1 -1
  29. data/lib/generators/rspec/scaffold/scaffold_generator.rb +50 -26
  30. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +15 -51
  31. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  32. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +32 -65
  33. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -9
  34. data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -2
  35. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
  36. data/lib/generators/rspec/scaffold/templates/request_spec.rb +153 -0
  37. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +10 -13
  38. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  39. data/lib/generators/rspec/system/system_generator.rb +24 -0
  40. data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
  41. data/lib/generators/rspec/view/view_generator.rb +4 -4
  42. data/lib/generators/rspec.rb +16 -5
  43. data/lib/rspec/rails/active_record.rb +1 -1
  44. data/lib/rspec/rails/adapters.rb +21 -76
  45. data/lib/rspec/rails/configuration.rb +86 -35
  46. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  47. data/lib/rspec/rails/example/controller_example_group.rb +5 -4
  48. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  49. data/lib/rspec/rails/example/helper_example_group.rb +2 -9
  50. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  51. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  52. data/lib/rspec/rails/example/rails_example_group.rb +2 -1
  53. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  54. data/lib/rspec/rails/example/system_example_group.rb +126 -0
  55. data/lib/rspec/rails/example/view_example_group.rb +47 -28
  56. data/lib/rspec/rails/example.rb +3 -0
  57. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
  58. data/lib/rspec/rails/feature_check.rb +16 -29
  59. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  60. data/lib/rspec/rails/fixture_file_upload_support.rb +39 -0
  61. data/lib/rspec/rails/fixture_support.rb +35 -32
  62. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
  63. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  64. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  65. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  66. data/lib/rspec/rails/matchers/active_job.rb +209 -25
  67. data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
  68. data/lib/rspec/rails/matchers/be_a_new.rb +6 -5
  69. data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
  70. data/lib/rspec/rails/matchers/be_valid.rb +1 -1
  71. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +227 -0
  72. data/lib/rspec/rails/matchers/have_http_status.rb +39 -18
  73. data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
  74. data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
  75. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  76. data/lib/rspec/rails/matchers/routing_matchers.rb +13 -13
  77. data/lib/rspec/rails/matchers.rb +11 -0
  78. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  79. data/lib/rspec/rails/vendor/capybara.rb +10 -13
  80. data/lib/rspec/rails/version.rb +1 -1
  81. data/lib/rspec/rails/view_assigns.rb +0 -18
  82. data/lib/rspec/rails/view_path_builder.rb +2 -2
  83. data/lib/rspec/rails/view_rendering.rb +10 -17
  84. data/lib/rspec/rails.rb +1 -0
  85. data/lib/rspec-rails.rb +10 -13
  86. data.tar.gz.sig +0 -0
  87. metadata +58 -35
  88. metadata.gz.sig +0 -0
  89. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -0,0 +1,153 @@
1
+ require 'rails_helper'
2
+
3
+ # This spec was generated by rspec-rails when you ran the scaffold generator.
4
+ # It demonstrates how one might use RSpec to test the controller code that
5
+ # was generated by Rails when you ran the scaffold generator.
6
+ #
7
+ # It assumes that the implementation code is generated by the rails scaffold
8
+ # generator. If you are using any extension libraries to generate different
9
+ # controller code, this generated spec may or may not pass.
10
+ #
11
+ # It only uses APIs available in rails and/or rspec-rails. There are a number
12
+ # of tools you can use to make these specs even more expressive, but we're
13
+ # sticking to rails and rspec-rails APIs to keep things simple and stable.
14
+
15
+ <% module_namespacing do -%>
16
+ RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
17
+ <% if mountable_engine? -%>
18
+ include Engine.routes.url_helpers
19
+ <% end -%>
20
+
21
+ # This should return the minimal set of attributes required to create a valid
22
+ # <%= class_name %>. As you add validations to <%= class_name %>, be sure to
23
+ # adjust the attributes here as well.
24
+ let(:valid_attributes) {
25
+ skip("Add a hash of attributes valid for your model")
26
+ }
27
+
28
+ let(:invalid_attributes) {
29
+ skip("Add a hash of attributes invalid for your model")
30
+ }
31
+
32
+ <% unless options[:singleton] -%>
33
+ describe "GET /index" do
34
+ it "renders a successful response" do
35
+ <%= class_name %>.create! valid_attributes
36
+ get <%= index_helper %>_url
37
+ expect(response).to be_successful
38
+ end
39
+ end
40
+ <% end -%>
41
+
42
+ describe "GET /show" do
43
+ it "renders a successful response" do
44
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
45
+ get <%= show_helper %>
46
+ expect(response).to be_successful
47
+ end
48
+ end
49
+
50
+ describe "GET /new" do
51
+ it "renders a successful response" do
52
+ get <%= new_helper %>
53
+ expect(response).to be_successful
54
+ end
55
+ end
56
+
57
+ describe "GET /edit" do
58
+ it "renders a successful response" do
59
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
60
+ get <%= edit_helper %>
61
+ expect(response).to be_successful
62
+ end
63
+ end
64
+
65
+ describe "POST /create" do
66
+ context "with valid parameters" do
67
+ it "creates a new <%= class_name %>" do
68
+ expect {
69
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
70
+ }.to change(<%= class_name %>, :count).by(1)
71
+ end
72
+
73
+ it "redirects to the created <%= singular_table_name %>" do
74
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
75
+ expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
76
+ end
77
+ end
78
+
79
+ context "with invalid parameters" do
80
+ it "does not create a new <%= class_name %>" do
81
+ expect {
82
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
83
+ }.to change(<%= class_name %>, :count).by(0)
84
+ end
85
+
86
+ <% if Rails.version.to_f < 7.0 %>
87
+ it "renders a successful response (i.e. to display the 'new' template)" do
88
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
89
+ expect(response).to be_successful
90
+ end
91
+ <% else %>
92
+ it "renders a response with 422 status (i.e. to display the 'new' template)" do
93
+ post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
94
+ expect(response).to have_http_status(:unprocessable_entity)
95
+ end
96
+ <% end %>
97
+ end
98
+ end
99
+
100
+ describe "PATCH /update" do
101
+ context "with valid parameters" do
102
+ let(:new_attributes) {
103
+ skip("Add a hash of attributes valid for your model")
104
+ }
105
+
106
+ it "updates the requested <%= singular_table_name %>" do
107
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
108
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
109
+ <%= file_name %>.reload
110
+ skip("Add assertions for updated state")
111
+ end
112
+
113
+ it "redirects to the <%= singular_table_name %>" do
114
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
115
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: new_attributes }
116
+ <%= file_name %>.reload
117
+ expect(response).to redirect_to(<%= singular_table_name %>_url(<%= file_name %>))
118
+ end
119
+ end
120
+
121
+ context "with invalid parameters" do
122
+ <% if Rails.version.to_f < 7.0 %>
123
+ it "renders a successful response (i.e. to display the 'edit' template)" do
124
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
125
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
126
+ expect(response).to be_successful
127
+ end
128
+ <% else %>
129
+ it "renders a response with 422 status (i.e. to display the 'edit' template)" do
130
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
131
+ patch <%= show_helper %>, params: { <%= singular_table_name %>: invalid_attributes }
132
+ expect(response).to have_http_status(:unprocessable_entity)
133
+ end
134
+ <% end %>
135
+ end
136
+ end
137
+
138
+ describe "DELETE /destroy" do
139
+ it "destroys the requested <%= singular_table_name %>" do
140
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
141
+ expect {
142
+ delete <%= show_helper %>
143
+ }.to change(<%= class_name %>, :count).by(-1)
144
+ end
145
+
146
+ it "redirects to the <%= table_name %> list" do
147
+ <%= file_name %> = <%= class_name %>.create! valid_attributes
148
+ delete <%= show_helper %>
149
+ expect(response).to redirect_to(<%= index_helper %>_url)
150
+ end
151
+ end
152
+ end
153
+ <% end -%>
@@ -3,47 +3,44 @@ require "rails_helper"
3
3
  <% module_namespacing do -%>
4
4
  RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:routing) %> do
5
5
  describe "routing" do
6
-
7
6
  <% unless options[:singleton] -%>
8
7
  it "routes to #index" do
9
- expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
8
+ expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index")
10
9
  end
11
10
 
12
11
  <% end -%>
13
12
  <% unless options[:api] -%>
14
13
  it "routes to #new" do
15
- expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
14
+ expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new")
16
15
  end
17
- <% end -%>
18
16
 
17
+ <% end -%>
19
18
  it "routes to #show" do
20
- expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1")
19
+ expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1")
21
20
  end
22
21
 
23
22
  <% unless options[:api] -%>
24
23
  it "routes to #edit" do
25
- expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1")
24
+ expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1")
26
25
  end
26
+
27
27
  <% end -%>
28
28
 
29
29
  it "routes to #create" do
30
- expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
30
+ expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
31
31
  end
32
32
 
33
33
  it "routes to #update via PUT" do
34
- expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
34
+ expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
35
35
  end
36
36
 
37
- <% if Rails::VERSION::STRING > '4' -%>
38
37
  it "routes to #update via PATCH" do
39
- expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1")
38
+ expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1")
40
39
  end
41
40
 
42
- <% end -%>
43
41
  it "routes to #destroy" do
44
- expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1")
42
+ expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1")
45
43
  end
46
-
47
44
  end
48
45
  end
49
46
  <% end -%>
@@ -3,9 +3,9 @@ require 'rails_helper'
3
3
  <% output_attributes = attributes.reject{|attribute| [:datetime, :timestamp, :time, :date].index(attribute.type) } -%>
4
4
  RSpec.describe "<%= ns_table_name %>/show", <%= type_metatag(:view) %> do
5
5
  before(:each) do
6
- @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
6
+ assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %>
7
7
  <% output_attributes.each_with_index do |attribute, attribute_index| -%>
8
- :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
8
+ <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%>
9
9
  <% end -%>
10
10
  <% if !output_attributes.empty? -%>
11
11
  ))
@@ -0,0 +1,24 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class SystemGenerator < Base
7
+ class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs"
8
+
9
+ def generate_system_spec
10
+ return unless options[:system_specs]
11
+
12
+ template template_name, target_path('system', class_path, filename)
13
+ end
14
+
15
+ def template_name
16
+ 'system_spec.rb'
17
+ end
18
+
19
+ def filename
20
+ "#{table_name}_spec.rb"
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:system) %> do
4
+ before do
5
+ driven_by(:rack_test)
6
+ end
7
+
8
+ pending "add some scenarios (or delete) #{__FILE__}"
9
+ end
@@ -4,17 +4,17 @@ module Rspec
4
4
  module Generators
5
5
  # @private
6
6
  class ViewGenerator < Base
7
- argument :actions, :type => :array, :default => [], :banner => "action action"
7
+ argument :actions, type: :array, default: [], banner: "action action"
8
8
 
9
- class_option :template_engine, :desc => "Template engine to generate view files"
9
+ class_option :template_engine, desc: "Template engine to generate view files"
10
10
 
11
11
  def create_view_specs
12
- empty_directory File.join("spec", "views", file_path)
12
+ empty_directory target_path("views", file_path)
13
13
 
14
14
  actions.each do |action|
15
15
  @action = action
16
16
  template 'view_spec.rb',
17
- File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
17
+ target_path("views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
18
18
  end
19
19
  end
20
20
  end
@@ -1,8 +1,9 @@
1
1
  require 'rails/generators/named_base'
2
+ require 'rspec/core'
2
3
  require 'rspec/rails/feature_check'
3
4
 
4
5
  # @private
5
- # Weirdly named generators namespace (should be `RSpec`) for compatability with
6
+ # Weirdly named generators namespace (should be `RSpec`) for compatibility with
6
7
  # rails loading.
7
8
  module Rspec
8
9
  # @private
@@ -19,10 +20,20 @@ module Rspec
19
20
  end
20
21
  end
21
22
 
22
- if ::Rails::VERSION::STRING < '3.1'
23
- def module_namespacing
24
- yield if block_given?
25
- end
23
+ # @private
24
+ # Load configuration from RSpec to ensure `--default-path` is set
25
+ def self.configuration
26
+ @configuration ||=
27
+ begin
28
+ configuration = RSpec.configuration
29
+ options = RSpec::Core::ConfigurationOptions.new({})
30
+ options.configure(configuration)
31
+ configuration
32
+ end
33
+ end
34
+
35
+ def target_path(*paths)
36
+ File.join(self.class.configuration.default_path, *paths)
26
37
  end
27
38
  end
28
39
  end
@@ -7,7 +7,7 @@ module RSpec
7
7
  def self.initialize_activerecord_configuration(config)
8
8
  config.before :suite do
9
9
  # This allows dynamic columns etc to be used on ActiveRecord models when creating instance_doubles
10
- if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks)
10
+ if defined?(ActiveRecord) && defined?(ActiveRecord::Base) && defined?(::RSpec::Mocks) && (::RSpec::Mocks.respond_to?(:configuration))
11
11
  ::RSpec::Mocks.configuration.when_declaring_verifying_double do |possible_model|
12
12
  target = possible_model.target
13
13
 
@@ -19,68 +19,15 @@ module RSpec
19
19
  end
20
20
  private_class_method :disable_testunit_autorun
21
21
 
22
- if ::Rails::VERSION::STRING >= '4.1.0'
23
- if defined?(Kernel.gem)
24
- gem 'minitest'
25
- else
26
- require 'minitest'
27
- end
28
- require 'minitest/assertions'
29
- # Constant aliased to either Minitest or TestUnit, depending on what is
30
- # loaded.
31
- Assertions = Minitest::Assertions
32
- elsif RUBY_VERSION >= '2.2.0'
33
- # Minitest / TestUnit has been removed from ruby core. However, we are
34
- # on an old Rails version and must load the appropriate gem
35
- if ::Rails::VERSION::STRING >= '4.0.0'
36
- # ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency
37
- # This gem has no `lib/minitest.rb` file.
38
- gem 'minitest' if defined?(Kernel.gem)
39
- require 'minitest/unit'
40
- Assertions = MiniTest::Assertions
41
- elsif ::Rails::VERSION::STRING >= '3.2.21'
42
- # TODO: Change the above check to >= '3.2.22' once it's released
43
- begin
44
- # Test::Unit "helpfully" sets up autoload for its `AutoRunner`.
45
- # While we do not reference it directly, when we load the `TestCase`
46
- # classes from AS (ActiveSupport), AS kindly references `AutoRunner`
47
- # for everyone.
48
- #
49
- # To handle this we need to pre-emptively load 'test/unit' and make
50
- # sure the version installed has `AutoRunner` (the 3.x line does to
51
- # date). If so, we turn the auto runner off.
52
- require 'test/unit'
53
- require 'test/unit/assertions'
54
- disable_testunit_autorun
55
- rescue LoadError => e
56
- raise LoadError, <<-ERR.squish, e.backtrace
57
- Ruby 2.2+ has removed test/unit from the core library. Rails
58
- requires this as a dependency. Please add test-unit gem to your
59
- Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})"
60
- ERR
61
- end
62
- Assertions = Test::Unit::Assertions
63
- else
64
- abort <<-MSG.squish
65
- Ruby 2.2+ is not supported on Rails #{::Rails::VERSION::STRING}.
66
- Check the Rails release notes for the appropriate update with
67
- support.
68
- MSG
69
- end
22
+ if defined?(Kernel.gem)
23
+ gem 'minitest'
70
24
  else
71
- begin
72
- require 'test/unit/assertions'
73
- rescue LoadError
74
- # work around for Rubinius not having a std std-lib
75
- require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
76
- require 'test/unit/assertions'
77
- end
78
- # Turn off test unit's auto runner for those using the gem
79
- disable_testunit_autorun
80
- # Constant aliased to either Minitest or TestUnit, depending on what is
81
- # loaded.
82
- Assertions = Test::Unit::Assertions
25
+ require 'minitest'
83
26
  end
27
+ require 'minitest/assertions'
28
+ # Constant aliased to either Minitest or TestUnit, depending on what is
29
+ # loaded.
30
+ Assertions = Minitest::Assertions
84
31
 
85
32
  # @private
86
33
  class AssertionDelegator < Module
@@ -103,6 +50,7 @@ module RSpec
103
50
  assertion_modules.each do |mod|
104
51
  mod.public_instance_methods.each do |method|
105
52
  next if method == :method_missing || method == "method_missing"
53
+
106
54
  define_method(method.to_sym) do |*args, &block|
107
55
  assertion_instance.send(method.to_sym, *args, &block)
108
56
  end
@@ -198,12 +146,11 @@ module RSpec
198
146
  # examples without exposing non-assertion methods in Test::Unit or
199
147
  # Minitest.
200
148
  def assertion_method_names
201
- methods = ::RSpec::Rails::Assertions.
202
- public_instance_methods.
203
- select do |m|
149
+ ::RSpec::Rails::Assertions
150
+ .public_instance_methods
151
+ .select do |m|
204
152
  m.to_s =~ /^(assert|flunk|refute)/
205
153
  end
206
- methods + test_unit_specific_methods
207
154
  end
208
155
 
209
156
  def define_assertion_delegators
@@ -213,18 +160,6 @@ module RSpec
213
160
  end
214
161
  end
215
162
  end
216
-
217
- # Starting on Rails 4, Minitest is the default testing framework so no
218
- # need to add TestUnit specific methods.
219
- if ::Rails::VERSION::STRING >= '4.0.0'
220
- def test_unit_specific_methods
221
- []
222
- end
223
- else
224
- def test_unit_specific_methods
225
- [:build_message]
226
- end
227
- end
228
163
  end
229
164
 
230
165
  class AssertionDelegator
@@ -246,5 +181,15 @@ module RSpec
246
181
  #
247
182
  # @private
248
183
  TestUnitAssertionAdapter = MinitestAssertionAdapter
184
+
185
+ # @private
186
+ module TaggedLoggingAdapter
187
+ require 'active_support/testing/tagged_logging'
188
+ include ActiveSupport::Testing::TaggedLogging
189
+
190
+ # Just a stub as TaggedLogging is calling `name`
191
+ def name
192
+ end
193
+ end
249
194
  end
250
195
  end
@@ -1,3 +1,4 @@
1
+ # rubocop: disable Metrics/ModuleLength
1
2
  module RSpec
2
3
  module Rails
3
4
  # Fake class to document RSpec Rails configuration options. In practice,
@@ -25,42 +26,47 @@ module RSpec
25
26
  #
26
27
  # @api private
27
28
  DIRECTORY_MAPPINGS = {
28
- :controller => %w[spec controllers],
29
- :helper => %w[spec helpers],
30
- :job => %w[spec jobs],
31
- :mailer => %w[spec mailers],
32
- :model => %w[spec models],
33
- :request => %w[spec (requests|integration|api)],
34
- :routing => %w[spec routing],
35
- :view => %w[spec views],
36
- :feature => %w[spec features]
29
+ channel: %w[spec channels],
30
+ controller: %w[spec controllers],
31
+ generator: %w[spec generator],
32
+ helper: %w[spec helpers],
33
+ job: %w[spec jobs],
34
+ mailer: %w[spec mailers],
35
+ model: %w[spec models],
36
+ request: %w[spec (requests|integration|api)],
37
+ routing: %w[spec routing],
38
+ view: %w[spec views],
39
+ feature: %w[spec features],
40
+ system: %w[spec system],
41
+ mailbox: %w[spec mailboxes]
37
42
  }
38
43
 
39
44
  # Sets up the different example group modules for the different spec types
40
45
  #
41
46
  # @api private
42
47
  def self.add_test_type_configurations(config)
43
- config.include RSpec::Rails::ControllerExampleGroup, :type => :controller
44
- config.include RSpec::Rails::HelperExampleGroup, :type => :helper
45
- config.include RSpec::Rails::ModelExampleGroup, :type => :model
46
- config.include RSpec::Rails::RequestExampleGroup, :type => :request
47
- config.include RSpec::Rails::RoutingExampleGroup, :type => :routing
48
- config.include RSpec::Rails::ViewExampleGroup, :type => :view
49
- config.include RSpec::Rails::FeatureExampleGroup, :type => :feature
48
+ config.include RSpec::Rails::ControllerExampleGroup, type: :controller
49
+ config.include RSpec::Rails::HelperExampleGroup, type: :helper
50
+ config.include RSpec::Rails::ModelExampleGroup, type: :model
51
+ config.include RSpec::Rails::RequestExampleGroup, type: :request
52
+ config.include RSpec::Rails::RoutingExampleGroup, type: :routing
53
+ config.include RSpec::Rails::ViewExampleGroup, type: :view
54
+ config.include RSpec::Rails::FeatureExampleGroup, type: :feature
50
55
  config.include RSpec::Rails::Matchers
56
+ config.include RSpec::Rails::SystemExampleGroup, type: :system
51
57
  end
52
58
 
53
59
  # @private
54
- # rubocop:disable Style/MethodLength
55
- def self.initialize_configuration(config)
60
+ def self.initialize_configuration(config) # rubocop:disable Metrics/MethodLength,Metrics/CyclomaticComplexity
56
61
  config.backtrace_exclusion_patterns << /vendor\//
57
62
  config.backtrace_exclusion_patterns << %r{lib/rspec/rails}
58
63
 
59
64
  # controller settings
60
- config.add_setting :infer_base_class_for_anonymous_controllers, :default => true
65
+ config.add_setting :infer_base_class_for_anonymous_controllers, default: true
61
66
 
62
67
  # fixture support
63
- config.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples
68
+ config.add_setting :use_active_record, default: true
69
+ config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples
64
70
  config.add_setting :use_instantiated_fixtures
65
71
  config.add_setting :global_fixtures
66
72
  config.add_setting :fixture_path
@@ -75,17 +81,19 @@ module RSpec
75
81
  # `RSpec::Rails::FixtureSupport` directly instead
76
82
  config.include RSpec::Rails::FixtureSupport
77
83
 
78
- if ::Rails::VERSION::STRING > '5'
79
- config.add_setting :file_fixture_path, :default => 'spec/fixtures/files'
80
- config.include RSpec::Rails::FileFixtureSupport
81
- end
84
+ config.add_setting :file_fixture_path, default: 'spec/fixtures/files'
85
+ config.include RSpec::Rails::FileFixtureSupport
86
+
87
+ # Add support for fixture_path on fixture_file_upload
88
+ config.include RSpec::Rails::FixtureFileUploadSupport
89
+
82
90
  # This allows us to expose `render_views` as a config option even though it
83
91
  # breaks the convention of other options by using `render_views` as a
84
92
  # command (i.e. `render_views = true`), where it would normally be used
85
93
  # as a getter. This makes it easier for rspec-rails users because we use
86
94
  # `render_views` directly in example groups, so this aligns the two APIs,
87
95
  # but requires this workaround:
88
- config.add_setting :rendering_views, :default => false
96
+ config.add_setting :rendering_views, default: false
89
97
 
90
98
  config.instance_exec do
91
99
  def render_views=(val)
@@ -97,13 +105,47 @@ module RSpec
97
105
  end
98
106
 
99
107
  def render_views?
100
- rendering_views
108
+ rendering_views?
109
+ end
110
+
111
+ undef :rendering_views? if respond_to?(:rendering_views?)
112
+ def rendering_views?
113
+ !!rendering_views
114
+ end
115
+
116
+ # Define boolean predicates rather than relying on rspec-core due
117
+ # to the bug fix in rspec/rspec-core#2736, note some of these
118
+ # predicates are a bit nonsensical, but they exist for backwards
119
+ # compatibility, we can tidy these up in `rspec-rails` 5.
120
+ undef :fixture_path? if respond_to?(:fixture_path?)
121
+ def fixture_path?
122
+ !!fixture_path
123
+ end
124
+
125
+ undef :global_fixtures? if respond_to?(:global_fixtures?)
126
+ def global_fixtures?
127
+ !!global_fixtures
128
+ end
129
+
130
+ undef :infer_base_class_for_anonymous_controllers? if respond_to?(:infer_base_class_for_anonymous_controllers?)
131
+ def infer_base_class_for_anonymous_controllers?
132
+ !!infer_base_class_for_anonymous_controllers
133
+ end
134
+
135
+ undef :use_instantiated_fixtures? if respond_to?(:use_instantiated_fixtures?)
136
+ def use_instantiated_fixtures?
137
+ !!use_instantiated_fixtures
138
+ end
139
+
140
+ undef :use_transactional_fixtures? if respond_to?(:use_transactional_fixtures?)
141
+ def use_transactional_fixtures?
142
+ !!use_transactional_fixtures
101
143
  end
102
144
 
103
145
  def infer_spec_type_from_file_location!
104
146
  DIRECTORY_MAPPINGS.each do |type, dir_parts|
105
147
  escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]')
106
- define_derived_metadata(:file_path => escaped_path) do |metadata|
148
+ define_derived_metadata(file_path: escaped_path) do |metadata|
107
149
  metadata[:type] ||= type
108
150
  end
109
151
  end
@@ -121,22 +163,31 @@ module RSpec
121
163
 
122
164
  if defined?(::Rails::Controller::Testing)
123
165
  [:controller, :view, :request].each do |type|
124
- config.include ::Rails::Controller::Testing::TestProcess, :type => type
125
- config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type
126
- config.include ::Rails::Controller::Testing::Integration, :type => type
166
+ config.include ::Rails::Controller::Testing::TestProcess, type: type
167
+ config.include ::Rails::Controller::Testing::TemplateAssertions, type: type
168
+ config.include ::Rails::Controller::Testing::Integration, type: type
127
169
  end
128
170
  end
129
171
 
130
- if defined?(ActionMailer)
131
- config.include RSpec::Rails::MailerExampleGroup, :type => :mailer
172
+ if RSpec::Rails::FeatureCheck.has_action_mailer?
173
+ config.include RSpec::Rails::MailerExampleGroup, type: :mailer
174
+ config.after { ActionMailer::Base.deliveries.clear }
175
+ end
176
+
177
+ if RSpec::Rails::FeatureCheck.has_active_job?
178
+ config.include RSpec::Rails::JobExampleGroup, type: :job
179
+ end
180
+
181
+ if RSpec::Rails::FeatureCheck.has_action_cable_testing?
182
+ config.include RSpec::Rails::ChannelExampleGroup, type: :channel
132
183
  end
133
184
 
134
- if defined?(ActiveJob)
135
- config.include RSpec::Rails::JobExampleGroup, :type => :job
185
+ if RSpec::Rails::FeatureCheck.has_action_mailbox?
186
+ config.include RSpec::Rails::MailboxExampleGroup, type: :mailbox
136
187
  end
137
188
  end
138
- # rubocop:enable Style/MethodLength
139
189
 
140
190
  initialize_configuration RSpec.configuration
141
191
  end
142
192
  end
193
+ # rubocop: enable Metrics/ModuleLength