rspec-rails 3.9.0 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Capybara.md +5 -54
  5. data/Changelog.md +212 -78
  6. data/README.md +27 -21
  7. data/lib/generators/rspec.rb +0 -6
  8. data/lib/generators/rspec/channel/channel_generator.rb +12 -0
  9. data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
  10. data/lib/generators/rspec/controller/controller_generator.rb +22 -5
  11. data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
  12. data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
  13. data/lib/generators/rspec/feature/feature_generator.rb +2 -2
  14. data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
  15. data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
  16. data/lib/generators/rspec/helper/helper_generator.rb +1 -1
  17. data/lib/generators/rspec/install/install_generator.rb +4 -4
  18. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
  19. data/lib/generators/rspec/integration/integration_generator.rb +3 -3
  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 +2 -1
  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 +5 -4
  26. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  27. data/lib/generators/rspec/request/request_generator.rb +1 -1
  28. data/lib/generators/rspec/scaffold/scaffold_generator.rb +29 -19
  29. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
  30. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  31. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +0 -48
  32. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -5
  33. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  34. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -5
  35. data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -0
  36. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
  37. data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
  38. data/lib/generators/rspec/system/system_generator.rb +14 -16
  39. data/lib/generators/rspec/view/view_generator.rb +2 -2
  40. data/lib/rspec-rails.rb +13 -16
  41. data/lib/rspec/rails/adapters.rb +11 -76
  42. data/lib/rspec/rails/configuration.rb +81 -37
  43. data/lib/rspec/rails/example.rb +2 -0
  44. data/lib/rspec/rails/example/channel_example_group.rb +93 -0
  45. data/lib/rspec/rails/example/controller_example_group.rb +4 -4
  46. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  47. data/lib/rspec/rails/example/helper_example_group.rb +2 -9
  48. data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
  49. data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
  50. data/lib/rspec/rails/example/rails_example_group.rb +1 -1
  51. data/lib/rspec/rails/example/request_example_group.rb +1 -4
  52. data/lib/rspec/rails/example/system_example_group.rb +29 -12
  53. data/lib/rspec/rails/example/view_example_group.rb +38 -27
  54. data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
  55. data/lib/rspec/rails/feature_check.rb +12 -29
  56. data/lib/rspec/rails/file_fixture_support.rb +9 -11
  57. data/lib/rspec/rails/fixture_file_upload_support.rb +33 -17
  58. data/lib/rspec/rails/fixture_support.rb +34 -32
  59. data/lib/rspec/rails/matchers.rb +10 -0
  60. data/lib/rspec/rails/matchers/action_cable.rb +65 -0
  61. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -0
  62. data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
  63. data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
  64. data/lib/rspec/rails/matchers/active_job.rb +169 -21
  65. data/lib/rspec/rails/matchers/base_matcher.rb +5 -10
  66. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +52 -28
  67. data/lib/rspec/rails/matchers/have_http_status.rb +11 -7
  68. data/lib/rspec/rails/matchers/have_rendered.rb +1 -0
  69. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  70. data/lib/rspec/rails/matchers/routing_matchers.rb +12 -12
  71. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  72. data/lib/rspec/rails/vendor/capybara.rb +10 -15
  73. data/lib/rspec/rails/version.rb +1 -1
  74. data/lib/rspec/rails/view_path_builder.rb +1 -1
  75. data/lib/rspec/rails/view_rendering.rb +15 -4
  76. metadata +49 -37
  77. metadata.gz.sig +0 -0
  78. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # rspec-rails [![Build Status][]][travis-ci] [![Code Climate][]][code-climate] [![Gem Version][]](gem-version)
1
+ # rspec-rails [![Code Climate][]][code-climate] [![Gem Version][]][gem-version]
2
2
 
3
3
  `rspec-rails` brings the [RSpec][] testing framework to [Ruby on Rails][]
4
4
  as a drop-in alternative to its default testing framework, Minitest.
@@ -8,9 +8,11 @@ They’re also specifications (or _specs,_ for short):
8
8
  detailed explanations of how the application is supposed to behave,
9
9
  expressed in plain English.
10
10
 
11
+ Use **[`rspec-rails` 4.x][]** for Rails from 5.0 to 6.0.
12
+ Use **[`rspec-rails` 3.x][]** for Rails earlier than 5.0.
11
13
  Use **[`rspec-rails` 1.x][]** for Rails 2.x.
