diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..6c6110e --- /dev/null +++ b/.rspec @@ -0,0 +1,4 @@ +--format documentation +--color +--require spec_helper +--order random diff --git a/.standard.yml b/.standard.yml new file mode 100644 index 0000000..72b2693 --- /dev/null +++ b/.standard.yml @@ -0,0 +1 @@ +ruby_version: 3.1 diff --git a/lib/errbit_plugin.rb b/lib/errbit_plugin.rb index 4a54ca1..3fb352d 100644 --- a/lib/errbit_plugin.rb +++ b/lib/errbit_plugin.rb @@ -3,5 +3,5 @@ require "errbit_plugin/version" require "errbit_plugin/registry" require "errbit_plugin/issue_tracker" -require "errbit_plugin/validate_issue_tracker" -require "errbit_plugin/issue_trackers/none" +require "errbit_plugin/issue_tracker_validator" +require "errbit_plugin/none_issue_tracker" diff --git a/lib/errbit_plugin/validate_issue_tracker.rb b/lib/errbit_plugin/issue_tracker_validator.rb similarity index 97% rename from lib/errbit_plugin/validate_issue_tracker.rb rename to lib/errbit_plugin/issue_tracker_validator.rb index a7c1fc7..6f65ebf 100644 --- a/lib/errbit_plugin/validate_issue_tracker.rb +++ b/lib/errbit_plugin/issue_tracker_validator.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module ErrbitPlugin - class ValidateIssueTracker + class IssueTrackerValidator def initialize(klass) @klass = klass @errors = [] diff --git a/lib/errbit_plugin/issue_trackers/none.rb b/lib/errbit_plugin/none_issue_tracker.rb similarity index 93% rename from lib/errbit_plugin/issue_trackers/none.rb rename to lib/errbit_plugin/none_issue_tracker.rb index cc7ecb7..0de3c8e 100644 --- a/lib/errbit_plugin/issue_trackers/none.rb +++ b/lib/errbit_plugin/none_issue_tracker.rb @@ -7,7 +7,7 @@ def self.label end def self.note - "When no issue tracker has been configured, you will be able to " << + "When no issue tracker has been configured, you will be able to " \ "leave comments on errors." end @@ -25,7 +25,7 @@ def self.icons def self.read_static_file(file) File.read(File.expand_path(File.join( - File.dirname(__FILE__), "..", "..", "..", "static", file + File.dirname(__FILE__), "..", "..", "static", file ))) end diff --git a/lib/errbit_plugin/registry.rb b/lib/errbit_plugin/registry.rb index adda68d..1ff9bdc 100644 --- a/lib/errbit_plugin/registry.rb +++ b/lib/errbit_plugin/registry.rb @@ -16,12 +16,12 @@ def self.add_issue_tracker(klass) "issue_tracker '#{key}' already registered" end - validate = ValidateIssueTracker.new(klass) + validator = IssueTrackerValidator.new(klass) - if validate.valid? + if validator.valid? @issue_trackers[key] = klass else - raise IncompatibilityError.new(validate.errors.join("; ")) + raise IncompatibilityError.new(validator.errors.join("; ")) end end diff --git a/spec/errbit_plugin/validate_issue_tracker_spec.rb b/spec/errbit_plugin/issue_tracker_validator_spec.rb similarity index 83% rename from spec/errbit_plugin/validate_issue_tracker_spec.rb rename to spec/errbit_plugin/issue_tracker_validator_spec.rb index bc8cfcf..e5a7aa1 100644 --- a/spec/errbit_plugin/validate_issue_tracker_spec.rb +++ b/spec/errbit_plugin/issue_tracker_validator_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe ErrbitPlugin::ValidateIssueTracker do +RSpec.describe ErrbitPlugin::IssueTrackerValidator do describe "#valid?" do context "with a complete class" do klass = Class.new(ErrbitPlugin::IssueTracker) do @@ -44,7 +44,7 @@ def url end it "valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be true end end @@ -91,11 +91,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "says :not_inherited" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:not_inherited]] end @@ -137,11 +137,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement label method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :label]] end @@ -183,11 +183,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement icons method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :icons]] end @@ -229,11 +229,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement fields method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :fields]] end @@ -275,11 +275,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement configured? method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :configured?]] end @@ -321,11 +321,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement errors method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :errors]] end @@ -367,10 +367,10 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement create_issue method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :create_issue]] end @@ -413,10 +413,10 @@ def url end it "is valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be true end it "not say not implement close_issue method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).not_to eql [[:instance_method_missing, :close_issue]] end @@ -458,11 +458,11 @@ def close_issue end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement url method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:instance_method_missing, :url]] end @@ -504,11 +504,11 @@ def url end it "not valid" do - expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false + expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false end it "say not implement note method" do - is = ErrbitPlugin::ValidateIssueTracker.new(klass) + is = ErrbitPlugin::IssueTrackerValidator.new(klass) is.valid? expect(is.errors).to eql [[:class_method_missing, :note]] end diff --git a/spec/errbit_plugin/none_issue_tracker_spec.rb b/spec/errbit_plugin/none_issue_tracker_spec.rb new file mode 100644 index 0000000..ea0b7e9 --- /dev/null +++ b/spec/errbit_plugin/none_issue_tracker_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe ErrbitPlugin::NoneIssueTracker do + let(:options) { {} } + + subject { described_class.new(options) } + + it { expect(subject).to be_an(ErrbitPlugin::IssueTracker) } + + it { expect(subject.configured?).to eq(false) } + + it { expect(subject.errors).to eq({}) } + + it { expect(subject.url).to eq("") } + + it { expect(subject.create_issue).to eq(false) } + + it { expect(subject.close_issue).to eq(false) } + + it { expect(described_class.label).to eq("none") } + + it { expect(described_class.note).to start_with("When no issue tracker") } + + it { expect(described_class.fields).to eq({}) } + + it { expect(described_class.icons).not_to be_empty } + + # TODO: .read_static_file +end diff --git a/spec/errbit_plugin/registry_spec.rb b/spec/errbit_plugin/registry_spec.rb index b405dbc..3ce12e6 100644 --- a/spec/errbit_plugin/registry_spec.rb +++ b/spec/errbit_plugin/registry_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe ErrbitPlugin::Registry do +RSpec.describe ErrbitPlugin::Registry do before do ErrbitPlugin::Registry.clear_issue_trackers end @@ -19,7 +19,7 @@ def self.label describe ".add_issue_tracker" do context "with issue_tracker class valid" do before do - allow(ErrbitPlugin::ValidateIssueTracker) + allow(ErrbitPlugin::IssueTrackerValidator) .to receive(:new) .with(tracker) .and_return(double(valid?: true, message: "")) @@ -42,7 +42,7 @@ def self.label context "with an IssueTracker not valid" do it "raise an IncompatibilityError" do - allow(ErrbitPlugin::ValidateIssueTracker) + allow(ErrbitPlugin::IssueTrackerValidator) .to receive(:new) .with(tracker) .and_return(double(valid?: false, message: "foo", errors: [])) @@ -52,7 +52,7 @@ def self.label end it "puts the errors in the exception message" do - allow(ErrbitPlugin::ValidateIssueTracker) + allow(ErrbitPlugin::IssueTrackerValidator) .to receive(:new) .with(tracker) .and_return(double(valid?: false, message: "foo", errors: ["one", "two"])) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f8869cf..040f26d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,17 +2,24 @@ require "simplecov" -SimpleCov.start +SimpleCov.start do + enable_coverage :branch + + primary_coverage :branch + + add_filter "spec/" +end require "errbit_plugin" RSpec.configure do |config| - config.run_all_when_everything_filtered = true - config.filter_run :focus - - # Run specs in random order to surface order dependencies. If you find an - # 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" + # Enable flags like --only-failures and --next-failure + config.example_status_persistence_file_path = ".rspec_status" + + # Disable RSpec exposing methods globally on `Module` and `main` + config.disable_monkey_patching! + + config.expect_with :rspec do |c| + c.syntax = :expect + end end