From 2e9295fbcb52f3c5fc281cf3e24e04050da56acb Mon Sep 17 00:00:00 2001 From: zverok Date: Fri, 11 Aug 2017 18:04:22 +0300 Subject: [PATCH] Rubocopping --- .rubocop.yml | 6 ++++ .rubocop_todo.yml | 32 +------------------- lib/saharspec/its/map.rb | 12 ++++---- lib/saharspec/matchers/send_message.rb | 8 +++-- spec/.rubocop.yml | 7 +++++ spec/saharspec/its/map_spec.rb | 3 +- spec/saharspec/matchers/send_message_spec.rb | 14 +++++++-- 7 files changed, 37 insertions(+), 45 deletions(-) create mode 100644 spec/.rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml index a1b60a6..c2cb2e7 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -26,3 +26,9 @@ Metrics/LineLength: Style/PercentLiteralDelimiters: PreferredDelimiters: default: '{}' + +Style/AndOr: + EnforcedStyle: conditionals + +Style/Documentation: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 95f63a7..20b192e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-08-07 17:22:54 +0300 using RuboCop version 0.49.1. +# on 2017-08-11 18:02:13 +0300 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -19,36 +19,6 @@ Lint/ShadowingOuterLocalVariable: Exclude: - 'lib/saharspec/get_webmock.rb' -# Offense count: 1 -# Configuration parameters: CountComments. -Metrics/MethodLength: - Max: 22 - -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'spec/saharspec/matchers/eq_mutliline_spec.rb' - -# Offense count: 2 -Style/CaseEquality: - Exclude: - - 'lib/saharspec/its_map.rb' - -# Offense count: 4 -Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/saharspec/its_call.rb' - - 'lib/saharspec/its_map.rb' - - 'lib/saharspec/matchers/eq_multiline.rb' - # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/saharspec/its/map.rb b/lib/saharspec/its/map.rb index ea619b4..8955cec 100644 --- a/lib/saharspec/its/map.rb +++ b/lib/saharspec/its/map.rb @@ -1,14 +1,14 @@ module Saharspec module ItsMap - def its_map(attribute, *options, &block) # rubocop:disable Metrics/AbcSize + def its_map(attribute, *options, &block) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength # rubocop:disable Lint/NestedMethodDefinition describe("map(&:#{attribute})") do let(:__its_map_subject) do - if Array === attribute - if subject.all? { |s| Hash === s } - subject.map { |s| + if Array === attribute # rubocop:disable Style/CaseEquality + if subject.all? { |s| Hash === s } # rubocop:disable Style/CaseEquality + subject.map do |s| attribute.inject(s) { |inner, attr| inner[attr] } - } + end else subject.map { |inner| inner[*attribute] } end @@ -37,7 +37,7 @@ def is_expected RSpec.configure do |rspec| rspec.extend Saharspec::ItsMap - rspec.backtrace_exclusion_patterns << %r(/lib/saharspec/its/map) + rspec.backtrace_exclusion_patterns << %r{/lib/saharspec/its/map} end RSpec::SharedContext.send(:include, Saharspec::ItsMap) diff --git a/lib/saharspec/matchers/send_message.rb b/lib/saharspec/matchers/send_message.rb index 4955db8..fd4fa28 100644 --- a/lib/saharspec/matchers/send_message.rb +++ b/lib/saharspec/matchers/send_message.rb @@ -30,7 +30,7 @@ def exactly(n) end def times - fail NoMethodError unless @times + raise NoMethodError unless @times self end @@ -61,7 +61,7 @@ def supports_block_expectations? end def description - 'to send %p.%s' % [@target, @method] + format('to send %p.%s', @target, @method) end def failure_message @@ -75,7 +75,9 @@ def failure_message_when_negated private def run(subject) - fail NoMethodError, "undefined method `#{@method}' for#{@target.inspect}:#{@target.class}" unless @target.respond_to?(@method) + @target.respond_to?(@method) or + raise NoMethodError, + "undefined method `#{@method}' for#{@target.inspect}:#{@target.class}" allow(@target).to allower subject.call end diff --git a/spec/.rubocop.yml b/spec/.rubocop.yml new file mode 100644 index 0000000..513f37e --- /dev/null +++ b/spec/.rubocop.yml @@ -0,0 +1,7 @@ +inherit_from: ../.rubocop.yml + +Style/BlockDelimiters: + Enabled: false + +Style/Semicolon: + Enabled: false diff --git a/spec/saharspec/its/map_spec.rb b/spec/saharspec/its/map_spec.rb index 40f4ce1..cbf8fba 100644 --- a/spec/saharspec/its/map_spec.rb +++ b/spec/saharspec/its/map_spec.rb @@ -33,8 +33,7 @@ def [](a, b) context 'nested hashes' do subject { [{a: {b: 1}}, {a: {b: 2}}, {a: {b: 3}}] } - its_map([:a, :b]) { is_expected.to eq [1, 2, 3] } + its_map(%i[a b]) { is_expected.to eq [1, 2, 3] } end end - end diff --git a/spec/saharspec/matchers/send_message_spec.rb b/spec/saharspec/matchers/send_message_spec.rb index 01419f1..95a3b9b 100644 --- a/spec/saharspec/matchers/send_message_spec.rb +++ b/spec/saharspec/matchers/send_message_spec.rb @@ -1,11 +1,17 @@ require 'saharspec/matchers/send_message' RSpec.describe :send_message do - let(:obj) { Object.new.tap { |o| def o.meth; 10 end } } + let(:obj) { + Object.new.tap { |o| + def o.meth + 10 + end + } + } context 'simple' do it { expect { obj.meth }.to send_message(obj, :meth) } - it { expect { }.not_to send_message(obj, :meth) } + it { expect {}.not_to send_message(obj, :meth) } it { expect { expect {}.to send_message(obj, :meth1) }.to raise_error(NoMethodError) } end @@ -13,7 +19,9 @@ it { expect { obj.meth(1, 2, 3) }.to send_message(obj, :meth).with(1, 2, 3) } it { expect { obj.meth(1, 3, 2) }.not_to send_message(obj, :meth).with(1, 2, 3) } it { expect { obj.meth([1, 3, 2]) }.to send_message(obj, :meth).with(array_including(2, 3)) } - it { expect { obj.meth([1, 3, 2]) }.not_to send_message(obj, :meth).with(array_including(3, 4)) } + it { + expect { obj.meth([1, 3, 2]) }.not_to send_message(obj, :meth).with(array_including(3, 4)) + } xit 'checks count' end