From 25eb796a72de375e0867c4b1e1b2d4da16bf9a49 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Sun, 20 Dec 2020 20:40:04 +0100 Subject: [PATCH 01/19] Bump CI Ruby to 3.0.0-rc1 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fa880114d9..a8172b1ed3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: RAILS_VERSION: '~> 6.1.0' # Rails 6.0 builds >= 2.5.0 - - ruby: 3.0 + - ruby: 3.0.0-rc1 env: RAILS_VERSION: '~> 6.0.0' - ruby: 2.7 From 4c909ae78c1b081801d1898c82eba2f0972f2872 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Mon, 21 Dec 2020 22:44:55 +0000 Subject: [PATCH 02/19] Set RSpec version from env --- rspec-rails.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rspec-rails.gemspec b/rspec-rails.gemspec index 0f67a2c4f9..8b52a8103f 100644 --- a/rspec-rails.gemspec +++ b/rspec-rails.gemspec @@ -46,7 +46,7 @@ Gem::Specification.new do |s| # get released. %w[core expectations mocks support].each do |name| if ENV['RSPEC_CI'] - s.add_runtime_dependency "rspec-#{name}", "= 4.0.0.pre" + s.add_runtime_dependency "rspec-#{name}", ENV.fetch('RSPEC_VERSION', '3.11.0.pre') elsif RSpec::Rails::Version::STRING =~ /pre/ # prerelease builds expected_rspec_version = "3.11.0.pre" s.add_runtime_dependency "rspec-#{name}", "= #{expected_rspec_version}" From 11e280ad503f7e96068be380bb355038ae6eb35b Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 19 Dec 2020 03:42:59 +0300 Subject: [PATCH 03/19] Stop using globally exposed DSL --- spec/support/generators.rb | 4 ++-- spec/support/shared_examples.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/support/generators.rb b/spec/support/generators.rb index 377c44d07a..9081b054dc 100644 --- a/spec/support/generators.rb +++ b/spec/support/generators.rb @@ -20,7 +20,7 @@ def self.included(klass) klass.include(RSpec::Rails::FeatureCheck) end - shared_examples_for 'a model generator with fixtures' do |name, class_name| + RSpec.shared_examples_for 'a model generator with fixtures' do |name, class_name| before { run_generator [name, '--fixture'] } describe 'the spec' do @@ -38,7 +38,7 @@ def self.included(klass) end end - shared_examples_for "a request spec generator" do + RSpec.shared_examples_for "a request spec generator" do describe 'generated with flag `--no-request-specs`' do before do run_generator %w[posts --no-request-specs] diff --git a/spec/support/shared_examples.rb b/spec/support/shared_examples.rb index bfadc8e1f0..510bc4fbc2 100644 --- a/spec/support/shared_examples.rb +++ b/spec/support/shared_examples.rb @@ -1,6 +1,6 @@ require 'pathname' -shared_examples_for "an rspec-rails example group mixin" do |type, *paths| +RSpec.shared_examples_for "an rspec-rails example group mixin" do |type, *paths| let(:mixin) { described_class } def define_group_in(path, group_definition) From 2223edac727e37d3f86cdc47c5dbc8489881baf4 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 19 Dec 2020 03:50:20 +0300 Subject: [PATCH 04/19] Only disable monkey patching if needed in specs --- spec/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f35f58cec..ee19719957 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -55,7 +55,8 @@ def self.run_all(reporter = nil) config.shared_context_metadata_behavior = :apply_to_host_groups - config.disable_monkey_patching! + # Zero monkey patching mode is the default and only mode in RSpec 4 + config.disable_monkey_patching! if config.respond_to?(:disable_monkey_patching!) config.warnings = true config.raise_on_warning = true From 243ec05264fdd47567cd3264be775dfe05053908 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Tue, 22 Dec 2020 03:33:50 +0300 Subject: [PATCH 05/19] Prevent an attempt of adding `should` for RSpec 4 --- lib/rspec/rails/extensions/active_record/proxy.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/rspec/rails/extensions/active_record/proxy.rb b/lib/rspec/rails/extensions/active_record/proxy.rb index b60ecb6a73..b42aaa917a 100644 --- a/lib/rspec/rails/extensions/active_record/proxy.rb +++ b/lib/rspec/rails/extensions/active_record/proxy.rb @@ -1,7 +1,10 @@ RSpec.configure do |rspec| # Delay this in order to give users a chance to configure `expect_with`... rspec.before(:suite) do - if defined?(RSpec::Matchers) && RSpec::Matchers.configuration.syntax.include?(:should) && defined?(ActiveRecord::Associations) + if defined?(RSpec::Matchers) && + RSpec::Matchers.configuration.respond_to?(:syntax) && # RSpec 4 dropped support for monkey-patching `should` syntax + RSpec::Matchers.configuration.syntax.include?(:should) && + defined?(ActiveRecord::Associations) RSpec::Matchers.configuration.add_should_and_should_not_to ActiveRecord::Associations::CollectionProxy end end From d01d41fbbd2e4f59b8ef5aa9b051d37b06daf364 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Wed, 23 Dec 2020 20:10:36 +0300 Subject: [PATCH 06/19] Add a check to support both RSpec 3 & 4 RSpec 4 has removed OperatorMatcher, as it was only supported by the should syntax, and not expect syntax. --- lib/rspec/rails/matchers/relation_match_array.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/rspec/rails/matchers/relation_match_array.rb b/lib/rspec/rails/matchers/relation_match_array.rb index 861843b356..419028fb8e 100644 --- a/lib/rspec/rails/matchers/relation_match_array.rb +++ b/lib/rspec/rails/matchers/relation_match_array.rb @@ -1,3 +1,3 @@ -if defined?(ActiveRecord::Relation) +if defined?(ActiveRecord::Relation) && defined?(RSpec::Matchers::BuiltIn::OperatorMatcher) # RSpec 4 removed OperatorMatcher RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::ContainExactly) end From 32d9231986bbf93fdd90241d65566e5cf53821a7 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Thu, 24 Dec 2020 13:29:23 +0100 Subject: [PATCH 07/19] Updated common plaintext files (from rspec-dev)main --- .github/FUNDING.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4fb398d245..1326a5c0a8 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,5 +1,5 @@ -# This file was generated on 2019-12-05T21:32:23+00:00 from the rspec-dev repo. +# This file was generated on 2020-12-23T21:24:00+01:00 from the rspec-dev repo. # DO NOT modify it by hand as your changes will get lost the next time it is generated. -github: [JonRowe] +github: [JonRowe, benoittgt] open_collective: rspec From 96bbc98796575a81dffa4e16a136ff038d0f605c Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 25 Dec 2020 18:48:30 +0000 Subject: [PATCH 08/19] Updated common plaintext files (from rspec-dev)main --- .github/FUNDING.yml | 2 +- BUILD_DETAIL.md | 20 ++++++++++---------- CODE_OF_CONDUCT.md | 2 +- CONTRIBUTING.md | 2 +- DEVELOPMENT.md | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 1326a5c0a8..d3a58b2083 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,4 +1,4 @@ -# This file was generated on 2020-12-23T21:24:00+01:00 from the rspec-dev repo. +# This file was generated on 2020-12-25T18:48:30+00:00 from the rspec-dev repo. # DO NOT modify it by hand as your changes will get lost the next time it is generated. github: [JonRowe, benoittgt] diff --git a/BUILD_DETAIL.md b/BUILD_DETAIL.md index fc5b269986..cd0b6ced6e 100644 --- a/BUILD_DETAIL.md +++ b/BUILD_DETAIL.md @@ -1,5 +1,5 @@ @@ -112,22 +112,23 @@ $ bundle exec yard doc --no-cache $ bin/yard doc --no-cache ``` -## Rubocop +## RuboCop -We use [Rubocop](https://github.com/rubocop-hq/rubocop) to enforce style conventions on the project so -that the code has stylistic consistency throughout. Run with: +We use [RuboCop](https://github.com/rubocop-hq/rubocop) to enforce style +conventions on the project so that the code has stylistic consistency +throughout. Run with: ``` -$ bundle exec rubocop +$ bundle exec rubocop lib # or, if you installed your bundle with `--standalone --binstubs`: -$ bin/rubocop +$ bin/rubocop lib ``` -Our Rubocop configuration is a work-in-progress, so if you get a failure -due to a Rubocop default, feel free to ask about changing the -configuration. Otherwise, you'll need to address the Rubocop failure, +Our RuboCop configuration is a work-in-progress, so if you get a failure +due to a RuboCop default, feel free to ask about changing the +configuration. Otherwise, you'll need to address the RuboCop failure, or, as a measure of last resort, by wrapping the offending code in comments like `# rubocop:disable SomeCheck` and `# rubocop:enable SomeCheck`. @@ -161,4 +162,3 @@ build for another repo, so our CI build includes a spec that runs the spec suite of each of the _other_ project repos. Note that we only run the spec suite, not the full build, of the other projects, as the spec suite runs very quickly compared to the full build. - diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 618d788d33..b6be7666ce 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,5 +1,5 @@ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0a3ce188c6..22f5f0bb2f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,5 @@ diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 57cdbffeb9..fd72bde592 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -1,5 +1,5 @@ From 7d81a6c67c4dd21c4746d8ba255a9bac314b8a9a Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Sun, 27 Dec 2020 11:48:32 +0000 Subject: [PATCH 09/19] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a8172b1ed3..fa880114d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: RAILS_VERSION: '~> 6.1.0' # Rails 6.0 builds >= 2.5.0 - - ruby: 3.0.0-rc1 + - ruby: 3.0 env: RAILS_VERSION: '~> 6.0.0' - ruby: 2.7 From caae8f9ea458d66dba89cf3d80db7fe60604d987 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Tue, 5 Jan 2021 21:45:34 +0300 Subject: [PATCH 10/19] Stop using run_all_when_everything_filtered --- spec/spec_helper.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ee19719957..d9e4eef338 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -47,8 +47,7 @@ def self.run_all(reporter = nil) mocks.verify_doubled_constant_names = true end - config.filter_run :focus - config.run_all_when_everything_filtered = true + config.filter_run_when_matching :focus config.order = :random Kernel.srand config.seed From 32a72ab6af568577e9cf8074bcc60aa7abffdcba Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sat, 9 Jan 2021 03:01:47 +0300 Subject: [PATCH 11/19] Conditionally use shared_context_metadata_behavior See https://github.com/rspec/rspec-core/pull/2834 --- spec/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d9e4eef338..12d9ced593 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -52,7 +52,8 @@ def self.run_all(reporter = nil) config.order = :random Kernel.srand config.seed - config.shared_context_metadata_behavior = :apply_to_host_groups + # shared_context_metadata_behavior is removed in RSpec 4 + config.shared_context_metadata_behavior = :apply_to_host_groups if config.respond_to?(:shared_context_metadata_behavior=) # Zero monkey patching mode is the default and only mode in RSpec 4 config.disable_monkey_patching! if config.respond_to?(:disable_monkey_patching!) From 6cfdf7095f94cce0eb7ee921ccf047118bf9c577 Mon Sep 17 00:00:00 2001 From: Alexander Ilyin Date: Sun, 10 Jan 2021 14:31:05 +0300 Subject: [PATCH 12/19] Update latest version in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a0507bff4..ea7ca3a16c 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ See the `4-0-maintenance` branch on Github if you want or require the latest sta ```ruby # Run against the latest stable release group :development, :test do - gem 'rspec-rails', '~> 4.0.1' + gem 'rspec-rails', '~> 4.0.2' end # Or, run against the main branch From 847f93293ef3036ba9f273a22e85957906850e3b Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 10 Jan 2021 17:11:57 +0300 Subject: [PATCH 13/19] Conditionally use include_chain_clauses_in_custom_matcher_descriptions --- spec/spec_helper.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 12d9ced593..6d3c5a3f64 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -38,7 +38,8 @@ def self.run_all(reporter = nil) # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration RSpec.configure do |config| config.expect_with :rspec do |expectations| - expectations.include_chain_clauses_in_custom_matcher_descriptions = true + # include_chain_clauses_in_custom_matcher_descriptions is removed in RSpec Expectations 4 + expectations.include_chain_clauses_in_custom_matcher_descriptions = true if expectations.respond_to?(:include_chain_clauses_in_custom_matcher_descriptions=) expectations.max_formatted_output_length = 1000 end From f420636ad8ac3eebaf3d46df79759f88ee61ec58 Mon Sep 17 00:00:00 2001 From: Akiomi Kamakura Date: Mon, 25 Jan 2021 12:34:34 +0900 Subject: [PATCH 14/19] Fix gem-version link in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea7ca3a16c..3f9070e9bf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# rspec-rails [![Build Status][]][travis-ci] [![Code Climate][]][code-climate] [![Gem Version][]](gem-version) +# rspec-rails [![Build Status][]][travis-ci] [![Code Climate][]][code-climate] [![Gem Version][]][gem-version] `rspec-rails` brings the [RSpec][] testing framework to [Ruby on Rails][] as a drop-in alternative to its default testing framework, Minitest. From 79e85915cdcfe7f8a13d79cd76993b52b1a16f7b Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 2 Feb 2021 20:47:14 +0000 Subject: [PATCH 15/19] Update redcarpet --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 8d74d1b894..26b7be09ba 100644 --- a/Gemfile +++ b/Gemfile @@ -8,7 +8,7 @@ gem 'yard', '~> 0.9.24', require: false group :documentation do gem 'github-markup', '~> 3.0.3' - gem 'redcarpet', '~> 3.4.0', platforms: [:ruby] + gem 'redcarpet', '~> 3.5.1', platforms: [:ruby] gem 'relish', '~> 0.7.1' end From 5a42aa579caf0cc7df4472196c30f6d244bb7036 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Sun, 14 Feb 2021 18:52:20 +0300 Subject: [PATCH 16/19] Stop using --color option --- .rspec | 1 - 1 file changed, 1 deletion(-) diff --git a/.rspec b/.rspec index 0a9952c333..d0f72792a9 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --warnings ---color --require spec_helper From 541f091d565db964a1ad73b2d42f5eb67014d8e7 Mon Sep 17 00:00:00 2001 From: Phil Pirozhkov Date: Tue, 16 Feb 2021 23:56:42 +0300 Subject: [PATCH 17/19] Use :skip instead of :if/:unless --- spec/rspec/rails/fixture_support_spec.rb | 2 +- spec/sanity_check_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/rspec/rails/fixture_support_spec.rb b/spec/rspec/rails/fixture_support_spec.rb index 0fcccafc01..674a065fab 100644 --- a/spec/rspec/rails/fixture_support_spec.rb +++ b/spec/rspec/rails/fixture_support_spec.rb @@ -12,7 +12,7 @@ module RSpec::Rails end end - it "will allow #setup_fixture to run successfully", if: Rails.version.to_f > 6.0 do + it "will allow #setup_fixture to run successfully", skip: Rails.version.to_f <= 6.0 do group = RSpec::Core::ExampleGroup.describe do include FixtureSupport diff --git a/spec/sanity_check_spec.rb b/spec/sanity_check_spec.rb index f1fdfe2494..3b6874647a 100644 --- a/spec/sanity_check_spec.rb +++ b/spec/sanity_check_spec.rb @@ -33,7 +33,7 @@ def with_clean_env end end - it "passes when libraries are required", unless: RSpec::Support::Ruby.jruby? do + it "passes when libraries are required", skip: RSpec::Support::Ruby.jruby? do script = tmp_root.join("pass_sanity_check") File.open(script, "w") do |f| f.write <<-EOF.gsub(/^\s+\|/, '') From 3f0212fc02c8e739db23524cf9e7ead77113019f Mon Sep 17 00:00:00 2001 From: Adam Piotrowski Date: Thu, 18 Feb 2021 11:56:53 +0100 Subject: [PATCH 18/19] Since rails 6.1.1 changed default behaviour of CRUD response for invalid attributes - to respond with 422 status, we have to update our scaffold for generating specs for Create and Update with invalid attributes. I updated both generators to check if controller responds with status 422 instead of 200. Applied that change only for rails 6.1.1 and higher --- lib/generators/rspec/scaffold/templates/request_spec.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/generators/rspec/scaffold/templates/request_spec.rb b/lib/generators/rspec/scaffold/templates/request_spec.rb index 4ce344e764..f6584b0ca0 100644 --- a/lib/generators/rspec/scaffold/templates/request_spec.rb +++ b/lib/generators/rspec/scaffold/templates/request_spec.rb @@ -82,10 +82,17 @@ }.to change(<%= class_name %>, :count).by(0) end + <% if Rails.version.to_f < 6.1 || Rails.version == '6.1.0' %> it "renders a successful response (i.e. to display the 'new' template)" do post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes } expect(response).to be_successful end + <% else %> + it "renders a response with 422 status - unporcessable entity" do + post <%= index_helper %>_url, params: { <%= ns_file_name %>: invalid_attributes } + expect(response.status).to eq(422) + end + <% end %> end end From d98ec7a8931bebdaf71caf2a318c685cdb878b3d Mon Sep 17 00:00:00 2001 From: Adam Piotrowski Date: Fri, 19 Feb 2021 15:06:15 +0100 Subject: [PATCH 19/19] gsubing generated widget files to test validation prepare valid and invalid attributes for widgets --- example_app_generator/generate_stuff.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/example_app_generator/generate_stuff.rb b/example_app_generator/generate_stuff.rb index ddb2c1a96f..e56c032321 100644 --- a/example_app_generator/generate_stuff.rb +++ b/example_app_generator/generate_stuff.rb @@ -167,4 +167,17 @@ def using_source_path(path) gsub_file 'spec/controllers/uploads_controller_spec.rb', 'skip("Add a hash of attributes valid for your model")', '{}' + +# adds validation to widget so our test for happy and unhappy path will be ready to test validation +gsub_file 'spec/requests/widgets_spec.rb', + 'skip("Add a hash of attributes invalid for your model")', + '{ name: "" }' + +gsub_file 'spec/requests/widgets_spec.rb', + 'skip("Add a hash of attributes valid for your model")', + '{ name: "lorem" }' + +gsub_file 'app/models/widget.rb', + 'end', + 'validates :name, presence: true; end' final_tasks