Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add rubocop and drop support for Rubies < 2.0 #124

Merged
merged 6 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Style/StringLiterals:
EnforcedStyle: double_quotes

Style/FrozenStringLiteralComment:
Enabled: false

# Allow some style changes in specs
Metrics/ModuleLength:
Exclude:
- spec/**/*
Metrics/BlockLength:
Exclude:
- spec/**/*
Style/BlockDelimiters:
Exclude:
- spec/**/*
Style/RescueModifier:
Exclude:
- spec/**/*
Metrics/MethodLength:
Exclude:
- spec/interactor/hooks_spec.rb
Style/IndentArray:
Exclude:
- spec/integration_spec.rb
- spec/interactor/hooks_spec.rb

# Allow nice tree-like comments in specs
Style/AsciiComments:
Exclude:
- spec/integration_spec.rb

# Here inconsistent indentation helps to understand
# tree nature of callbacks.
Style/AlignArray:
Exclude:
- spec/integration_spec.rb

# This could be removed if throws are used instead of
# raising Failure in #fail!
Lint/HandleExceptions:
Exclude:
- lib/interactor.rb

Style/EmptyMethod:
Enabled: false

AllCops:
TargetRubyVersion: 2.0
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ language: ruby
matrix:
allow_failures:
- rvm: ruby-head
- rvm: "2.0"
notifications:
webhooks:
on_start: always
Expand All @@ -27,5 +28,5 @@ rvm:
- "2.3.3"
- "2.4.0"
- ruby-head
script: bundle exec rspec
script: bundle exec rake
sudo: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gemspec
group :test do
gem "codeclimate-test-reporter", require: false
gem "rspec", "~> 3.2"
gem "rubocop", "~> 0.47.1"
end
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
require "rubocop/rake_task"

RSpec::Core::RakeTask.new(:spec)
RuboCop::RakeTask.new(:rubocop)

task default: :spec
task default: [:spec, :rubocop]
8 changes: 6 additions & 2 deletions interactor.gemspec
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
# encoding: utf-8
require "English"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I didn't know about this!


Gem::Specification.new do |spec|
spec.name = "interactor"
spec.version = "4.0.0"

spec.author = "Collective Idea"
spec.email = "[email protected]"
spec.description = "Interactor provides a common interface for performing complex user interactions."
spec.description = "Interactor provides a common interface for performing " \
"complex user interactions."
spec.summary = "Simple interactor implementation"
spec.homepage = "https://github.com/collectiveidea/interactor"
spec.license = "MIT"

spec.files = `git ls-files`.split($/)
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.test_files = spec.files.grep(/^spec/)

spec.required_ruby_version = ">= 2.0"

spec.add_development_dependency "bundler", "~> 1.9"
spec.add_development_dependency "rake", "~> 10.4"
end
2 changes: 1 addition & 1 deletion lib/interactor/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Context < OpenStruct
#
# Returns the Interactor::Context.
def self.build(context = {})
self === context ? context : new(context)
context.is_a?(Context) ? context : new(context)
end

# Public: Whether the Interactor::Context is successful. By default, a new
Expand Down
4 changes: 2 additions & 2 deletions lib/interactor/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ def with_hooks
#
# Returns nothing.
def run_around_hooks(&block)
self.class.around_hooks.reverse.inject(block) { |chain, hook|
self.class.around_hooks.reverse.inject(block) do |chain, hook|
proc { run_hook(hook, chain) }
}.call
end.call
end

# Internal: Run before hooks.
Expand Down
65 changes: 42 additions & 23 deletions spec/integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,23 @@
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

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

Expand All @@ -25,7 +35,8 @@ def build_organizer(options = {}, &block)
# └─ interactor5

let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are this and the similar changes below just a line length concern?

Copy link
Contributor Author

@hedgesky hedgesky Mar 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. Both ways have their benefits and downsides. Introducing intermediate variable seems a bit clumsy, but it keeps lines short. Short lines are easier to perceive and they are two-panes-friendly:
2017-03-22_15-36-32

Anyway, it's not a big issue if concentrated in a single file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm all for the 80 character limit but I typically relax that rule a bit for specs. But maybe I shouldn't!

around do |interactor|
context.steps << :around_before
interactor.call
Expand Down Expand Up @@ -315,7 +326,8 @@ def rollback

context "when an around hook fails early" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.fail!
context.steps << :around_before
Expand Down Expand Up @@ -345,9 +357,10 @@ def rollback

context "when an around hook errors early" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
raise "foo"
unexpected_error!
context.steps << :around_before
interactor.call
context.steps << :around_after
Expand Down Expand Up @@ -381,7 +394,8 @@ def rollback

context "when a before hook fails" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
Expand Down Expand Up @@ -412,15 +426,16 @@ def rollback

context "when a before hook errors" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
context.steps << :around_after
end

before do
raise "foo"
unexpected_error!
context.steps << :before
end

Expand Down Expand Up @@ -449,7 +464,8 @@ def rollback

context "when an after hook fails" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
Expand Down Expand Up @@ -500,7 +516,8 @@ def rollback

context "when an after hook errors" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
Expand All @@ -512,7 +529,7 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after
end
end
Expand Down Expand Up @@ -557,7 +574,8 @@ def rollback

context "when an around hook fails late" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
Expand Down Expand Up @@ -609,11 +627,12 @@ def rollback

context "when an around hook errors late" do
let(:organizer) {
build_organizer(organize: [organizer2, interactor3, organizer4, interactor5]) do
interactors = [organizer2, interactor3, organizer4, interactor5]
build_organizer(organize: interactors) do
around do |interactor|
context.steps << :around_before
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after
end

Expand Down Expand Up @@ -716,7 +735,7 @@ def rollback
let(:interactor3) {
build_interactor do
around do |interactor|
raise "foo"
unexpected_error!
context.steps << :around_before3
interactor.call
context.steps << :around_after3
Expand Down Expand Up @@ -823,7 +842,7 @@ def rollback
end

before do
raise "foo"
unexpected_error!
context.steps << :before3
end

Expand Down Expand Up @@ -933,7 +952,7 @@ def rollback
end

def call
raise "foo"
unexpected_error!
context.steps << :call3
end

Expand Down Expand Up @@ -1032,7 +1051,7 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after3
end

Expand Down Expand Up @@ -1128,7 +1147,7 @@ def rollback
around do |interactor|
context.steps << :around_before3
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after3
end

Expand Down Expand Up @@ -1233,7 +1252,7 @@ def rollback
let(:interactor4b) {
build_interactor do
around do |interactor|
raise "foo"
unexpected_error!
context.steps << :around_before4b
interactor.call
context.steps << :around_after4b
Expand Down Expand Up @@ -1350,7 +1369,7 @@ def rollback
end

before do
raise "foo"
unexpected_error!
context.steps << :before4b
end

Expand Down Expand Up @@ -1470,7 +1489,7 @@ def rollback
end

def call
raise "foo"
unexpected_error!
context.steps << :call4b
end

Expand Down Expand Up @@ -1579,7 +1598,7 @@ def rollback
end

after do
raise "foo"
unexpected_error!
context.steps << :after4b
end

Expand Down Expand Up @@ -1685,7 +1704,7 @@ def rollback
around do |interactor|
context.steps << :around_before4b
interactor.call
raise "foo"
unexpected_error!
context.steps << :around_after4b
end

Expand Down
3 changes: 2 additions & 1 deletion spec/support/lint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +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")

Expand Down