From 8a0bf0f846ead18e7583326252827540cce99ce1 Mon Sep 17 00:00:00 2001 From: dblock Date: Sat, 20 Aug 2016 10:05:56 -0400 Subject: [PATCH 1/2] Added Dager, PR linting. --- .travis.yml | 26 +++++++------- CHANGELOG.md | 5 ++- Dangerfile | 79 +++++++++++++++++++++++++++++++++++++++++ Gemfile | 37 +++++++++++++------ Rakefile | 10 +++--- features/support/env.rb | 2 +- hyperclient.gemspec | 7 ---- test/test_helper.rb | 6 ++-- 8 files changed, 133 insertions(+), 39 deletions(-) create mode 100644 Dangerfile diff --git a/.travis.yml b/.travis.yml index a9f85ce..75ceedf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,19 +1,21 @@ -rvm: - - 1.9.3 - - 2.0.0 - - 2.1 - - 2.2 - - 2.3.0 - - rbx-2 - - jruby-19mode - - ruby-head - - jruby-head +language: ruby + +sudo: false matrix: + include: + - rvm: 2.3.1 + script: + - bundle exec danger + - rvm: 2.3.1 + - rvm: 2.3.0 + - rvm: 2.2.5 + - rvm: rbx-2 + - rvm: ruby-head + - rvm: jruby-head allow_failures: - rvm: ruby-head - rvm: jruby-head - rvm: rbx-2 -before_install: - - gem install bundler +bundler_args: --without development diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dbbd46..83a4b57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ ### 0.8.2 (Next) -Your contribution here. +This version is no longer tested with Ruby < 2.2. + +* [#105](https://github.com/codegram/hyperclient/pull/105): Added Danger, PR linter - [@dblock](https://github.com/dblock). +* Your contribution here. ### 0.8.1 (March 15, 2016) diff --git a/Dangerfile b/Dangerfile new file mode 100644 index 0000000..9cc182e --- /dev/null +++ b/Dangerfile @@ -0,0 +1,79 @@ +# -------------------------------------------------------------------------------------------------------------------- +# Has any changes happened inside the actual library code? +# -------------------------------------------------------------------------------------------------------------------- +has_app_changes = !git.modified_files.grep(/lib/).empty? +has_spec_changes = !git.modified_files.grep(/spec/).empty? && !git.modified_files.grep(/features/).empty? +has_changelog_changes = git.modified_files.include?('CHANGELOG.md') +has_dangerfile_changes = git.modified_files.include?('Dangerfile') +has_rakefile_changes = git.modified_files.include?('Rakefile') +has_code_changes = has_app_changes || has_dangerfile_changes || has_rakefile_changes + +# -------------------------------------------------------------------------------------------------------------------- +# You've made changes to lib, but didn't write any tests? +# -------------------------------------------------------------------------------------------------------------------- +if has_app_changes && !has_spec_changes + warn("There're library changes, but not tests. That's OK as long as you're refactoring existing code.", sticky: false) +end + +# -------------------------------------------------------------------------------------------------------------------- +# You've made changes to specs, but no library code has changed? +# -------------------------------------------------------------------------------------------------------------------- +if !has_app_changes && has_spec_changes + message('We really appreciate pull requests that demonstrate issues, even without a fix. That said, the next step is to try and fix the failing tests!', sticky: false) +end + +# -------------------------------------------------------------------------------------------------------------------- +# Have you updated CHANGELOG.md? +# -------------------------------------------------------------------------------------------------------------------- +if !has_changelog_changes && has_code_changes + pr_number = github.pr_json['number'] + markdown <<-MARKDOWN +Here's an example of a CHANGELOG.md entry: + +```markdown +* [##{pr_number}](https://github.com/ruby-grape/grape/pull/#{pr_number}): #{github.pr_title} - [@#{github.pr_author}](https://github.com/#{github.pr_author}). +``` +MARKDOWN + warn("Unless you're refactoring existing code, please update CHANGELOG.md.", sticky: false) +end + +# -------------------------------------------------------------------------------------------------------------------- +# Is the CHANGELOG.md format correct? +# -------------------------------------------------------------------------------------------------------------------- + +your_contribution_here = false +errors = 0 +File.open('CHANGELOG.md').each_line do |line| + # ignore lines that aren't changes + next unless line[0] == '*' + # notice your contribution here + if line == "* Your contribution here.\n" + your_contribution_here = true + next + end + # match the PR format, with or without PR number + next if line =~ %r{^\*\s[\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$} + next if line =~ %r{^\*\s\[\#\d+\]\(https:\/\/github\.com\/.*\d+\)\: [\`[:upper:]].* \- \[\@[\w\d\-\_]+\]\(https:\/\/github\.com\/.*[\w\d\-\_]+\)\.$} + errors += 1 + markdown <<-MARKDOWN +```markdown +#{line}``` + MARKDOWN +end + +fail("One of the lines below found in CHANGELOG.md doesn't match the expected format. Please make it look like the other lines, pay attention to periods and spaces.", sticky: false) if errors > 0 +fail('Please put back the `* Your contribution here.` line into CHANGELOG.md.', sticky: false) unless your_contribution_here + +# -------------------------------------------------------------------------------------------------------------------- +# Don't let testing shortcuts get into master by accident, +# ensuring that we don't get green builds based on a subset of tests. +# -------------------------------------------------------------------------------------------------------------------- + +(git.modified_files + git.added_files - %w(Dangerfile)).each do |file| + next unless File.file?(file) + contents = File.read(file) + if file.start_with?('spec') + fail("`xit` or `fit` left in tests (#{file})") if contents =~ /^\w*[xf]it/ + fail("`fdescribe` left in tests (#{file})") if contents =~ /^\w*fdescribe/ + end +end diff --git a/Gemfile b/Gemfile index ba19f5a..5d70655 100644 --- a/Gemfile +++ b/Gemfile @@ -2,14 +2,29 @@ source 'https://rubygems.org' gemspec -gem 'rake' -gem 'growl' -gem 'guard' -gem 'guard-minitest' -gem 'guard-spinach' -gem 'pry' - -gem 'yard', '~> 0.8' -gem 'yard-tomdoc' -gem 'simplecov', require: false -gem 'rubocop', '~> 0.33.0', require: false +group :development do + gem 'growl' + gem 'guard' + gem 'guard-minitest' + gem 'guard-spinach' + gem 'pry' +end + +group :development, :test do + gem 'yard', '~> 0.8' + gem 'yard-tomdoc' + gem 'rake' + gem 'simplecov', require: false + gem 'rubocop', '~> 0.33.0', require: false +end + +group :test do + gem 'futuroscope', github: 'codegram/futuroscope' + gem 'danger', '~> 2.1', require: false + gem 'minitest' + gem 'turn' + gem 'webmock' + gem 'mocha' + gem 'rack-test' + gem 'spinach' +end diff --git a/Rakefile b/Rakefile index 5bc3a61..7e7216f 100755 --- a/Rakefile +++ b/Rakefile @@ -1,9 +1,9 @@ #!/usr/bin/env rake -begin - require 'bundler/setup' -rescue LoadError - puts 'You must `gem install bundler` and `bundle install` to run rake tasks' -end +require 'rubygems' +require 'bundler' +Bundler.setup :default, :test, :development + +Bundler::GemHelper.install_tasks if ENV['COVERAGE'] require 'simplecov' diff --git a/features/support/env.rb b/features/support/env.rb index f7c5519..5d73b35 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -1,4 +1,4 @@ require 'minitest/spec' require 'webmock' +WebMock.enable! require 'hyperclient' -require 'pry' diff --git a/hyperclient.gemspec b/hyperclient.gemspec index a4974df..485a0ff 100644 --- a/hyperclient.gemspec +++ b/hyperclient.gemspec @@ -21,11 +21,4 @@ Gem::Specification.new do |gem| gem.add_dependency 'uri_template' gem.add_dependency 'net-http-digest_auth' gem.add_dependency 'faraday-digestauth' - - gem.add_development_dependency 'minitest' - gem.add_development_dependency 'turn' - gem.add_development_dependency 'webmock' - gem.add_development_dependency 'mocha' - gem.add_development_dependency 'rack-test' - gem.add_development_dependency 'spinach' end diff --git a/test/test_helper.rb b/test/test_helper.rb index 85cd1c1..54ba450 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,12 +1,10 @@ $LOAD_PATH << 'lib' -gem 'minitest' require 'minitest/spec' require 'minitest/autorun' require 'mocha/setup' require 'turn' require 'json' -require 'pry' MiniTest::Unit::TestCase.class_eval do def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block) @@ -14,3 +12,7 @@ def stub_request(conn, adapter_class = Faraday::Adapter::Test, &stubs_block) conn.builder.swap(adapter_handler, adapter_class, &stubs_block) end end + +require 'futuroscope' +require 'futuroscope/pools/no_pool' +Futuroscope.default_pool = Futuroscope::Pools::NoPool.new From 7169b78f0685e6e8a7d9549b42079fb6d3d1a66e Mon Sep 17 00:00:00 2001 From: dblock Date: Sat, 20 Aug 2016 10:54:01 -0400 Subject: [PATCH 2/2] Upgraded RuboCop to 0.42.0. --- .rubocop_todo.yml | 28 +++++++++++++++------------- Gemfile | 2 +- examples/splines_api.rb | 2 +- lib/hyperclient/attributes.rb | 2 +- lib/hyperclient/collection.rb | 4 ++-- lib/hyperclient/entry_point.rb | 24 ++++++++++++------------ lib/hyperclient/link_collection.rb | 2 +- lib/hyperclient/resource.rb | 2 +- lib/hyperclient/version.rb | 2 +- 9 files changed, 35 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 07aeb71..d4da6b5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-03-15 15:48:04 -0400 using RuboCop version 0.33.0. +# on 2016-08-20 10:53:42 -0400 using RuboCop version 0.42.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -12,7 +12,8 @@ Metrics/ClassLength: Max: 103 # Offense count: 85 -# Configuration parameters: AllowURI, URISchemes. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# URISchemes: http, https Metrics/LineLength: Max: 142 @@ -33,28 +34,21 @@ Style/AsciiComments: # Offense count: 2 # Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: nested, compact Style/ClassAndModuleChildren: Exclude: - 'features/steps/api_navigation.rb' - 'features/steps/default_config.rb' -# Offense count: 14 +# Offense count: 4 Style/Documentation: Exclude: + - 'spec/**/*' + - 'test/**/*' - 'features/steps/api_navigation.rb' - 'features/steps/default_config.rb' - 'features/support/api.rb' - 'features/support/fixtures.rb' - - 'lib/hyperclient/version.rb' - - 'test/faraday/connection_test.rb' - - 'test/hyperclient/attributes_test.rb' - - 'test/hyperclient/collection_test.rb' - - 'test/hyperclient/curie_test.rb' - - 'test/hyperclient/entry_point_test.rb' - - 'test/hyperclient/link_collection_test.rb' - - 'test/hyperclient/link_test.rb' - - 'test/hyperclient/resource_collection_test.rb' - - 'test/hyperclient/resource_test.rb' # Offense count: 2 Style/DoubleNegation: @@ -64,15 +58,23 @@ Style/DoubleNegation: # Offense count: 5 # Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: line_count_dependent, lambda, literal Style/Lambda: Exclude: - 'test/hyperclient/entry_point_test.rb' - 'test/hyperclient/link_test.rb' - 'test/hyperclient/resource_test.rb' +# Offense count: 1 +Style/MethodMissing: + Exclude: + - 'lib/hyperclient/collection.rb' + # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: - 'features/support/api.rb' diff --git a/Gemfile b/Gemfile index 5d70655..6de6c19 100644 --- a/Gemfile +++ b/Gemfile @@ -15,7 +15,7 @@ group :development, :test do gem 'yard-tomdoc' gem 'rake' gem 'simplecov', require: false - gem 'rubocop', '~> 0.33.0', require: false + gem 'rubocop', '~> 0.42.0', require: false end group :test do diff --git a/examples/splines_api.rb b/examples/splines_api.rb index 7e5d25e..34d3b43 100644 --- a/examples/splines_api.rb +++ b/examples/splines_api.rb @@ -7,7 +7,7 @@ # enumerate splines api.splines.each do |spline| - puts "#{spline.uuid}" + puts spline.uuid.to_s puts " reticulated: #{spline.reticulated ? 'yes' : 'no'}" puts " thumbnail: #{spline['images:thumbnail']}" end diff --git a/lib/hyperclient/attributes.rb b/lib/hyperclient/attributes.rb index 446670c..9cb9a84 100644 --- a/lib/hyperclient/attributes.rb +++ b/lib/hyperclient/attributes.rb @@ -9,7 +9,7 @@ module Hyperclient # resource.attributes.title # class Attributes < Collection - RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/] # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1 + RESERVED_PROPERTIES = [/^_links$/, /^_embedded$/].freeze # http://tools.ietf.org/html/draft-kelly-json-hal#section-4.1 # Public: Initializes the Attributes of a Resource. # diff --git a/lib/hyperclient/collection.rb b/lib/hyperclient/collection.rb index 6d2179c..ac2efc4 100644 --- a/lib/hyperclient/collection.rb +++ b/lib/hyperclient/collection.rb @@ -62,7 +62,7 @@ def [](name) def to_h @collection.to_hash end - alias_method :to_hash, :to_h + alias to_hash to_h def to_s to_hash @@ -76,7 +76,7 @@ def to_s # Returns an Object. def method_missing(method_name, *_args, &_block) @collection.fetch(method_name.to_s) do - fail "Could not find `#{method_name}` in #{self.class.name}" + raise "Could not find `#{method_name}` in #{self.class.name}" end end diff --git a/lib/hyperclient/entry_point.rb b/lib/hyperclient/entry_point.rb index 108879e..587efd0 100644 --- a/lib/hyperclient/entry_point.rb +++ b/lib/hyperclient/entry_point.rb @@ -52,15 +52,15 @@ def initialize(url, &_block) def connection(options = {}, &block) @faraday_options ||= options.dup if block_given? - fail ConnectionAlreadyInitializedError if @connection - if @faraday_options.delete(:default) == false - @faraday_block = block - else - @faraday_block = lambda do |conn| - default_faraday_block.call conn - block.call conn - end - end + raise ConnectionAlreadyInitializedError if @connection + @faraday_block = if @faraday_options.delete(:default) == false + block + else + lambda do |conn| + default_faraday_block.call conn + yield conn + end + end else @connection ||= Faraday.new(_url, faraday_options, &faraday_block) end @@ -78,7 +78,7 @@ def headers # # value - A Hash containing headers to include with every API request. def headers=(value) - fail ConnectionAlreadyInitializedError if @connection + raise ConnectionAlreadyInitializedError if @connection @headers = value end @@ -93,7 +93,7 @@ def faraday_options # # value - A Hash containing options to pass to Faraday def faraday_options=(value) - fail ConnectionAlreadyInitializedError if @connection + raise ConnectionAlreadyInitializedError if @connection @faraday_options = value end @@ -108,7 +108,7 @@ def faraday_block # # value - A Proc accepting a Faraday::Connection. def faraday_block=(value) - fail ConnectionAlreadyInitializedError if @connection + raise ConnectionAlreadyInitializedError if @connection @faraday_block = value end diff --git a/lib/hyperclient/link_collection.rb b/lib/hyperclient/link_collection.rb index 09f525c..dc9a2e2 100644 --- a/lib/hyperclient/link_collection.rb +++ b/lib/hyperclient/link_collection.rb @@ -19,7 +19,7 @@ class LinkCollection < Collection # curies - The Hash with link curies. # entry_point - The EntryPoint object to inject the configuration. def initialize(collection, curies, entry_point) - fail "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect) + raise "Invalid response for LinkCollection. The response was: #{collection.inspect}" if collection && !collection.respond_to?(:collect) @_curies = (curies || {}).reduce({}) do |hash, curie_hash| curie = build_curie(curie_hash, entry_point) diff --git a/lib/hyperclient/resource.rb b/lib/hyperclient/resource.rb index 171b0ae..f8b2acb 100644 --- a/lib/hyperclient/resource.rb +++ b/lib/hyperclient/resource.rb @@ -65,7 +65,7 @@ def fetch(key, *args) elsif block_given? yield key else - fail KeyError + raise KeyError end end diff --git a/lib/hyperclient/version.rb b/lib/hyperclient/version.rb index 253a0d2..36787ac 100644 --- a/lib/hyperclient/version.rb +++ b/lib/hyperclient/version.rb @@ -1,3 +1,3 @@ module Hyperclient - VERSION = '0.8.2' + VERSION = '0.8.2'.freeze end