Skip to content

Implement feedbacks from #2071 for RSpec 4 #2081

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

Merged
merged 13 commits into from
Feb 22, 2019
Merged
Show file tree
Hide file tree
Changes from 12 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
2 changes: 0 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ PerlBackrefs:
Style/AccessModifierDeclarations:
Enabled: false


Naming/MemoizedInstanceVariableName:
Enabled: false

Expand All @@ -68,4 +67,3 @@ Lint/EmptyExpression:

Layout/AlignHash:
Enabled: false

7 changes: 5 additions & 2 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 5 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use exact pins. We want to pin to some low version, which is the lowest version that we support, such that as new versions get released, we know RSpec still works with old versions of those gems.

I'd say gem 'redcarpet', '3.4.x' where x is the highest currently released version in the series, and the same for all other gems in this file.

gem 'github-markup', '~> 3.0'
gem 'relish'
end

platforms :jruby do
Expand All @@ -27,15 +28,15 @@ end

gem 'ffi', '~> 1.9.25'

gem 'rake', '>= 10.0.0'
gem 'rake', '~> 12'

gem 'mime-types', '< 3'

gem 'capybara', '~> 2.13', :require => false

gem 'nokogiri', '1.8.5'

gem "rubyzip", '>= 1.2.2'
gem "rubyzip", '~> 1.2'

gem 'rubocop'

Expand Down
1 change: 1 addition & 0 deletions example_app_generator/generate_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

if RUBY_VERSION < '2.2.2'
gsub_file "Gemfile", /.*rdoc.*/, "gem 'rdoc', '< 6'"
end
Expand Down
3 changes: 1 addition & 2 deletions lib/generators/rspec/model/model_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

end

private
Expand Down
26 changes: 26 additions & 0 deletions lib/generators/rspec/system/system_generator.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions lib/generators/rspec/system/templates/system_spec.rb
Original file line number Diff line number Diff line change
@@ -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
23 changes: 3 additions & 20 deletions spec/generators/rspec/model/model_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
40 changes: 40 additions & 0 deletions spec/generators/rspec/system/system_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions spec/support/generators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down