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 - diff --git a/Changelog.md b/Changelog.md index f2237f1587..af757c6ff3 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,15 +4,18 @@ 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) +* Namespaced fixtures now generate a `/` seperated path rather than an `_`. + (@nxlith, #2077) 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) + 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) diff --git a/Gemfile b/Gemfile index 37c9ba8f12..2ff6e38eb8 100644 --- a/Gemfile +++ b/Gemfile @@ -11,8 +11,9 @@ 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.0' + gem 'github-markup', '~> 3.0.3' + gem 'relish', '~> 0.7.1' end platforms :jruby do @@ -27,7 +28,7 @@ end gem 'ffi', '~> 1.9.25' -gem 'rake', '>= 10.0.0' +gem 'rake', '~> 12' gem 'mime-types', '< 3' @@ -35,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' 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 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/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/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/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 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