Skip to content

Commit

Permalink
✅ More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pboling committed Sep 17, 2024
1 parent aa31ff8 commit f1fb44a
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 3 deletions.
24 changes: 24 additions & 0 deletions spec/gem_bench/gemfile_line_tokenizer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "rspec"

RSpec.describe GemBench::GemfileLineTokenizer do
subject(:instance) { described_class.new(*args) }

let(:args) {
[
all_lines,
line,
index,
]
}
let(:all_lines) { %w(hello darkness) }
let(:line) { "hello" }
let(:index) { 0 }

describe "::new" do
it "succeeds" do
block_is_expected.to not_raise_error
end
end
end
33 changes: 30 additions & 3 deletions spec/gem_bench/scout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
end
end

context "bundler error" do
context "early bundler error" do
subject(:instance) { described_class.new }

before do
allow(Bundler).to receive(:rubygems).and_raise(Bundler::GemfileNotFound)
end

let(:instance) { described_class.new }

it "does not raise error" do
expect { instance }.not_to raise_error
end
Expand All @@ -55,6 +55,33 @@
expect(instance.check_gemfile?).to be(false)
expect(Bundler).to have_received(:rubygems)
end

it "sets gem_paths to empty" do
expect(instance.gem_paths).to be_empty
expect(Bundler).to have_received(:rubygems)
end
end

context "late bundler error" do
subject(:instance) { described_class.new }

before do
allow(Bundler).to receive(:bundle_path).and_raise(Bundler::GemfileNotFound)
end

it "does not raise error" do
expect { instance }.not_to raise_error
end

it "sets check_gemfile to false" do
expect(instance.check_gemfile?).to be(false)
expect(Bundler).to have_received(:bundle_path)
end

it "sets gem_paths to soemthing" do
expect(instance.gem_paths).to include(match(/\/gems/))
expect(Bundler).to have_received(:bundle_path)
end
end
end

Expand Down
30 changes: 30 additions & 0 deletions spec/gem_bench/strict_version_gem_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

RSpec.describe GemBench::StrictVersionGem do
subject(:instance) { described_class.new(*args) }

let(:args) {
[
name,
version,
version_type,
valid,
relevant_lines,
index,
tokenized_line,
]
}
let(:name) { "oh_hi" }
let(:version) { "5.7.4" }
let(:version_type) { :constraint }
let(:valid) { true }
let(:relevant_lines) { %w(hello darkness) }
let(:index) { 1 }
let(:tokenized_line) { "oh_hi" }

describe "::new" do
it "succeeds" do
block_is_expected.to not_raise_error
end
end
end
75 changes: 75 additions & 0 deletions spec/gem_bench/strict_version_requirement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

require "rspec"

RSpec.describe GemBench::StrictVersionRequirement do
subject(:instance) { described_class.new(options) }

let(:options) { {} }

describe "::new" do
it "succeeds" do
block_is_expected.to not_raise_error
end
end

describe "#versions_present?" do
subject(:versions_present) { instance.versions_present? }

it "succeeds" do
block_is_expected.to not_raise_error
end
end

describe "#list_missing_version_constraints" do
subject(:list_missing_version_constraints) { instance.list_missing_version_constraints }

it "succeeds" do
block_is_expected.to not_raise_error
end
end

describe "#find" do
subject(:find) { instance.find(name) }

let(:name) { "hello" }

it "succeeds" do
block_is_expected.to not_raise_error
end

context "when not found" do
it "returns nil" do
expect(find).to be_nil
end
end
end

describe "#gem_at" do
subject(:gem_at) { instance.gem_at(index) }

let(:index) { 1 }

it "succeeds" do
block_is_expected.to not_raise_error
end

context "when not found" do
it "returns nil" do
expect(gem_at).to be_nil
end
end
end

describe "#print" do
subject(:print) { instance.print }

it "succeeds" do
block_is_expected.to not_raise_error
end

it "has output" do
expect { print }.to output(/The gems that need to be improved are:/).to_stdout
end
end
end

0 comments on commit f1fb44a

Please sign in to comment.