diff --git a/Gemfile b/Gemfile index 74963f6..e92d854 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,11 @@ # frozen_string_literal: true -source 'https://rubygems.org' +source "https://rubygems.org" # Specify your gem's dependencies in errbit_plugin.gemspec gemspec gem "rake" -gem 'rspec' +gem "rspec" +gem "standard" gem "simplecov", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 21c40ef..821aaff 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,9 +6,21 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.4.3) diff-lcs (1.6.1) docile (1.4.1) + json (2.10.2) + language_server-protocol (3.17.0.4) + lint_roller (1.1.0) + parallel (1.26.3) + parser (3.3.7.4) + ast (~> 2.4.1) + racc + prism (1.4.0) + racc (1.8.1) + rainbow (3.1.1) rake (13.2.1) + regexp_parser (2.10.0) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -22,12 +34,46 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-support (3.13.2) + rubocop (1.75.2) + json (~> 2.3) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) + parallel (~> 1.10) + parser (>= 3.3.0.2) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.44.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.44.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.25.0) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + ruby-progressbar (1.13.0) simplecov (0.22.0) docile (~> 1.1) simplecov-html (~> 0.11) simplecov_json_formatter (~> 0.1) simplecov-html (0.13.1) simplecov_json_formatter (0.1.4) + standard (1.49.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.75.2) + standard-custom (~> 1.0.0) + standard-performance (~> 1.8) + standard-custom (1.0.2) + lint_roller (~> 1.0) + rubocop (~> 1.50) + standard-performance (1.8.0) + lint_roller (~> 1.1) + rubocop-performance (~> 1.25.0) + unicode-display_width (3.1.4) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) PLATFORMS arm64-darwin-24 @@ -37,6 +83,7 @@ DEPENDENCIES rake rspec simplecov + standard BUNDLED WITH 2.6.7 diff --git a/README.md b/README.md index c642817..ef48ba8 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # ErrbitPlugin +[![RSpec](https://github.com/errbit/errbit_plugin/actions/workflows/rspec.yml/badge.svg)](https://github.com/errbit/errbit_plugin/actions/workflows/rspec.yml) +[![RSpec on JRuby](https://github.com/errbit/errbit_plugin/actions/workflows/jruby.yml/badge.svg)](https://github.com/errbit/errbit_plugin/actions/workflows/jruby.yml) +[![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard) + ErrbitPlugin provides a set of base classes that you can extend to create Errbit plugins. diff --git a/errbit_plugin.gemspec b/errbit_plugin.gemspec index c5883ad..99db404 100644 --- a/errbit_plugin.gemspec +++ b/errbit_plugin.gemspec @@ -1,21 +1,20 @@ # frozen_string_literal: true -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'errbit_plugin/version' +require "errbit_plugin/version" Gem::Specification.new do |spec| - spec.name = "errbit_plugin" - spec.version = ErrbitPlugin::VERSION - spec.authors = ["Stephen Crosby"] - spec.email = ["stevecrozz@gmail.com"] - spec.description = %q{Base to create an errbit plugin} - spec.summary = %q{Base to create an errbit plugin} - spec.homepage = "http://github.com/errbit/errbit" - spec.license = "MIT" + spec.name = "errbit_plugin" + spec.version = ErrbitPlugin::VERSION + spec.authors = ["Stephen Crosby"] + spec.email = ["stevecrozz@gmail.com"] + spec.description = "Base to create an errbit plugin" + spec.summary = "Base to create an errbit plugin" + spec.homepage = "http://github.com/errbit/errbit" + spec.license = "MIT" - spec.files = `git ls-files`.split($/) - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } - spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) + spec.files = `git ls-files`.split($/) + spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.require_paths = ["lib"] end diff --git a/lib/errbit_plugin/issue_trackers/none.rb b/lib/errbit_plugin/issue_trackers/none.rb index 6bd59a8..cc7ecb7 100644 --- a/lib/errbit_plugin/issue_trackers/none.rb +++ b/lib/errbit_plugin/issue_trackers/none.rb @@ -2,31 +2,55 @@ module ErrbitPlugin class NoneIssueTracker < IssueTracker - def self.label; 'none'; end + def self.label + "none" + end + def self.note - 'When no issue tracker has been configured, you will be able to ' << - 'leave comments on errors.' + "When no issue tracker has been configured, you will be able to " << + "leave comments on errors." + end + + def self.fields + {} end - def self.fields; {}; end + def self.icons @icons ||= { - create: ['image/png', read_static_file('none_create.png')], - goto: ['image/png', read_static_file('none_create.png')], - inactive: ['image/png', read_static_file('none_inactive.png')], + create: ["image/png", read_static_file("none_create.png")], + goto: ["image/png", read_static_file("none_create.png")], + inactive: ["image/png", read_static_file("none_inactive.png")] } end + def self.read_static_file(file) File.read(File.expand_path(File.join( - File.dirname(__FILE__), '..', '..', '..', 'static', file))) + File.dirname(__FILE__), "..", "..", "..", "static", file + ))) end + ## # The NoneIssueTracker is mark like configured? false because it not valid # like a real IssueTracker - def configured?; false; end - def errors; {}; end - def url; ''; end - def create_issue(*); false; end - def close_issue(*); false; end + def configured? + false + end + + def errors + {} + end + + def url + "" + end + + def create_issue(*) + false + end + + def close_issue(*) + false + end end end diff --git a/lib/errbit_plugin/registry.rb b/lib/errbit_plugin/registry.rb index 35b1b88..adda68d 100644 --- a/lib/errbit_plugin/registry.rb +++ b/lib/errbit_plugin/registry.rb @@ -2,6 +2,7 @@ module ErrbitPlugin class IncompatibilityError < StandardError; end + class AlreadyRegisteredError < StandardError; end module Registry @@ -20,7 +21,7 @@ def self.add_issue_tracker(klass) if validate.valid? @issue_trackers[key] = klass else - raise IncompatibilityError.new(validate.errors.join('; ')) + raise IncompatibilityError.new(validate.errors.join("; ")) end end diff --git a/lib/errbit_plugin/validate_issue_tracker.rb b/lib/errbit_plugin/validate_issue_tracker.rb index bbb8c58..a7c1fc7 100644 --- a/lib/errbit_plugin/validate_issue_tracker.rb +++ b/lib/errbit_plugin/validate_issue_tracker.rb @@ -19,11 +19,11 @@ def valid? private def good_inherit? - unless @klass.ancestors.include?(ErrbitPlugin::IssueTracker) + if @klass.ancestors.include?(ErrbitPlugin::IssueTracker) + true + else add_errors(:not_inherited) false - else - true end end @@ -57,7 +57,7 @@ def instance @instance ||= @klass.new({}) end - def add_errors(key, value=nil) + def add_errors(key, value = nil) @errors << [key, value].compact end end diff --git a/lib/errbit_plugin/version.rb b/lib/errbit_plugin/version.rb index 4f5e6c5..9762eac 100644 --- a/lib/errbit_plugin/version.rb +++ b/lib/errbit_plugin/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module ErrbitPlugin - VERSION = '0.7.0' + VERSION = "0.7.0" end diff --git a/spec/errbit_plugin/registry_spec.rb b/spec/errbit_plugin/registry_spec.rb index edd44cb..b405dbc 100644 --- a/spec/errbit_plugin/registry_spec.rb +++ b/spec/errbit_plugin/registry_spec.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe ErrbitPlugin::Registry do before do @@ -10,7 +10,7 @@ let(:tracker) { tracker = Class.new(ErrbitPlugin::IssueTracker) do def self.label - 'something' + "something" end end tracker @@ -22,16 +22,16 @@ def self.label allow(ErrbitPlugin::ValidateIssueTracker) .to receive(:new) .with(tracker) - .and_return(double(:valid? => true, :message => '')) + .and_return(double(valid?: true, message: "")) end - it 'add new issue_tracker plugin' do + it "add new issue_tracker plugin" do ErrbitPlugin::Registry.add_issue_tracker(tracker) expect(ErrbitPlugin::Registry.issue_trackers).to eq({ - 'something' => tracker + "something" => tracker }) end context "with already issue_tracker with this key" do - it 'raise ErrbitPlugin::AlreadyRegisteredError' do + it "raise ErrbitPlugin::AlreadyRegisteredError" do ErrbitPlugin::Registry.add_issue_tracker(tracker) expect { ErrbitPlugin::Registry.add_issue_tracker(tracker) @@ -41,26 +41,26 @@ def self.label end context "with an IssueTracker not valid" do - it 'raise an IncompatibilityError' do + it "raise an IncompatibilityError" do allow(ErrbitPlugin::ValidateIssueTracker) .to receive(:new) .with(tracker) - .and_return(double(:valid? => false, :message => 'foo', :errors => [])) + .and_return(double(valid?: false, message: "foo", errors: [])) expect { ErrbitPlugin::Registry.add_issue_tracker(tracker) }.to raise_error(ErrbitPlugin::IncompatibilityError) end - it 'puts the errors in the exception message' do + it "puts the errors in the exception message" do allow(ErrbitPlugin::ValidateIssueTracker) .to receive(:new) .with(tracker) - .and_return(double(:valid? => false, :message => 'foo', :errors => ['one', 'two'])) + .and_return(double(valid?: false, message: "foo", errors: ["one", "two"])) begin ErrbitPlugin::Registry.add_issue_tracker(tracker) rescue ErrbitPlugin::IncompatibilityError => e - expect(e.message).to eq('one; two') + expect(e.message).to eq("one; two") end end end diff --git a/spec/errbit_plugin/validate_issue_tracker_spec.rb b/spec/errbit_plugin/validate_issue_tracker_spec.rb index 1d3e6a3..bc8cfcf 100644 --- a/spec/errbit_plugin/validate_issue_tracker_spec.rb +++ b/spec/errbit_plugin/validate_issue_tracker_spec.rb @@ -1,47 +1,100 @@ # frozen_string_literal: true -require 'spec_helper' +require "spec_helper" describe ErrbitPlugin::ValidateIssueTracker do describe "#valid?" do - context "with a complete class" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end - end - - it 'valid' do + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end + end + + it "valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true end end context "with class not inherit from ErrbitPlugin::IssueTracker" do klass = Class.new do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def initialize(params); end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end - end - - it 'not valid' do + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def initialize(params) + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end + end + + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'says :not_inherited' do + it "says :not_inherited" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:not_inherited]] @@ -50,21 +103,44 @@ def url; 'http'; end context "with no label method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement label method' do + it "say not implement label method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :label]] @@ -73,21 +149,44 @@ def url; 'http'; end context "with no icons method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.label; 'alabel'; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.label + "alabel" + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement icons method' do + it "say not implement icons method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :icons]] @@ -96,21 +195,44 @@ def url; 'http'; end context "without fields method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement fields method' do + it "say not implement fields method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :fields]] @@ -119,21 +241,44 @@ def url; 'http'; end context "without configured? method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement configured? method' do + it "say not implement configured? method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :configured?]] @@ -142,21 +287,44 @@ def url; 'http'; end context "without errors method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement errors method' do + it "say not implement errors method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :errors]] @@ -165,20 +333,43 @@ def url; 'http'; end context "without create_issue method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def close_issue; 'http'; end - def url; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def close_issue + "http" + end + + def url + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement create_issue method' do + it "say not implement create_issue method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :create_issue]] @@ -188,20 +379,43 @@ def url; 'http'; end context "without close_issue method" do # this is an optional method klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def url; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def url + "http" + end end - it 'is valid' do + it "is valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true end - it 'not say not implement close_issue method' do + it "not say not implement close_issue method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).not_to eql [[:instance_method_missing, :close_issue]] @@ -210,21 +424,44 @@ def url; 'http'; end context "without url method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.note; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end + def self.label + "foo" + end + + def self.note + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement url method' do + it "say not implement url method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :url]] @@ -233,21 +470,44 @@ def close_issue; 'http'; end context "without note method" do klass = Class.new(ErrbitPlugin::IssueTracker) do - def self.label; 'foo'; end - def self.fields; ['foo']; end - def self.icons; {}; end - def configured?; true; end - def errors; true; end - def create_issue; 'http'; end - def close_issue; 'http'; end - def url; 'foo'; end + def self.label + "foo" + end + + def self.fields + ["foo"] + end + + def self.icons + {} + end + + def configured? + true + end + + def errors + true + end + + def create_issue + "http" + end + + def close_issue + "http" + end + + def url + "foo" + end end - it 'not valid' do + it "not valid" do expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false end - it 'say not implement note method' do + it "say not implement note method" do is = ErrbitPlugin::ValidateIssueTracker.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :note]] diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d263a08..f8869cf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,10 +1,10 @@ # frozen_string_literal: true -require 'simplecov' +require "simplecov" SimpleCov.start -require 'errbit_plugin' +require "errbit_plugin" RSpec.configure do |config| config.run_all_when_everything_filtered = true @@ -14,5 +14,5 @@ # order dependency and want to debug it, you can fix the order by providing # the seed, which is printed after each run. # --seed 1234 - config.order = 'random' + config.order = "random" end