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 more tests #16

Merged
merged 13 commits into from
Apr 10, 2025
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
4 changes: 4 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
--format documentation
--color
--require spec_helper
--order random
1 change: 1 addition & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby_version: 3.1
4 changes: 2 additions & 2 deletions lib/errbit_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

module ErrbitPlugin
class ValidateIssueTracker
class IssueTrackerValidator
def initialize(klass)
@klass = klass
@errors = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions lib/errbit_plugin/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/errbit_plugin/none_issue_tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions spec/errbit_plugin/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "spec_helper"

describe ErrbitPlugin::Registry do
RSpec.describe ErrbitPlugin::Registry do
before do
ErrbitPlugin::Registry.clear_issue_trackers
end
Expand All @@ -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: ""))
Expand All @@ -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: []))
Expand All @@ -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"]))
Expand Down
25 changes: 16 additions & 9 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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