diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 4fb398d245..d3a58b2083 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-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] +github: [JonRowe, benoittgt] open_collective: rspec diff --git a/.rspec b/.rspec index 0a9952c333..d0f72792a9 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1,2 @@ --warnings ---color --require spec_helper 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 @@ 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 diff --git a/README.md b/README.md index 5a0507bff4..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. @@ -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 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 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 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 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 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}" 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+\|/, '') diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3f35f58cec..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 @@ -47,15 +48,16 @@ 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 - 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=) - 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 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)