diff --git a/.travis.yml b/.travis.yml index 67bf4febf..bca20c340 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: ruby +cache: bundler env: - DB=postgresql bundler_args: --without development staging production diff --git a/Gemfile b/Gemfile index e75da11b3..cad46d3e8 100644 --- a/Gemfile +++ b/Gemfile @@ -135,8 +135,6 @@ group :development, :test do # debug gem 'pry', '0.10.1' - # code review - gem 'rubycritic', '3.2.0' gem 'bullet', '4.14.7' # for finding database optimizations gem 'bundler-audit' gem 'brakeman', '3.6.1', require: false # for security audit' diff --git a/Gemfile.lock b/Gemfile.lock index 0305e57d5..ea08f79a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -141,8 +141,6 @@ GEM xpath (~> 2.0) chronic (0.10.2) cliver (0.3.2) - codeclimate-engine-rb (0.4.0) - virtus (~> 1.0) codeclimate-test-reporter (1.0.8) simplecov (<= 0.13) coderay (1.1.0) @@ -195,15 +193,6 @@ GEM ffi (1.9.18) figaro (1.1.1) thor (~> 0.14) - flay (2.8.1) - erubis (~> 2.7.0) - path_expander (~> 1.0) - ruby_parser (~> 3.0) - sexp_processor (~> 4.0) - flog (4.6.1) - path_expander (~> 1.0) - ruby_parser (~> 3.1, > 3.1.0) - sexp_processor (~> 4.8) globalid (0.3.7) activesupport (>= 4.1.0) grape (0.12.0) @@ -271,7 +260,7 @@ GEM liquid (3.0.6) loofah (2.0.3) nokogiri (>= 1.5.9) - mail (2.6.4) + mail (2.6.5) mime-types (>= 1.16, < 4) method_source (0.8.2) mime-types (3.1) @@ -303,7 +292,6 @@ GEM orm_adapter (0.5.0) parser (2.4.0.0) ast (~> 2.2) - path_expander (1.0.1) pdfkit (0.6.2) pg (0.19.0) phantomjs (1.9.8.0) @@ -372,10 +360,6 @@ GEM i18n polyamorous (~> 1.1) rdoc (4.3.0) - reek (4.6.1) - codeclimate-engine-rb (~> 0.4.0) - parser (>= 2.3.1.2, < 2.5) - rainbow (~> 2.0) ref (2.0.0) request_store (1.1.0) responders (2.3.0) @@ -414,15 +398,6 @@ GEM ruby-progressbar (1.8.1) ruby_parser (3.8.4) sexp_processor (~> 4.1) - rubycritic (3.2.0) - flay (~> 2.8) - flog (~> 4.4) - launchy (= 2.4.3) - parser (= 2.4.0) - rainbow (~> 2.1) - reek (~> 4.4) - ruby_parser (~> 3.8) - virtus (~> 1.0) safe_yaml (1.0.4) sass (3.4.23) sass-rails (5.0.6) @@ -581,7 +556,6 @@ DEPENDENCIES rest-client rspec-rails (~> 3.6) rubocop (= 0.48.1) - rubycritic (= 3.2.0) sass-rails (= 5.0.6) sdoc (= 0.4.1) select2-rails (= 3.5.9.3) diff --git a/bin/robot b/bin/robot index a9255c78d..864ed6b52 100755 --- a/bin/robot +++ b/bin/robot @@ -58,9 +58,6 @@ BCODE=0 # tmp bundle exec brakeman -q echo "END_OF_SECURITY_RESULTS" -# update code review -bundle exec rubycritic app lib - if [ $RCODE == 0 ] && [ $TCODE == 0 ] &&[ $BCODE == 0 ]; then exit 0 else diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 0006986b0..cd242967b 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -9,7 +9,6 @@ require 'support/requests/session_helpers' require 'support/requests/epp_helpers' require 'support/features/session_helpers' require 'support/matchers/alias_attribute' -require 'support/matchers/active_job' require 'support/matchers/epp/code' require 'support/capybara' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e5e131454..03ebbc9b3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,17 +6,7 @@ if ENV['TRAVIS'] SimpleCov.start end - RSpec.configure do |config| - # https://github.com/rspec/rspec-rails/issues/1076 - config.around :each, type: :view do |example| - config.mock_with :rspec do |mocks| - mocks.verify_partial_doubles = false - example.run - mocks.verify_partial_doubles = true - end - end - # rspec-expectations config goes here. You can use an alternate # assertion/expectation library such as wrong or the stdlib/minitest # assertions if you prefer. diff --git a/spec/support/matchers/active_job.rb b/spec/support/matchers/active_job.rb deleted file mode 100644 index 1a3f70a7a..000000000 --- a/spec/support/matchers/active_job.rb +++ /dev/null @@ -1,252 +0,0 @@ -require "active_job/base" -require "active_job/arguments" - -# This matcher is needed because it is absent it rspec-rails 3.3.2 - -module RSpec - module Rails - module Matchers - # Namespace for various implementations of ActiveJob features - # - # @api private - module ActiveJob - # rubocop: disable Style/ClassLength - # @private - class Base < RSpec::Matchers::BuiltIn::BaseMatcher - def initialize - @args = [] - @queue = nil - @at = nil - @block = Proc.new {} - set_expected_number(:exactly, 1) - end - - def with(*args, &block) - @args = args - @block = block if block.present? - self - end - - def on_queue(queue) - @queue = queue - self - end - - def at(date) - @at = date - self - end - - def exactly(count) - set_expected_number(:exactly, count) - self - end - - def at_least(count) - set_expected_number(:at_least, count) - self - end - - def at_most(count) - set_expected_number(:at_most, count) - self - end - - def times - self - end - - def once - exactly(:once) - end - - def twice - exactly(:twice) - end - - def thrice - exactly(:thrice) - end - - def failure_message - "expected to enqueue #{base_message}" - end - - def failure_message_when_negated - "expected not to enqueue #{base_message}" - end - - def message_expectation_modifier - case @expectation_type - when :exactly then "exactly" - when :at_most then "at most" - when :at_least then "at least" - end - end - - def supports_block_expectations? - true - end - - private - - def check(jobs) - @matching_jobs_count = jobs.count do |job| - if serialized_attributes.all? { |key, value| value == job[key] } - args = ::ActiveJob::Arguments.deserialize(job[:args]) - @block.call(*args) - true - else - false - end - end - - case @expectation_type - when :exactly then @expected_number == @matching_jobs_count - when :at_most then @expected_number >= @matching_jobs_count - when :at_least then @expected_number <= @matching_jobs_count - end - end - - def base_message - "#{message_expectation_modifier} #{@expected_number} jobs,".tap do |msg| - msg << " with #{@args}," if @args.any? - msg << " on queue #{@queue}," if @queue - msg << " at #{@at}," if @at - msg << " but enqueued #{@matching_jobs_count}" - end - end - - def serialized_attributes - {}.tap do |attributes| - attributes[:args] = ::ActiveJob::Arguments.serialize(@args) if @args.any? - attributes[:at] = @at.to_f if @at - attributes[:queue] = @queue if @queue - attributes[:job] = @job if @job - end - end - - def set_expected_number(relativity, count) - @expectation_type = relativity - @expected_number = case count - when :once then 1 - when :twice then 2 - when :thrice then 3 - else Integer(count) - end - end - - def queue_adapter - ::ActiveJob::Base.queue_adapter - end - end - # rubocop: enable Style/ClassLength - - # @private - class HaveEnqueuedJob < Base - def initialize(job) - super() - @job = job - end - - def matches?(proc) - raise ArgumentError, "have_enqueued_job and enqueue_job only support block expectations" unless Proc === proc - - original_enqueued_jobs_count = queue_adapter.enqueued_jobs.count - proc.call - in_block_jobs = queue_adapter.enqueued_jobs.drop(original_enqueued_jobs_count) - - check(in_block_jobs) - end - end - - # @private - class HaveBeenEnqueued < Base - def matches?(job) - @job = job - check(queue_adapter.enqueued_jobs) - end - end - end - - # @api public - # Passes if a job has been enqueued inside block. May chain at_least, at_most or exactly to specify a number of times. - # - # @example - # expect { - # HeavyLiftingJob.perform_later - # }.to have_enqueued_job - # - # # Using alias - # expect { - # HeavyLiftingJob.perform_later - # }.to enqueue_job - # - # expect { - # HelloJob.perform_later - # HeavyLiftingJob.perform_later - # }.to have_enqueued_job(HelloJob).exactly(:once) - # - # expect { - # 3.times { HelloJob.perform_later } - # }.to have_enqueued_job(HelloJob).at_least(2).times - # - # expect { - # HelloJob.perform_later - # }.to have_enqueued_job(HelloJob).at_most(:twice) - # - # expect { - # HelloJob.perform_later - # HeavyLiftingJob.perform_later - # }.to have_enqueued_job(HelloJob).and have_enqueued_job(HeavyLiftingJob) - # - # expect { - # HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42) - # }.to have_enqueued_job.with(42).on_queue("low").at(Date.tomorrow.noon) - def have_enqueued_job(job = nil) - check_active_job_adapter - ActiveJob::HaveEnqueuedJob.new(job) - end - alias_method :enqueue_job, :have_enqueued_job - - # @api public - # Passes if a job has been enqueued. May chain at_least, at_most or exactly to specify a number of times. - # - # @example - # before { ActiveJob::Base.queue_adapter.enqueued_jobs.clear } - # - # HeavyLiftingJob.perform_later - # expect(HeavyLiftingJob).to have_been_enqueued - # - # HelloJob.perform_later - # HeavyLiftingJob.perform_later - # expect(HeavyLiftingJob).to have_been_enqueued.exactly(:once) - # - # 3.times { HelloJob.perform_later } - # expect(HelloJob).to have_been_enqueued.at_least(2).times - # - # HelloJob.perform_later - # expect(HelloJob).to enqueue_job(HelloJob).at_most(:twice) - # - # HelloJob.perform_later - # HeavyLiftingJob.perform_later - # expect(HelloJob).to have_been_enqueued - # expect(HeavyLiftingJob).to have_been_enqueued - # - # HelloJob.set(wait_until: Date.tomorrow.noon, queue: "low").perform_later(42) - # expect(HelloJob).to have_been_enqueued.with(42).on_queue("low").at(Date.tomorrow.noon) - def have_been_enqueued - check_active_job_adapter - ActiveJob::HaveBeenEnqueued.new - end - - private - - # @private - def check_active_job_adapter - return if ::ActiveJob::QueueAdapters::TestAdapter === ::ActiveJob::Base.queue_adapter - raise StandardError, "To use ActiveJob matchers set `ActiveJob::Base.queue_adapter = :test`" - end - end - end -end diff --git a/spec/views/admin/billing/prices/_form.html.erb_spec.rb b/spec/views/admin/billing/prices/_form.html.erb_spec.rb index ff7c55dcb..9f4ba785c 100644 --- a/spec/views/admin/billing/prices/_form.html.erb_spec.rb +++ b/spec/views/admin/billing/prices/_form.html.erb_spec.rb @@ -5,10 +5,13 @@ RSpec.describe 'admin/billing/prices/_form' do let(:price) { build_stubbed(:price) } before :example do - allow(view).to receive(:price).and_return(price) - allow(view).to receive(:zones).and_return([]) - allow(view).to receive(:operation_categories).and_return([]) - allow(view).to receive(:durations).and_return([]) + without_partial_double_verification do + allow(view).to receive(:price).and_return(price) + allow(view).to receive(:zones).and_return([]) + allow(view).to receive(:operation_categories).and_return([]) + allow(view).to receive(:durations).and_return([]) + end + stub_template '_form_errors' => '' end diff --git a/spec/views/admin/domains/edit.html.erb_spec.rb b/spec/views/admin/domains/edit.html.erb_spec.rb index b3cc5d834..212b8091b 100644 --- a/spec/views/admin/domains/edit.html.erb_spec.rb +++ b/spec/views/admin/domains/edit.html.erb_spec.rb @@ -6,7 +6,10 @@ RSpec.describe 'admin/domains/edit' do before :example do allow(DomainPresenter).to receive(:new).and_return(domain_presenter) - allow(view).to receive(:force_delete_templates) + + without_partial_double_verification do + allow(view).to receive(:force_delete_templates) + end assign(:domain, domain) diff --git a/spec/views/mailers/shared/registrant/registrant_shared.rb b/spec/views/mailers/shared/registrant/registrant_shared.rb index 5537680f1..dd27c8e95 100644 --- a/spec/views/mailers/shared/registrant/registrant_shared.rb +++ b/spec/views/mailers/shared/registrant/registrant_shared.rb @@ -5,8 +5,10 @@ RSpec.shared_examples 'domain mailer registrant info' do |template_path| let(:registrant) { instance_spy(RegistrantPresenter) } before :example do - allow(view).to receive(:registrant).and_return(registrant) - allow(view).to receive(:address_processing) + without_partial_double_verification do + allow(view).to receive(:registrant).and_return(registrant) + allow(view).to receive(:address_processing) + end end it 'has name' do diff --git a/spec/views/mailers/shared/registrar/registrar_shared.rb b/spec/views/mailers/shared/registrar/registrar_shared.rb index 2f8311545..93f228f97 100644 --- a/spec/views/mailers/shared/registrar/registrar_shared.rb +++ b/spec/views/mailers/shared/registrar/registrar_shared.rb @@ -4,7 +4,9 @@ RSpec.shared_examples 'domain mailer registrar info' do let(:registrar) { instance_spy(RegistrarPresenter) } before :example do - allow(view).to receive(:registrar).and_return(registrar) + without_partial_double_verification do + allow(view).to receive(:registrar).and_return(registrar) + end end attributes = %i( diff --git a/spec/views/registrar/contacts/_form.haml_spec.rb b/spec/views/registrar/contacts/_form.haml_spec.rb index b1ecdf0cf..c1588f0ec 100644 --- a/spec/views/registrar/contacts/_form.haml_spec.rb +++ b/spec/views/registrar/contacts/_form.haml_spec.rb @@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/_form' do let(:contact) { instance_spy(Depp::Contact) } before :example do - allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {})) + without_partial_double_verification do + allow(view).to receive(:f).and_return(ActionView::Helpers::FormBuilder.new(:contact, contact, view, {})) + end + assign(:contact, contact) stub_template 'registrar/shared/_error_messages' => '' @@ -16,7 +19,9 @@ RSpec.describe 'registrar/contacts/_form' do context 'when address processing is enabled' do before do - allow(view).to receive(:address_processing?).and_return(true) + without_partial_double_verification do + allow(view).to receive(:address_processing?).and_return(true) + end end it 'has address' do @@ -27,7 +32,9 @@ RSpec.describe 'registrar/contacts/_form' do context 'when address processing is disabled' do before do - allow(view).to receive(:address_processing?).and_return(false) + without_partial_double_verification do + allow(view).to receive(:address_processing?).and_return(false) + end end it 'has no address' do diff --git a/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb b/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb index b5f428ca1..55ac79e9e 100644 --- a/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb +++ b/spec/views/registrar/contacts/form/_legal_document.haml_spec.rb @@ -4,7 +4,10 @@ RSpec.describe 'registrar/contacts/form/_legal_document' do let(:contact) { instance_spy(Depp::Contact) } before :example do - allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {})) + without_partial_double_verification do + allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:depp_contact, contact, view, {})) + end + assign(:contact, contact) end diff --git a/spec/views/registrar/domains/_form.haml_spec.rb b/spec/views/registrar/domains/_form.haml_spec.rb index b7833f92a..f0e646fb8 100644 --- a/spec/views/registrar/domains/_form.haml_spec.rb +++ b/spec/views/registrar/domains/_form.haml_spec.rb @@ -4,7 +4,10 @@ RSpec.describe 'registrar/domains/_form' do let(:domain) { instance_spy(Depp::Domain) } before :example do - allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {})) + without_partial_double_verification do + allow(view).to receive(:f).and_return(DefaultFormBuilder.new(:domain, domain, view, {})) + end + assign(:domain, domain) stub_template 'registrar/domains/form/_general' => ''