-
Notifications
You must be signed in to change notification settings - Fork 40
Use next_rails namespace on spec tests. #117
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these tests were moved from |
||
|
||
describe "#compatible_ruby_version" do | ||
context "when rails_version is a valid one" do | ||
it "returns the correct ruby version" do | ||
|
@@ -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" } | ||
|
JuanVqz marked this conversation as resolved.
Show resolved
Hide resolved
|
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JuanVqz we do not need these specs anymore? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @julioalucero thank you for catching it! I fixed it already, please feel free to review it again when possible 👍 |
||
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") | ||
|
@@ -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") | ||
|
||
|
@@ -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 |
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 | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case we still need the
require_relatvie
because the deprecation_tracker class is out of thenext_rails
namespace. 👍