Skip to content

Commit

Permalink
Rubocopping
Browse files Browse the repository at this point in the history
  • Loading branch information
zverok committed Aug 11, 2017
1 parent 1335d2c commit 2e9295f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
6 changes: 6 additions & 0 deletions .rubocop.yml
Expand Up @@ -26,3 +26,9 @@ Metrics/LineLength:
Style/PercentLiteralDelimiters:
PreferredDelimiters:
default: '{}'

Style/AndOr:
EnforcedStyle: conditionals

Style/Documentation:
Enabled: false
32 changes: 1 addition & 31 deletions .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
Expand All @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions 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
Expand Down Expand Up @@ -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)
8 changes: 5 additions & 3 deletions lib/saharspec/matchers/send_message.rb
Expand Up @@ -30,7 +30,7 @@ def exactly(n)
end

def times
fail NoMethodError unless @times
raise NoMethodError unless @times
self
end

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions spec/.rubocop.yml
@@ -0,0 +1,7 @@
inherit_from: ../.rubocop.yml

Style/BlockDelimiters:
Enabled: false

Style/Semicolon:
Enabled: false
3 changes: 1 addition & 2 deletions spec/saharspec/its/map_spec.rb
Expand Up @@ -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
14 changes: 11 additions & 3 deletions spec/saharspec/matchers/send_message_spec.rb
@@ -1,19 +1,27 @@
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

context 'arguments' do
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
Expand Down

0 comments on commit 2e9295f

Please sign in to comment.