diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f68196c --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,123 @@ +inherit_from: + - .rubocop_todo.yml + +AllCops: + TargetRubyVersion: 1.9 + Exclude: + - tmp/**/* + - lib/bundler/vendor/**/* + - vendor/bundle/**/* + DisplayCopNames: true + +# Lint + +# They are idiomatic +Lint/AssignmentInCondition: + Enabled: false + +Lint/EndAlignment: + AlignWith: variable + AutoCorrect: true + +Lint/UnusedMethodArgument: + Enabled: false + +# Style + +Style/AccessModifierIndentation: + EnforcedStyle: outdent + +Style/Alias: + EnforcedStyle: prefer_alias_method + +Style/AlignParameters: + EnforcedStyle: with_fixed_indentation + +Style/MultilineBlockChain: + Enabled: false + +Style/MultilineOperationIndentation: + EnforcedStyle: indented + +Style/PerlBackrefs: + Enabled: false + +Style/SingleLineBlockParams: + Enabled: false + +Style/SpaceInsideBlockBraces: + SpaceBeforeBlockParameters: false + +Style/TrivialAccessors: + Enabled: false + +# We adopted raise instead of fail. +Style/SignalException: + EnforcedStyle: only_raise + +Style/StringLiterals: + EnforcedStyle: double_quotes + +Style/StringLiteralsInInterpolation: + EnforcedStyle: double_quotes + +# Having these make it easier to *not* forget to add one when adding a new +# value and you can simply copy the previous line. +Style/TrailingCommaInLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingUnderscoreVariable: + Enabled: false + +# `String.new` is preferred style with enabled frozen string literal +Style/EmptyLiteral: + Enabled: false + +# 1.8.7 support + +Style/Lambda: + Enabled: false + +Style/DotPosition: + EnforcedStyle: trailing + +Style/EachWithObject: + Enabled: false + +Style/SpecialGlobalVars: + Enabled: false + +Style/TrailingCommaInArguments: + Enabled: false + +Performance/FlatMap: + Enabled: false + +# Metrics + +# We've chosen to use Rubocop only for style, and not for complexity or quality checks. +Metrics/ClassLength: + Enabled: false + +Metrics/ModuleLength: + Enabled: false + +Metrics/MethodLength: + Enabled: false + +Metrics/BlockNesting: + Enabled: false + +Metrics/AbcSize: + Enabled: false + +Metrics/CyclomaticComplexity: + Enabled: false + +Metrics/ParameterLists: + Enabled: false + +# It will be obvious which code is complex, Rubocop should only lint simple +# rules for us. +Metrics/PerceivedComplexity: + Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..3a23005 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,248 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-07-27 12:41:39 -0500 using RuboCop version 0.41.2. +# 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 +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 4 +Lint/Eval: + Exclude: + - 'lib/bundler.rb' + - 'lib/bundler/endpoint_specification.rb' + - 'spec/support/streams.rb' + +# Offense count: 4 +Lint/HandleExceptions: + Exclude: + - 'lib/bundler/installer.rb' + - 'lib/bundler/psyched_yaml.rb' + - 'lib/bundler/vendored_persistent.rb' + +# Offense count: 1 +Lint/IneffectiveAccessModifier: + Exclude: + - 'lib/bundler/settings.rb' + +# Offense count: 3 +Lint/NestedMethodDefinition: + Exclude: + - 'lib/bundler/inline.rb' + - 'spec/support/builders.rb' + +# Offense count: 5 +Lint/RescueException: + Exclude: + - 'lib/bundler/cli.rb' + - 'lib/bundler/dsl.rb' + - 'lib/bundler/friendly_errors.rb' + - 'lib/bundler/rubygems_integration.rb' + - 'lib/bundler/worker.rb' + +# Offense count: 1 +Lint/UselessAccessModifier: + Exclude: + - 'lib/bundler/fetcher.rb' + +# Offense count: 6 +Lint/UselessAssignment: + Exclude: + - 'lib/bundler/index.rb' + - 'lib/bundler/installer.rb' + +# Offense count: 1686 +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes. +# URISchemes: http, https +Metrics/LineLength: + Max: 207 + +# Offense count: 3 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 6 +# Cop supports --auto-correct. +Performance/RedundantBlockCall: + Exclude: + - 'lib/bundler/dsl.rb' + - 'lib/bundler/gem_helper.rb' + - 'lib/bundler/retry.rb' + - 'lib/bundler/shared_helpers.rb' + - 'spec/support/helpers.rb' + +# Offense count: 2 +# Cop supports --auto-correct. +Performance/RedundantMatch: + Exclude: + - 'lib/bundler/definition.rb' + - 'lib/bundler/lockfile_parser.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Exclude: + - 'lib/bundler/cli/gem.rb' + - 'spec/support/helpers.rb' + +# Offense count: 1 +Style/AccessorMethodName: + Exclude: + - 'lib/bundler/source/git.rb' + +# Offense count: 3 +Style/CaseEquality: + Exclude: + - 'lib/bundler/dsl.rb' + - 'lib/bundler/match_platform.rb' + - 'lib/bundler/rubygems_ext.rb' + +# Offense count: 23 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: nested, compact +Style/ClassAndModuleChildren: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Exclude: + - 'lib/bundler/cli.rb' + - 'lib/bundler/cli/gem.rb' + - 'lib/bundler/cli/lock.rb' + - 'lib/bundler/cli/platform.rb' + - 'lib/bundler/dsl.rb' + - 'lib/bundler/lazy_specification.rb' + - 'lib/bundler/psyched_yaml.rb' + - 'lib/bundler/rubygems_integration.rb' + - 'lib/bundler/source/git.rb' + - 'lib/bundler/source/rubygems.rb' + +# Offense count: 138 +Style/Documentation: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Style/ExtraSpacing: + Exclude: + - 'lib/bundler/cli.rb' + +# Offense count: 4 +# Configuration parameters: AllowedVariables. +Style/GlobalVars: + Exclude: + - 'lib/bundler/cli.rb' + - 'spec/spec_helper.rb' + - 'spec/support/helpers.rb' + +# Offense count: 1 +Style/IfInsideElse: + Exclude: + - 'lib/bundler/cli/install.rb' + +# Offense count: 1 +Style/IfUnlessModifierOfIfUnless: + Exclude: + - 'spec/support/helpers.rb' + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Style/IndentArray: + EnforcedStyle: consistent + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: module_function, extend_self +Style/ModuleFunction: + Exclude: + - 'lib/bundler/shared_helpers.rb' + - 'spec/support/path.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: aligned, indented, indented_relative_to_receiver +Style/MultilineMethodCallIndentation: + Exclude: + - 'lib/bundler/cli/common.rb' + - 'spec/bundler/plugin/source_list_spec.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/NestedParenthesizedCalls: + Exclude: + - 'lib/bundler/resolver.rb' + - 'spec/commands/lock_spec.rb' + - 'spec/runtime/setup_spec.rb' + +# Offense count: 9 +# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. +# NamePrefix: is_, has_, have_ +# NamePrefixBlacklist: is_, has_, have_ +# NameWhitelist: is_a? +Style/PredicateName: + Exclude: + - 'spec/**/*' + - 'lib/bundler/definition.rb' + - 'lib/bundler/installer/parallel_installer.rb' + - 'lib/bundler/settings.rb' + - 'lib/bundler/source/git.rb' + - 'lib/bundler/source/git/git_proxy.rb' + - 'lib/bundler/source/path.rb' + +# Offense count: 25 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/RedundantParentheses: + Exclude: + - 'lib/bundler/cli/console.rb' + - 'lib/bundler/dsl.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/SpaceAroundOperators: + Exclude: + - 'lib/bundler/retry.rb' + +# Offense count: 10 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +# SupportedStyles: comma, consistent_comma, no_comma +Style/TrailingCommaInLiteral: + Exclude: + - 'lib/bundler/cli/gem.rb' + - 'lib/bundler/dependency.rb' + - 'lib/bundler/fetcher.rb' + - 'lib/bundler/gem_helpers.rb' + - 'lib/bundler/graph.rb' + - 'lib/bundler/ruby_version.rb' + - 'lib/bundler/similarity_detector.rb' + - 'spec/support/artifice/endpoint.rb' + +# Offense count: 18 +# Cop supports --auto-correct. +Style/UnneededInterpolation: + Exclude: + - 'lib/bundler/cli/config.rb' + - 'lib/bundler/env.rb' + - 'spec/bundler/shared_helpers_spec.rb' + - 'spec/cache/git_spec.rb' + - 'spec/commands/exec_spec.rb' + - 'spec/support/artifice/endpoint.rb' + - 'spec/support/artifice/endpoint_500.rb' + - 'spec/support/fakeweb/windows.rb' diff --git a/Gemfile b/Gemfile index fa75df1..b4e2a20 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ -source 'https://rubygems.org' +source "https://rubygems.org" gemspec diff --git a/Gemfile.lock b/Gemfile.lock index e89eacf..4551afd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,13 +6,18 @@ PATH GEM remote: https://rubygems.org/ specs: + ast (2.3.0) coderay (1.1.1) diff-lcs (1.2.5) method_source (0.8.2) + parser (2.3.1.4) + ast (~> 2.2) + powerpack (0.1.1) pry (0.10.3) coderay (~> 1.1.0) method_source (~> 0.8.1) slop (~> 3.4) + rainbow (2.1.0) rake (10.5.0) rspec (3.5.0) rspec-core (~> 3.5.0) @@ -27,7 +32,15 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.5.0) rspec-support (3.5.0) + rubocop (0.44.1) + parser (>= 2.3.1.1, < 3.0) + powerpack (~> 0.1) + rainbow (>= 1.99.1, < 3.0) + ruby-progressbar (~> 1.7) + unicode-display_width (~> 1.0, >= 1.0.1) + ruby-progressbar (1.8.1) slop (3.6.0) + unicode-display_width (1.1.1) PLATFORMS ruby @@ -38,6 +51,7 @@ DEPENDENCIES pry (~> 0) rake (~> 10.0) rspec (~> 3.0) + rubocop (~> 0.44.1) BUNDLED WITH 1.13.6 diff --git a/Rakefile b/Rakefile index 9cdfeae..6ef899d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,7 +1,9 @@ require "bundler/gem_tasks" require "rspec/core/rake_task" +require "rubocop/rake_task" -RSpec::Core::RakeTask.new(:spec) +RuboCop::RakeTask.new -task :default => :spec +RSpec::Core::RakeTask.new(:spec) +task default: [:rubocop, :spec] diff --git a/lib/manpages.rb b/lib/manpages.rb index d747be8..cb271f2 100644 --- a/lib/manpages.rb +++ b/lib/manpages.rb @@ -5,5 +5,4 @@ require "manpages/gem_version" module Manpages - end diff --git a/lib/manpages/gem_version.rb b/lib/manpages/gem_version.rb index 3e7191f..cbd8527 100644 --- a/lib/manpages/gem_version.rb +++ b/lib/manpages/gem_version.rb @@ -1,24 +1,21 @@ module Manpages - class GemVersion - def initialize(gem_spec) @gem_spec = gem_spec end - def is_latest? + def latest? latest_gem.nil? || latest_gem <= @gem_spec.version end - private + private def latest_gem all_gem_versions.sort.last end def all_gem_versions - Gem::Specification.each.select { |spec| @gem_spec.name === spec.name }.map(&:version) + Gem::Specification.each.select {|spec| @gem_spec.name == spec.name }.map(&:version) end - end end diff --git a/lib/manpages/install.rb b/lib/manpages/install.rb index 364b294..476eb42 100644 --- a/lib/manpages/install.rb +++ b/lib/manpages/install.rb @@ -1,7 +1,5 @@ module Manpages - class Install - def initialize(gem_spec, gem_dir, target_dir) @gem_spec = gem_spec @gem_dir = gem_dir @@ -9,10 +7,10 @@ def initialize(gem_spec, gem_dir, target_dir) end def install_manpages - link_manpages if GemVersion.new(@gem_spec).is_latest? + link_manpages if GemVersion.new(@gem_spec).latest? end - private + private def link_manpages ManFiles.new(@gem_dir, @target_dir).manpages.each do |file| @@ -27,11 +25,9 @@ def link_manpage(file) begin FileUtils.mkdir_p(File.dirname(man_target_file)) FileUtils.ln_s(file, man_target_file, force: true) - rescue => e + rescue puts "Problems creating symlink #{man_target_file}" end end - end - end diff --git a/lib/manpages/man_files.rb b/lib/manpages/man_files.rb index 1c4fdff..7d173b6 100644 --- a/lib/manpages/man_files.rb +++ b/lib/manpages/man_files.rb @@ -1,6 +1,5 @@ module Manpages class ManFiles - def initialize(gem_dir, target_dir) @gem_dir = gem_dir @target_dir = target_dir @@ -15,7 +14,7 @@ def manpages end def man_dir - @man_dir ||= File.join(@gem_dir, 'man') + @man_dir ||= File.join(@gem_dir, "man") end def man_file_path(file) @@ -23,6 +22,5 @@ def man_file_path(file) man_section = file.match(/.*\.(\d*)/) File.join(@target_dir, "man#{man_section[1]}", basename) end - end end diff --git a/lib/manpages/uninstall.rb b/lib/manpages/uninstall.rb index d23f9d1..82eb7e0 100644 --- a/lib/manpages/uninstall.rb +++ b/lib/manpages/uninstall.rb @@ -1,7 +1,5 @@ module Manpages - class Uninstall - def initialize(gem_spec, gem_dir, target_dir) @gem_spec = gem_spec @gem_dir = gem_dir @@ -9,10 +7,10 @@ def initialize(gem_spec, gem_dir, target_dir) end def uninstall_manpages - unlink_manpages if GemVersion.new(@gem_spec).is_latest? + unlink_manpages if GemVersion.new(@gem_spec).latest? end - private + private def unlink_manpages ManFiles.new(@gem_dir, @target_dir).manpages.each do |file| @@ -22,10 +20,8 @@ def unlink_manpages def unlink_manpage(file) man_target_file = ManFiles.new(@gem_dir, @target_dir).man_file_path(file) - if File.symlink?(man_target_file) && File.readlink(man_target_file) == file - FileUtils.rm(man_target_file) - end + FileUtils.rm(man_target_file) if File.symlink?(man_target_file) && + File.readlink(man_target_file) == file end - end end diff --git a/lib/manpages/version.rb b/lib/manpages/version.rb index 1ac9251..cab2879 100644 --- a/lib/manpages/version.rb +++ b/lib/manpages/version.rb @@ -1,3 +1,3 @@ module Manpages - VERSION = "0.3.2" + VERSION = "0.3.2".freeze end diff --git a/lib/rubygems_plugin.rb b/lib/rubygems_plugin.rb index 82b62d5..8be06b2 100644 --- a/lib/rubygems_plugin.rb +++ b/lib/rubygems_plugin.rb @@ -1,4 +1,4 @@ -require 'manpages' +require "manpages" Gem.post_install do |installer| source_dir = installer.spec.gem_dir diff --git a/manpages.gemspec b/manpages.gemspec index f761fc5..317caf8 100644 --- a/manpages.gemspec +++ b/manpages.gemspec @@ -1,8 +1,8 @@ # coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require 'manpages/version' +require "manpages/version" Gem::Specification.new do |spec| spec.name = "manpages" @@ -15,13 +15,16 @@ Gem::Specification.new do |spec| spec.license = "MIT" spec.homepage = "https://github.com/bitboxer/manpages" - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } + spec.files = `git ls-files -z`.split("\x0").reject do |f| + f.match(%r{^(test|spec|features)/}) + end spec.bindir = "exe" - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } + spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f) } spec.require_paths = ["lib"] spec.add_development_dependency "bundler", "~> 1.8" spec.add_development_dependency "rake", "~> 10.0" spec.add_development_dependency "rspec", "~> 3.0" - spec.add_development_dependency "pry", '~> 0' + spec.add_development_dependency "pry", "~> 0" + spec.add_development_dependency "rubocop", "~> 0.44.1" end diff --git a/spec/manpages/gem_version_spec.rb b/spec/manpages/gem_version_spec.rb index f64c89a..cf84dc5 100644 --- a/spec/manpages/gem_version_spec.rb +++ b/spec/manpages/gem_version_spec.rb @@ -1,32 +1,27 @@ -require 'spec_helper' -require 'ostruct' +require "spec_helper" +require "ostruct" describe Manpages::GemVersion do - - context '#is_latest?' do - - it 'Returns true if there is no other gem version' do + context "#latest?" do + it "Returns true if there is no other gem version" do gem_spec = Gem::Specification.new(name: "manpages_test") - expect(Manpages::GemVersion.new(gem_spec).is_latest?).to be_truthy + expect(Manpages::GemVersion.new(gem_spec).latest?).to be_truthy end - it 'Returns true if it is the newest version' do + it "Returns true if it is the newest version" do gem_spec = Gem::Specification.new("manpages_test", Gem::Version.new("0.1.0")) allow(Gem::Specification).to receive(:each).and_return([ - OpenStruct.new(name: "manpages_test", version: Gem::Version.new("0.0.1")) + OpenStruct.new(name: "manpages_test", version: Gem::Version.new("0.0.1")), ]) - expect(Manpages::GemVersion.new(gem_spec).is_latest?).to be_truthy + expect(Manpages::GemVersion.new(gem_spec).latest?).to be_truthy end - it 'Returns false if it is not the newest version of a gem' do + it "Returns false if it is not the newest version of a gem" do gem_spec = Gem::Specification.new("manpages_test", Gem::Version.new("0.1.0")) allow(Gem::Specification).to receive(:each).and_return([ - OpenStruct.new(name: "manpages_test", version: Gem::Version.new("1.0.0")) + OpenStruct.new(name: "manpages_test", version: Gem::Version.new("1.0.0")), ]) - expect(Manpages::GemVersion.new(gem_spec).is_latest?).to be_falsy + expect(Manpages::GemVersion.new(gem_spec).latest?).to be_falsy end - end - - end diff --git a/spec/manpages/install_spec.rb b/spec/manpages/install_spec.rb index 415fe28..760992b 100644 --- a/spec/manpages/install_spec.rb +++ b/spec/manpages/install_spec.rb @@ -1,9 +1,8 @@ -require 'spec_helper' -require 'fileutils' +require "spec_helper" +require "fileutils" describe Manpages::Install do - - it 'copies the man pages to a correct directory structure' do + it "copies the man pages to a correct directory structure" do Manpages::Install.new( Gem::Specification.new(name: "manpages_test"), "spec/data", @@ -13,11 +12,11 @@ "spec/tmp/man/man1", "spec/tmp/man/man1/example.1", "spec/tmp/man/man2", - "spec/tmp/man/man2/example.2" + "spec/tmp/man/man2/example.2", ] end - it 'ignores gems without a man dir' do + it "ignores gems without a man dir" do Manpages::Install.new( Gem::Specification.new(name: "manpages_test"), "spec/non_existent", @@ -26,8 +25,8 @@ expect(Dir.glob("spec/tmp/man/**/*")).to match_array [] end - it 'Does not install if version is too old' do - expect_any_instance_of(Manpages::GemVersion).to receive(:is_latest?).and_return(false) + it "Does not install if version is too old" do + expect_any_instance_of(Manpages::GemVersion).to receive(:latest?).and_return(false) Manpages::Install.new( Gem::Specification.new(name: "manpages_test"), "spec/data", @@ -36,7 +35,7 @@ expect(Dir.glob("spec/tmp/man/**/*")).to match_array [] end - it 'does not overwrite file if it is not a symlink' do + it "does not overwrite file if it is not a symlink" do FileUtils.mkdir_p "spec/tmp/man/man1" FileUtils.touch "spec/tmp/man/man1/example.1" Manpages::Install.new( @@ -47,7 +46,7 @@ expect(File.symlink?("spec/tmp/man/man1/example.1")).to be_falsy end - it 'overwrite file if it is a symlink' do + it "overwrite file if it is a symlink" do FileUtils.mkdir_p "spec/tmp/man/man1" FileUtils.ln_s("README.md", "spec/tmp/man/man1/example.1") Manpages::Install.new( @@ -59,18 +58,18 @@ expect(File.readlink("spec/tmp/man/man1/example.1")).to eql "spec/data/man/example.1" end - it 'handles permission problems gracefully' do + it "handles permission problems gracefully" do FileUtils.mkdir_p("spec/tmp") FileUtils.chmod(400, "spec/tmp") - expect { + expect do Manpages::Install.new( Gem::Specification.new(name: "manpages_test"), "spec/data", - "spec/tmp/man" + "spec/tmp/man", ).install_manpages - }.to output( - "Problems creating symlink spec/tmp/man/man1/example.1\n" + + end.to output( + "Problems creating symlink spec/tmp/man/man1/example.1\n" \ "Problems creating symlink spec/tmp/man/man2/example.2\n" ).to_stdout FileUtils.rm_r "spec/tmp" diff --git a/spec/manpages/man_files_spec.rb b/spec/manpages/man_files_spec.rb index 8f99cb6..7292d44 100644 --- a/spec/manpages/man_files_spec.rb +++ b/spec/manpages/man_files_spec.rb @@ -1,35 +1,27 @@ -require 'spec_helper' -require 'fileutils' +require "spec_helper" +require "fileutils" describe Manpages::ManFiles do - - context '#manpages' do - - it 'returns a list of man files' do + context "#manpages" do + it "returns a list of man files" do expect(Manpages::ManFiles.new("spec/data", "").manpages).to match_array [ "spec/data/man/example.1", - "spec/data/man/example.2" + "spec/data/man/example.2", ] end - end - context '#man_dir' do - - it 'returns the man directory within the gem' do + context "#man_dir" do + it "returns the man directory within the gem" do expect(Manpages::ManFiles.new("spec/data", "").man_dir).to eq "spec/data/man" end - end - context '#man_file_path' do - - it 'returns the target path of the man file' do + context "#man_file_path" do + it "returns the target path of the man file" do expect( Manpages::ManFiles.new("spec/data", "spec/tmp/man").man_file_path("example.1") ).to eq "spec/tmp/man/man1/example.1" end - end - end diff --git a/spec/manpages/uninstall_spec.rb b/spec/manpages/uninstall_spec.rb index d07439c..6114dde 100644 --- a/spec/manpages/uninstall_spec.rb +++ b/spec/manpages/uninstall_spec.rb @@ -1,13 +1,12 @@ -require 'spec_helper' -require 'fileutils' +require "spec_helper" +require "fileutils" describe Manpages::Uninstall do - before :each do FileUtils.mkdir_p("spec/tmp/man/man1") end - it 'Deletes a manpage if the link is to this gem' do + it "Deletes a manpage if the link is to this gem" do FileUtils.ln_s("spec/data/man/example.1", "spec/tmp/man/man1/example.1") Manpages::Uninstall.new( Gem::Specification.new(name: "manpages_test"), @@ -17,7 +16,7 @@ expect(Dir.glob("spec/tmp/man/**/*")).to match_array ["spec/tmp/man/man1"] end - it 'Does not delete a manpage if it does not link to this gem' do + it "Does not delete a manpage if it does not link to this gem" do FileUtils.ln_s("README.md", "spec/tmp/man/man1/example.1") Manpages::Uninstall.new( Gem::Specification.new(name: "manpages_test"), @@ -26,12 +25,12 @@ ).uninstall_manpages expect(Dir.glob("spec/tmp/man/**/*")).to match_array [ "spec/tmp/man/man1", - "spec/tmp/man/man1/example.1" + "spec/tmp/man/man1/example.1", ] end - it 'Does not uninstall if version is too old' do - expect_any_instance_of(Manpages::GemVersion).to receive(:is_latest?).and_return(false) + it "Does not uninstall if version is too old" do + expect_any_instance_of(Manpages::GemVersion).to receive(:latest?).and_return(false) FileUtils.ln_s("spec/data/man/example.1", "spec/tmp/man/man1/example.1") Manpages::Uninstall.new( Gem::Specification.new(name: "manpages_test"), @@ -40,8 +39,7 @@ ).uninstall_manpages expect(Dir.glob("spec/tmp/man/**/*")).to match_array [ "spec/tmp/man/man1", - "spec/tmp/man/man1/example.1" + "spec/tmp/man/man1/example.1", ] end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6348f90..9de64f3 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,11 +1,10 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) -require 'manpages' -require 'pry' +$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__) +require "manpages" +require "pry" -require_relative '../lib/manpages' +require_relative "../lib/manpages" RSpec.configure do |config| - config.before(:each) do FileUtils.mkdir_p("spec/tmp") end @@ -13,5 +12,4 @@ config.after(:each) do FileUtils.rm_rf("spec/tmp") end - end