Skip to content

[WiP] Update of request specs generator due to change in rails 6.1 controller default behaviour. #2464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
--warnings
--color
--require spec_helper
20 changes: 10 additions & 10 deletions BUILD_DETAIL.md
Original file line number Diff line number Diff line change
@@ -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.
-->

Expand Down Expand Up @@ -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`.

Expand Down Expand Up @@ -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.

2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -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.
-->

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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.
-->

Expand Down
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
@@ -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.
-->

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions example_app_generator/generate_stuff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions lib/generators/rspec/scaffold/templates/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion lib/rspec/rails/extensions/active_record/proxy.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/rspec/rails/matchers/relation_match_array.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion rspec-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
2 changes: 1 addition & 1 deletion spec/rspec/rails/fixture_support_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/sanity_check_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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+\|/, '')
Expand Down
12 changes: 7 additions & 5 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/support/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down