Skip to content

Commit

Permalink
Implement dependency update checking.
Browse files Browse the repository at this point in the history
  • Loading branch information
waltfy authored and greysteil committed Oct 2, 2015
1 parent e716bb7 commit 6b5c72f
Show file tree
Hide file tree
Showing 9 changed files with 252 additions and 2 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# editorconfig.org
root = true

[*]
indent_size = 2
translate_tabs_to_spaces = true
indent_style = spaces
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ gem "gemnasium-parser", "~> 0.1.9"
group :development do
gem "rspec", "~> 3.3.0"
gem "rspec-its", "~> 1.2.0", require: "rspec/its"
gem 'webmock'
end
10 changes: 9 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.8)
crack (0.4.2)
safe_yaml (~> 1.0.0)
diff-lcs (1.2.5)
gemnasium-parser (0.1.9)
rspec (3.3.0)
Expand All @@ -19,6 +22,10 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.3.0)
rspec-support (3.3.0)
safe_yaml (1.0.4)
webmock (1.21.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)

PLATFORMS
ruby
Expand All @@ -27,6 +34,7 @@ DEPENDENCIES
gemnasium-parser (~> 0.1.9)
rspec (~> 3.3.0)
rspec-its (~> 1.2.0)
webmock

BUNDLED WITH
1.10.4
1.10.6
32 changes: 32 additions & 0 deletions lib/bumper/update_checker/update_checker.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# require "gem/version"
require "net/http"
require "json"

module UpdateChecker

# checks for dependencies that are out of date
#
# usage:
# UpdateChecker::RubyUpdateChecker.new(initial_dependencies).run
#
# dependencies, Array
# return an Array of dependencies that are out of date
class RubyUpdateChecker
def initialize(dependencies)
@dependencies = dependencies
end

def run
@dependencies.select do |dependency|
latest_version = get_latest(dependency)["version"]
Gem::Version.new(latest_version) > Gem::Version.new(dependency.version)
end
end

private

def get_latest(dependency)
JSON.parse(Net::HTTP.get(URI("https://rubygems.org/api/v1/gems/#{dependency.name}.json")))
end
end
end
2 changes: 1 addition & 1 deletion spec/bumper/file_parsers/ruby_file_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require "bumper/file_parsers/ruby_file_parser"

RSpec.describe FileParsers::RubyFileParser do
let(:gemfile) { File.read('spec/fixtures/Gemfile') }
let(:gemfile) { File.read("spec/fixtures/Gemfile") }
let(:parser) { FileParsers::RubyFileParser.new(gemfile) }
subject(:dependencies) { parser.parse }

Expand Down
63 changes: 63 additions & 0 deletions spec/bumper/update_checker/update_checker_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "spec_helper"
require "bumper/dependency"
require "bumper/update_checker/update_checker"

RSpec.describe UpdateChecker::RubyUpdateChecker do
let(:outdated_dependency) {
File.read("spec/fixtures/out_of_date_dependency_response.json")
}

let(:outdated_dependency_json) {
JSON.parse(outdated_dependency)
}

let(:latest_dependency) {
File.read("spec/fixtures/up_to_date_dependency_response.json")
}

let(:latest_dependency_json) {
JSON.parse(latest_dependency)
}

before do
stub_request(
:get,
"https://rubygems.org/api/v1/gems/#{outdated_dependency_json["name"]}.json"
).
to_return(:status => 200, :body => outdated_dependency, :headers => {})

stub_request(
:get,
"https://rubygems.org/api/v1/gems/#{latest_dependency_json["name"]}.json"
).
to_return(:status => 200, :body => latest_dependency, :headers => {})
end

# TODO: tests need mocking
let(:initial_dependencies) do
[
Dependency.new(
name: latest_dependency_json["name"],
version: latest_dependency_json["version"]
),
Dependency.new(
name: outdated_dependency_json["name"],
version: "1.2.0"
)
]
end

let(:checker) { UpdateChecker::RubyUpdateChecker.new(initial_dependencies) }
subject(:dependencies) { checker.run }

its(:length) { is_expected.to eq(1) }

