diff --git a/.rubocop.yml b/.rubocop.yml index 06aeef8..707bc16 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,58 +9,6 @@ AllCops: - "db/schema.rb" TargetRubyVersion: 2.1 -Naming/AccessorMethodName: - Description: Check the naming of accessor methods for get_/set_. - Enabled: false - -Style/Alias: - Description: Use alias_method instead of alias. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#alias-method - Enabled: false - -Style/Attr: - Description: Checks for uses of Module#attr. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#attr - Enabled: false - -Style/CollectionMethods: - Description: Preferred collection methods. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#map-find-select-reduce-size - Enabled: true - PreferredMethods: - collect: map - collect!: map! - find: detect - find_all: select - inject: reduce - -Style/Documentation: - Description: Document classes and non-namespace modules. - Enabled: false - -Layout/DotPosition: - Description: Checks the position of the dot in multi-line method calls. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-multi-line-chains - Enabled: true - EnforcedStyle: trailing - SupportedStyles: - - leading - - trailing - -Style/DoubleNegation: - Description: Checks for uses of double negation (!!). - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-bang-bang - Enabled: false - -Style/EachWithObject: - Description: Prefer `each_with_object` over `inject` or `reduce`. - Enabled: false - -Style/EmptyLiteral: - Description: Prefer literals to Array.new/Hash.new/String.new. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#literal-array-hash - Enabled: false - Naming/FileName: Description: Use snake_case for source file names. StyleGuide: https://github.com/bbatsov/ruby-style-guide#snake-case-files @@ -68,230 +16,10 @@ Naming/FileName: Exclude: - lib/benchmark-memory.rb -Style/GuardClause: - Description: Check for conditionals that can be replaced with guard clauses - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-nested-conditionals - Enabled: false - MinBodyLength: 1 - -Style/HashSyntax: - Description: Check the style of Hash syntax. - Enabled: true - EnforcedStyle: hash_rockets - SupportedStyles: - - hash_rockets - - ruby19 - - ruby19_no_mixed_keys - -Style/IfUnlessModifier: - Description: Favor modifier if/unless usage when you have a single-line body. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier - Enabled: false - -Style/InlineComment: - Description: Avoid inline comments. - Enabled: false - -Style/ModuleFunction: - Description: Checks for usage of `extend self` in modules. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#module-function - Enabled: false - -Style/OneLineConditional: - Description: Favor the ternary operator(?:) over if/then/else/end constructs. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#ternary-operator - Enabled: false - -Style/OptionHash: - Description: Do not use option hashes when you can use keyword arguments. - Enabled: false - -Style/PercentLiteralDelimiters: - Description: Use `%`-literal delimiters consistently - StyleGuide: https://github.com/bbatsov/ruby-style-guide#percent-literal-braces - Enabled: false - PreferredDelimiters: - "%": "()" - "%i": "()" - "%q": "()" - "%Q": "()" - "%r": "{}" - "%s": "()" - "%w": "()" - "%W": "()" - "%x": "()" - -Style/PerlBackrefs: - Description: Avoid Perl-style regex back references. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-perl-regexp-last-matchers - Enabled: false - -Naming/PredicateName: - Description: Check the names of predicate methods. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#bool-methods-qmark - Enabled: true - NamePrefix: - - is_ - - has_ - - have_ - NamePrefixBlacklist: - - is_ - Exclude: - - spec/**/* - -Style/RaiseArgs: - Description: Checks the arguments passed to raise/fail. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#exception-class-messages - Enabled: true - EnforcedStyle: exploded - SupportedStyles: - - compact - - exploded - -Style/Send: - Description: Prefer `Object#__send__` or `Object#public_send` to `send`, as `send` - may overlap with existing methods. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#prefer-public-send - Enabled: false - -Style/SignalException: - Description: Checks for proper usage of fail and raise. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#fail-method - Enabled: true - EnforcedStyle: semantic - SupportedStyles: - - only_raise - - only_fail - - semantic - -Style/SingleLineBlockParams: - Description: Enforces the names of some block params. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#reduce-blocks - Enabled: false - Methods: - - reduce: - - a - - e - - inject: - - a - - e - -Style/SingleLineMethods: - Description: Avoid single-line methods. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-single-line-methods - Enabled: false - AllowIfMethodIsEmpty: true - -Layout/SpaceInsideHashLiteralBraces: - EnforcedStyle: no_space - EnforcedStyleForEmptyBraces: no_space - SupportedStyles: - - space - - no_space - -Style/SpecialGlobalVars: - Description: Avoid Perl-style global variables. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-cryptic-perlisms - Enabled: false - -Style/StringLiterals: - Description: Checks if uses of quotes match the configured preference. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#consistent-string-literals - Enabled: true - EnforcedStyle: double_quotes - SupportedStyles: - - single_quotes - - double_quotes - -Style/StringLiteralsInInterpolation: - Description: Checks if uses of quotes inside expressions in interpolated strings - match the configured preference. - Enabled: true - EnforcedStyle: single_quotes - SupportedStyles: - - single_quotes - - double_quotes - -Style/TrailingCommaInLiteral: - Description: Checks for trailing comma in parameter lists and literals. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#no-trailing-array-commas - Enabled: true - EnforcedStyleForMultiline: comma - -Style/VariableInterpolation: - Description: Do not interpolate global, instance and class variables directly in - strings. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#curlies-interpolate - Enabled: false - -Style/WhenThen: - Description: Use when x then ... for one-line cases. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#one-line-cases - Enabled: false - -Lint/AssignmentInCondition: - Description: Do not use assignment in conditions. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#safe-assignment-in-condition - Enabled: false - AllowSafeAssignment: true - -Lint/EachWithObjectArgument: - Description: Check for immutable argument given to each_with_object. - Enabled: true - -Lint/HandleExceptions: - Description: Do not suppress exception. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#dont-hide-exceptions - Enabled: false - -Lint/LiteralInInterpolation: - Description: Checks for literals used in interpolation. - Enabled: false - -Metrics/AbcSize: - Description: A calculated magnitude based on number of assignments, branches, and - conditions. - Enabled: false - Max: 15 - Metrics/BlockLength: Exclude: - spec/**/*.rb -Metrics/ClassLength: - Description: Avoid classes longer than 100 lines of code. - Enabled: false - CountComments: false - Max: 100 - -Metrics/ModuleLength: - CountComments: false - Max: 100 - Description: Avoid modules longer than 100 lines of code. - Enabled: false - -Metrics/CyclomaticComplexity: - Description: A complexity metric that is strongly correlated to the number of test - cases needed to validate a method. - Enabled: false - Max: 6 - Metrics/MethodLength: - Description: Avoid methods longer than 10 lines of code. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#short-methods - Enabled: false - CountComments: false - Max: 10 - -Metrics/ParameterLists: - Description: Avoid parameter lists longer than three or four parameters. - StyleGuide: https://github.com/bbatsov/ruby-style-guide#too-many-params - Enabled: false - Max: 5 - CountKeywordArgs: true - -Metrics/PerceivedComplexity: - Description: A complexity metric geared towards measuring complexity for a human - reader. - Enabled: false - Max: 7 + Exclude: + - spec/**/*.rb diff --git a/Gemfile b/Gemfile index ca67bd3..eb014ca 100644 --- a/Gemfile +++ b/Gemfile @@ -1,25 +1,25 @@ -source "https://rubygems.org" +source 'https://rubygems.org' gemspec group :development do - gem "guard" - gem "guard-bundler" - gem "guard-inch" - gem "guard-rspec", "~> 4.6" - gem "guard-rubocop" - gem "inch" - gem "rake", "~> 10" - gem "rubocop", "0.52.1" - gem "yard", "~> 0.9.11" + gem 'guard' + gem 'guard-bundler' + gem 'guard-inch' + gem 'guard-rspec', '~> 4.6' + gem 'guard-rubocop' + gem 'inch' + gem 'rake', '~> 10' + gem 'rubocop', '0.52.1' + gem 'yard', '~> 0.9.11' group :test do - gem "pry" + gem 'pry' end end group :test do - gem "codeclimate-test-reporter", :require => false - gem "rspec", "~> 3.4" - gem "simplecov" + gem 'codeclimate-test-reporter', require: false + gem 'rspec', '~> 3.4' + gem 'simplecov' end diff --git a/Guardfile b/Guardfile index 436ceda..b949549 100644 --- a/Guardfile +++ b/Guardfile @@ -1,14 +1,14 @@ guard :bundler do - watch("Gemfile") - watch("interactor-contracts.gemspec") + watch('Gemfile') + watch('interactor-contracts.gemspec') end guard :inch do watch(/.+\.rb/) end -guard :rspec, :cmd => "bundle exec rspec" do - watch("spec/spec_helper.rb") { "spec" } +guard :rspec, cmd: 'bundle exec rspec' do + watch('spec/spec_helper.rb') { 'spec' } watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } diff --git a/Rakefile b/Rakefile index 000e6f3..9079338 100644 --- a/Rakefile +++ b/Rakefile @@ -1,17 +1,17 @@ -require "bundler" +require 'bundler' Bundler.setup Bundler::GemHelper.install_tasks -require "inch/rake" +require 'inch/rake' Inch::Rake::Suggest.new(:inch) -require "rspec/core/rake_task" +require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -require "rubocop/rake_task" +require 'rubocop/rake_task' RuboCop::RakeTask.new(:rubocop) -require "yard/rake/yardoc_task" +require 'yard/rake/yardoc_task' YARD::Rake::YardocTask.new(:yard) -task :default => %i(spec rubocop yard inch) +task default: %i[spec rubocop yard inch] diff --git a/benchmark-memory.gemspec b/benchmark-memory.gemspec index eaf1e9e..d8c8ee2 100644 --- a/benchmark-memory.gemspec +++ b/benchmark-memory.gemspec @@ -1,22 +1,22 @@ -require File.expand_path("../lib/benchmark/memory/version", __FILE__) +require File.expand_path('../lib/benchmark/memory/version', __FILE__) Gem::Specification.new do |spec| - spec.name = "benchmark-memory" + spec.name = 'benchmark-memory' spec.version = Benchmark::Memory::VERSION - spec.authors = ["Michael Herold"] - spec.email = ["michael.j.herold@gmail.com"] + spec.authors = ['Michael Herold'] + spec.email = ['michael.j.herold@gmail.com'] - spec.summary = "Benchmark-style memory profiling for Ruby 2.1+" + spec.summary = 'Benchmark-style memory profiling for Ruby 2.1+' spec.description = spec.summary - spec.homepage = "https://github.com/michaelherold/benchmark-memory" - spec.license = "MIT" + spec.homepage = 'https://github.com/michaelherold/benchmark-memory' + spec.license = 'MIT' - spec.files = %w(CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile) - spec.files += %w(benchmark-memory.gemspec) - spec.files += Dir["lib/**/*.rb"] - spec.require_paths = ["lib"] + spec.files = %w[CHANGELOG.md CONTRIBUTING.md LICENSE.md README.md Rakefile] + spec.files += %w[benchmark-memory.gemspec] + spec.files += Dir['lib/**/*.rb'] + spec.require_paths = ['lib'] - spec.add_dependency "memory_profiler", "~> 0.9" + spec.add_dependency 'memory_profiler', '~> 0.9' - spec.add_development_dependency "bundler", "~> 1.12" + spec.add_development_dependency 'bundler', '~> 1.12' end diff --git a/bin/console b/bin/console index ac2a2c8..270c56f 100755 --- a/bin/console +++ b/bin/console @@ -1,7 +1,7 @@ #!/usr/bin/env ruby -require "bundler/setup" -require "benchmark/memory" +require 'bundler/setup' +require 'benchmark/memory' # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. @@ -10,5 +10,5 @@ require "benchmark/memory" # require "pry" # Pry.start -require "irb" +require 'irb' IRB.start diff --git a/lib/benchmark-memory.rb b/lib/benchmark-memory.rb index 328f63a..336166e 100644 --- a/lib/benchmark-memory.rb +++ b/lib/benchmark-memory.rb @@ -1 +1 @@ -require "benchmark/memory" +require 'benchmark/memory' diff --git a/lib/benchmark/memory.rb b/lib/benchmark/memory.rb index bddbc32..7346e65 100644 --- a/lib/benchmark/memory.rb +++ b/lib/benchmark/memory.rb @@ -1,6 +1,6 @@ -require "benchmark/memory/errors" -require "benchmark/memory/job" -require "benchmark/memory/version" +require 'benchmark/memory/errors' +require 'benchmark/memory/job' +require 'benchmark/memory/version' # Performance benchmarking library module Benchmark @@ -13,14 +13,9 @@ module Memory # # @return [Report] def memory(quiet: false) - unless block_given? - fail( - ConfigurationError, - "You did not give a test block to your call to `Benchmark.memory`" - ) - end + raise ConfigurationError unless block_given? - job = Job.new(:quiet => quiet) + job = Job.new(quiet: quiet) yield job diff --git a/lib/benchmark/memory/errors.rb b/lib/benchmark/memory/errors.rb index d99e753..1370d8f 100644 --- a/lib/benchmark/memory/errors.rb +++ b/lib/benchmark/memory/errors.rb @@ -2,6 +2,10 @@ module Benchmark module Memory Error = Class.new(StandardError) - ConfigurationError = Class.new(Error) + ConfigurationError = Class.new(Error) do + def message + 'You did not give a test block to your call to `Benchmark.memory`' + end + end end end diff --git a/lib/benchmark/memory/held_results.rb b/lib/benchmark/memory/held_results.rb index 774ae53..42f814e 100644 --- a/lib/benchmark/memory/held_results.rb +++ b/lib/benchmark/memory/held_results.rb @@ -1,5 +1,5 @@ -require "forwardable" -require "benchmark/memory/held_results/entry_serializer" +require 'forwardable' +require 'benchmark/memory/held_results/entry_serializer' module Benchmark module Memory @@ -30,7 +30,7 @@ def initialize(path = nil) # # @return [void] def add_result(entry) - with_hold_file("a") do |file| + with_hold_file('a') do |file| file.write EntrySerializer.new(entry) file.write "\n" end @@ -51,16 +51,14 @@ def any? # # @return [void] def cleanup - if @path.is_a?(String) && File.exist?(@path) - File.delete(@path) - end + File.delete(@path) if @path.is_a?(String) && File.exist?(@path) end # Check whether to hold results. # # @return [Boolean] def holding? - !!@path + !!@path # rubocop:disable Style/DoubleNegation end # Check whether an entry has been added to the results. @@ -94,7 +92,7 @@ def load # @param _block [Proc] The block to execute on each line of the file. # # @return [void] - def with_hold_file(access_mode = "r", &_block) + def with_hold_file(access_mode = 'r', &_block) return unless @path if @path.is_a?(String) diff --git a/lib/benchmark/memory/held_results/entry_serializer.rb b/lib/benchmark/memory/held_results/entry_serializer.rb index 189e133..8d2d593 100644 --- a/lib/benchmark/memory/held_results/entry_serializer.rb +++ b/lib/benchmark/memory/held_results/entry_serializer.rb @@ -1,6 +1,6 @@ -require "benchmark/memory/held_results/serializer" -require "benchmark/memory/held_results/measurement_serializer" -require "benchmark/memory/report/entry" +require 'benchmark/memory/held_results/serializer' +require 'benchmark/memory/held_results/measurement_serializer' +require 'benchmark/memory/report/entry' module Benchmark module Memory @@ -14,8 +14,8 @@ class EntrySerializer < Serializer # @return [Report::Entry] def load(hash) @object = Report::Entry.new( - hash["item"], - MeasurementSerializer.load(hash["measurement"]) + hash['item'], + MeasurementSerializer.load(hash['measurement']) ) self end @@ -25,8 +25,8 @@ def load(hash) # @return [Hash] The entry as a Hash. def to_h { - :item => object.label, - :measurement => MeasurementSerializer.new(object.measurement).to_h, + item: object.label, + measurement: MeasurementSerializer.new(object.measurement).to_h } end end diff --git a/lib/benchmark/memory/held_results/measurement_serializer.rb b/lib/benchmark/memory/held_results/measurement_serializer.rb index 54fb565..f8b8d97 100644 --- a/lib/benchmark/memory/held_results/measurement_serializer.rb +++ b/lib/benchmark/memory/held_results/measurement_serializer.rb @@ -1,6 +1,6 @@ -require "benchmark/memory/held_results/serializer" -require "benchmark/memory/held_results/metric_serializer" -require "benchmark/memory/measurement" +require 'benchmark/memory/held_results/serializer' +require 'benchmark/memory/held_results/metric_serializer' +require 'benchmark/memory/measurement' module Benchmark module Memory @@ -14,9 +14,9 @@ class MeasurementSerializer < Serializer # @return [Measurement] def load(hash) @object = Measurement.new( - :memory => MetricSerializer.load(hash["memory"]), - :objects => MetricSerializer.load(hash["objects"]), - :strings => MetricSerializer.load(hash["strings"]) + memory: MetricSerializer.load(hash['memory']), + objects: MetricSerializer.load(hash['objects']), + strings: MetricSerializer.load(hash['strings']) ) self end @@ -26,9 +26,9 @@ def load(hash) # @return [Hash] The measurement as a Hash. def to_h { - :memory => MetricSerializer.new(object.memory).to_h, - :objects => MetricSerializer.new(object.objects).to_h, - :strings => MetricSerializer.new(object.strings).to_h, + memory: MetricSerializer.new(object.memory).to_h, + objects: MetricSerializer.new(object.objects).to_h, + strings: MetricSerializer.new(object.strings).to_h } end end diff --git a/lib/benchmark/memory/held_results/metric_serializer.rb b/lib/benchmark/memory/held_results/metric_serializer.rb index eacfdbc..6d77ba1 100644 --- a/lib/benchmark/memory/held_results/metric_serializer.rb +++ b/lib/benchmark/memory/held_results/metric_serializer.rb @@ -1,5 +1,5 @@ -require "benchmark/memory/held_results/serializer" -require "benchmark/memory/measurement/metric" +require 'benchmark/memory/held_results/serializer' +require 'benchmark/memory/measurement/metric' module Benchmark module Memory @@ -14,9 +14,9 @@ class MetricSerializer < Serializer # def load(hash) @object = Measurement::Metric.new( - hash["type"], - hash["allocated"], - hash["retained"] + hash['type'], + hash['allocated'], + hash['retained'] ) self end @@ -26,9 +26,9 @@ def load(hash) # @return [Hash] The metric as a Hash. def to_h { - :allocated => object.allocated, - :retained => object.retained, - :type => object.type, + allocated: object.allocated, + retained: object.retained, + type: object.type } end end diff --git a/lib/benchmark/memory/held_results/serializer.rb b/lib/benchmark/memory/held_results/serializer.rb index 874db52..bde2bac 100644 --- a/lib/benchmark/memory/held_results/serializer.rb +++ b/lib/benchmark/memory/held_results/serializer.rb @@ -1,4 +1,4 @@ -require "json" +require 'json' module Benchmark module Memory @@ -33,9 +33,9 @@ def initialize(object = nil) # @raise [NotImplementedError] # If the inheriting subclass didn't implement. def load(_hash) - fail( + raise( NotImplementedError, - "You must implement a concrete version in a subclass" + 'You must implement a concrete version in a subclass' ) end @@ -45,9 +45,9 @@ def load(_hash) # @raise [NotImplementedError] # If the inheriting subclass didn't implement. def to_h - fail( + raise( NotImplementedError, - "You must implement a concrete version in a subclass" + 'You must implement a concrete version in a subclass' ) end @@ -57,7 +57,7 @@ def to_h def to_json JSON.generate(to_h) end - alias_method :to_s, :to_json + alias to_s to_json end end end diff --git a/lib/benchmark/memory/helpers.rb b/lib/benchmark/memory/helpers.rb index 2569f2b..84f2528 100644 --- a/lib/benchmark/memory/helpers.rb +++ b/lib/benchmark/memory/helpers.rb @@ -1,3 +1,5 @@ +require 'benchmark/memory/human_readable_unit' + module Benchmark module Memory # Helper methods for formatting output. @@ -23,22 +25,9 @@ def rjust(label) # # @return [String] The scaled value. def scale(value) - scale = Math.log10(value) - scale = 0 if scale.infinite? - scale = (scale / 3).to_i - suffix = - case scale - when 1 then "k" - when 2 then "M" - when 3 then "B" - when 4 then "T" - when 5 then "Q" - else - scale = 0 - " " - end + value = HumanReadableUnit.new(value) - format("%10.3f#{suffix}", value.to_f / (1000**scale)) + format("%10.3f#{value.unit}", value.to_f / (1000**value.scale)) end module_function :scale end diff --git a/lib/benchmark/memory/human_readable_unit.rb b/lib/benchmark/memory/human_readable_unit.rb new file mode 100644 index 0000000..f384bab --- /dev/null +++ b/lib/benchmark/memory/human_readable_unit.rb @@ -0,0 +1,38 @@ +module Benchmark + module Memory + # Transforms raw numbers into a human-readable scale and suffix + class HumanReadableUnit < SimpleDelegator + # Instantiates a HumanReadableUnit from a numeric value + # + # @param value [Numeric] the value make human-readable + def initialize(value) + super(value) + end + + # @return [Integer] the exponential scale of the value + def scale + scale = Math.log10(__getobj__) + scale = 0 if scale.infinite? + scale = (scale / 3).to_i + + if scale <= 5 + scale + else + 0 + end + end + + # @return [String] the single-character unit for the value + def unit + case scale + when 1 then 'k' + when 2 then 'M' + when 3 then 'B' + when 4 then 'T' + when 5 then 'Q' + else ' ' + end + end + end + end +end diff --git a/lib/benchmark/memory/job.rb b/lib/benchmark/memory/job.rb index ca5b711..1c207de 100644 --- a/lib/benchmark/memory/job.rb +++ b/lib/benchmark/memory/job.rb @@ -1,9 +1,9 @@ -require "forwardable" -require "benchmark/memory/job/task" -require "benchmark/memory/job/io_output" -require "benchmark/memory/job/null_output" -require "benchmark/memory/held_results" -require "benchmark/memory/report" +require 'forwardable' +require 'benchmark/memory/job/task' +require 'benchmark/memory/job/io_output' +require 'benchmark/memory/job/null_output' +require 'benchmark/memory/held_results' +require 'benchmark/memory/report' module Benchmark module Memory @@ -63,9 +63,9 @@ def hold!(held_path) # @param block [Proc] Code the measure. # # @raise [ArgumentError] if no code block is specified. - def report(label = "", &block) + def report(label = '', &block) unless block_given? - fail ArgumentError, "You did not specify a block for the item" + raise ArgumentError, 'You did not specify a block for the item' end tasks.push Task.new(label, block) @@ -97,21 +97,9 @@ def run # @return [Boolean] A flag indicating whether to hold or not. def run_task(task) if @held_results.include?(task) - measurement = @held_results[task.label] - full_report.add_entry(task, measurement) - false + run_with_held_results(task) else - measurement = task.call - entry = full_report.add_entry(task, measurement) - @output.put_entry(entry) - - if task == tasks.last - @held_results.cleanup - false - else - @held_results.add_result(entry) - @held_results.holding? - end + run_without_held_results(task) end end @@ -119,9 +107,9 @@ def run_task(task) # # @return [void] def run_comparison - if compare? && full_report.comparable? - @output.put_comparison(full_report.comparison) - end + return unless compare? && full_report.comparable? + + @output.put_comparison(full_report.comparison) end # Check whether the job is set to quiet. @@ -130,6 +118,28 @@ def run_comparison def quiet? @quiet end + + private + + def run_with_held_results(task) + measurement = @held_results[task.label] + full_report.add_entry(task, measurement) + false + end + + def run_without_held_results(task) + measurement = task.call + entry = full_report.add_entry(task, measurement) + @output.put_entry(entry) + + if task == tasks.last + @held_results.cleanup + false + else + @held_results.add_result(entry) + @held_results.holding? + end + end end end end diff --git a/lib/benchmark/memory/job/io_output.rb b/lib/benchmark/memory/job/io_output.rb index fbaba4c..7b616eb 100644 --- a/lib/benchmark/memory/job/io_output.rb +++ b/lib/benchmark/memory/job/io_output.rb @@ -1,5 +1,5 @@ -require "benchmark/memory/job/io_output/comparison_formatter" -require "benchmark/memory/job/io_output/entry_formatter" +require 'benchmark/memory/job/io_output/comparison_formatter' +require 'benchmark/memory/job/io_output/entry_formatter' module Benchmark module Memory @@ -25,7 +25,7 @@ def put_entry(entry) # @return [void] def put_comparison(comparison) @io.puts - @io.puts "Comparison:" + @io.puts 'Comparison:' @io.puts ComparisonFormatter.new(comparison) end @@ -33,7 +33,7 @@ def put_comparison(comparison) # # @return [void] def put_header - @io.puts "Calculating -------------------------------------" + @io.puts 'Calculating -------------------------------------' end # Put a notice that the execution is holding for another run. @@ -41,8 +41,8 @@ def put_header # @return [void] def put_hold_notice @io.puts - @io.puts "Pausing here -- run Ruby again to " \ - "measure the next benchmark..." + @io.puts 'Pausing here -- run Ruby again to ' \ + 'measure the next benchmark...' end end end diff --git a/lib/benchmark/memory/job/io_output/comparison_formatter.rb b/lib/benchmark/memory/job/io_output/comparison_formatter.rb index d77bb50..aa8de98 100644 --- a/lib/benchmark/memory/job/io_output/comparison_formatter.rb +++ b/lib/benchmark/memory/job/io_output/comparison_formatter.rb @@ -1,5 +1,5 @@ -require "benchmark/memory/helpers" -require "benchmark/memory/job/io_output/metric_formatter" +require 'benchmark/memory/helpers' +require 'benchmark/memory/job/io_output/metric_formatter' module Benchmark module Memory @@ -23,7 +23,7 @@ def initialize(comparison) # # @return [String] def to_s - return "" unless comparison.possible? + return '' unless comparison.possible? output = StringIO.new best, *rest = comparison.entries @@ -45,7 +45,7 @@ def add_best_summary(best, output) end def add_comparison(entry, best, output) - output << summary_message("%20s: %10i allocated - ", entry) + output << summary_message('%20s: %10i allocated - ', entry) output << comparison_between(entry, best) output << "\n" end @@ -54,9 +54,9 @@ def comparison_between(entry, best) ratio = entry.allocated_memory.to_f / best.allocated_memory.to_f if ratio.abs > 1 - format("%.2fx more", ratio) + format('%.2fx more', ratio) else - "same" + 'same' end end diff --git a/lib/benchmark/memory/job/io_output/entry_formatter.rb b/lib/benchmark/memory/job/io_output/entry_formatter.rb index 37c393c..c94afea 100644 --- a/lib/benchmark/memory/job/io_output/entry_formatter.rb +++ b/lib/benchmark/memory/job/io_output/entry_formatter.rb @@ -1,6 +1,6 @@ -require "stringio" -require "benchmark/memory/helpers" -require "benchmark/memory/job/io_output/metric_formatter" +require 'stringio' +require 'benchmark/memory/helpers' +require 'benchmark/memory/job/io_output/metric_formatter' module Benchmark module Memory @@ -26,11 +26,14 @@ def initialize(entry) def to_s output = StringIO.new output << rjust(entry.label) - entry.measurement.each_with_index.map do |metric, index| - output << " " * 20 unless index.zero? - output << MetricFormatter.new(metric) - output << "\n" + + first, *rest = *entry.measurement + + output << "#{MetricFormatter.new(first)}\n" + rest.each do |metric| + output << "#{' ' * 20}#{MetricFormatter.new(metric)}\n" end + output.string end end diff --git a/lib/benchmark/memory/job/io_output/metric_formatter.rb b/lib/benchmark/memory/job/io_output/metric_formatter.rb index 1197106..56d33d7 100644 --- a/lib/benchmark/memory/job/io_output/metric_formatter.rb +++ b/lib/benchmark/memory/job/io_output/metric_formatter.rb @@ -1,4 +1,4 @@ -require "benchmark/memory/helpers" +require 'benchmark/memory/helpers' module Benchmark module Memory @@ -22,7 +22,7 @@ def initialize(metric) # # @return [String] def to_s - [allocated_message, retained_message].join(" ") + [allocated_message, retained_message].join(' ') end private @@ -30,17 +30,17 @@ def to_s # @return [String] the formated string for allocated memory def allocated_message format( - "%s %s", - :allocated => scale(metric.allocated), - :type => metric.type + '%s %s', + allocated: scale(metric.allocated), + type: metric.type ) end # @return [String] the formated string for retained memory def retained_message format( - "(%s retained)", - :retained => scale(metric.retained) + '(%s retained)', + retained: scale(metric.retained) ) end end diff --git a/lib/benchmark/memory/job/task.rb b/lib/benchmark/memory/job/task.rb index c2df6db..5fd2043 100644 --- a/lib/benchmark/memory/job/task.rb +++ b/lib/benchmark/memory/job/task.rb @@ -1,5 +1,5 @@ -require "memory_profiler" -require "benchmark/memory/measurement" +require 'memory_profiler' +require 'benchmark/memory/measurement' module Benchmark module Memory @@ -14,7 +14,7 @@ class Task # @raise [ArgumentError] if the action does not respond to `#call`. def initialize(label, action) unless action.respond_to?(:call) - fail( + raise( ArgumentError, "Invalid action (#{@action.inspect} does not respond to call)" ) diff --git a/lib/benchmark/memory/measurement.rb b/lib/benchmark/memory/measurement.rb index adee99e..a10e642 100644 --- a/lib/benchmark/memory/measurement.rb +++ b/lib/benchmark/memory/measurement.rb @@ -1,5 +1,5 @@ -require "forwardable" -require "benchmark/memory/measurement/metric" +require 'forwardable' +require 'benchmark/memory/measurement/metric_extractor' module Benchmark module Memory @@ -14,23 +14,11 @@ class Measurement # @param result [MemoryProfiler::Results] # The results of a MemoryProfiler report. def self.from_result(result) - memory = Metric.new( - :memsize, - result.total_allocated_memsize, - result.total_retained_memsize - ) - objects = Metric.new( - :objects, - result.total_allocated, - result.total_retained - ) - strings = Metric.new( - :strings, - result.strings_allocated.size, - result.strings_retained.size - ) + memory = MetricExtractor.extract_memory(result) + objects = MetricExtractor.extract_objects(result) + strings = MetricExtractor.extract_strings(result) - new(:memory => memory, :objects => objects, :strings => strings) + new(memory: memory, objects: objects, strings: strings) end # Instantiate a Measurement of memory usage. diff --git a/lib/benchmark/memory/measurement/metric.rb b/lib/benchmark/memory/measurement/metric.rb index 1426adc..b96c91f 100644 --- a/lib/benchmark/memory/measurement/metric.rb +++ b/lib/benchmark/memory/measurement/metric.rb @@ -1,4 +1,4 @@ -require "benchmark/memory/helpers" +require 'benchmark/memory/helpers' module Benchmark module Memory diff --git a/lib/benchmark/memory/measurement/metric_extractor.rb b/lib/benchmark/memory/measurement/metric_extractor.rb new file mode 100644 index 0000000..57a5508 --- /dev/null +++ b/lib/benchmark/memory/measurement/metric_extractor.rb @@ -0,0 +1,44 @@ +require 'benchmark/memory/measurement/metric' + +module Benchmark + module Memory + # Extracts metrics from a memory profiler result + class MetricExtractor + # Extracts the memory-specific metrics from a profiler result + # + # @param result [MemoryProfiler::Results] + # @return [Benchmark::Memory::Measurement::Metric] + def self.extract_memory(result) + Measurement::Metric.new( + :memsize, + result.total_allocated_memsize, + result.total_retained_memsize + ) + end + + # Extracts the object-specific metrics from a profiler result + # + # @param result [MemoryProfiler::Results] + # @return [Benchmark::Memory::Measurement::Metric] + def self.extract_objects(result) + Measurement::Metric.new( + :objects, + result.total_allocated, + result.total_retained + ) + end + + # Extracts the string-specific metrics from a profiler result + # + # @param result [MemoryProfiler::Results] + # @return [Benchmark::Memory::Measurement::Metric] + def self.extract_strings(result) + Measurement::Metric.new( + :strings, + result.strings_allocated.size, + result.strings_retained.size + ) + end + end + end +end diff --git a/lib/benchmark/memory/report.rb b/lib/benchmark/memory/report.rb index 0c83512..83851c7 100644 --- a/lib/benchmark/memory/report.rb +++ b/lib/benchmark/memory/report.rb @@ -1,5 +1,5 @@ -require "benchmark/memory/report/comparison" -require "benchmark/memory/report/entry" +require 'benchmark/memory/report/comparison' +require 'benchmark/memory/report/entry' module Benchmark module Memory diff --git a/lib/benchmark/memory/report/entry.rb b/lib/benchmark/memory/report/entry.rb index ac32949..6051f74 100644 --- a/lib/benchmark/memory/report/entry.rb +++ b/lib/benchmark/memory/report/entry.rb @@ -1,4 +1,4 @@ -require "forwardable" +require 'forwardable' module Benchmark module Memory diff --git a/lib/benchmark/memory/version.rb b/lib/benchmark/memory/version.rb index c22bf31..a7dd80b 100644 --- a/lib/benchmark/memory/version.rb +++ b/lib/benchmark/memory/version.rb @@ -1,5 +1,5 @@ module Benchmark module Memory - VERSION = "0.1.2".freeze + VERSION = '0.1.2'.freeze end end diff --git a/spec/benchmark/memory/held_results/entry_serializer_spec.rb b/spec/benchmark/memory/held_results/entry_serializer_spec.rb index fa8636b..4bbf75c 100644 --- a/spec/benchmark/memory/held_results/entry_serializer_spec.rb +++ b/spec/benchmark/memory/held_results/entry_serializer_spec.rb @@ -1,8 +1,8 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::HeldResults::EntrySerializer do - describe ".load" do - it "converts JSON documents into entries" do + describe '.load' do + it 'converts JSON documents into entries' do document = '{"item":"my super cool test",' \ '"measurement":' \ @@ -18,8 +18,8 @@ end end - describe "#to_s" do - it "converts the entry into a JSON document" do + describe '#to_s' do + it 'converts the entry into a JSON document' do result = described_class.new(create_entry).to_s expected_result = @@ -36,7 +36,7 @@ def create_entry Benchmark::Memory::Report::Entry.new( - "my super cool test", + 'my super cool test', create_measurement ) end @@ -59,9 +59,9 @@ def create_measurement ) Benchmark::Memory::Measurement.new( - :strings => strings, - :objects => objects, - :memory => memsize + strings: strings, + objects: objects, + memory: memsize ) end end diff --git a/spec/benchmark/memory/helpers_spec.rb b/spec/benchmark/memory/helpers_spec.rb index 0a3719b..5e6bf4b 100644 --- a/spec/benchmark/memory/helpers_spec.rb +++ b/spec/benchmark/memory/helpers_spec.rb @@ -1,17 +1,17 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Helpers do - describe "#scale" do - it "scales values into human terms" do + describe '#scale' do + it 'scales values into human terms' do scale = ->(value) { Benchmark::Memory::Helpers.scale(value) } - expect(scale.call(1)).to eq(" 1.000 ") - expect(scale.call(123)).to eq(" 123.000 ") - expect(scale.call(1_234)).to eq(" 1.234k") - expect(scale.call(1_234_567)).to eq(" 1.235M") - expect(scale.call(1_234_567_890)).to eq(" 1.235B") - expect(scale.call(1_234_567_890_123)).to eq(" 1.235T") - expect(scale.call(1_234_567_890_123_456)).to eq(" 1.235Q") + expect(scale.call(1)).to eq(' 1.000 ') + expect(scale.call(123)).to eq(' 123.000 ') + expect(scale.call(1_234)).to eq(' 1.234k') + expect(scale.call(1_234_567)).to eq(' 1.235M') + expect(scale.call(1_234_567_890)).to eq(' 1.235B') + expect(scale.call(1_234_567_890_123)).to eq(' 1.235T') + expect(scale.call(1_234_567_890_123_456)).to eq(' 1.235Q') end end end diff --git a/spec/benchmark/memory/job/io_output/comparison_formatter_spec.rb b/spec/benchmark/memory/job/io_output/comparison_formatter_spec.rb index 19db81d..857c0d1 100644 --- a/spec/benchmark/memory/job/io_output/comparison_formatter_spec.rb +++ b/spec/benchmark/memory/job/io_output/comparison_formatter_spec.rb @@ -1,15 +1,15 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Job::IOOutput::ComparisonFormatter do - describe "#to_s" do - it "is blank when the comparison is not possible" do + describe '#to_s' do + it 'is blank when the comparison is not possible' do comp = comparison([]) formatter = described_class.new(comp) expect(formatter.to_s).to be_empty end - it "outputs a comparison of the entries" do + it 'outputs a comparison of the entries' do entries = [create_high_entry, create_medium_entry, create_low_entry] comp = comparison(entries) formatter = described_class.new(comp) @@ -41,7 +41,7 @@ def comparison(entries) def create_high_entry Benchmark::Memory::Report::Entry.new( - "high", + 'high', create_measurement(10_000, 5_000) ) end @@ -49,14 +49,14 @@ def create_high_entry def create_low_entry Benchmark::Memory::Report::Entry.new( - "low", + 'low', create_measurement(2_500, 1_250) ) end def create_medium_entry Benchmark::Memory::Report::Entry.new( - "medium", + 'medium', create_measurement(5_000, 2_500) ) end @@ -79,9 +79,9 @@ def create_measurement(allocated, retained) ) Benchmark::Memory::Measurement.new( - :strings => strings, - :objects => objects, - :memory => memsize + strings: strings, + objects: objects, + memory: memsize ) end end diff --git a/spec/benchmark/memory/job/io_output_spec.rb b/spec/benchmark/memory/job/io_output_spec.rb index 2d09ed3..a1d387e 100644 --- a/spec/benchmark/memory/job/io_output_spec.rb +++ b/spec/benchmark/memory/job/io_output_spec.rb @@ -1,8 +1,8 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Job::IOOutput do - describe "#put_entry" do - it "outputs onto the passed IO" do + describe '#put_entry' do + it 'outputs onto the passed IO' do entry = create_entry io = StringIO.new output = described_class.new(io) @@ -15,7 +15,7 @@ def create_entry Benchmark::Memory::Report::Entry.new( - "my super cool test", + 'my super cool test', create_measurement ) end @@ -38,9 +38,9 @@ def create_measurement ) Benchmark::Memory::Measurement.new( - :strings => strings, - :objects => objects, - :memory => memsize + strings: strings, + objects: objects, + memory: memsize ) end end diff --git a/spec/benchmark/memory/job/task_spec.rb b/spec/benchmark/memory/job/task_spec.rb index a45a781..fb8f5b6 100644 --- a/spec/benchmark/memory/job/task_spec.rb +++ b/spec/benchmark/memory/job/task_spec.rb @@ -1,18 +1,18 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Job::Task do - describe ".new" do - it "raises an ArgumentError when the action is not a callable" do + describe '.new' do + it 'raises an ArgumentError when the action is not a callable' do expect do - described_class.new("label", nil) + described_class.new('label', nil) end.to raise_error(ArgumentError) end end - describe "#call" do - it "returns a measurement of the memory usage in the action" do + describe '#call' do + it 'returns a measurement of the memory usage in the action' do action = -> {} - entry = described_class.new("empty proc", action) + entry = described_class.new('empty proc', action) expect(entry.call).to be_a Benchmark::Memory::Measurement end diff --git a/spec/benchmark/memory/job_spec.rb b/spec/benchmark/memory/job_spec.rb index 966c04a..32db30a 100644 --- a/spec/benchmark/memory/job_spec.rb +++ b/spec/benchmark/memory/job_spec.rb @@ -1,37 +1,37 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Job do - describe "#report" do - it "raises an ArgumentError when no block is specified" do + describe '#report' do + it 'raises an ArgumentError when no block is specified' do job = create_job - expect { job.report("riddle me this") }.to raise_error(ArgumentError) + expect { job.report('riddle me this') }.to raise_error(ArgumentError) end - it "adds a task to the list of tasks in the job" do + it 'adds a task to the list of tasks in the job' do job = create_job - expect { job.report("riddle me that") {} }.to( + expect { job.report('riddle me that') {} }.to( change(job.tasks, :count).by(1) ) end end - describe "#run" do - it "adds an entry to the report for each task" do + describe '#run' do + it 'adds an entry to the report for each task' do job = create_job - job.report("with you") {} - job.report("my brown eyed girl") {} + job.report('with you') {} + job.report('my brown eyed girl') {} expect { job.run }.to change(job.full_report.entries, :count).by(2) end - context "holding" do - it "only executes one task for each call to run" do + context 'holding' do + it 'only executes one task for each call to run' do hold_buffer = StringIO.new job, output = create_job_and_output - job.report("with you") {} - job.report("my brown eyed girl") {} + job.report('with you') {} + job.report('my brown eyed girl') {} job.hold!(hold_buffer) expect { job.run }.to change(job.full_report.entries, :count).by(1) @@ -43,8 +43,8 @@ # Reset for the second run hold_buffer.rewind job, output = create_job_and_output - job.report("with you") {} - job.report("my brown eyed girl") {} + job.report('with you') {} + job.report('my brown eyed girl') {} job.hold!(hold_buffer) expect { job.run }.to change(job.full_report.entries, :count).by(2) @@ -56,8 +56,8 @@ end end - describe "#run_comparison" do - it "does not run if there are no entries" do + describe '#run_comparison' do + it 'does not run if there are no entries' do job, output = create_job_and_output job.run @@ -66,10 +66,10 @@ expect(output.string).not_to match(/Comparison/) end - it "runs when there are entries and the job is configured to compare" do + it 'runs when there are entries and the job is configured to compare' do job, output = create_job_and_output - job.report("with you") {} - job.report("my brown eyed girl") {} + job.report('with you') {} + job.report('my brown eyed girl') {} job.compare! job.run @@ -79,11 +79,11 @@ end end - describe "#quiet?" do - it "prevents any output from being written" do - job, output = create_job_and_output(:quiet => true) - job.report("with you") {} - job.report("my brown eyed girl") {} + describe '#quiet?' do + it 'prevents any output from being written' do + job, output = create_job_and_output(quiet: true) + job.report('with you') {} + job.report('my brown eyed girl') {} job.compare! job.run @@ -95,7 +95,7 @@ def create_job_and_output(quiet: false) output = StringIO.new - job = Benchmark::Memory::Job.new(:output => output, :quiet => quiet) + job = Benchmark::Memory::Job.new(output: output, quiet: quiet) [job, output] end diff --git a/spec/benchmark/memory/measurement/metric_spec.rb b/spec/benchmark/memory/measurement/metric_spec.rb index f2b78ca..b972dcf 100644 --- a/spec/benchmark/memory/measurement/metric_spec.rb +++ b/spec/benchmark/memory/measurement/metric_spec.rb @@ -1,8 +1,8 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Measurement::Metric do - describe "#to_s" do - it "is of consistent length" do + describe '#to_s' do + it 'is of consistent length' do examples = [0, 100, 1_000, 1_000_000, 1_000_000_000, 1_000_000_000_000] lengths = examples.map do |i| metric = described_class.new(:fake, i * 2, i) diff --git a/spec/benchmark/memory/report/comparison_spec.rb b/spec/benchmark/memory/report/comparison_spec.rb index 42ce400..6ece282 100644 --- a/spec/benchmark/memory/report/comparison_spec.rb +++ b/spec/benchmark/memory/report/comparison_spec.rb @@ -1,8 +1,8 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Report::Comparison do - describe "#entries" do - it "is sorted from smallest allocation to largest" do + describe '#entries' do + it 'is sorted from smallest allocation to largest' do high_entry = create_high_entry low_entry = create_low_entry @@ -14,7 +14,7 @@ def create_high_entry Benchmark::Memory::Report::Entry.new( - "high", + 'high', create_measurement(10_000, 5_000) ) end @@ -22,7 +22,7 @@ def create_high_entry def create_low_entry Benchmark::Memory::Report::Entry.new( - "low", + 'low', create_measurement(2_500, 1_250) ) end @@ -45,9 +45,9 @@ def create_measurement(allocated, retained) ) Benchmark::Memory::Measurement.new( - :strings => strings, - :objects => objects, - :memory => memsize + strings: strings, + objects: objects, + memory: memsize ) end end diff --git a/spec/benchmark/memory/report_spec.rb b/spec/benchmark/memory/report_spec.rb index e9c0598..6a159fb 100644 --- a/spec/benchmark/memory/report_spec.rb +++ b/spec/benchmark/memory/report_spec.rb @@ -1,16 +1,16 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory::Report do - it "is initialized with a blank list of entries" do + it 'is initialized with a blank list of entries' do report = described_class.new expect(report.entries).to be_empty end - describe "#add_entry" do - it "adds an entry to the list of entries" do + describe '#add_entry' do + it 'adds an entry to the list of entries' do report = described_class.new - task = Benchmark::Memory::Job::Task.new("do nothing", -> {}) + task = Benchmark::Memory::Job::Task.new('do nothing', -> {}) measurement = create_measurement expect { report.add_entry(task, measurement) }.to( @@ -21,9 +21,9 @@ def create_measurement metrics = { - :memory => create_metric, - :objects => create_metric, - :strings => create_metric, + memory: create_metric, + objects: create_metric, + strings: create_metric } Benchmark::Memory::Measurement.new(metrics) end diff --git a/spec/benchmark/memory_spec.rb b/spec/benchmark/memory_spec.rb index 3394b5e..d54081d 100644 --- a/spec/benchmark/memory_spec.rb +++ b/spec/benchmark/memory_spec.rb @@ -1,15 +1,15 @@ -require "spec_helper" +require 'spec_helper' RSpec.describe Benchmark::Memory do - it "has a version number" do + it 'has a version number' do expect(Benchmark::Memory::VERSION).not_to be nil end - it "exposes .memory on Benchmark" do + it 'exposes .memory on Benchmark' do expect(Benchmark).to respond_to(:memory) end - describe ".memory" do + describe '.memory' do around(:each) do |spec| old_stdout = $stdout $stdout = StringIO.new @@ -17,13 +17,13 @@ $stdout = old_stdout end - it "raises an error when not given a block" do + it 'raises an error when not given a block' do expect { Benchmark.memory }.to raise_error( Benchmark::Memory::ConfigurationError ) end - it "returns a report" do + it 'returns a report' do expect(Benchmark.memory {}).to be_a(Benchmark::Memory::Report) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c914a94..322cc4d 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,14 +1,14 @@ -if ENV["COVERAGE"] || ENV["CI"] - require "simplecov" +if ENV['COVERAGE'] || ENV['CI'] + require 'simplecov' SimpleCov.start do - add_filter "/spec/" + add_filter '/spec/' end end -require "benchmark/memory" -require "pry" -require "rspec" +require 'benchmark/memory' +require 'pry' +require 'rspec' RSpec.configure do |config| config.expect_with :rspec do |expectations| @@ -23,9 +23,9 @@ config.filter_run :focus config.run_all_when_everything_filtered = true config.disable_monkey_patching! - config.default_formatter = "doc" if config.files_to_run.one? + config.default_formatter = 'doc' if config.files_to_run.one? - config.profile_examples = 10 if ENV["PROFILE"] + config.profile_examples = 10 if ENV['PROFILE'] config.order = :random Kernel.srand config.seed