rspec-rails 4.0.0.beta3 → 4.0.0

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 (61) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/Capybara.md +5 -54
  4. data/Changelog.md +70 -12
  5. data/README.md +4 -5
  6. data/lib/generators/rspec/controller/controller_generator.rb +13 -5
  7. data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
  8. data/lib/generators/rspec/controller/templates/routing_spec.rb +1 -1
  9. data/lib/generators/rspec/feature/feature_generator.rb +2 -2
  10. data/lib/generators/rspec/{generators → generator}/generator_generator.rb +2 -2
  11. data/lib/generators/rspec/{generators → generator}/templates/generator_spec.rb +0 -0
  12. data/lib/generators/rspec/helper/helper_generator.rb +1 -1
  13. data/lib/generators/rspec/install/install_generator.rb +4 -4
  14. data/lib/generators/rspec/install/templates/spec/rails_helper.rb +17 -16
  15. data/lib/generators/rspec/integration/integration_generator.rb +3 -3
  16. data/lib/generators/rspec/mailer/mailer_generator.rb +1 -1
  17. data/lib/generators/rspec/model/model_generator.rb +4 -4
  18. data/lib/generators/rspec/scaffold/scaffold_generator.rb +26 -18
  19. data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +0 -36
  20. data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
  21. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +10 -10
  22. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
  23. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  24. data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
  25. data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
  26. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
  27. data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
  28. data/lib/generators/rspec/system/system_generator.rb +1 -1
  29. data/lib/generators/rspec/view/view_generator.rb +2 -2
  30. data/lib/generators/rspec.rb +0 -6
  31. data/lib/rspec/rails/adapters.rb +10 -76
  32. data/lib/rspec/rails/configuration.rb +35 -35
  33. data/lib/rspec/rails/example/channel_example_group.rb +2 -2
  34. data/lib/rspec/rails/example/controller_example_group.rb +4 -4
  35. data/lib/rspec/rails/example/feature_example_group.rb +6 -26
  36. data/lib/rspec/rails/example/helper_example_group.rb +2 -10
  37. data/lib/rspec/rails/example/rails_example_group.rb +1 -1
  38. data/lib/rspec/rails/example/system_example_group.rb +10 -4
  39. data/lib/rspec/rails/example/view_example_group.rb +38 -48
  40. data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
  41. data/lib/rspec/rails/feature_check.rb +1 -28
  42. data/lib/rspec/rails/fixture_file_upload_support.rb +1 -1
  43. data/lib/rspec/rails/fixture_support.rb +37 -31
  44. data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +3 -3
  45. data/lib/rspec/rails/matchers/action_cable.rb +1 -1
  46. data/lib/rspec/rails/matchers/active_job.rb +126 -16
  47. data/lib/rspec/rails/matchers/base_matcher.rb +4 -10
  48. data/lib/rspec/rails/matchers/have_enqueued_mail.rb +6 -3
  49. data/lib/rspec/rails/matchers/have_http_status.rb +7 -7
  50. data/lib/rspec/rails/matchers/routing_matchers.rb +11 -11
  51. data/lib/rspec/rails/tasks/rspec.rake +7 -17
  52. data/lib/rspec/rails/vendor/capybara.rb +10 -15
  53. data/lib/rspec/rails/version.rb +1 -1
  54. data/lib/rspec/rails/view_path_builder.rb +1 -1
  55. data/lib/rspec/rails/view_rendering.rb +3 -3
  56. data/lib/rspec-rails.rb +6 -9
  57. data.tar.gz.sig +0 -0
  58. metadata +30 -29
  59. metadata.gz.sig +0 -0
  60. data/lib/generators/rspec/observer/observer_generator.rb +0 -13
  61. data/lib/generators/rspec/observer/templates/observer_spec.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ae59820fb98850c1f67442c749ce42e76895fca3a17f952ac36d752903fd986
4
- data.tar.gz: 713bb7441b6d66036dc73f2f9fa448419390627890ab0bf6a535c84800758939
3
+ metadata.gz: 8e8f5dabd4f5335dc409c77670d7aef552636874486111f105613d54e4270375
4
+ data.tar.gz: 72f211f8667a1d6faedaa8e02877958ccd742c5591107ed568a620fc38999c55
5
5
  SHA512:
