Skip to content

Commit 3914b7a

Browse files
authored
Add more tests (#16)
* Configure simplecov * Configure RSpec * Configure standard * Fix tests * Rename ValidateIssueTracker -> IssueTrackerValidator * Rename * Move * Add empty test * Add failing tests * Fix code * Fix FrozenError * Configure simplecov * Update tests
1 parent a904ef1 commit 3914b7a

10 files changed

+86
-43
lines changed

.rspec

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
--format documentation
2+
--color
3+
--require spec_helper
4+
--order random

.standard.yml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ruby_version: 3.1

lib/errbit_plugin.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
require "errbit_plugin/version"
44
require "errbit_plugin/registry"
55
require "errbit_plugin/issue_tracker"
6-
require "errbit_plugin/validate_issue_tracker"
7-
require "errbit_plugin/issue_trackers/none"
6+
require "errbit_plugin/issue_tracker_validator"
7+
require "errbit_plugin/none_issue_tracker"

lib/errbit_plugin/validate_issue_tracker.rb lib/errbit_plugin/issue_tracker_validator.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
module ErrbitPlugin
4-
class ValidateIssueTracker
4+
class IssueTrackerValidator
55
def initialize(klass)
66
@klass = klass
77
@errors = []

lib/errbit_plugin/issue_trackers/none.rb lib/errbit_plugin/none_issue_tracker.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def self.label
77
end
88

99
def self.note
10-
"When no issue tracker has been configured, you will be able to " <<
10+
"When no issue tracker has been configured, you will be able to " \
1111
"leave comments on errors."
1212
end
1313

@@ -25,7 +25,7 @@ def self.icons
2525

2626
def self.read_static_file(file)
2727
File.read(File.expand_path(File.join(
28-
File.dirname(__FILE__), "..", "..", "..", "static", file
28+
File.dirname(__FILE__), "..", "..", "static", file
2929
)))
3030
end
3131

lib/errbit_plugin/registry.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ def self.add_issue_tracker(klass)
1616
"issue_tracker '#{key}' already registered"
1717
end
1818

19-
validate = ValidateIssueTracker.new(klass)
19+
validator = IssueTrackerValidator.new(klass)
2020

21-
if validate.valid?
21+
if validator.valid?
2222
@issue_trackers[key] = klass
2323
else
24-
raise IncompatibilityError.new(validate.errors.join("; "))
24+
raise IncompatibilityError.new(validator.errors.join("; "))
2525
end
2626
end
2727

spec/errbit_plugin/validate_issue_tracker_spec.rb spec/errbit_plugin/issue_tracker_validator_spec.rb

+22-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "spec_helper"
44

5-
describe ErrbitPlugin::ValidateIssueTracker do
5+
RSpec.describe ErrbitPlugin::IssueTrackerValidator do
66
describe "#valid?" do
77
context "with a complete class" do
88
klass = Class.new(ErrbitPlugin::IssueTracker) do
@@ -44,7 +44,7 @@ def url
4444
end
4545

4646
it "valid" do
47-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true
47+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be true
4848
end
4949
end
5050

@@ -91,11 +91,11 @@ def url
9191
end
9292

9393
it "not valid" do
94-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
94+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
9595
end
9696

9797
it "says :not_inherited" do
98-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
98+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
9999
is.valid?
100100
expect(is.errors).to eql [[:not_inherited]]
101101
end
@@ -137,11 +137,11 @@ def url
137137
end
138138

139139
it "not valid" do
140-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
140+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
141141
end
142142

143143
it "say not implement label method" do
144-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
144+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
145145
is.valid?
146146
expect(is.errors).to eql [[:class_method_missing, :label]]
147147
end
@@ -183,11 +183,11 @@ def url
183183
end
184184

185185
it "not valid" do
186-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
186+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
187187
end
188188

189189
it "say not implement icons method" do
190-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
190+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
191191
is.valid?
192192
expect(is.errors).to eql [[:class_method_missing, :icons]]
193193
end
@@ -229,11 +229,11 @@ def url
229229
end
230230

231231
it "not valid" do
232-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
232+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
233233
end
234234

235235
it "say not implement fields method" do
236-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
236+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
237237
is.valid?
238238
expect(is.errors).to eql [[:class_method_missing, :fields]]
239239
end
@@ -275,11 +275,11 @@ def url
275275
end
276276

277277
it "not valid" do
278-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
278+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
279279
end
280280

281281
it "say not implement configured? method" do
282-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
282+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
283283
is.valid?
284284
expect(is.errors).to eql [[:instance_method_missing, :configured?]]
285285
end
@@ -321,11 +321,11 @@ def url
321321
end
322322

323323
it "not valid" do
324-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
324+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
325325
end
326326

327327
it "say not implement errors method" do
328-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
328+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
329329
is.valid?
330330
expect(is.errors).to eql [[:instance_method_missing, :errors]]
331331
end
@@ -367,10 +367,10 @@ def url
367367
end
368368

369369
it "not valid" do
370-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
370+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
371371
end
372372
it "say not implement create_issue method" do
373-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
373+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
374374
is.valid?
375375
expect(is.errors).to eql [[:instance_method_missing, :create_issue]]
376376
end
@@ -413,10 +413,10 @@ def url
413413
end
414414

415415
it "is valid" do
416-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be true
416+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be true
417417
end
418418
it "not say not implement close_issue method" do
419-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
419+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
420420
is.valid?
421421
expect(is.errors).not_to eql [[:instance_method_missing, :close_issue]]
422422
end
@@ -458,11 +458,11 @@ def close_issue
458458
end
459459

460460
it "not valid" do
461-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
461+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
462462
end
463463

464464
it "say not implement url method" do
465-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
465+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
466466
is.valid?
467467
expect(is.errors).to eql [[:instance_method_missing, :url]]
468468
end
@@ -504,11 +504,11 @@ def url
504504
end
505505

506506
it "not valid" do
507-
expect(ErrbitPlugin::ValidateIssueTracker.new(klass).valid?).to be false
507+
expect(ErrbitPlugin::IssueTrackerValidator.new(klass).valid?).to be false
508508
end
509509

510510
it "say not implement note method" do
511-
is = ErrbitPlugin::ValidateIssueTracker.new(klass)
511+
is = ErrbitPlugin::IssueTrackerValidator.new(klass)
512512
is.valid?
513513
expect(is.errors).to eql [[:class_method_missing, :note]]
514514
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require "spec_helper"
4+
5+
RSpec.describe ErrbitPlugin::NoneIssueTracker do
6+
let(:options) { {} }
7+
8+
subject { described_class.new(options) }
9+
10+
it { expect(subject).to be_an(ErrbitPlugin::IssueTracker) }
11+
12+
it { expect(subject.configured?).to eq(false) }
13+
14+
it { expect(subject.errors).to eq({}) }
15+
16+
it { expect(subject.url).to eq("") }
17+
18+
it { expect(subject.create_issue).to eq(false) }
19+
20+
it { expect(subject.close_issue).to eq(false) }
21+
22+
it { expect(described_class.label).to eq("none") }
23+
24+
it { expect(described_class.note).to start_with("When no issue tracker") }
25+
26+
it { expect(described_class.fields).to eq({}) }
27+
28+
it { expect(described_class.icons).not_to be_empty }
29+
30+
# TODO: .read_static_file
31+
end

spec/errbit_plugin/registry_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require "spec_helper"
44

5-
describe ErrbitPlugin::Registry do
5+
RSpec.describe ErrbitPlugin::Registry do
66
before do
77
ErrbitPlugin::Registry.clear_issue_trackers
88
end
@@ -19,7 +19,7 @@ def self.label
1919
describe ".add_issue_tracker" do
2020
context "with issue_tracker class valid" do
2121
before do
22-
allow(ErrbitPlugin::ValidateIssueTracker)
22+
allow(ErrbitPlugin::IssueTrackerValidator)
2323
.to receive(:new)
2424
.with(tracker)
2525
.and_return(double(valid?: true, message: ""))
@@ -42,7 +42,7 @@ def self.label
4242

4343
context "with an IssueTracker not valid" do
4444
it "raise an IncompatibilityError" do
45-
allow(ErrbitPlugin::ValidateIssueTracker)
45+
allow(ErrbitPlugin::IssueTrackerValidator)
4646
.to receive(:new)
4747
.with(tracker)
4848
.and_return(double(valid?: false, message: "foo", errors: []))
@@ -52,7 +52,7 @@ def self.label
5252
end
5353

5454
it "puts the errors in the exception message" do
55-
allow(ErrbitPlugin::ValidateIssueTracker)
55+
allow(ErrbitPlugin::IssueTrackerValidator)
5656
.to receive(:new)
5757
.with(tracker)
5858
.and_return(double(valid?: false, message: "foo", errors: ["one", "two"]))

spec/spec_helper.rb

+16-9
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,24 @@
22

33
require "simplecov"
44

5-
SimpleCov.start
5+
SimpleCov.start do
6+
enable_coverage :branch
7+
8+
primary_coverage :branch
9+
10+
add_filter "spec/"
11+
end
612

713
require "errbit_plugin"
814

915
RSpec.configure do |config|
10-
config.run_all_when_everything_filtered = true
11-
config.filter_run :focus
12-
13-
# Run specs in random order to surface order dependencies. If you find an
14-
# order dependency and want to debug it, you can fix the order by providing
15-
# the seed, which is printed after each run.
16-
# --seed 1234
17-
config.order = "random"
16+
# Enable flags like --only-failures and --next-failure
17+
config.example_status_persistence_file_path = ".rspec_status"
18+
19+
# Disable RSpec exposing methods globally on `Module` and `main`
20+
config.disable_monkey_patching!
21+
22+
config.expect_with :rspec do |c|
23+
c.syntax = :expect
24+
end
1825
end

0 commit comments

Comments
 (0)