From e9a30dc5f1043ffa6bba7b7847579d118589f021 Mon Sep 17 00:00:00 2001 From: Anton Chuchkalov Date: Thu, 23 Mar 2017 11:12:52 +0300 Subject: [PATCH] implemented requested changes (#124) --- .rubocop.yml | 3 ++ Gemfile | 1 + interactor.gemspec | 3 +- lib/interactor.rb | 6 ++-- spec/integration_spec.rb | 64 +++++++++++++++++++++++++++++----------- spec/support/lint.rb | 5 ++-- 6 files changed, 58 insertions(+), 24 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index de66a53..717ebdf 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -42,5 +42,8 @@ Lint/HandleExceptions: Exclude: - lib/interactor.rb +Style/EmptyMethod: + Enabled: false + AllCops: TargetRubyVersion: 2.1 diff --git a/Gemfile b/Gemfile index b5be352..d309077 100644 --- a/Gemfile +++ b/Gemfile @@ -5,4 +5,5 @@ gemspec group :test do gem "codeclimate-test-reporter", require: false gem "rspec", "~> 3.2" + gem "rubocop", "~> 0.47.1" end diff --git a/interactor.gemspec b/interactor.gemspec index cf877f9..b8a4524 100644 --- a/interactor.gemspec +++ b/interactor.gemspec @@ -16,9 +16,8 @@ Gem::Specification.new do |spec| spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR) spec.test_files = spec.files.grep(/^spec/) - spec.required_ruby_version = ">= 2.1" + spec.required_ruby_version = ">= 2.0" spec.add_development_dependency "bundler", "~> 1.9" spec.add_development_dependency "rake", "~> 10.4" - spec.add_development_dependency "rubocop", "~> 0.47.1" end diff --git a/lib/interactor.rb b/lib/interactor.rb index d645ab3..2423630 100644 --- a/lib/interactor.rb +++ b/lib/interactor.rb @@ -153,12 +153,14 @@ def run! # each interactor class. # # Returns nothing. - def call; end + def call + end # Public: Reverse prior invocation of an Interactor instance. Any interactor # class that requires undoing upon downstream failure is expected to overwrite # the "rollback" instance method. # # Returns nothing. - def rollback; end + def rollback + end end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 4177aaa..045fc0c 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -2,6 +2,11 @@ def build_interactor(&block) interactor = Class.new.send(:include, Interactor) interactor.class_eval(&block) if block + interactor.class_eval do + def unexpected_error! + raise "foo" + end + end interactor end @@ -9,6 +14,11 @@ def build_organizer(options = {}, &block) organizer = Class.new.send(:include, Interactor::Organizer) organizer.organize(options[:organize]) if options[:organize] organizer.class_eval(&block) if block + organizer.class_eval do + def unexpected_error! + raise "foo" + end + end organizer end @@ -349,8 +359,11 @@ def rollback let(:organizer) { interactors = [organizer2, interactor3, organizer4, interactor5] build_organizer(organize: interactors) do - around do |_interactor| - raise "foo" + around do |interactor| + unexpected_error! + context.steps << :around_before + interactor.call + context.steps << :around_after end before do @@ -422,7 +435,8 @@ def rollback end before do - raise "foo" + unexpected_error! + context.steps << :before end after do @@ -515,7 +529,8 @@ def rollback end after do - raise "foo" + unexpected_error! + context.steps << :after end end } @@ -617,7 +632,8 @@ def rollback around do |interactor| context.steps << :around_before interactor.call - raise "foo" + unexpected_error! + context.steps << :around_after end before do @@ -718,8 +734,11 @@ def rollback context "when a nested around hook errors early" do let(:interactor3) { build_interactor do - around do |_interactor| - raise "foo" + around do |interactor| + unexpected_error! + context.steps << :around_before3 + interactor.call + context.steps << :around_after3 end before do @@ -823,7 +842,8 @@ def rollback end before do - raise "foo" + unexpected_error! + context.steps << :before3 end after do @@ -932,7 +952,8 @@ def rollback end def call - raise "foo" + unexpected_error! + context.steps << :call3 end def rollback @@ -1030,7 +1051,8 @@ def rollback end after do - raise "foo" + unexpected_error! + context.steps << :after3 end def call @@ -1125,7 +1147,8 @@ def rollback around do |interactor| context.steps << :around_before3 interactor.call - raise "foo" + unexpected_error! + context.steps << :around_after3 end before do @@ -1228,8 +1251,11 @@ def rollback context "when a deeply nested around hook errors early" do let(:interactor4b) { build_interactor do - around do |_interactor| - raise "foo" + around do |interactor| + unexpected_error! + context.steps << :around_before4b + interactor.call + context.steps << :around_after4b end before do @@ -1343,7 +1369,8 @@ def rollback end before do - raise "foo" + unexpected_error! + context.steps << :before4b end after do @@ -1462,7 +1489,8 @@ def rollback end def call - raise "foo" + unexpected_error! + context.steps << :call4b end def rollback @@ -1570,7 +1598,8 @@ def rollback end after do - raise "foo" + unexpected_error! + context.steps << :after4b end def call @@ -1675,7 +1704,8 @@ def rollback around do |interactor| context.steps << :around_before4b interactor.call - raise "foo" + unexpected_error! + context.steps << :around_after4b end before do diff --git a/spec/support/lint.rb b/spec/support/lint.rb index b8fd9d3..73346e5 100644 --- a/spec/support/lint.rb +++ b/spec/support/lint.rb @@ -43,9 +43,8 @@ let(:context) { double(:context) } it "initializes a context" do - expect( - Interactor::Context - ).to receive(:build).once.with(foo: "bar") { context } + expect(Interactor::Context).to receive(:build) + .once.with(foo: "bar") { context } instance = interactor.new(foo: "bar")