6
- metadata.gz: 691dc937903a8aaac3e23feff435710e521082a0ace9bddc00cba9bd9ecb52610104b66458c900ababcf19a74e341affa78c109eb589faa7c25f7320db82954a
7
- data.tar.gz: 56d7c5dbd4a1e437f5f011274f084a6e1a835b0795d369fe56e53b993dbf4a199067b96f73e2ae2aad7b6c556ee6dcb6b24cd46fd12a967bfe15e50450367bce
6
+ metadata.gz: a4125a040fcc9d7b1e9d8ee802f2d9ad75bc581a3e9263c329db8ddaccfd49988ccaab066c0aebad50e3b78a99d0ebe22e04a9648e44f6e1284325ea112e4c63
7
+ data.tar.gz: e08c9439828c7f1b2f3ec543ea72d554f92d79adde6cb01e19d8486c3fc64887432239d1159d4aea7a6b8811cd4f3aaff811b777b3dff80569facfaa38ede625
checksums.yaml.gz.sig CHANGED
Binary file
data/Capybara.md CHANGED
@@ -1,58 +1,19 @@
1
1
  rspec-rails supports integration with Capybara out of the box by adding
2
2
  its Capybara::DSL (visit/page) and Capybara::RSpecMatchers to the
3
- examples in the applicable directories, which differ slightly between
4
- Capybara 1.x and Capybara >= 2.x.
3
+ examples in the applicable directories.
5
4
 
6
5
  ## Capybara::DSL
7
6
 
8
7
  Adds the `visit` and `page` methods, which work together to simulate a
9
8
  GET request and provide access to the result (via `page`).
10
9
 
11
- ## Capybara::RSpecMatchers
12
-
13
- Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
14
-
15
- ## Capybara 1.x
16
-
17
- Capybara::DSL is added to examples in:
18
-
19
- * spec/requests # included by Capybara
20
- * spec/controllers
21
-
22
- Capybara::RSpecMatchers is added to examples in:
23
-
24
- * spec/requests # included by Capybara
25
- * spec/controllers
26
- * spec/views
27
- * spec/helpers
28
- * spec/mailers
29
-
30
- ## Capybara 2.0
31
-
32
- To use Capybara 2.0, you need rspec-rails-2.11.1 or greater.
33
-
34
10
  Capybara::DSL is added to examples in:
35
11
 
36
12
  * spec/features
37
13
 
38
- Capybara::RSpecMatchers is added to examples in:
39
-
40
- * spec/features
41
- * spec/controllers
42
- * spec/views
43
- * spec/helpers
44
- * spec/mailers
45
-
46
- ## Upgrading to Capybara-2.0
47
-
48
- Many users have been confused by the co-existence of the the
49
- Capybara::DSL (visit/page) alongside the rack-test DSL
50
- (get|post|put|delete|head/response.body) in examples in spec/requests
51
- and spec/controllers. As of rspec-rails-2.11.1 and capybara-2.0.0.beta2, these
52
- are separated as follows:
14
+ ## Capybara::RSpecMatchers
53
15
 
54
- * Capybara::DSL is included `spec/features`
55
- * rack-test DSL is included in `spec/requests` and `spec/controllers`
16
+ Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
56
17
 
57
18
  Capybara::RSpecMatchers is added to examples in:
58
19
 
@@ -62,16 +23,6 @@ Capybara::RSpecMatchers is added to examples in:
62
23
  * spec/helpers
63
24
  * spec/mailers
64
25
 
65
- If you're upgrading to Capybara-2.0 and you used visit/page in
66
- spec/requests you'll want to move those examples to spec/features and
67
- they should just work.
68
-
69
- If you want to leave those examples in spec/requests, you can include
70
- Capybara::DSL in those examples yourself as follows, but this is
71
- absolutely not recommended as you will be overriding the intended
72
- behavior and accepting the risks associated with doing so:
26
+ ## Upgrading to Capybara-3.x
73
27
 