describe "the first dependency" do
subject { dependencies.first }

it { is_expected.to be_a(Dependency) }
its(:name) { is_expected.to eq(outdated_dependency_json["name"]) }
its(:version) { is_expected.to eq("1.2.0") }
end

end
67 changes: 67 additions & 0 deletions spec/fixtures/out_of_date_dependency_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "outdated",
"downloads": 54431629,
"version": "1.2.3",
"version_downloads": 341108,
"platform": "ruby",
"authors": "David Heinemeier Hansson",
"info": "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.",
"licenses": [
"MIT"
],
"metadata": {},
"sha": "1c33dd7c280d1c5dc4235509f774d673bac1d3f2e8c53b1353f677e7578ffc5a",
"project_uri": "https://rubygems.org/gems/rails",
"gem_uri": "https://rubygems.org/gems/rails-4.2.4.gem",
"homepage_uri": "http://www.rubyonrails.org",
"wiki_uri": "http://wiki.rubyonrails.org",
"documentation_uri": "http://api.rubyonrails.org",
"mailing_list_uri": "http://groups.google.com/group/rubyonrails-talk",
"source_code_uri": "http://github.com/rails/rails",
"bug_tracker_uri": "http://github.com/rails/rails/issues",
"dependencies": {
"development": [],
"runtime": [
{
"name": "actionmailer",
"requirements": "= 4.2.4"
},
{
"name": "actionpack",
"requirements": "= 4.2.4"
},
{
"name": "actionview",
"requirements": "= 4.2.4"
},
{
"name": "activejob",
"requirements": "= 4.2.4"
},
{
"name": "activemodel",
"requirements": "= 4.2.4"
},
{
"name": "activerecord",
"requirements": "= 4.2.4"
},
{
"name": "activesupport",
"requirements": "= 4.2.4"
},
{
"name": "bundler",
"requirements": "< 2.0, >= 1.3.0"
},
{
"name": "railties",
"requirements": "= 4.2.4"
},
{
"name": "sprockets-rails",
"requirements": ">= 0"
}
]
}
}
67 changes: 67 additions & 0 deletions spec/fixtures/up_to_date_dependency_response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"name": "latest",
"downloads": 54431629,
"version": "4.2.4",
"version_downloads": 341108,
"platform": "ruby",
"authors": "David Heinemeier Hansson",
"info": "Ruby on Rails is a full-stack web framework optimized for programmer happiness and sustainable productivity. It encourages beautiful code by favoring convention over configuration.",
"licenses": [
"MIT"
],
"metadata": {},
"sha": "1c33dd7c280d1c5dc4235509f774d673bac1d3f2e8c53b1353f677e7578ffc5a",
"project_uri": "https://rubygems.org/gems/rails",
"gem_uri": "https://rubygems.org/gems/rails-4.2.4.gem",
"homepage_uri": "http://www.rubyonrails.org",
"wiki_uri": "http://wiki.rubyonrails.org",
"documentation_uri": "http://api.rubyonrails.org",
"mailing_list_uri": "http://groups.google.com/group/rubyonrails-talk",
"source_code_uri": "http://github.com/rails/rails",
"bug_tracker_uri": "http://github.com/rails/rails/issues",
"dependencies": {
"development": [],
"runtime": [
{
"name": "actionmailer",
"requirements": "= 4.2.4"
},
{
"name": "actionpack",
"requirements": "= 4.2.4"
},
{
"name": "actionview",
"requirements": "= 4.2.4"
},
{
"name": "activejob",
"requirements": "= 4.2.4"
},
{
"name": "activemodel",
"requirements": "= 4.2.4"
},
{
"name": "activerecord",
"requirements": "= 4.2.4"
},
{
"name": "activesupport",
"requirements": "= 4.2.4"
},
{
"name": "bundler",
"requirements": "< 2.0, >= 1.3.0"
},
{
"name": "railties",
"requirements": "= 4.2.4"
},
{
"name": "sprockets-rails",
"requirements": ">= 0"
}
]
}
}
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
require "rspec/its"
require "webmock/rspec"

0 comments on commit 6b5c72f

Please sign in to comment.