diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4dffc2e57..49612257d1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,10 +18,6 @@ Metrics/MethodLength: Style/EachWithObject: Enabled: false -# ruby 1.8.7 only had support for hash rockets -Style/HashSyntax: - EnforcedStyle: hash_rockets # default: ruby19 - # the new lambda syntax was not supported in ruby 1.8.7 Style/Lambda: Enabled: false diff --git a/Capybara.md b/Capybara.md index c448f130c4..2936a242cf 100644 --- a/Capybara.md +++ b/Capybara.md @@ -73,5 +73,5 @@ behavior and accepting the risks associated with doing so: # not recommended! RSpec.configure do |c| - c.include Capybara::DSL, :file_path => "spec/requests" + c.include Capybara::DSL, file_path: "spec/requests" end diff --git a/Changelog.md b/Changelog.md index b5895adc07..65875591d7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -344,10 +344,10 @@ Enhancements: * Improve controller and routing spec calls to `routes` by using `yield` instead of `call`. (Anton Davydov, #1308) * Add support for `ActiveJob` specs as standard `RSpec::Rails::RailsExampleGoup`s - via both `:type => :job` and inferring type from spec directory `spec/jobs`. + via both `type: :job` and inferring type from spec directory `spec/jobs`. (Gabe Martin-Dempesy, #1361) * Include `RSpec::Rails::FixtureSupport` into example groups using metadata - `:use_fixtures => true`. (Aaron Kromer, #1372) + `use_fixtures: true`. (Aaron Kromer, #1372) * Include `rspec:request` generator for generating request specs; this is an alias of `rspec:integration` (Aaron Kromer, #1378) * Update `rails_helper` generator with a default check to abort the spec run @@ -488,7 +488,7 @@ Enhancements: Bug Fixes: * Fix an inconsistency in the generated scaffold specs for a controller. (Andy Waite) -* Ensure `config.before(:all, :type => )` hooks run before groups +* Ensure `config.before(:all, type: )` hooks run before groups of the given type, even when the type is inferred by the file location. (Jon Rowe, Myron Marston) * Switch to parsing params with `Rack::Utils::parse_nested_query` to match Rails. @@ -938,7 +938,7 @@ This release is compatible with rails-3.1.0.rc1, but not rails-3.1.0.beta1 * Enhancements * include ApplicationHelper in helper object in helper specs * include request spec extensions in files in spec/integration - * include controller spec extensions in groups that use :type => :controller + * include controller spec extensions in groups that use type: :controller * same for :model, :view, :helper, :mailer, :request, :routing * Bug fixes diff --git a/Gemfile b/Gemfile index ec02a32457..5f0f8a13b5 100644 --- a/Gemfile +++ b/Gemfile @@ -7,12 +7,12 @@ gemspec rspec_dependencies_gemfile = File.expand_path("../Gemfile-rspec-dependencies", __FILE__) eval_gemfile rspec_dependencies_gemfile -gem 'yard', '~> 0.8.7', :require => false +gem 'yard', '~> 0.8.7', require: false ### deps for rdoc.info group :documentation do - gem 'redcarpet', '~> 3.4.0', platforms: [:ruby] gem 'github-markup', '~> 3.0.3' + gem 'redcarpet', '~> 3.4.0', platforms: [:ruby] gem 'relish', '~> 0.7.1' end @@ -36,8 +36,8 @@ else end if MAJOR >= 6 + gem 'selenium-webdriver', '~> 3.5', require: false gem 'sqlite3', '~> 1.4', platforms: [:ruby] - gem 'selenium-webdriver', '~> 3.5', :require => false else gem 'sqlite3', '~> 1.3.6', platforms: [:ruby] end @@ -57,7 +57,7 @@ if RUBY_VERSION < '2.4.0' gem 'minitest', '< 5.12.0' end -gem 'capybara', '~> 2.13', :require => false +gem 'capybara', '~> 2.13', require: false if MAJOR < 6 gem 'nokogiri', '1.8.5' diff --git a/README.md b/README.md index 3dc5247470..72d2c81920 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,7 @@ Use **[`rspec-rails` 1.x][]** for Rails 2.x. # (requires master-branch versions of all related RSpec libraries) group :development, :test do %w[rspec-core rspec-expectations rspec-mocks rspec-rails rspec-support].each do |lib| - gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'master' + gem lib, git: "https://github.com/rspec/#{lib}.git", branch: 'master' end end ``` diff --git a/features/matchers/have_broadcasted_matcher.feature b/features/matchers/have_broadcasted_matcher.feature index f83fd6af20..ecacadafe9 100644 --- a/features/matchers/have_broadcasted_matcher.feature +++ b/features/matchers/have_broadcasted_matcher.feature @@ -104,7 +104,7 @@ Feature: have_broadcasted matcher """ruby require "rails_helper" - RSpec.describe ChatChannel, :type => :channel do + RSpec.describe ChatChannel, type: :channel do it "successfully subscribes" do user = User.new(42) diff --git a/features/matchers/have_enqueued_mail_matcher.feature b/features/matchers/have_enqueued_mail_matcher.feature index e1ebbf886e..c8fc5031b4 100644 --- a/features/matchers/have_enqueued_mail_matcher.feature +++ b/features/matchers/have_enqueued_mail_matcher.feature @@ -33,7 +33,7 @@ Feature: have_enqueued_mail matcher it "matches with enqueued mailer" do ActiveJob::Base.queue_adapter = :test expect { - NotificationsMailer.signup.deliver_later(:wait_until => Date.tomorrow.noon) + NotificationsMailer.signup.deliver_later(wait_until: Date.tomorrow.noon) }.to have_enqueued_mail.at(Date.tomorrow.noon) end end diff --git a/features/step_definitions/additional_cli_steps.rb b/features/step_definitions/additional_cli_steps.rb index 622ddbec33..e4d7cd07ee 100644 --- a/features/step_definitions/additional_cli_steps.rb +++ b/features/step_definitions/additional_cli_steps.rb @@ -1,10 +1,10 @@ begin require "active_job" -rescue LoadError # rubocop:disable Lint/HandleExceptions +rescue LoadError # rubocop:disable Lint/SuppressedException end begin require "action_cable" -rescue LoadError # rubocop:disable Lint/HandleExceptions +rescue LoadError # rubocop:disable Lint/SuppressedException end require "rails/version" diff --git a/lib/generators/rspec/controller/controller_generator.rb b/lib/generators/rspec/controller/controller_generator.rb index dc3c23d37b..a82a2cfbd1 100644 --- a/lib/generators/rspec/controller/controller_generator.rb +++ b/lib/generators/rspec/controller/controller_generator.rb @@ -4,12 +4,12 @@ module Rspec module Generators # @private class ControllerGenerator < Base - argument :actions, :type => :array, :default => [], :banner => "action action" + argument :actions, type: :array, default: [], banner: "action action" - class_option :template_engine, :desc => "Template engine to generate view files" - class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs" - class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs" - class_option :routing_specs, :type => :boolean, :default => false, :desc => "Generate routing specs" + class_option :template_engine, desc: "Template engine to generate view files" + class_option :controller_specs, type: :boolean, default: true, desc: "Generate controller specs" + class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs" + class_option :routing_specs, type: :boolean, default: false, desc: "Generate routing specs" def generate_controller_spec return unless options[:controller_specs] diff --git a/lib/generators/rspec/controller/templates/routing_spec.rb b/lib/generators/rspec/controller/templates/routing_spec.rb index 08550dd20a..2fe851d0e2 100644 --- a/lib/generators/rspec/controller/templates/routing_spec.rb +++ b/lib/generators/rspec/controller/templates/routing_spec.rb @@ -5,7 +5,7 @@ describe 'routing' do <% for action in actions -%> it 'routes to #<%= action %>' do - expect(:get => "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>") + expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>") end <% end -%> end diff --git a/lib/generators/rspec/feature/feature_generator.rb b/lib/generators/rspec/feature/feature_generator.rb index 66c469bebc..5b9bfc4675 100644 --- a/lib/generators/rspec/feature/feature_generator.rb +++ b/lib/generators/rspec/feature/feature_generator.rb @@ -4,8 +4,8 @@ module Rspec module Generators # @private class FeatureGenerator < Base - class_option :feature_specs, :type => :boolean, :default => true, :desc => "Generate feature specs" - class_option :singularize, :type => :boolean, :default => false, :desc => "Singularize the generated feature" + class_option :feature_specs, type: :boolean, default: true, desc: "Generate feature specs" + class_option :singularize, type: :boolean, default: false, desc: "Singularize the generated feature" def generate_feature_spec return unless options[:feature_specs] diff --git a/lib/generators/rspec/generators/generator_generator.rb b/lib/generators/rspec/generators/generator_generator.rb index 7ce9806c41..0b55fccc45 100644 --- a/lib/generators/rspec/generators/generator_generator.rb +++ b/lib/generators/rspec/generators/generator_generator.rb @@ -4,7 +4,7 @@ module Rspec module Generators # @private class GeneratorsGenerator < Base - class_option :generator_specs, :type => :boolean, :default => false, :desc => "Generate generator specs" + class_option :generator_specs, type: :boolean, default: false, desc: "Generate generator specs" def generate_generator_spec return unless options[:generator_specs] diff --git a/lib/generators/rspec/helper/helper_generator.rb b/lib/generators/rspec/helper/helper_generator.rb index 466cb51c08..a035f8e4a7 100644 --- a/lib/generators/rspec/helper/helper_generator.rb +++ b/lib/generators/rspec/helper/helper_generator.rb @@ -4,7 +4,7 @@ module Rspec module Generators # @private class HelperGenerator < Base - class_option :helper_specs, :type => :boolean, :default => true + class_option :helper_specs, type: :boolean, default: true def generate_helper_spec return unless options[:helper_specs] diff --git a/lib/generators/rspec/install/install_generator.rb b/lib/generators/rspec/install/install_generator.rb index a8d8612e7e..8b832089d3 100644 --- a/lib/generators/rspec/install/install_generator.rb +++ b/lib/generators/rspec/install/install_generator.rb @@ -32,8 +32,8 @@ def copy_rails_files def generate_rspec_init(tmpdir) initializer = ::RSpec::Core::ProjectInitializer.new( - :destination => tmpdir, - :report_stream => StringIO.new + destination: tmpdir, + report_stream: StringIO.new ) initializer.run @@ -47,7 +47,7 @@ def replace_generator_command(spec_helper_path) gsub_file spec_helper_path, 'rspec --init', 'rails generate rspec:install', - :verbose => false + verbose: false end def remove_warnings_configuration(spec_helper_path) @@ -56,7 +56,7 @@ def remove_warnings_configuration(spec_helper_path) gsub_file spec_helper_path, /#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/, '', - :verbose => false + verbose: false end end end diff --git a/lib/generators/rspec/install/templates/spec/rails_helper.rb b/lib/generators/rspec/install/templates/spec/rails_helper.rb index 03672af7f6..71e7104d57 100644 --- a/lib/generators/rspec/install/templates/spec/rails_helper.rb +++ b/lib/generators/rspec/install/templates/spec/rails_helper.rb @@ -63,7 +63,7 @@ # You can disable this behaviour by removing the line below, and instead # explicitly tag your specs with their type, e.g.: # - # RSpec.describe UsersController, :type => :controller do + # RSpec.describe UsersController, type: :controller do # # ... # end # diff --git a/lib/generators/rspec/integration/integration_generator.rb b/lib/generators/rspec/integration/integration_generator.rb index b48923c715..f820b017f9 100644 --- a/lib/generators/rspec/integration/integration_generator.rb +++ b/lib/generators/rspec/integration/integration_generator.rb @@ -7,9 +7,9 @@ class IntegrationGenerator < Base # Add a deprecation for this class, before rspec-rails 4, to use the # `RequestGenerator` instead class_option :request_specs, - :type => :boolean, - :default => true, - :desc => "Generate request specs" + type: :boolean, + default: true, + desc: "Generate request specs" def generate_request_spec return unless options[:request_specs] diff --git a/lib/generators/rspec/mailer/mailer_generator.rb b/lib/generators/rspec/mailer/mailer_generator.rb index 768dfe8d45..0030dbffe4 100644 --- a/lib/generators/rspec/mailer/mailer_generator.rb +++ b/lib/generators/rspec/mailer/mailer_generator.rb @@ -5,7 +5,7 @@ module Rspec module Generators # @private class MailerGenerator < Base - argument :actions, :type => :array, :default => [], :banner => "method method" + argument :actions, type: :array, default: [], banner: "method method" def generate_mailer_spec template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb") diff --git a/lib/generators/rspec/model/model_generator.rb b/lib/generators/rspec/model/model_generator.rb index fcbaaecb52..6ab0ffb666 100644 --- a/lib/generators/rspec/model/model_generator.rb +++ b/lib/generators/rspec/model/model_generator.rb @@ -5,10 +5,10 @@ module Generators # @private class ModelGenerator < Base argument :attributes, - :type => :array, - :default => [], - :banner => "field:type field:type" - class_option :fixture, :type => :boolean + type: :array, + default: [], + banner: "field:type field:type" + class_option :fixture, type: :boolean def create_model_spec template_file = File.join( diff --git a/lib/generators/rspec/scaffold/scaffold_generator.rb b/lib/generators/rspec/scaffold/scaffold_generator.rb index 67cf0c85a7..3bb6ec91d0 100644 --- a/lib/generators/rspec/scaffold/scaffold_generator.rb +++ b/lib/generators/rspec/scaffold/scaffold_generator.rb @@ -7,17 +7,17 @@ module Generators class ScaffoldGenerator < Base include ::Rails::Generators::ResourceHelpers source_paths << File.expand_path('../helper/templates', __dir__) - argument :attributes, :type => :array, :default => [], :banner => "field:type field:type" + argument :attributes, type: :array, default: [], banner: "field:type field:type" - class_option :orm, :desc => "ORM used to generate the controller" - class_option :template_engine, :desc => "Template engine to generate view files" - class_option :singleton, :type => :boolean, :desc => "Supply to create a singleton controller" - class_option :api, :type => :boolean, :desc => "Skip specs unnecessary for API-only apps" + class_option :orm, desc: "ORM used to generate the controller" + class_option :template_engine, desc: "Template engine to generate view files" + class_option :singleton, type: :boolean, desc: "Supply to create a singleton controller" + class_option :api, type: :boolean, desc: "Skip specs unnecessary for API-only apps" - class_option :controller_specs, :type => :boolean, :default => true, :desc => "Generate controller specs" - class_option :view_specs, :type => :boolean, :default => true, :desc => "Generate view specs" - class_option :helper_specs, :type => :boolean, :default => true, :desc => "Generate helper specs" - class_option :routing_specs, :type => :boolean, :default => true, :desc => "Generate routing specs" + class_option :controller_specs, type: :boolean, default: true, desc: "Generate controller specs" + class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs" + class_option :helper_specs, type: :boolean, default: true, desc: "Generate helper specs" + class_option :routing_specs, type: :boolean, default: true, desc: "Generate routing specs" def initialize(*args, &blk) @generator_args = args.first @@ -60,7 +60,7 @@ def generate_routing_spec template 'routing_spec.rb', template_file end - hook_for :integration_tool, :as => :integration + hook_for :integration_tool, as: :integration protected diff --git a/lib/generators/rspec/scaffold/templates/api_controller_spec.rb b/lib/generators/rspec/scaffold/templates/api_controller_spec.rb index 39d055b674..1fc24e8402 100644 --- a/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/api_controller_spec.rb @@ -60,7 +60,7 @@ it "returns a success response" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if RUBY_VERSION < '1.9.3' -%> - get :show, {:id => <%= file_name %>.to_param}, valid_session + get :show, {id: <%= file_name %>.to_param}, valid_session <% else -%> get :show, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> @@ -73,7 +73,7 @@ it "creates a new <%= class_name %>" do expect { <% if RUBY_VERSION < '1.9.3' -%> - post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session + post :create, {<%= ns_file_name %>: valid_attributes}, valid_session <% else -%> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -82,7 +82,7 @@ it "renders a JSON response with the new <%= ns_file_name %>" do <% if RUBY_VERSION < '1.9.3' -%> - post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session + post :create, {<%= ns_file_name %>: valid_attributes}, valid_session <% else %> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -95,7 +95,7 @@ context "with invalid params" do it "renders a JSON response with errors for the new <%= ns_file_name %>" do <% if RUBY_VERSION < '1.9.3' -%> - post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session + post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session <% else %> post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session <% end -%> @@ -114,7 +114,7 @@ it "updates the requested <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if RUBY_VERSION < '1.9.3' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session <% else -%> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session <% end -%> @@ -125,7 +125,7 @@ it "renders a JSON response with the <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if RUBY_VERSION < '1.9.3' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session <% else %> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -138,7 +138,7 @@ it "renders a JSON response with errors for the <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if RUBY_VERSION < '1.9.3' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session <% else %> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session <% end -%> @@ -153,7 +153,7 @@ <%= file_name %> = <%= class_name %>.create! valid_attributes expect { <% if RUBY_VERSION < '1.9.3' -%> - delete :destroy, {:id => <%= file_name %>.to_param}, valid_session + delete :destroy, {id: <%= file_name %>.to_param}, valid_session <% else -%> delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> diff --git a/lib/generators/rspec/scaffold/templates/controller_spec.rb b/lib/generators/rspec/scaffold/templates/controller_spec.rb index 7f5799a199..b2a80a38e0 100644 --- a/lib/generators/rspec/scaffold/templates/controller_spec.rb +++ b/lib/generators/rspec/scaffold/templates/controller_spec.rb @@ -60,7 +60,7 @@ it "returns a success response" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - get :show, {:id => <%= file_name %>.to_param}, valid_session + get :show, {id: <%= file_name %>.to_param}, valid_session <% else -%> get :show, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> @@ -83,7 +83,7 @@ it "returns a success response" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - get :edit, {:id => <%= file_name %>.to_param}, valid_session + get :edit, {id: <%= file_name %>.to_param}, valid_session <% else -%> get :edit, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> @@ -96,7 +96,7 @@ it "creates a new <%= class_name %>" do expect { <% if Rails::VERSION::STRING < '5.0' -%> - post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session + post :create, {<%= ns_file_name %>: valid_attributes}, valid_session <% else -%> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -105,7 +105,7 @@ it "redirects to the created <%= ns_file_name %>" do <% if Rails::VERSION::STRING < '5.0' -%> - post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session + post :create, {<%= ns_file_name %>: valid_attributes}, valid_session <% else -%> post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -116,7 +116,7 @@ context "with invalid params" do it "returns a success response (i.e. to display the 'new' template)" do <% if Rails::VERSION::STRING < '5.0' -%> - post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session + post :create, {<%= ns_file_name %>: invalid_attributes}, valid_session <% else -%> post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session <% end -%> @@ -134,7 +134,7 @@ it "updates the requested <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, valid_session <% else -%> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session <% end -%> @@ -145,7 +145,7 @@ it "redirects to the <%= ns_file_name %>" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, valid_session <% else -%> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session <% end -%> @@ -157,7 +157,7 @@ it "returns a success response (i.e. to display the 'edit' template)" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session + put :update, {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, valid_session <% else -%> put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session <% end -%> @@ -171,7 +171,7 @@ <%= file_name %> = <%= class_name %>.create! valid_attributes expect { <% if Rails::VERSION::STRING < '5.0' -%> - delete :destroy, {:id => <%= file_name %>.to_param}, valid_session + delete :destroy, {id: <%= file_name %>.to_param}, valid_session <% else -%> delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> @@ -181,7 +181,7 @@ it "redirects to the <%= table_name %> list" do <%= file_name %> = <%= class_name %>.create! valid_attributes <% if Rails::VERSION::STRING < '5.0' -%> - delete :destroy, {:id => <%= file_name %>.to_param}, valid_session + delete :destroy, {id: <%= file_name %>.to_param}, valid_session <% else -%> delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session <% end -%> diff --git a/lib/generators/rspec/scaffold/templates/edit_spec.rb b/lib/generators/rspec/scaffold/templates/edit_spec.rb index 3774477f57..072c2f0a66 100644 --- a/lib/generators/rspec/scaffold/templates/edit_spec.rb +++ b/lib/generators/rspec/scaffold/templates/edit_spec.rb @@ -5,7 +5,7 @@ before(:each) do @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %> <% output_attributes.each_with_index do |attribute, attribute_index| -%> - :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> + <%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> <% end -%> <%= output_attributes.empty? ? "" : " ))\n" -%> end diff --git a/lib/generators/rspec/scaffold/templates/index_spec.rb b/lib/generators/rspec/scaffold/templates/index_spec.rb index e813cfa91c..fc5a0f285b 100644 --- a/lib/generators/rspec/scaffold/templates/index_spec.rb +++ b/lib/generators/rspec/scaffold/templates/index_spec.rb @@ -7,7 +7,7 @@ <% [1,2].each_with_index do |id, model_index| -%> <%= class_name %>.create!(<%= output_attributes.empty? ? (model_index == 1 ? ')' : '),') : '' %> <% output_attributes.each_with_index do |attribute, attribute_index| -%> - :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> + <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> <% end -%> <% if !output_attributes.empty? -%> <%= model_index == 1 ? ')' : '),' %> @@ -19,7 +19,7 @@ it "renders a list of <%= ns_table_name %>" do render <% for attribute in output_attributes -%> - assert_select "tr>td", :text => <%= value_for(attribute) %>.to_s, :count => 2 + assert_select "tr>td", text: <%= value_for(attribute) %>.to_s, count: 2 <% end -%> end end diff --git a/lib/generators/rspec/scaffold/templates/new_spec.rb b/lib/generators/rspec/scaffold/templates/new_spec.rb index 2fe5c1367d..3756604a24 100644 --- a/lib/generators/rspec/scaffold/templates/new_spec.rb +++ b/lib/generators/rspec/scaffold/templates/new_spec.rb @@ -5,7 +5,7 @@ before(:each) do assign(:<%= ns_file_name %>, <%= class_name %>.new(<%= '))' if output_attributes.empty? %> <% output_attributes.each_with_index do |attribute, attribute_index| -%> - :<%= attribute.name %> => <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> + <%= attribute.name %>: <%= attribute.default.inspect %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> <% end -%> <%= !output_attributes.empty? ? " ))\n end" : " end" %> diff --git a/lib/generators/rspec/scaffold/templates/routing_spec.rb b/lib/generators/rspec/scaffold/templates/routing_spec.rb index a81d765a21..265ecd4f3f 100644 --- a/lib/generators/rspec/scaffold/templates/routing_spec.rb +++ b/lib/generators/rspec/scaffold/templates/routing_spec.rb @@ -5,41 +5,41 @@ describe "routing" do <% unless options[:singleton] -%> it "routes to #index" do - expect(:get => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index") + expect(get: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#index") end <% end -%> <% unless options[:api] -%> it "routes to #new" do - expect(:get => "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new") + expect(get: "/<%= ns_table_name %>/new").to route_to("<%= ns_table_name %>#new") end <% end -%> it "routes to #show" do - expect(:get => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", :id => "1") + expect(get: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#show", id: "1") end <% unless options[:api] -%> it "routes to #edit" do - expect(:get => "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", :id => "1") + expect(get: "/<%= ns_table_name %>/1/edit").to route_to("<%= ns_table_name %>#edit", id: "1") end <% end -%> it "routes to #create" do - expect(:post => "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create") + expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create") end it "routes to #update via PUT" do - expect(:put => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1") + expect(put: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1") end it "routes to #update via PATCH" do - expect(:patch => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", :id => "1") + expect(patch: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#update", id: "1") end it "routes to #destroy" do - expect(:delete => "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", :id => "1") + expect(delete: "/<%= ns_table_name %>/1").to route_to("<%= ns_table_name %>#destroy", id: "1") end end end diff --git a/lib/generators/rspec/scaffold/templates/show_spec.rb b/lib/generators/rspec/scaffold/templates/show_spec.rb index 90247c5c18..15811dea5a 100644 --- a/lib/generators/rspec/scaffold/templates/show_spec.rb +++ b/lib/generators/rspec/scaffold/templates/show_spec.rb @@ -5,7 +5,7 @@ before(:each) do @<%= ns_file_name %> = assign(:<%= ns_file_name %>, <%= class_name %>.create!(<%= '))' if output_attributes.empty? %> <% output_attributes.each_with_index do |attribute, attribute_index| -%> - :<%= attribute.name %> => <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> + <%= attribute.name %>: <%= value_for(attribute) %><%= attribute_index == output_attributes.length - 1 ? '' : ','%> <% end -%> <% if !output_attributes.empty? -%> )) diff --git a/lib/generators/rspec/system/system_generator.rb b/lib/generators/rspec/system/system_generator.rb index 937241733e..ca994bf4b7 100644 --- a/lib/generators/rspec/system/system_generator.rb +++ b/lib/generators/rspec/system/system_generator.rb @@ -5,7 +5,7 @@ module Rspec module Generators # @private class SystemGenerator < Base - class_option :system_specs, :type => :boolean, :default => true, :desc => "Generate system specs" + class_option :system_specs, type: :boolean, default: true, desc: "Generate system specs" def generate_system_spec return unless options[:system_specs] diff --git a/lib/generators/rspec/view/view_generator.rb b/lib/generators/rspec/view/view_generator.rb index 7a7c002c22..5de24267e5 100644 --- a/lib/generators/rspec/view/view_generator.rb +++ b/lib/generators/rspec/view/view_generator.rb @@ -4,9 +4,9 @@ module Rspec module Generators # @private class ViewGenerator < Base - argument :actions, :type => :array, :default => [], :banner => "action action" + argument :actions, type: :array, default: [], banner: "action action" - class_option :template_engine, :desc => "Template engine to generate view files" + class_option :template_engine, desc: "Template engine to generate view files" def create_view_specs empty_directory File.join("spec", "views", file_path) diff --git a/lib/rspec-rails.rb b/lib/rspec-rails.rb index 2cabaaf16a..707e3b6d99 100644 --- a/lib/rspec-rails.rb +++ b/lib/rspec-rails.rb @@ -31,7 +31,7 @@ class Railtie < ::Rails::Railtie # This is called after the environment has been loaded but before Rails # sets the default for the `preview_path` initializer "rspec_rails.action_mailer", - :before => "action_mailer.set_configs" do |app| + before: "action_mailer.set_configs" do |app| setup_preview_path(app) end diff --git a/lib/rspec/rails/configuration.rb b/lib/rspec/rails/configuration.rb index 38d67f9501..8e0bb9929b 100644 --- a/lib/rspec/rails/configuration.rb +++ b/lib/rspec/rails/configuration.rb @@ -25,33 +25,33 @@ class Configuration # # @api private DIRECTORY_MAPPINGS = { - :channel => %w[spec channels], - :controller => %w[spec controllers], - :helper => %w[spec helpers], - :job => %w[spec jobs], - :mailer => %w[spec mailers], - :model => %w[spec models], - :request => %w[spec (requests|integration|api)], - :routing => %w[spec routing], - :view => %w[spec views], - :feature => %w[spec features], - :system => %w[spec system], - :mailbox => %w[spec mailboxes] + channel: %w[spec channels], + controller: %w[spec controllers], + helper: %w[spec helpers], + job: %w[spec jobs], + mailer: %w[spec mailers], + model: %w[spec models], + request: %w[spec (requests|integration|api)], + routing: %w[spec routing], + view: %w[spec views], + feature: %w[spec features], + system: %w[spec system], + mailbox: %w[spec mailboxes] } # Sets up the different example group modules for the different spec types # # @api private def self.add_test_type_configurations(config) - config.include RSpec::Rails::ControllerExampleGroup, :type => :controller - config.include RSpec::Rails::HelperExampleGroup, :type => :helper - config.include RSpec::Rails::ModelExampleGroup, :type => :model - config.include RSpec::Rails::RequestExampleGroup, :type => :request - config.include RSpec::Rails::RoutingExampleGroup, :type => :routing - config.include RSpec::Rails::ViewExampleGroup, :type => :view - config.include RSpec::Rails::FeatureExampleGroup, :type => :feature + config.include RSpec::Rails::ControllerExampleGroup, type: :controller + config.include RSpec::Rails::HelperExampleGroup, type: :helper + config.include RSpec::Rails::ModelExampleGroup, type: :model + config.include RSpec::Rails::RequestExampleGroup, type: :request + config.include RSpec::Rails::RoutingExampleGroup, type: :routing + config.include RSpec::Rails::ViewExampleGroup, type: :view + config.include RSpec::Rails::FeatureExampleGroup, type: :feature config.include RSpec::Rails::Matchers - config.include RSpec::Rails::SystemExampleGroup, :type => :system + config.include RSpec::Rails::SystemExampleGroup, type: :system end # @private @@ -61,10 +61,10 @@ def self.initialize_configuration(config) config.backtrace_exclusion_patterns << %r{lib/rspec/rails} # controller settings - config.add_setting :infer_base_class_for_anonymous_controllers, :default => true + config.add_setting :infer_base_class_for_anonymous_controllers, default: true # fixture support - config.add_setting :use_transactional_fixtures, :alias_with => :use_transactional_examples + config.add_setting :use_transactional_fixtures, alias_with: :use_transactional_examples config.add_setting :use_instantiated_fixtures config.add_setting :global_fixtures config.add_setting :fixture_path @@ -80,7 +80,7 @@ def self.initialize_configuration(config) config.include RSpec::Rails::FixtureSupport if ::Rails::VERSION::STRING > '5' - config.add_setting :file_fixture_path, :default => 'spec/fixtures/files' + config.add_setting :file_fixture_path, default: 'spec/fixtures/files' config.include RSpec::Rails::FileFixtureSupport end @@ -93,7 +93,7 @@ def self.initialize_configuration(config) # as a getter. This makes it easier for rspec-rails users because we use # `render_views` directly in example groups, so this aligns the two APIs, # but requires this workaround: - config.add_setting :rendering_views, :default => false + config.add_setting :rendering_views, default: false config.instance_exec do def render_views=(val) @@ -111,7 +111,7 @@ def render_views? def infer_spec_type_from_file_location! DIRECTORY_MAPPINGS.each do |type, dir_parts| escaped_path = Regexp.compile(dir_parts.join('[\\\/]') + '[\\\/]') - define_derived_metadata(:file_path => escaped_path) do |metadata| + define_derived_metadata(file_path: escaped_path) do |metadata| metadata[:type] ||= type end end @@ -129,26 +129,26 @@ def filter_rails_from_backtrace! if defined?(::Rails::Controller::Testing) [:controller, :view, :request].each do |type| - config.include ::Rails::Controller::Testing::TestProcess, :type => type - config.include ::Rails::Controller::Testing::TemplateAssertions, :type => type - config.include ::Rails::Controller::Testing::Integration, :type => type + config.include ::Rails::Controller::Testing::TestProcess, type: type + config.include ::Rails::Controller::Testing::TemplateAssertions, type: type + config.include ::Rails::Controller::Testing::Integration, type: type end end if RSpec::Rails::FeatureCheck.has_action_mailer? - config.include RSpec::Rails::MailerExampleGroup, :type => :mailer + config.include RSpec::Rails::MailerExampleGroup, type: :mailer end if RSpec::Rails::FeatureCheck.has_active_job? - config.include RSpec::Rails::JobExampleGroup, :type => :job + config.include RSpec::Rails::JobExampleGroup, type: :job end if RSpec::Rails::FeatureCheck.has_action_cable_testing? - config.include RSpec::Rails::ChannelExampleGroup, :type => :channel + config.include RSpec::Rails::ChannelExampleGroup, type: :channel end if RSpec::Rails::FeatureCheck.has_action_mailbox? - config.include RSpec::Rails::MailboxExampleGroup, :type => :mailbox + config.include RSpec::Rails::MailboxExampleGroup, type: :mailbox end end # rubocop:enable Metrics/MethodLength diff --git a/lib/rspec/rails/example/controller_example_group.rb b/lib/rspec/rails/example/controller_example_group.rb index 198f22ab5f..3150f3d469 100644 --- a/lib/rspec/rails/example/controller_example_group.rb +++ b/lib/rspec/rails/example/controller_example_group.rb @@ -94,9 +94,9 @@ def self.name self.routes = ActionDispatch::Routing::RouteSet.new.tap do |r| r.draw do resources resource_name, - :as => resource_as, - :module => resource_module, - :path => resource_path + as: resource_as, + module: resource_module, + path: resource_path end end end @@ -159,7 +159,7 @@ def rescue_with_handler(exception) # # expect do # bypass_rescue - # get :show, :id => profile.id + 1 + # get :show, id: profile.id + 1 # end.to raise_error(/403 Forbidden/) # end # end diff --git a/lib/rspec/rails/example/feature_example_group.rb b/lib/rspec/rails/example/feature_example_group.rb index 06ae978503..9cee0120e0 100644 --- a/lib/rspec/rails/example/feature_example_group.rb +++ b/lib/rspec/rails/example/feature_example_group.rb @@ -37,9 +37,9 @@ def visit(*) unless RSpec.respond_to?(:feature) opts = { - :capybara_feature => true, - :type => :feature, - :skip => <<-EOT.squish + capybara_feature: true, + type: :feature, + skip: <<-EOT.squish Feature specs require the Capybara (https://github.com/jnicklas/capybara) gem, version 2.2.0 or later. We recommend version 2.4.0 or later to avoid some deprecation warnings and have support for @@ -63,7 +63,7 @@ def visit(*) main_feature = nil unless c.expose_dsl_globally? c.alias_example_group_to :feature, opts c.alias_example_to :scenario - c.alias_example_to :xscenario, :skip => 'Temporarily skipped with xscenario' + c.alias_example_to :xscenario, skip: 'Temporarily skipped with xscenario' end # Due to load order issues and `config.expose_dsl_globally?` defaulting to diff --git a/lib/rspec/rails/example/view_example_group.rb b/lib/rspec/rails/example/view_example_group.rb index 39ef6a8365..93a2033f9d 100644 --- a/lib/rspec/rails/example/view_example_group.rb +++ b/lib/rspec/rails/example/view_example_group.rb @@ -50,9 +50,9 @@ module ExampleMethods end # @overload render - # @overload render({:partial => path_to_file}) - # @overload render({:partial => path_to_file}, {... locals ...}) - # @overload render({:partial => path_to_file}, {... locals ...}) do ... end + # @overload render({partial: path_to_file}) + # @overload render({partial: path_to_file}, {... locals ...}) + # @overload render({partial: path_to_file}, {... locals ...}) do ... end # # Delegates to ActionView::Base#render, so see documentation on that # for more info. @@ -62,7 +62,7 @@ module ExampleMethods # # describe "widgets/new.html.erb" do # it "shows all the widgets" do - # render # => view.render(:file => "widgets/new.html.erb") + # render # => view.render(file: "widgets/new.html.erb") # # ... # end # end @@ -105,7 +105,7 @@ def params # @deprecated Use `view` instead. def template - RSpec.deprecate("template", :replacement => "view") + RSpec.deprecate("template", replacement: "view") view end @@ -152,7 +152,7 @@ def _default_render_options # the original string. match = path_regex.match(_default_file_to_render) - render_options = { :template => match[:template] } + render_options = { template: match[:template] } render_options[:handlers] = [match[:handler]] if match[:handler] render_options[:formats] = [match[:format].to_sym] if match[:format] render_options[:locales] = [match[:locale]] if match[:locale] diff --git a/lib/rspec/rails/fixture_file_upload_support.rb b/lib/rspec/rails/fixture_file_upload_support.rb index c222eeaf0b..ade379bc38 100644 --- a/lib/rspec/rails/fixture_file_upload_support.rb +++ b/lib/rspec/rails/fixture_file_upload_support.rb @@ -2,7 +2,7 @@ module RSpec module Rails # @private module FixtureFileUploadSupport - delegate :fixture_file_upload, :to => :rails_fixture_file_wrapper + delegate :fixture_file_upload, to: :rails_fixture_file_wrapper private diff --git a/lib/rspec/rails/matchers/action_cable.rb b/lib/rspec/rails/matchers/action_cable.rb index 42534b59c0..12b811d7b4 100644 --- a/lib/rspec/rails/matchers/action_cable.rb +++ b/lib/rspec/rails/matchers/action_cable.rb @@ -48,7 +48,7 @@ module ActionCable def have_broadcasted_to(target = nil) check_action_cable_adapter - ActionCable::HaveBroadcastedTo.new(target, :channel => described_class) + ActionCable::HaveBroadcastedTo.new(target, channel: described_class) end alias_method :broadcast_to, :have_broadcasted_to diff --git a/lib/rspec/rails/matchers/have_http_status.rb b/lib/rspec/rails/matchers/have_http_status.rb index 2a6d77bc84..5e67280aaa 100644 --- a/lib/rspec/rails/matchers/have_http_status.rb +++ b/lib/rspec/rails/matchers/have_http_status.rb @@ -293,9 +293,9 @@ def failure_message_when_negated protected RESPONSE_METHODS = { - :success => 'successful', - :error => 'server_error', - :missing => 'not_found' + success: 'successful', + error: 'server_error', + missing: 'not_found' }.freeze def check_expected_status(test_response, expected) diff --git a/lib/rspec/rails/matchers/routing_matchers.rb b/lib/rspec/rails/matchers/routing_matchers.rb index 9bca99eda5..621b06b00e 100644 --- a/lib/rspec/rails/matchers/routing_matchers.rb +++ b/lib/rspec/rails/matchers/routing_matchers.rb @@ -14,7 +14,7 @@ def initialize(scope, *expected) @expected.merge!(expected[0]) else controller, action = expected[0].split('#') - @expected.merge!(:controller => controller, :action => action) + @expected.merge!(controller: controller, action: action) end end @@ -26,7 +26,7 @@ def matches?(verb_to_path_map) path, query = *verb_to_path_map.values.first.split('?') @scope.assert_recognizes( @expected, - { :method => verb_to_path_map.keys.first, :path => path }, + { method: verb_to_path_map.keys.first, path: path }, Rack::Utils.parse_nested_query(query) ) end @@ -50,12 +50,12 @@ def description # # @example # - # expect(:get => "/things/special").to route_to( - # :controller => "things", - # :action => "special" + # expect(get: "/things/special").to route_to( + # controller: "things", + # action: "special" # ) # - # expect(:get => "/things/special").to route_to("things#special") + # expect(get: "/things/special").to route_to("things#special") # # @see https://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes def route_to(*expected) @@ -72,7 +72,7 @@ def matches?(path) @actual = path match_unless_raises ActionController::RoutingError do @routing_options = @scope.routes.recognize_path( - path.values.first, :method => path.keys.first + path.values.first, method: path.keys.first ) end end @@ -95,9 +95,9 @@ def description # `RouteSet#recognize_path`. # # @example You can use route helpers provided by rspec-rails. - # expect(:get => "/a/path").to be_routable - # expect(:post => "/another/path").to be_routable - # expect(:put => "/yet/another/path").to be_routable + # expect(get: "/a/path").to be_routable + # expect(post: "/another/path").to be_routable + # expect(put: "/yet/another/path").to be_routable def be_routable BeRoutableMatcher.new(self) end diff --git a/lib/rspec/rails/tasks/rspec.rake b/lib/rspec/rails/tasks/rspec.rake index 339de95bc6..a58a518ffb 100644 --- a/lib/rspec/rails/tasks/rspec.rake +++ b/lib/rspec/rails/tasks/rspec.rake @@ -3,12 +3,12 @@ if default = Rake.application.instance_variable_get('@tasks')['default'] default.prerequisites.delete('test') end -task :default => :spec +task default: :spec -task :stats => "spec:statsetup" +task stats: "spec:statsetup" desc "Run all specs in spec directory (excluding plugin specs)" -RSpec::Core::RakeTask.new(:spec => "spec:prepare") +RSpec::Core::RakeTask.new(spec: "spec:prepare") namespace :spec do types = begin @@ -38,7 +38,7 @@ namespace :spec do # RCov task only enabled for Ruby 1.8 if RUBY_VERSION < '1.9' desc "Run all specs with rcov" - RSpec::Core::RakeTask.new(:rcov => "spec:prepare") do |t| + RSpec::Core::RakeTask.new(rcov: "spec:prepare") do |t| t.rcov = true t.pattern = "./spec/**/*_spec.rb" t.rcov_opts = '--exclude /gems/,/Library/,/usr/,lib/tasks,.bundle,config,/lib/rspec/,/lib/rspec-,spec' diff --git a/lib/rspec/rails/vendor/capybara.rb b/lib/rspec/rails/vendor/capybara.rb index 996a42b114..1d3124c79a 100644 --- a/lib/rspec/rails/vendor/capybara.rb +++ b/lib/rspec/rails/vendor/capybara.rb @@ -16,24 +16,24 @@ RSpec.configure do |c| if defined?(Capybara::DSL) - c.include Capybara::DSL, :type => :feature + c.include Capybara::DSL, type: :feature if defined?(ActionPack) && ActionPack::VERSION::STRING >= "5.1" - c.include Capybara::DSL, :type => :system + c.include Capybara::DSL, type: :system end end if defined?(Capybara::RSpecMatchers) - c.include Capybara::RSpecMatchers, :type => :view - c.include Capybara::RSpecMatchers, :type => :helper - c.include Capybara::RSpecMatchers, :type => :mailer - c.include Capybara::RSpecMatchers, :type => :controller - c.include Capybara::RSpecMatchers, :type => :feature - c.include Capybara::RSpecMatchers, :type => :system + c.include Capybara::RSpecMatchers, type: :view + c.include Capybara::RSpecMatchers, type: :helper + c.include Capybara::RSpecMatchers, type: :mailer + c.include Capybara::RSpecMatchers, type: :controller + c.include Capybara::RSpecMatchers, type: :feature + c.include Capybara::RSpecMatchers, type: :system end unless defined?(Capybara::RSpecMatchers) || defined?(Capybara::DSL) - c.include Capybara, :type => :request - c.include Capybara, :type => :controller + c.include Capybara, type: :request + c.include Capybara, type: :controller end end end diff --git a/lib/rspec/rails/view_path_builder.rb b/lib/rspec/rails/view_path_builder.rb index 9969a95a46..6f55f279fa 100644 --- a/lib/rspec/rails/view_path_builder.rb +++ b/lib/rspec/rails/view_path_builder.rb @@ -20,7 +20,7 @@ def initialize(route_set) # view_path_builder.path_for({ :controller => 'posts', :action => 'delete' }) # # => ActionController::UrlGenerationError: No route matches {:action=>"delete", :controller=>"posts"} def path_for(path_params) - url_for(path_params.merge(:only_path => true)) + url_for(path_params.merge(only_path: true)) rescue => e e.message end diff --git a/lib/rspec/rails/view_rendering.rb b/lib/rspec/rails/view_rendering.rb index 79b5139d87..22eff75ba2 100644 --- a/lib/rspec/rails/view_rendering.rb +++ b/lib/rspec/rails/view_rendering.rb @@ -55,9 +55,9 @@ def self.nullify_template_rendering(templates) "", template.identifier, EmptyTemplateHandler, - :virtual_path => template.virtual_path, - :format => template_format(template), - :locals => [] + virtual_path: template.virtual_path, + format: template_format(template), + locals: [] ) end end diff --git a/spec/generators/rspec/controller/controller_generator_spec.rb b/spec/generators/rspec/controller/controller_generator_spec.rb index 861aa54c3b..80bd53d9d5 100644 --- a/spec/generators/rspec/controller/controller_generator_spec.rb +++ b/spec/generators/rspec/controller/controller_generator_spec.rb @@ -116,7 +116,7 @@ it { is_expected.to contain(/^RSpec.describe 'PostsController', #{type_metatag(:routing)}/) } it { is_expected.to contain(/describe 'routing'/) } it { is_expected.to contain(/it 'routes to #seek'/) } - it { is_expected.to contain(/expect\(:get => "\/posts\/seek"\).to route_to\("posts#seek"\)/) } + it { is_expected.to contain(/expect\(get: "\/posts\/seek"\).to route_to\("posts#seek"\)/) } end end diff --git a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb index a6a4ccc459..3fc754b26c 100644 --- a/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +++ b/spec/generators/rspec/scaffold/scaffold_generator_spec.rb @@ -2,7 +2,7 @@ require 'generators/rspec/scaffold/scaffold_generator' require 'support/generators' -RSpec.describe Rspec::Generators::ScaffoldGenerator, :type => :generator do +RSpec.describe Rspec::Generators::ScaffoldGenerator, type: :generator do setup_default_destination describe 'standard controller spec' do @@ -98,16 +98,16 @@ before { run_generator %w(posts upvotes:integer downvotes:integer) } subject { file("spec/views/posts/index.html.erb_spec.rb") } it { is_expected.to exist } - it { is_expected.to contain('assert_select "tr>td", :text => 2.to_s, :count => 2') } - it { is_expected.to contain('assert_select "tr>td", :text => 3.to_s, :count => 2') } + it { is_expected.to contain('assert_select "tr>td", text: 2.to_s, count: 2') } + it { is_expected.to contain('assert_select "tr>td", text: 3.to_s, count: 2') } end describe 'with multiple float attributes index' do before { run_generator %w(posts upvotes:float downvotes:float) } subject { file("spec/views/posts/index.html.erb_spec.rb") } it { is_expected.to exist } - it { is_expected.to contain('assert_select "tr>td", :text => 2.5.to_s, :count => 2') } - it { is_expected.to contain('assert_select "tr>td", :text => 3.5.to_s, :count => 2') } + it { is_expected.to contain('assert_select "tr>td", text: 2.5.to_s, count: 2') } + it { is_expected.to contain('assert_select "tr>td", text: 3.5.to_s, count: 2') } end case diff --git a/spec/rspec/rails/configuration_spec.rb b/spec/rspec/rails/configuration_spec.rb index 5538eeffa8..3b904cd97b 100644 --- a/spec/rspec/rails/configuration_spec.rb +++ b/spec/rspec/rails/configuration_spec.rb @@ -59,11 +59,11 @@ context "adds settings" do include_examples "adds setting", :infer_base_class_for_anonymous_controllers, - :default => true + default: true include_examples "adds setting", :use_transactional_fixtures, - :alias_with => :use_transactional_examples + alias_with: :use_transactional_examples include_examples "adds setting", :use_instantiated_fixtures @@ -131,7 +131,7 @@ def in_inferring_type_from_location_environment "./#{location}/foos_spec.rb" ) group = RSpec.describe("Arbitrary Description") - expect(group.metadata).to include(:type => type) + expect(group.metadata).to include(type: type) end end end @@ -167,17 +167,17 @@ def in_inferring_type_from_location_environment a_controller_class = Class.new stub_const "SomeController", a_controller_class - group = RSpec.describe(SomeController, :type => :controller) + group = RSpec.describe(SomeController, type: :controller) expect(group.controller_class).to be(a_controller_class) expect(group.new).to be_a(RSpec::Rails::ControllerExampleGroup) end - it "metadata `:type => :helper` sets up helper example groups" do + it "metadata `type: :helper` sets up helper example groups" do a_helper_module = Module.new stub_const "SomeHelper", a_helper_module - group = RSpec.describe(SomeHelper, :type => :helper) + group = RSpec.describe(SomeHelper, type: :helper) expect( group.determine_default_helper_class(:ignored) @@ -185,16 +185,16 @@ def in_inferring_type_from_location_environment expect(group.new).to be_a(RSpec::Rails::HelperExampleGroup) end - it "metadata `:type => :model` sets up model example groups" do + it "metadata `type: :model` sets up model example groups" do a_model_class = Class.new stub_const "SomeModel", a_model_class - group = RSpec.describe(SomeModel, :type => :model) + group = RSpec.describe(SomeModel, type: :model) expect(group.new).to be_a(RSpec::Rails::ModelExampleGroup) end - it "metadata `:type => :request` sets up request example groups" do + it "metadata `type: :request` sets up request example groups" do a_rails_app = double("Rails application") the_rails_module = Module.new allow(the_rails_module).to receive(:application) { a_rails_app } @@ -202,33 +202,33 @@ def in_inferring_type_from_location_environment stub_const "Rails", the_rails_module stub_const 'Rails::VERSION', version - group = RSpec.describe("Some Request API", :type => :request) + group = RSpec.describe("Some Request API", type: :request) expect(group.new.app).to be(a_rails_app) expect(group.new).to be_a(RSpec::Rails::RequestExampleGroup) end - it "metadata `:type => :routing` sets up routing example groups" do + it "metadata `type: :routing` sets up routing example groups" do a_controller_class = Class.new stub_const "SomeController", a_controller_class - group = RSpec.describe(SomeController, :type => :routing) + group = RSpec.describe(SomeController, type: :routing) expect(group).to respond_to(:routes) expect(group.new).to be_a(RSpec::Rails::RoutingExampleGroup) end - it "metadata `:type => :view` sets up view example groups" do + it "metadata `type: :view` sets up view example groups" do a_helper_module = Module.new stub_const "SomeControllerHelper", a_helper_module - group = RSpec.describe("some_controller/action.html.erb", :type => :view) + group = RSpec.describe("some_controller/action.html.erb", type: :view) expect(group._default_helper).to be(a_helper_module) expect(group.new).to be_a(RSpec::Rails::ViewExampleGroup) end - it "metadata `:type => :feature` sets up feature example groups" do + it "metadata `type: :feature` sets up feature example groups" do a_rails_app = double("Rails application") the_rails_module = Module.new allow(the_rails_module).to receive(:application) { a_rails_app } @@ -236,7 +236,7 @@ def in_inferring_type_from_location_environment stub_const "Rails", the_rails_module stub_const 'Rails::VERSION', version - group = RSpec.describe("Some feature description", :type => :feature) + group = RSpec.describe("Some feature description", type: :feature) example = group.new expect(example).to respond_to(:visit) @@ -244,10 +244,10 @@ def in_inferring_type_from_location_environment end if defined?(ActionMailer) - it "metadata `:type => :mailer` sets up mailer example groups" do + it "metadata `type: :mailer` sets up mailer example groups" do a_mailer_class = Class.new stub_const "SomeMailer", a_mailer_class - group = RSpec.describe(SomeMailer, :type => :mailer) + group = RSpec.describe(SomeMailer, type: :mailer) expect(group.mailer_class).to be(a_mailer_class) expect(group.new).to be_a(RSpec::Rails::MailerExampleGroup) end diff --git a/spec/rspec/rails/example/routing_example_group_spec.rb b/spec/rspec/rails/example/routing_example_group_spec.rb index 3e3593cf6e..ebc42dafcf 100644 --- a/spec/rspec/rails/example/routing_example_group_spec.rb +++ b/spec/rspec/rails/example/routing_example_group_spec.rb @@ -14,9 +14,9 @@ module RSpec::Rails example = group.new # Yes, this is quite invasive - url_helpers = double('url_helpers', :foo_path => "foo") - routes = double('routes', :url_helpers => url_helpers) - allow(example).to receive_messages(:routes => routes) + url_helpers = double('url_helpers', foo_path: "foo") + routes = double('routes', url_helpers: url_helpers) + allow(example).to receive_messages(routes: routes) expect(example.foo_path).to eq("foo") end diff --git a/spec/rspec/rails/matchers/be_new_record_spec.rb b/spec/rspec/rails/matchers/be_new_record_spec.rb index 7e38c7faf4..5b4213e39d 100644 --- a/spec/rspec/rails/matchers/be_new_record_spec.rb +++ b/spec/rspec/rails/matchers/be_new_record_spec.rb @@ -2,7 +2,7 @@ describe "be_new_record" do context "a new record" do - let(:record) { double('record', :new_record? => true) } + let(:record) { double('record', new_record?: true) } it "passes" do expect(record).to be_new_record @@ -16,7 +16,7 @@ end context "a persisted record" do - let(:record) { double('record', :new_record? => false) } + let(:record) { double('record', new_record?: false) } it "fails" do expect(record).not_to be_new_record diff --git a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb index 749d521d43..871092a879 100644 --- a/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb +++ b/spec/rspec/rails/matchers/have_enqueued_mail_spec.rb @@ -25,7 +25,7 @@ def email_with_args(arg1, arg2); end end end -RSpec.describe "HaveEnqueuedMail matchers", :skip => !RSpec::Rails::FeatureCheck.has_active_job? do +RSpec.describe "HaveEnqueuedMail matchers", skip: !RSpec::Rails::FeatureCheck.has_active_job? do before do ActiveJob::Base.queue_adapter = :test end @@ -240,7 +240,7 @@ def email_with_args(arg1, arg2); end send_time = Date.tomorrow.noon expect { - TestMailer.test_email.deliver_later(:wait_until => send_time) + TestMailer.test_email.deliver_later(wait_until: send_time) }.to have_enqueued_email(TestMailer, :test_email).at(send_time) end @@ -249,7 +249,7 @@ def email_with_args(arg1, arg2); end expect { expect { - TestMailer.test_email.deliver_later(:wait_until => send_time + 1) + TestMailer.test_email.deliver_later(wait_until: send_time + 1) }.to have_enqueued_email(TestMailer, :test_email).at(send_time) }.to raise_error(/expected to enqueue TestMailer.test_email exactly 1 time at #{send_time.strftime('%F %T')}/) end @@ -259,20 +259,20 @@ def email_with_args(arg1, arg2); end slightly_earlier = 58.seconds.from_now expect { - TestMailer.test_email.deliver_later(:wait_until => slightly_earlier) + TestMailer.test_email.deliver_later(wait_until: slightly_earlier) }.to have_enqueued_email(TestMailer, :test_email).at(a_value_within(5.seconds).of(future)) end it "passes when deliver_later is called with a queue argument" do expect { - TestMailer.test_email.deliver_later(:queue => 'urgent_mail') + TestMailer.test_email.deliver_later(queue: 'urgent_mail') }.to have_enqueued_email(TestMailer, :test_email).on_queue('urgent_mail') end it "generates a failure message with on_queue" do expect { expect { - TestMailer.test_email.deliver_later(:queue => 'not_urgent_mail') + TestMailer.test_email.deliver_later(queue: 'not_urgent_mail') }.to have_enqueued_email(TestMailer, :test_email).on_queue('urgent_mail') }.to raise_error(/expected to enqueue TestMailer.test_email exactly 1 time on queue urgent_mail/) end @@ -295,7 +295,7 @@ def self.name; "NonMailerJob"; end expect { non_mailer_job.perform_later TestMailer.test_email.deliver_later - TestMailer.email_with_args(3, 4).deliver_later(:wait_until => send_time, :queue => queue) + TestMailer.email_with_args(3, 4).deliver_later(wait_until: send_time, queue: queue) }.to have_enqueued_email(TestMailer, :email_with_args).with(1, 2) }.to raise_error(message) end @@ -338,15 +338,15 @@ def self.name; "NonMailerJob"; end midnight = Date.tomorrow.midnight expect { - TestMailer.email_with_args('high', 'noon').deliver_later(:wait_until => noon) - TestMailer.email_with_args('midnight', 'rider').deliver_later(:wait_until => midnight) + TestMailer.email_with_args('high', 'noon').deliver_later(wait_until: noon) + TestMailer.email_with_args('midnight', 'rider').deliver_later(wait_until: midnight) }.to have_enqueued_mail(TestMailer, :email_with_args).at(noon).with { |first_arg, second_arg| expect(first_arg).to eq('high') expect(second_arg).to eq('noon') } end - context 'when parameterized', :skip => !RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? do + context 'when parameterized', skip: !RSpec::Rails::FeatureCheck.has_action_mailer_parameterized? do it "passes when mailer is parameterized" do expect { TestMailer.with('foo' => 'bar').test_email.deliver_later @@ -371,7 +371,7 @@ def self.name; "NonMailerJob"; end end end - context 'mailer job is unified', :skip => !RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? do + context 'mailer job is unified', skip: !RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery? do it "passes when mailer is parameterized" do expect { UnifiedMailer.with('foo' => 'bar').test_email.deliver_later @@ -389,13 +389,13 @@ def self.name; "NonMailerJob"; end expect { UnifiedMailer.with('foo' => 'bar').test_email.deliver_later }.to have_enqueued_mail(UnifiedMailer, :test_email).with( - a_hash_including(:params => { 'foo' => 'bar' }) + a_hash_including(params: { 'foo' => 'bar' }) ) expect { UnifiedMailer.with('foo' => 'bar').email_with_args(1, 2).deliver_later }.to have_enqueued_mail(UnifiedMailer, :email_with_args).with( - a_hash_including(:params => { 'foo' => 'bar' }, :args => [1, 2]) + a_hash_including(params: { 'foo' => 'bar' }, args: [1, 2]) ) end end