74
- # not recommended!
75
- RSpec.configure do |c|
76
- c.include Capybara::DSL, :file_path => "spec/requests"
77
- end
28
+ Consult the official [Upgrading from Capybara 2.x to 3.x](https://github.com/teamcapybara/capybara/blob/master/UPGRADING.md#upgrading-from-capybara-2x-to-3x) guide.
data/Changelog.md CHANGED
@@ -1,9 +1,50 @@
1
- ### Development
2
- [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.0...master)
1
+ ### 4.0.0.rc1 / 2020-03-13
2
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta4...v4.0.0.rc1)
3
+
4
+ Enhancements:
5
+
6
+ * Allow `ActiveJob` matchers `#on_queue` modifier to take symbolic queue names. (Nils Sommer, #2283)
7
+ * The scaffold generator now generates request specs in preference to controller specs.
8
+ (Luka Lüdicke, #2288)
9
+ * Add configuration option to disable ActiveRecord. (Jon Rowe, Phil Pirozhkov, Hermann Mayer, #2266)
10
+ * Set `ActionDispatch::SystemTesting::Server.silence_puma = true` when running system specs.
11
+ (ta1kt0me, Benoit Tigeot, #2289)
12
+
13
+ Bug Fixes:
14
+
15
+ * Restore previous conditional check for setting `default_url_options` in feature
16
+ specs, prevents a `NoMethodError` in some scenarios. (Eugene Kenny, #2277)
17
+ * Allow changing `ActiveJob::Base.queue_adapter` inside a system spec.
18
+ (Jonathan Rochkind, #2242)
19
+ * `rails generate generator` command now creates related spec file (Joel Azemar, #2217)
20
+ * Relax upper `capybara` version constraint to allow for Capybara 3.x (Phil Pirozhkov, #2281)
21
+ * Clear ActionMailer test mailbox after each example (Benoit Tigeot, #2293)
22
+
23
+ ### 4.0.0.beta4
24
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta3...v4.0.0.beta4)
25
+
26
+ Enhancements:
27
+
28
+ * Add argument matcher support to `have_enqueued_*` matchers. (Phil Pirozhkov, #2206)
29
+ * Switch generated templates to use ruby 1.9 hash keys. (Tanbir Hasan, #2224)
30
+ * Add `have_been_performed`/`have_performed_job`/`perform_job` ActiveJob
31
+ matchers (Isaac Seymour, #1785)
32
+ * Default to generating request specs rather than controller specs when
33
+ generating a controller (Luka Lüdicke, #2222)
34
+
35
+ Bug Fixes:
36
+
37
+ * Prevent `driven_by(:selenium)` being called due to hook precedence.
38
+ (Takumi Shotoku, #2188)
39
+ * Prevent a `WrongScopeError` being thrown during loading fixtures on Rails
40
+ 6.1 development version. (Edouard Chin, #2215)
41
+ * Fix Mocha mocking support with `should`. (Phil Pirozhkov, #2256)
42
+
43
+ ### 4.0.0.beta3
44
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta2...v4.0.0.beta3)
3
45
 
4
46
  Enhancements:
5
47
 
6
- * Adds support for Rails 6. (Penelope Phippen, Benoit Tigeot, Jon Rowe, #2071)
7
48
  * Adds support for JRuby on Rails 5.2 and 6
8
49
  * Add support for parameterised mailers (Ignatius Reza, #2125)
9
50
  * Add ActionMailbox spec helpers and test type (James Dabbs, #2119)
@@ -17,17 +58,34 @@ Enhancements:
17
58
 
18
59
  Bug Fixes:
19
60
 
61
+ * Replace `before_teardown` as well as `after_teardown` to ensure screenshots
62
+ are generated correctly. (Jon Rowe, #2164)
63
+ * `ActionView::FixtureResolver#hash` has been renamed to `ActionView::FixtureResolver#data`.
64
+ (Penelope Phippen, #2076)
65
+ * Add missing require for `have_enqueued_mail` matcher. (Ignatius Reza, #2117)
66
+
67
+ ### 4.0.0.beta2
68
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v4.0.0.beta1...v4.0.0.beta2)
69
+
70
+ Bug Fixes:
71
+
72
+ * Fix version dependencies in gemspec.
73
+
74
+ ### 4.0.0.beta1
75
+ [Full Changelog](https://github.com/rspec/rspec-rails/compare/v3.9.0...v4.0.0.beta1)
76
+
77
+ Enhancements:
78
+
79
+ * Adds support for Rails 6. (Penelope Phippen, Benoit Tigeot, Jon Rowe, #2071)
80
+
81
+ Bug Fixes:
82
+
20
83
  * `EmptyTemplateHandler.call` now needs to support an additional argument in
21
84
  Rails 6. (Pavel Rosický, #2089)
22
85
  * Suppress warning from `SQLite3Adapter.represent_boolean_as_integer` which is
23
86
  deprecated. (Pavel Rosický, #2092)
24
87
  * `ActionView::Template#formats` has been deprecated and replaced by
25
88
  `ActionView::Template#format`(Seb Jacobs, #2100)
26
- * Replace `before_teardown` as well as `after_teardown` to ensure screenshots
27
- are generated correctly. (Jon Rowe, #2164)
28
- * `ActionView::FixtureResolver#hash` has been renamed to `ActionView::FixtureResolver#data`.
29
- (Penelope Phippen, #2076)
30
- * Add missing require for `have_enqueued_mail` matcher. (Ignatius Reza, #2117)
31
89
 
32
90
  Breaking Changes:
33
91
 
@@ -341,10 +399,10 @@ Enhancements:
341
399
  * Improve controller and routing spec calls to `routes` by using `yield`
342
400
  instead of `call`. (Anton Davydov, #1308)
343
401
  * Add support for `ActiveJob` specs as standard `RSpec::Rails::RailsExampleGoup`s
344
- via both `:type => :job` and inferring type from spec directory `spec/jobs`.
402
+ via both `type: :job` and inferring type from spec directory `spec/jobs`.
345
403
  (Gabe Martin-Dempesy, #1361)
346
404
  * Include `RSpec::Rails::FixtureSupport` into example groups using metadata
347
- `:use_fixtures => true`. (Aaron Kromer, #1372)
405
+ `use_fixtures: true`. (Aaron Kromer, #1372)
348
406
  * Include `rspec:request` generator for generating request specs; this is an
349
407
  alias of `rspec:integration` (Aaron Kromer, #1378)
350
408
  * Update `rails_helper` generator with a default check to abort the spec run
@@ -485,7 +543,7 @@ Enhancements:
485
543
  Bug Fixes:
486
544
 
487
545
  * Fix an inconsistency in the generated scaffold specs for a controller. (Andy Waite)
488
- * Ensure `config.before(:all, :type => <type>)` hooks run before groups
546
+ * Ensure `config.before(:all, type: <type>)` hooks run before groups
489
547
  of the given type, even when the type is inferred by the file
490
548
  location. (Jon Rowe, Myron Marston)
491
549
  * Switch to parsing params with `Rack::Utils::parse_nested_query` to match Rails.
@@ -935,7 +993,7 @@ This release is compatible with rails-3.1.0.rc1, but not rails-3.1.0.beta1
935
993
  * Enhancements
936
994
  * include ApplicationHelper in helper object in helper specs
937
995
  * include request spec extensions in files in spec/integration
938
- * include controller spec extensions in groups that use :type => :controller
996
+ * include controller spec extensions in groups that use type: :controller
939
997
  * same for :model, :view, :helper, :mailer, :request, :routing
940
998
 
941
999
  * Bug fixes
data/README.md CHANGED
@@ -28,14 +28,14 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x.
28
28
  ```ruby
29
29
  # Run against the latest stable release
30
30
  group :development, :test do
31
- gem 'rspec-rails', '~> 3.8'
31
+ gem 'rspec-rails', '~> 4.0'
32
32
  end
33
33
 
34
34
  # Or, run against the master branch
35
35
  # (requires master-branch versions of all related RSpec libraries)
36
36
  group :development, :test do
37
37
  %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'
38
+ gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master'
39
39
  end
40
40
  end
41
41
  ```
@@ -119,8 +119,7 @@ $ bundle exec rspec --help
119
119
  ```
120
120
 
121
121
  **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):
122
+ you can generate a binstub at `bin/rspec` and use that instead:
124
123
 
125
124
  ```sh
126
125
  $ bundle binstubs rspec-core
@@ -362,7 +361,7 @@ you can run the specs and Cucumber features, or submit a pull request.
362
361
  ### Recommended third-party extensions
363
362
 
364
363
  * [FactoryBot](https://github.com/thoughtbot/factory_bot)
365
- * [Capybara](https://github.com/jnicklas/capybara)
364
+ * [Capybara](https://github.com/teamcapybara/capybara)
366
365
  (Included by default in Rails 5.1+.
367
366
  Note that [additional configuration is required][] to use the Capybara DSL
368
367
  anywhere other than system specs and feature specs.)
@@ -4,12 +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, :desc => "Generate controller specs"
11
- class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
12
- class_option :routing_specs, :type => :boolean, :default => false, :desc => "Generate routing specs"
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}_request_spec.rb")
20
+ end
13
21
 
14
22
  def generate_controller_spec
15
23
  return unless options[:controller_specs]
@@ -0,0 +1,14 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
4
+ <% namespaced_path = regular_class_path.join('/') %>
5
+ <% for action in actions -%>
6
+ describe "GET /<%= action %>" do
7
+ it "returns http success" do
8
+ get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
9
+ expect(response).to have_http_status(:success)
10
+ end
11
+ end
12
+
13
+ <% end -%>
14
+ end
@@ -5,7 +5,7 @@ RSpec.describe '<%= class_name %>Controller', <%= type_metatag(:routing) %> do
5
5
  describe 'routing' do
6
6
  <% for action in actions -%>
7
7
  it 'routes to #<%= action %>' do
8
- expect(:get => "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
8
+ expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
9
9
  end
10
10
  <% end -%>
11
11
  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]
@@ -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")
@@ -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(
@@ -7,17 +7,18 @@ module Rspec
7
7
  class ScaffoldGenerator < Base
8
8
  include ::Rails::Generators::ResourceHelpers
9
9
  source_paths << File.expand_path('../helper/templates', __dir__)
10
- argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
10
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
11
11
 
12
- class_option :orm, :desc => "ORM used to generate the controller"
13
- class_option :template_engine, :desc => "Template engine to generate view files"
14
- class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller"
15
- class_option :api, :type => :boolean, :desc => "Skip specs unnecessary for API-only apps"
12
+ class_option :orm, desc: "ORM used to generate the controller"
13
+ class_option :template_engine, desc: "Template engine to generate view files"
14
+ class_option :singleton, type: :boolean, desc: "Supply to create a singleton controller"
15
+ class_option :api, type: :boolean, desc: "Skip specs unnecessary for API-only apps"
16
16
 
17
- class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs"
18
- class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs"
19
- class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs"
20
- class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs"
17
+ class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
18
+ class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
19
+ class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
20
+ class_option :helper_specs, type: :boolean, default: true, desc: "Generate helper specs"
21
+ class_option :routing_specs, type: :boolean, default: true, desc: "Generate routing specs"
21
22
 
22
23
  def initialize(*args, &blk)
23
24
  @generator_args = args.first
@@ -27,15 +28,20 @@ module Rspec
27
28
  def generate_controller_spec
28
29
  return unless options[:controller_specs]
29
30
 
30
- template_file = File.join(
31
- 'spec/controllers',
32
- controller_class_path,
33
- "#{controller_file_name}_controller_spec.rb"
34
- )
35
31
  if options[:api]
36
- template 'api_controller_spec.rb', template_file
32
+ template 'api_controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
33
+ else
34
+ template 'controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
35
+ end
36
+ end
37
+
38
+ def generate_request_spec
39
+ return unless options[:request_specs]
40
+
41
+ if options[:api]
42
+ template 'api_request_spec.rb', template_file(folder: 'requests')
37
43
  else
38
- template 'controller_spec.rb', template_file
44
+ template 'request_spec.rb', template_file(folder: 'requests')
39
45
  end
40
46
  end
41
47
 
@@ -60,8 +66,6 @@ module Rspec
60
66
  template 'routing_spec.rb', template_file
61
67
  end
62
68
 
63
- hook_for :integration_tool, :as => :integration
64
-
65
69
  protected
66
70
 
67
71
  attr_reader :generator_args
@@ -116,6 +120,10 @@ module Rspec
116
120
  end
117
121
  end
118
122
 
123
+ def template_file(folder:, suffix: '')
124
+ File.join('spec', folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
125
+ end
126
+
119
127
  def banner
120
128
  self.class.banner
121
129
  end