Skip to content

Commit

Permalink
Merge pull request #117 from fastruby/fix-namespace-specs
Browse files Browse the repository at this point in the history
Use next_rails namespace on spec tests.
  • Loading branch information
etagwerker authored Sep 24, 2024
2 parents 715535f + e9a816b commit f226eb8
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 124 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# main [(unreleased)](https://github.com/fastruby/next_rails/compare/v1.3.0...main)

* Your changes/patches go here.
- [CHORE: Use next_rails namespace on spec tests.](https://github.com/fastruby/next_rails/pull/117)

- [CHORE: Remove 2.0.0, 2.1, 2.2 Ruby support](https://github.com/fastruby/next_rails/pull/126)
- [CHORE: Update compatibility for Ruby versions to use Rainbow](https://github.com/fastruby/next_rails/pull/125)
Expand Down
79 changes: 0 additions & 79 deletions spec/bundle_report_spec.rb

This file was deleted.

6 changes: 5 additions & 1 deletion spec/deprecation_tracker_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

require "spec_helper"

require "date"
require "tempfile"
require_relative "spec_helper"
require_relative "../lib/deprecation_tracker"

RSpec::Matchers.define_negated_matcher :not_raise_error, :raise_error
Expand Down
80 changes: 77 additions & 3 deletions spec/next_rails/bundle_report_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,81 @@
require_relative ".././spec_helper"
require_relative "../../lib/next_rails/bundle_report"
# frozen_string_literal: true

require "rainbow/refinement"

using Rainbow

require "spec_helper"

RSpec.describe NextRails::BundleReport do
describe '.outdated' do
let(:mock_version) { Struct.new(:version, :age) }
let(:mock_gem) { Struct.new(:name, :version, :age, :latest_version, :up_to_date?, :created_at, :sourced_from_git?) }
let(:format_str) { '%b %e, %Y' }
let(:alpha_date) { Date.parse('2022-01-01') }
let(:alpha_age) { alpha_date.strftime(format_str) }
let(:bravo_date) { Date.parse('2022-02-02') }
let(:bravo_age) { bravo_date.strftime(format_str) }
let(:charlie_date) { Date.parse('2022-03-03') }
let(:charlie_age) { charlie_date.strftime(format_str) }

before do
allow(NextRails::GemInfo).to receive(:all).and_return(
[
mock_gem.new('alpha', '0.0.1', alpha_age, mock_version.new('0.0.2', bravo_age), false, alpha_date, false),
mock_gem.new('bravo', '0.2.0', bravo_age, mock_version.new('0.2.2', charlie_age), false, bravo_date, true)
]
)
end

context 'when writing human-readable output' do
#subject { described_class.outdated }

it 'invokes $stdout.puts properly', :aggregate_failures do
allow($stdout)
.to receive(:puts)
.with("#{'alpha 0.0.1'.bold.white}: released #{alpha_age} (latest version, 0.0.2, released #{bravo_age})\n")
allow($stdout)
.to receive(:puts)
.with("#{'bravo 0.2.0'.bold.white}: released #{bravo_age} (latest version, 0.2.2, released #{charlie_age})\n")
allow($stdout).to receive(:puts).with('')
allow($stdout).to receive(:puts).with(<<-EO_MULTLINE_STRING)
#{'1'.yellow} gems are sourced from git
#{'2'.red} of the 2 gems are out-of-date (100%)
EO_MULTLINE_STRING
end
end

context 'when writing JSON output' do
it 'JSON is correctly formatted' do
gems = NextRails::GemInfo.all
out_of_date_gems = gems.reject(&:up_to_date?).sort_by(&:created_at)
sourced_from_git = gems.select(&:sourced_from_git?)

expect(NextRails::BundleReport.build_json(out_of_date_gems, gems.count, sourced_from_git.count)).to eq(
{
outdated_gems: [
{ name: 'alpha', installed_version: '0.0.1', installed_age: alpha_age, latest_version: '0.0.2',
latest_age: bravo_age },
{ name: 'bravo', installed_version: '0.2.0', installed_age: bravo_age, latest_version: '0.2.2',
latest_age: charlie_age }
],
sourced_from_git_count: sourced_from_git.count,
total_gem_count: gems.count
}
)
end
end
end

describe ".compatibility" do
describe "output" do
it "returns ERB generated output" do
output = NextRails::BundleReport.erb_output({}, [], 7.0)
expect(output).to match "gems incompatible with Rails 7.0"
end
end
end

describe "#compatible_ruby_version" do
context "when rails_version is a valid one" do
it "returns the correct ruby version" do
Expand All @@ -18,7 +92,7 @@
expect(ruby_version).to eq(">= 2.7.0")
end
end

context "when rails_version is an invalid one" do
it "returns nil for ruby version" do
rails_version = { rails_version: "0.0.0" }
Expand Down
45 changes: 40 additions & 5 deletions spec/next_rails/gem_info_spec.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
require_relative ".././spec_helper"
require_relative "../../lib/next_rails/gem_info"
# frozen_string_literal: true

require "spec_helper"

require "timecop"

RSpec.describe NextRails::GemInfo do
let(:release_date) { Time.utc(2019, 7, 6, 0, 0, 0) }
let(:now) { Time.utc(2019, 7, 6, 12, 0, 0) }
let(:spec) do
Gem::Specification.new do |s|
s.date = release_date
s.version = "1.0.0"
end
end

subject { NextRails::GemInfo.new(spec) }

describe "#age" do
around do |example|
Timecop.travel(now) do
example.run
end
end

let(:result) { now.strftime("%b %e, %Y") }

it "returns a date" do
expect(subject.age).to eq(result)
end
end

describe "#up_to_date?" do
it "is up to date" do
allow(Gem).to receive(:latest_spec_for).and_return(spec)
expect(subject.up_to_date?).to be_truthy
end
end

describe "#state" do
let(:mock_gem) { Struct.new(:name, :version, :runtime_dependencies) }
let(:mocked_dependency) { Struct.new(:name, :requirement) }

it "returns :incompatible if gem specifies a rails dependency but no compatible version is found" do
# set up a mock gem with with a rails dependency that is unsatisfied by the version given
mocked_dependency_requirement = double("requirement")
Expand Down Expand Up @@ -36,11 +72,11 @@

expect(gem_info.state(rails_version)).to eq(:no_new_version)
end

end

describe "#find_latest_compatible" do
let(:mock_gem) { Struct.new(:name, :version) }

it "sets latest_compatible_version to NullGem if no specs are found" do
gem = mock_gem.new('gem_name', "0.0.1")

Expand All @@ -53,6 +89,5 @@
gem_info.find_latest_compatible
expect(gem_info.latest_compatible_version).to be_a(NextRails::GemInfo::NullGemInfo)
end

end
end
end
4 changes: 4 additions & 0 deletions spec/next_rails_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# frozen_string_literal: true

require "spec_helper"

require "fileutils"

RSpec.describe NextRails do
Expand Down
36 changes: 0 additions & 36 deletions spec/ten_years_rails/gem_info_spec.rb

This file was deleted.

0 comments on commit f226eb8

Please sign in to comment.