From 84b97ab7ef51dc477d93980d7201b9e5c0a61451 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 1 Feb 2019 09:14:29 +0100 Subject: [PATCH 01/13] Add generator for system spec * added generator for system spec * fixed spec for --no-system-specs * refactored to ensure that both usecases are using same path * Refere to system spec instead of feature spec * Specs need to be different for Rails under 5.1 * Don't provide system spec generator under Rails 5.1 --- .../rspec/system/system_generator.rb | 26 ++++++++++++ .../rspec/system/templates/system_spec.rb | 9 +++++ .../rspec/system/system_generator_spec.rb | 40 +++++++++++++++++++ 3 files changed, 75 insertions(+) create mode 100644 lib/generators/rspec/system/system_generator.rb create mode 100644 lib/generators/rspec/system/templates/system_spec.rb create mode 100644 spec/generators/rspec/system/system_generator_spec.rb diff --git a/lib/generators/rspec/system/system_generator.rb b/lib/generators/rspec/system/system_generator.rb new file mode 100644 index 0000000000..937241733e --- /dev/null +++ b/lib/generators/rspec/system/system_generator.rb @@ -0,0 +1,26 @@ +require 'generators/rspec' + +if ::Rails::VERSION::STRING >= '5.1' + module Rspec + module Generators + # @private + class SystemGenerator < Base + class_option :system_specs, :type => :boolean, :default => true, :desc => "Generate system specs" + + def generate_system_spec + return unless options[:system_specs] + + template template_name, File.join('spec/system', class_path, filename) + end + + def template_name + 'system_spec.rb' + end + + def filename + "#{table_name}_spec.rb" + end + end + end + end +end diff --git a/lib/generators/rspec/system/templates/system_spec.rb b/lib/generators/rspec/system/templates/system_spec.rb new file mode 100644 index 0000000000..7784273a7a --- /dev/null +++ b/lib/generators/rspec/system/templates/system_spec.rb @@ -0,0 +1,9 @@ +require 'rails_helper' + +RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:system) %> do + before do + driven_by(:rack_test) + end + + pending "add some scenarios (or delete) #{__FILE__}" +end diff --git a/spec/generators/rspec/system/system_generator_spec.rb b/spec/generators/rspec/system/system_generator_spec.rb new file mode 100644 index 0000000000..b63bf66623 --- /dev/null +++ b/spec/generators/rspec/system/system_generator_spec.rb @@ -0,0 +1,40 @@ +# Generators are not automatically loaded by rails +if ::Rails::VERSION::STRING >= '5.1' + require 'generators/rspec/system/system_generator' + require 'support/generators' + + RSpec.describe Rspec::Generators::SystemGenerator, :type => :generator do + setup_default_destination + + describe "system specs" do + subject(:system_spec) { file("spec/system/posts_spec.rb") } + describe "are generated independently from the command line" do + before do + run_generator %w(posts) + end + describe "the spec" do + it "exists" do + expect(system_spec).to exist + end + it "contains 'rails_helper'" do + expect(system_spec).to contain(/require 'rails_helper'/) + end + it "contains the system" do + expect(system_spec).to contain(/^RSpec.describe \"Posts\", #{type_metatag(:system)}/) + end + end + end + + describe "are not generated" do + before do + run_generator %w(posts --no-system-specs) + end + describe "the spec" do + it "does not exist" do + expect(system_spec).to_not exist + end + end + end + end + end +end From a1fc17adfbab00dd74760fda3471dd588330010d Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 1 Feb 2019 09:18:25 +0100 Subject: [PATCH 02/13] Changelog for #1933 Merged via #2075 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index f2237f1587..d5d443bdd4 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,8 @@ Enhancements supported. (OKURA Masafumi, #2048) * Add `have_enqueued` matcher as a "super" matcher to the `ActiveJob` matchers making it easier to match on `ActiveJob` delivered emails (Joel Lubrano, #2047) +* Add generator for system specs on Rails upper or equal to 5.1 (Andrzej Sliwa, + #1933) ### 3.8.2 / 2019-01-13 [Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.8.1...v3.8.2) From fd0a5cbddad2ea8828c2617c58316b3ffa1bad94 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Fri, 1 Feb 2019 09:42:17 +0000 Subject: [PATCH 03/13] Cleanup changelog [skip ci] --- Changelog.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/Changelog.md b/Changelog.md index d5d443bdd4..f3486ac824 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,7 +4,7 @@ Bug Fixes: * Make the `ActiveJob` matchers fail when multiple jobs are queued for negated - matches. e.g. `expect { job; job; }.to_not have_enqueued_job + matches. e.g. `expect { job; job; }.to_not have_enqueued_job. (Emric Istanful, #2069) Enhancements @@ -12,9 +12,8 @@ Enhancements * Use `__dir__` instead of `__FILE__` in generated `rails_helper.rb` where supported. (OKURA Masafumi, #2048) * Add `have_enqueued` matcher as a "super" matcher to the `ActiveJob` matchers - making it easier to match on `ActiveJob` delivered emails (Joel Lubrano, #2047) -* Add generator for system specs on Rails upper or equal to 5.1 (Andrzej Sliwa, - #1933) + making it easier to match on `ActiveJob` delivered emails. (Joel Lubrano, #2047) +* Add generator for system specs on Rails 5.1 and above. (Andrzej Sliwa, #1933) ### 3.8.2 / 2019-01-13 [Full Changelog](http://github.com/rspec/rspec-rails/compare/v3.8.1...v3.8.2) From 8fd6def1030ab0999d403ed4296477038e78fc50 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Mon, 11 Feb 2019 13:40:36 +0100 Subject: [PATCH 04/13] Pin sqlite to avoid build issue (#2078) Related: https://github.com/rails/rails/issues/35153 and https://github.com/rails/rails/pull/35154 --- example_app_generator/generate_app.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/example_app_generator/generate_app.rb b/example_app_generator/generate_app.rb index 6841db7695..73309322f9 100644 --- a/example_app_generator/generate_app.rb +++ b/example_app_generator/generate_app.rb @@ -23,6 +23,7 @@ gsub_file "Gemfile", /.*debugger.*/, '' gsub_file "Gemfile", /.*byebug.*/, "gem 'byebug', '~> 9.0.6'" gsub_file "Gemfile", /.*puma.*/, "" + gsub_file "Gemfile", /.*sqlite3.*/, "gem 'sqlite3', '~> 1.3.6'" if RUBY_VERSION < '2.2.2' gsub_file "Gemfile", /.*rdoc.*/, "gem 'rdoc', '< 6'" end From 5cf1874bdc69094e36204ac45bb4710bc5d8f8f9 Mon Sep 17 00:00:00 2001 From: Michel Ocon Date: Sun, 10 Feb 2019 12:53:07 -0600 Subject: [PATCH 05/13] Fix fixtures path for model generator when using namespaced models --- lib/generators/rspec/model/model_generator.rb | 3 +-- .../rspec/model/model_generator_spec.rb | 23 +++---------------- spec/support/generators.rb | 18 +++++++++++++++ 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/lib/generators/rspec/model/model_generator.rb b/lib/generators/rspec/model/model_generator.rb index a775e52022..789fcda83c 100644 --- a/lib/generators/rspec/model/model_generator.rb +++ b/lib/generators/rspec/model/model_generator.rb @@ -23,8 +23,7 @@ def create_model_spec def create_fixture_file return unless missing_fixture_replacement? - - template 'fixtures.yml', File.join('spec/fixtures', "#{table_name}.yml") + template 'fixtures.yml', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml") end private diff --git a/spec/generators/rspec/model/model_generator_spec.rb b/spec/generators/rspec/model/model_generator_spec.rb index dee5c99e2f..aabf05b83e 100644 --- a/spec/generators/rspec/model/model_generator_spec.rb +++ b/spec/generators/rspec/model/model_generator_spec.rb @@ -12,27 +12,10 @@ gen.invoke_all end - describe 'the generated files' do - describe 'with fixtures' do - before do - run_generator %w(posts --fixture) - end - - describe 'the spec' do - subject { file('spec/models/posts_spec.rb') } - - it { is_expected.to exist } - it { is_expected.to contain(/require 'rails_helper'/) } - it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:model)}/) } - end - - describe 'the fixtures' do - subject { file('spec/fixtures/posts.yml') } - - it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) } - end - end + it_behaves_like 'a model generator with fixtures', 'admin/posts', 'Admin::Posts' + it_behaves_like 'a model generator with fixtures', 'posts', 'Posts' + describe 'the generated files' do describe 'without fixtures' do before do run_generator %w(posts) diff --git a/spec/support/generators.rb b/spec/support/generators.rb index d380353b1b..9f38e14132 100644 --- a/spec/support/generators.rb +++ b/spec/support/generators.rb @@ -19,6 +19,24 @@ def self.included(klass) klass.extend(Macros) end + shared_examples_for 'a model generator with fixtures' do |name, class_name| + before { run_generator [name, '--fixture'] } + + describe 'the spec' do + subject { file("spec/models/#{name}_spec.rb") } + + it { is_expected.to exist } + it { is_expected.to contain(/require 'rails_helper'/) } + it { is_expected.to contain(/^RSpec.describe #{class_name}, #{type_metatag(:model)}/) } + end + + describe 'the fixtures' do + subject { file("spec/fixtures/#{name}.yml") } + + it { is_expected.to contain(Regexp.new('# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html')) } + end + end + shared_examples_for "a request spec generator" do describe 'generated with flag `--no-request-specs`' do before do From 122f64d32d2300ce61354de6cf6fda7b2f6ac145 Mon Sep 17 00:00:00 2001 From: Jon Rowe Date: Tue, 12 Feb 2019 10:01:23 +0000 Subject: [PATCH 06/13] Changelog for #2077 --- Changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Changelog.md b/Changelog.md index f3486ac824..af757c6ff3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -6,6 +6,8 @@ Bug Fixes: * Make the `ActiveJob` matchers fail when multiple jobs are queued for negated matches. e.g. `expect { job; job; }.to_not have_enqueued_job. (Emric Istanful, #2069) +* Namespaced fixtures now generate a `/` seperated path rather than an `_`. + (@nxlith, #2077) Enhancements From fa4f6f0527c84e6900e54a04e590d10e2eae0a80 Mon Sep 17 00:00:00 2001 From: Sam Phippen Date: Sat, 19 Jan 2019 18:03:30 +0000 Subject: [PATCH 07/13] Gets rubocop working on modern rubocops and rubies. --- lib/rspec/rails/feature_check.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/rspec/rails/feature_check.rb b/lib/rspec/rails/feature_check.rb index efd28d8e61..eeec5ee9c7 100644 --- a/lib/rspec/rails/feature_check.rb +++ b/lib/rspec/rails/feature_check.rb @@ -1,6 +1,7 @@ module RSpec module Rails # @private + # Disable some cops until https://github.com/bbatsov/rubocop/issues/1310 module FeatureCheck module_function def can_check_pending_migrations? From 7fafb659756bb8c6c9cbfb57998b5885b46799f2 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 22 Feb 2019 22:59:47 +0100 Subject: [PATCH 08/13] Remove useless empty lines --- .rubocop.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a76dfa982e..ebd3a6def8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -47,7 +47,6 @@ PerlBackrefs: Style/AccessModifierDeclarations: Enabled: false - Naming/MemoizedInstanceVariableName: Enabled: false @@ -68,4 +67,3 @@ Lint/EmptyExpression: Layout/AlignHash: Enabled: false - From 443a8464aec586e6027a5c5edfc07683d8b5d821 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 22 Feb 2019 23:00:33 +0100 Subject: [PATCH 09/13] Keep using relish gem for documentation See: https://github.com/rspec/rspec-rails/pull/2071#discussion_r249281658 --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index 37c9ba8f12..21e871fe37 100644 --- a/Gemfile +++ b/Gemfile @@ -13,6 +13,7 @@ gem 'yard', '~> 0.8.7', :require => false group :documentation do gem 'redcarpet', '2.3.0' gem 'github-markup', '1.0.0' + gem 'relish' end platforms :jruby do From 0e6119e2f142587c32683f01cc56f8f0173be423 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 22 Feb 2019 23:02:42 +0100 Subject: [PATCH 10/13] Bump rake and let bundler decide for rubyzip and rake --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 21e871fe37..0fe304cca1 100644 --- a/Gemfile +++ b/Gemfile @@ -28,7 +28,7 @@ end gem 'ffi', '~> 1.9.25' -gem 'rake', '>= 10.0.0' +gem 'rake', '~> 12' gem 'mime-types', '< 3' @@ -36,7 +36,7 @@ gem 'capybara', '~> 2.13', :require => false gem 'nokogiri', '1.8.5' -gem "rubyzip", '>= 1.2.2' +gem "rubyzip", '~> 1.2' gem 'rubocop' From 734f8d74f6eb5bbaa44fadab24f5768fb480008e Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 22 Feb 2019 23:07:47 +0100 Subject: [PATCH 11/13] Bump redcarpet and github-markup dependencies for documentation --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index 0fe304cca1..5acb6de645 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,8 @@ gem 'yard', '~> 0.8.7', :require => false ### deps for rdoc.info group :documentation do - gem 'redcarpet', '2.3.0' - gem 'github-markup', '1.0.0' + gem 'redcarpet', '~> 3.4' + gem 'github-markup', '~> 3.0' gem 'relish' end From 58088d801f621c1b551dcb88ad540071e49e3dd0 Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Fri, 22 Feb 2019 23:13:54 +0100 Subject: [PATCH 12/13] Remove useless comment for rubocop issue --- lib/rspec/rails/feature_check.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/rspec/rails/feature_check.rb b/lib/rspec/rails/feature_check.rb index eeec5ee9c7..efd28d8e61 100644 --- a/lib/rspec/rails/feature_check.rb +++ b/lib/rspec/rails/feature_check.rb @@ -1,7 +1,6 @@ module RSpec module Rails # @private - # Disable some cops until https://github.com/bbatsov/rubocop/issues/1310 module FeatureCheck module_function def can_check_pending_migrations? From c8e1ba5384337a6a5af3a70ab41ee719832f98fa Mon Sep 17 00:00:00 2001 From: Benoit Tigeot Date: Sat, 23 Feb 2019 00:38:06 +0100 Subject: [PATCH 13/13] Pin documentation gems to specific versions --- Gemfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 5acb6de645..2ff6e38eb8 100644 --- a/Gemfile +++ b/Gemfile @@ -11,9 +11,9 @@ gem 'yard', '~> 0.8.7', :require => false ### deps for rdoc.info group :documentation do - gem 'redcarpet', '~> 3.4' - gem 'github-markup', '~> 3.0' - gem 'relish' + gem 'redcarpet', '~> 3.4.0' + gem 'github-markup', '~> 3.0.3' + gem 'relish', '~> 0.7.1' end platforms :jruby do