From cdec8fc7f2648f1854bb5f474f3b749bb099cc87 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Mon, 10 Nov 2014 15:17:28 +0100 Subject: [PATCH] Enforce code coverage minimums --- .rubocop.yml | 2 +- lib/naught/null_class_builder.rb | 2 +- spec/mimic_spec.rb | 31 +++++++++---------------------- spec/naught_spec.rb | 8 +------- spec/predicate_spec.rb | 9 ++------- spec/spec_helper.rb | 14 ++++++++------ 6 files changed, 22 insertions(+), 44 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a80be72..507ee27 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ Metrics/BlockNesting: Metrics/LineLength: AllowURI: true - Max: 90 # TODO: Lower to 80 + Max: 93 # TODO: Lower to 80 Metrics/MethodLength: CountComments: false diff --git a/lib/naught/null_class_builder.rb b/lib/naught/null_class_builder.rb index 0b08b99..15f24c6 100644 --- a/lib/naught/null_class_builder.rb +++ b/lib/naught/null_class_builder.rb @@ -31,7 +31,7 @@ def null_equivalents @null_equivalents ||= [nil] end - def generate_class + def generate_class # rubocop:disable AbcSize respond_to_any_message unless interface_defined? generation_mod = Module.new customization_mod = customization_module # get a local binding diff --git a/spec/mimic_spec.rb b/spec/mimic_spec.rb index 338ab05..f4f192d 100644 --- a/spec/mimic_spec.rb +++ b/spec/mimic_spec.rb @@ -3,31 +3,20 @@ describe 'null object mimicking a class' do class User - def login - 'bob' - end + attr_reader :login end module Authorizable - def authorized_for?(_) - true - end + def authorized_for?(_); end end class LibraryPatron < User include Authorizable + attr_reader :name - def member? - true - end + def member?; end - def name - 'Bob' - end - - def notify_of_overdue_books(_) - puts 'Notifying...' - end + def notify_of_overdue_books(_); end end subject(:null) { mimic_class.new } @@ -82,9 +71,7 @@ def notify_of_overdue_books(_) describe 'with an instance as example' do let(:mimic_class) do milton = LibraryPatron.new - def milton.stapler - 'red swingline' - end + def milton.stapler; end Naught.build do |b| b.mimic :example => milton end @@ -110,7 +97,7 @@ def milton.stapler end end - def self.it_behaves_like_a_black_hole_mimic + shared_examples_for 'a black hole mimic' do it 'returns self from mimicked methods' do expect(null.info).to equal(null) expect(null.error).to equal(null) @@ -122,7 +109,7 @@ def self.it_behaves_like_a_black_hole_mimic end end - it_behaves_like_a_black_hole_mimic + it_should_behave_like 'a black hole mimic' describe '(reverse order)' do let(:mimic_class) do @@ -132,7 +119,7 @@ def self.it_behaves_like_a_black_hole_mimic end end - it_behaves_like_a_black_hole_mimic + it_should_behave_like 'a black hole mimic' end end diff --git a/spec/naught_spec.rb b/spec/naught_spec.rb index e4ce0d5..c573d40 100644 --- a/spec/naught_spec.rb +++ b/spec/naught_spec.rb @@ -2,13 +2,7 @@ describe 'null object impersonating another type' do class Point - def x - 23 - end - - def y - 42 - end + attr_reader :x, :y end subject(:null) { impersonation_class.new } diff --git a/spec/predicate_spec.rb b/spec/predicate_spec.rb index 475b463..a3ce2b0 100644 --- a/spec/predicate_spec.rb +++ b/spec/predicate_spec.rb @@ -51,13 +51,8 @@ end class Coffee - def black? - true - end - - def origin - 'Ethiopia' - end + attr_reader :origin + def black?; end end describe '(mimic)' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e58b711..9df516d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,14 @@ GEM_ROOT = File.expand_path('../../', __FILE__) $LOAD_PATH.unshift File.join(GEM_ROOT, 'lib') -if ENV['TRAVIS'] - require 'coveralls' - Coveralls.wear! -else - require 'simplecov' - SimpleCov.start +require 'simplecov' +require 'coveralls' + +SimpleCov.formatters = [SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter] + +SimpleCov.start do + add_filter '/spec/' + minimum_coverage(97.7) end require 'naught'