12
14
 
13
- [Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=master
15
+ [Build Status]: https://secure.travis-ci.org/rspec/rspec-rails.svg?branch=main
14
16
  [travis-ci]: https://travis-ci.org/rspec/rspec-rails
15
17
  [Code Climate]: https://codeclimate.com/github/rspec/rspec-rails.svg
16
18
  [code-climate]: https://codeclimate.com/github/rspec/rspec-rails
@@ -19,23 +21,28 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
19
21
  [RSpec]: https://rspec.info/
20
22
  [Ruby on Rails]: https://rubyonrails.org/
21
23
  [`rspec-rails` 1.x]: https://github.com/dchelimsky/rspec-rails
24
+ [`rspec-rails` 3.x]: https://github.com/rspec/rspec-rails/tree/3-9-maintenance
25
+ [`rspec-rails` 4.x]: https://github.com/rspec/rspec-rails/tree/4-1-maintenance
22
26
 
23
27
  ## Installation
24
28
 
29
+ **IMPORTANT** This README / branch refers to the 5.0.x series of releases.
30
+ See the [`main` branch on Github](https://github.com/rspec/rspec-rails/tree/main) for more up to date releases.
31
+
25
32
  1. Add `rspec-rails` to **both** the `:development` and `:test` groups
26
33
  of your app’s `Gemfile`:
27
34
 
28
35
  ```ruby
29
- # Run against the latest stable release
36
+ # Run against this stable release
30
37
  group :development, :test do
31
- gem 'rspec-rails', '~> 3.8'
38
+ gem 'rspec-rails', '~> 5.0.0'
32
39
  end
33
40
 
34
- # Or, run against the master branch
35
- # (requires master-branch versions of all related RSpec libraries)
41
+ # Or, run against the main branch
42
+ # (requires main-branch versions of all related RSpec libraries)
36
43
  group :development, :test do
37
44
  %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib|
38
- gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master'
45
+ gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'main'
39
46
  end
40
47
  end
41
48
  ```
@@ -119,8 +126,7 @@ $ bundle exec rspec --help
119
126
  ```
120
127
 
121
128
  **Optional:** If `bundle exec rspec` is too verbose for you,
122
- you can generate a binstub at `bin/rspec`
123
- and use that instead (Rails 4+ only):
129
+ you can generate a binstub at `bin/rspec` and use that instead:
124
130
 
125
131
  ```sh
126
132
  $ bundle binstubs rspec-core
@@ -183,17 +189,17 @@ In addition to [the matchers that come standard in RSpec][],
183
189
  here are some extras that make it easier
184
190
  to test the various parts of a Rails system:
185
191
 
186
- | RSpec matcher | Delegates to | Available in | Notes |
187
- | ------------------------ | ----------------- | ------------------------------- | -------------------------------------------------------- |
188
- | [`be_a_new`][] | | all | primarily intended for controller specs |
189
- | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
190
- | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
191
- | [`route_to`] | `assert_routing` | routing / controller | replaces `route_for` from version 1.x |
192
- | [`be_routable`] | | routing / controller | usu. for `expect(...).not_to be_routable` |
193
- | [`have_http_status`][] | | request / controller / feature | |
194
- | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
195
- | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
196
- | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
192
+ | RSpec matcher | Delegates to | Available in | Notes |
193
+ | ------------------------ | ------------------- | ------------------------------- | -------------------------------------------------------- |
194
+ | [`be_a_new`][] | | all | primarily intended for controller specs |
195
+ | [`render_template`][] | `assert_template` | request / controller / view | use with `expect(response).to` |
196
+ | [`redirect_to`][] | `assert_redirect` | request / controller | use with `expect(response).to` |
197
+ | [`route_to`] | `assert_recognizes` | routing / controller | use with `expect(...).to route_to` |
198
+ | [`be_routable`] | | routing / controller | use with `expect(...).not_to be_routable` |
199
+ | [`have_http_status`][] | | request / controller / feature | |
200
+ | [`match_array`][] | | all | for comparing arrays of ActiveRecord objects |
201
+ | [`have_been_enqueued`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
202
+ | [`have_enqueued_job`][] | | all | requires config: `ActiveJob::Base.queue_adapter = :test` |
197
203
 
198
204
  Follow the links above for examples of how each matcher is used.
199
205
 
@@ -362,7 +368,7 @@ you can run the specs and Cucumber features, or submit a pull request.
362
368
  ### Recommended third-party extensions
363
369
 
364
370
  * [FactoryBot](https://github.com/thoughtbot/factory_bot)
365
- * [Capybara](https://github.com/jnicklas/capybara)
371
+ * [Capybara](https://github.com/teamcapybara/capybara)
366
372
  (Included by default in Rails 5.1+.
367
373
  Note that [additional configuration is required][] to use the Capybara DSL
368
374
  anywhere other than system specs and feature specs.)
@@ -18,12 +18,6 @@ module Rspec
18
18
  @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
19
19
  end
20
20
  end
21
-
22
- if ::Rails::VERSION::STRING < '3.1'
23
- def module_namespacing
24
- yield if block_given?
25
- end
26
- end
27
21
  end
28
22
  end
29
23
  end
@@ -0,0 +1,12 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class ChannelGenerator < Base
7
+ def create_channel_spec
8
+ template 'channel_spec.rb.erb', File.join('spec/channels', class_path, "#{file_name}_channel_spec.rb")
9
+ end
10
+ end
11
+ end
12
+ end
@@ -1,7 +1,7 @@
1
1
  require 'rails_helper'
2
2
 
3
3
  <% module_namespacing do -%>
4
- RSpec.describe <%= class_name %>Observer, <%= type_metatag(:observer) %> do
4
+ RSpec.describe <%= class_name %>Channel, <%= type_metatag(:channel) %> do
5
5
  pending "add some examples to (or delete) #{__FILE__}"
6
6
  end
7
7
  <% end -%>
@@ -4,11 +4,20 @@ module Rspec
4
4
  module Generators
5
5
  # @private
6
6
  class ControllerGenerator < 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"
10
- class_option :controller_specs, :type => :boolean, :default => true
11
- class_option :view_specs, :type => :boolean, :default => true
9
+ class_option :template_engine, desc: "Template engine to generate view files"
10
+ class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
11
+ class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
12
+ class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
13
+ class_option :routing_specs, type: :boolean, default: false, desc: "Generate routing specs"
14
+
15
+ def generate_request_spec
16
+ return unless options[:request_specs]
17
+
18
+ template 'request_spec.rb',
19
+ File.join('spec/requests', class_path, "#{file_name}_spec.rb")
20
+ end
12
21
 
13
22
  def generate_controller_spec
14
23
  return unless options[:controller_specs]
@@ -18,7 +27,7 @@ module Rspec
18
27
  end
19
28
 
20
29
  def generate_view_specs
21
- return if actions.empty?
30
+ return if actions.empty? && behavior == :invoke
22
31
  return unless options[:view_specs] && options[:template_engine]
23
32
 
24
33
  empty_directory File.join("spec", "views", file_path)
@@ -29,6 +38,14 @@ module Rspec
29
38
  File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
30
39
  end
31
40
  end
41
+
42
+ def generate_routing_spec
43
+ return if actions.empty?
44
+ return unless options[:routing_specs]
45
+
46
+ template 'routing_spec.rb',
47
+ File.join('spec/routing', class_path, "#{file_name}_routing_spec.rb")
48
+ end
32
49
  end
33
50
  end
34
51
  end
@@ -0,0 +1,19 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4
+ <% namespaced_path = regular_class_path.join('/') -%>
5
+ <% if actions.empty? -%>
6
+ describe "GET /index" do
7
+ pending "add some examples (or delete) #{__FILE__}"
8
+ end
9
+ <% end -%>
10
+ <% for action in actions -%>
11
+ describe "GET /<%= action %>" do
12
+ it "returns http success" do
13
+ get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
14
+ expect(response).to have_http_status(:success)
15
+ end
16
+ end
17
+
18
+ <% end -%>
19
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe '<%= class_name %>Controller', <%= type_metatag(:routing) %> do
5
+ describe 'routing' do
6
+ <% for action in actions -%>
7
+ it 'routes to #<%= action %>' do
8
+ expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
9
+ end
10
+ <% end -%>
11
+ end
12
+ end
13
+ <% end -%>
@@ -4,8 +4,8 @@ module Rspec
4
4
  module Generators
5
5
  # @private
6
6
  class FeatureGenerator < Base
7
- class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs"
8
- class_option :singularize, :type => :boolean, :default => false, :desc => "Singularize the generated feature"
7
+ class_option :feature_specs, type: :boolean, default: true, desc: "Generate feature specs"
8
+ class_option :singularize, type: :boolean, default: false, desc: "Singularize the generated feature"
9
9
 
10
10
  def generate_feature_spec
11
11
  return unless options[:feature_specs]
@@ -3,8 +3,8 @@ require 'generators/rspec'
3
3
  module Rspec
4
4
  module Generators
5
5
  # @private
6
- class GeneratorsGenerator < Base
7
- class_option :generator_specs, :type => :boolean, :default => false, :desc => "Generate generator specs"
6
+ class GeneratorGenerator < Base
7
+ class_option :generator_specs, type: :boolean, default: true, desc: "Generate generator specs"
8
8
 
9
9
  def generate_generator_spec
10
10
  return unless options[:generator_specs]
@@ -4,7 +4,7 @@ module Rspec
4
4
  module Generators
5
5
  # @private
6
6
  class HelperGenerator < Base
7
- class_option :helper_specs, :type => :boolean, :default => true
7
+ class_option :helper_specs, type: :boolean, default: true
8
8
 
9
9
  def generate_helper_spec
10
10
  return unless options[:helper_specs]
@@ -32,8 +32,8 @@ DESC
32
32
 
33
33
  def generate_rspec_init(tmpdir)
34
34
  initializer = ::RSpec::Core::ProjectInitializer.new(
35
- :destination => tmpdir,
36
- :report_stream => StringIO.new
35
+ destination: tmpdir,
36
+ report_stream: StringIO.new
37
37
  )
38
38
  initializer.run
39
39
 
@@ -47,7 +47,7 @@ DESC
47
47
  gsub_file spec_helper_path,
48
48
  'rspec --init',
49
49
  'rails generate rspec:install',
50
- :verbose => false
50
+ verbose: false
51
51
  end
52
52
 
53
53
  def remove_warnings_configuration(spec_helper_path)
@@ -56,7 +56,7 @@ DESC
56
56
  gsub_file spec_helper_path,
57
57
  /#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
58
58
  '',
59
- :verbose => false
59
+ verbose: false
60
60
  end
61
61
  end
62
62
  end
@@ -1,11 +1,7 @@
1
1
  # This file is copied to spec/ when you run 'rails generate rspec:install'
2
2
  require 'spec_helper'
3
3
  ENV['RAILS_ENV'] ||= 'test'
4
- <% if RUBY_VERSION >= '2.0.0' %>
5
4
  require File.expand_path('../config/environment', __dir__)
6
- <% else %>
7
- require File.expand_path('../../config/environment', __FILE__)
8
- <% end %>
9
5
  # Prevent database truncation if the environment is production
10
6
  abort("The Rails environment is running in production mode!") if Rails.env.production?
11
7
  require 'rspec/rails'
@@ -24,9 +20,9 @@ require 'rspec/rails'
24
20
  # directory. Alternatively, in the individual `*_spec.rb` files, manually
25
21
  # require only the support files necessary.
26
22
  #
27
- # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].each { |f| require f }
23
+ # Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
28
24
 
29
- <% if RSpec::Rails::FeatureCheck.can_maintain_test_schema? -%>
25
+ <% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
30
26
  # Checks for pending migrations and applies them before tests are run.
31
27
  # If you are not using ActiveRecord, you can remove these lines.
32
28
  begin
@@ -35,15 +31,6 @@ rescue ActiveRecord::PendingMigrationError => e
35
31
  puts e.to_s.strip
36
32
  exit 1
37
33
  end
38
- <% elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? -%>
39
- # Checks for pending migrations before tests are run.
40
- # If you are not using ActiveRecord, you can remove these lines.
41
- begin
42
- ActiveRecord::Migration.check_pending!
43
- rescue ActiveRecord::PendingMigrationError => e
44
- puts e.to_s.strip
45
- exit 1
46
- end
47
34
  <% end -%>
48
35
  RSpec.configure do |config|
49
36
  <% if RSpec::Rails::FeatureCheck.has_active_record? -%>
@@ -55,6 +42,20 @@ RSpec.configure do |config|
55
42
  # instead of true.
56
43
  config.use_transactional_fixtures = true
57
44
 
45
+ # You can uncomment this line to turn off ActiveRecord support entirely.
46
+ # config.use_active_record = false
47
+
48
+ <% else -%>
49
+ # Remove this line to enable support for ActiveRecord
50
+ config.use_active_record = false
51
+
52
+ # If you enable ActiveRecord support you should unncomment these lines,
53
+ # note if you'd prefer not to run each example within a transaction, you
54
+ # should set use_transactional_fixtures to false.
55
+ #
56
+ # config.fixture_path = "#{::Rails.root}/spec/fixtures"
57
+ # config.use_transactional_fixtures = true
58
+
58
59
  <% end -%>
59
60
  # RSpec Rails can automatically mix in different behaviours to your tests
60
61
  # based on their file location, for example enabling you to call `get` and
@@ -63,7 +64,7 @@ RSpec.configure do |config|
63
64
  # You can disable this behaviour by removing the line below, and instead
64
65
  # explicitly tag your specs with their type, e.g.:
65
66
  #
66
- # RSpec.describe UsersController, :type => :controller do
67
+ # RSpec.describe UsersController, type: :controller do
67
68
  # # ...
68
69
  # end
69
70
  #
@@ -7,9 +7,9 @@ module Rspec
7
7
  # Add a deprecation for this class, before rspec-rails 4, to use the
8
8
  # `RequestGenerator` instead
9
9
  class_option :request_specs,
10
- :type => :boolean,
11
- :default => true,
12
- :desc => "Generate request specs"
10
+ type: :boolean,
11
+ default: true,
12
+ desc: "Generate request specs"
13
13
 
14
14
  def generate_request_spec
15
15
  return unless options[:request_specs]
@@ -0,0 +1,14 @@
1
+ require 'generators/rspec'
2
+
3
+ module Rspec
4
+ module Generators
5
+ # @private
6
+ class MailboxGenerator < Base
7
+ def create_mailbox_spec
8
+ template('mailbox_spec.rb.erb',
9
+ File.join('spec/mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
10
+ )
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ require 'rails_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ RSpec.describe <%= class_name %>Mailbox, <%= type_metatag(:mailbox) %> do
5
+ pending "add some examples to (or delete) #{__FILE__}"
6
+ end
7
+ <% end -%>
@@ -5,7 +5,7 @@ module Rspec
5
5
  module Generators
6
6
  # @private
7
7
  class MailerGenerator < Base
8
- argument :actions, :type => :array, :default => [], :banner => "method method"
8
+ argument :actions, type: :array, default: [], banner: "method method"
9
9
 
10
10
  def generate_mailer_spec
11
11
  template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
@@ -20,6 +20,7 @@ module Rspec
20
20
 
21
21
  def generate_preview_files
22
22
  return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
23
+
23
24
  template "preview.rb", File.join("spec/mailers/previews", class_path, "#{file_name}_preview.rb")
24
25
  end
25
26
  end
@@ -1,10 +1,10 @@
1
1
  require "rails_helper"
2
2
 
3
3
  <% module_namespacing do -%>
4
- RSpec.describe <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>, <%= type_metatag(:mailer) %> do
4
+ RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
5
5
  <% for action in actions -%>
6
6
  describe "<%= action %>" do
7
- let(:mail) { <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %> }
7
+ let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
8
8
 
9
9
  it "renders the headers" do
10
10
  expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
@@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview
5
5
 
6
6
  # Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
7
7
  def <%= action %>
8
- <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %>
8
+ <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
9
9
  end
10
10
  <% end -%>
11
11
 
@@ -5,10 +5,10 @@ module Rspec
5
5
  # @private
6
6
  class ModelGenerator < Base
7
7
  argument :attributes,
8
- :type => :array,
9
- :default => [],
10
- :banner => "field:type field:type"
11
- class_option :fixture, :type => :boolean
8
+ type: :array,
9
+ default: [],
10
+ banner: "field:type field:type"
11
+ class_option :fixture, type: :boolean
12
12
 
13
13
  def create_model_spec
14
14
  template_file = File.join(
@@ -23,6 +23,7 @@ module Rspec
23
23
 
24
24
  def create_fixture_file
25
25
  return unless missing_fixture_replacement?
26
+
26
27
  template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
27
28
  end
28
29