diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f4e0828..d4758d0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,18 +1,21 @@ name: CI -on: push +on: + push: + branches: [master, main] + pull_request: jobs: - build: + test: runs-on: ubuntu-latest strategy: fail-fast: false matrix: - ruby-version: ['2.7', '3.0', '3.1', '3.2'] + ruby-version: ['3.3', '3.4', '4.0'] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 @@ -22,6 +25,35 @@ jobs: - name: Run tests run: bundle exec rspec + env: + COVERAGE: 'true' - - name: Run mutant - run: bundle exec mutant run + rubocop: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '4.0' + bundler-cache: true + + - name: Run RuboCop + run: bundle exec rubocop + + audit: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '4.0' + bundler-cache: true + + - name: Run bundler-audit + run: bundle exec bundler-audit check --update diff --git a/.pelusa.yml b/.pelusa.yml deleted file mode 100644 index c5c35ef..0000000 --- a/.pelusa.yml +++ /dev/null @@ -1,9 +0,0 @@ -sources: lib/**/*.rb -lints: - InstanceVariables: - limit: 1 - LineRestriction: - limit: 87 - ElseClauses: - exclude: - - 'IceNine::Freezer' diff --git a/.rubocop.yml b/.rubocop.yml index 9c91d1f..9d77ada 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,8 +1,93 @@ +plugins: + - rubocop-performance + - rubocop-rspec + AllCops: + NewCops: enable + TargetRubyVersion: 3.3 + SuggestExtensions: false Exclude: - - 'Gemfile' - - 'Gemfile.devtools' - 'benchmarks/**/*' - - 'ice_nine.gemspec' - 'vendor/**/*' - - 'Guardfile' + +# This codebase favours a very dense, "one class/module per concept" style +# with lots of tiny classes (e.g. lib/ice_nine/freezer/*.rb), so the +# class-level documentation cop is enough; per-file/module-length limits +# below are relaxed to match that style rather than forcing artificial +# splits. +Style/Documentation: + Enabled: true + +Style/ClassAndModuleChildren: + Exclude: + - 'spec/**/*_spec.rb' + +Metrics/ClassLength: + Max: 100 + +Metrics/ModuleLength: + Max: 100 + Exclude: + - 'spec/**/*' + +Metrics/BlockLength: + Exclude: + - 'spec/**/*' + - 'ice_nine.gemspec' + +# The library re-opens IceNine::Freezer for each supported Ruby core class, +# so short single-purpose subclasses are idiomatic here, not a smell. +Style/EmptyMethod: + EnforcedStyle: expanded + +Layout/LineLength: + Max: 100 + +RSpec/MultipleMemoizedHelpers: + Enabled: false + +RSpec/NestedGroups: + Max: 5 + +RSpec/ExampleLength: + Enabled: false + +RSpec/MultipleExpectations: + Enabled: false + +# The suite consistently defines a single `subject` per example group and +# references it explicitly for readability in multi-line expectations +# instead of relying on the implicit `is_expected` syntax. +RSpec/NamedSubject: + Enabled: false + +# These doubles stand in for arbitrary opaque objects that are only ever +# identity-compared (`be(...)`); there is no real interface to verify them +# against. +RSpec/VerifiedDoubles: + Enabled: false + +# element_reader_spec.rb intentionally defines and removes real global +# constants (Hash::Test, Application::User, Mash::State, ...) to exercise +# IceNine::Freezer's name-based constant lookup across namespaces -- that is +# the exact behaviour under test, not a leaky-state accident stub_const +# would paper over. +RSpec/RemoveConst: + Exclude: + - 'spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb' + +RSpec/LeakyConstantDeclaration: + Exclude: + - 'spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb' + +RSpec/BeforeAfterAll: + Exclude: + - 'spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb' + +Lint/ConstantDefinitionInBlock: + Exclude: + - 'spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb' + +Lint/EmptyClass: + Exclude: + - 'spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb' diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..d13e837 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +4.0.6 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 333b403..4a8550b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,5 +7,5 @@ Contributing * Follow this [style guide](https://github.com/dkubb/styleguide). * Add specs for it. This is important so I don't break it in a future version unintentionally. Tests must cover all branches within the code, and code must be fully covered. * Commit, do not mess with Rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) -* Run "rake ci". This must pass and not show any regressions in the metrics for the code to be merged. +* Run `bundle exec rake`. This runs the spec suite (with 100% line/branch coverage enforced) and RuboCop, and must pass with no regressions for the code to be merged. * Send me a pull request. Bonus points for topic branches. diff --git a/Gemfile b/Gemfile index ea82bc2..b00b4c3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,15 +1,23 @@ -# encoding: utf-8 +# frozen_string_literal: true source 'https://rubygems.org' gemspec group :development, :test do - gem 'rspec', '~> 3.8', '>= 3.8.0' - gem 'mutant', github: 'mbj/mutant' - gem 'mutant-rspec', github: 'mbj/mutant' + gem 'rake', '~> 13.2' + gem 'rspec', '~> 3.13' - source 'https://oss:sxCL1o1navkPi2XnGB5WYBrhpY9iKIPL@gem.mutant.dev' do - gem 'mutant-license' - end + # No longer bundled with Ruby by default since 3.4; the numeric freezer + # specs exercise BigDecimal explicitly. + gem 'bigdecimal', '~> 3.1' + + gem 'rubocop', '~> 1.75', require: false + gem 'rubocop-performance', '~> 1.24', require: false + gem 'rubocop-rspec', '~> 3.6', require: false + + gem 'simplecov', '~> 0.22', require: false + gem 'yard', '~> 0.9', require: false + + gem 'bundler-audit', '~> 0.9', require: false end diff --git a/Gemfile.devtools b/Gemfile.devtools deleted file mode 100644 index 09ebbfe..0000000 --- a/Gemfile.devtools +++ /dev/null @@ -1,72 +0,0 @@ -# encoding: utf-8 - -group :development do - gem 'rake', '~> 10.4.0' - gem 'rspec', '~> 3.1.0' - gem 'rspec-core', '~> 3.1.7' - gem 'rspec-its', '~> 1.1.0' - gem 'yard', '~> 0.8.7.6' - - platform :rbx do - gem 'rubysl-singleton', '~> 2.0.0' - end -end - -group :yard do - gem 'kramdown', '~> 1.5.0' -end - -group :guard do - gem 'guard', '~> 2.10.1' - gem 'guard-bundler', '~> 2.0.0' - gem 'guard-rspec', '~> 4.3.1' - gem 'guard-rubocop', '~> 1.2.0' - - # file system change event handling - gem 'listen', '~> 2.8.1' - gem 'rb-fchange', '~> 0.0.6', require: false - gem 'rb-fsevent', '~> 0.9.4', require: false - gem 'rb-inotify', '~> 0.9.5', require: false - - # notification handling - gem 'libnotify', '~> 0.8.4', require: false - gem 'rb-notifu', '~> 0.0.4', require: false - gem 'terminal-notifier-guard', '~> 1.6.4', require: false -end - -group :metrics do - gem 'coveralls', '~> 0.7.2' - gem 'flay', '~> 2.5.0' - gem 'flog', '~> 4.3.0' - gem 'reek', '~> 1.5.0' - gem 'rubocop', '~> 0.27.1' - gem 'simplecov', '~> 0.9.1' - gem 'yardstick', '~> 0.9.9' - - platforms :mri do - gem 'mutant', '~> 0.6.7', git: 'https://github.com/mbj/mutant.git' - gem 'mutant-rspec', '~> 0.6.7', git: 'https://github.com/mbj/mutant.git' - end - - platforms :ruby_19, :ruby_20 do - gem 'yard-spellcheck', '~> 0.1.5' - end - - platform :rbx do - gem 'json', '~> 1.8.1' - gem 'racc', '~> 1.4.12' - gem 'rubysl-logger', '~> 2.1.0' - gem 'rubysl-open-uri', '~> 2.0.0' - gem 'rubysl-prettyprint', '~> 2.0.3' - end -end - -group :benchmarks do - gem 'rbench', '~> 0.2.3' -end - -platform :jruby do - group :jruby do - gem 'jruby-openssl', '~> 0.9.4' - end -end diff --git a/Guardfile b/Guardfile deleted file mode 100644 index 2218cb6..0000000 --- a/Guardfile +++ /dev/null @@ -1,24 +0,0 @@ -# encoding: utf-8 - -guard :bundler do - watch('Gemfile') -end - -# rubocop:disable LineLength -guard :rspec, cli: File.read('.rspec').split.join(' '), keep_failed: false do - # run all specs if configuration is modified - watch('Guardfile') { 'spec' } - watch('Gemfile.lock') { 'spec' } - watch('spec/spec_helper.rb') { 'spec' } - - # run all specs if supporting files files are modified - watch(%r{\Aspec/(?:lib|support|shared)/.+\.rb\z}) { 'spec' } - - # run unit specs if associated lib code is modified - watch(/\Alib\/(.+)\.rb/) { |m| Dir["spec/unit/#{m[1]}"] } - watch(%r{\Alib/(.+)/support/(.+)\.rb\z}) { |m| Dir["spec/unit/#{m[1]}/#{m[2]}"] } - watch("lib/#{File.basename(File.expand_path('../', __FILE__))}.rb") { 'spec' } - - # run a spec if it is modified - watch(%r{\Aspec/(?:unit|integration)/.+_spec\.rb\z}) -end diff --git a/README.md b/README.md index 08e19c7..4a75ba2 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,9 @@ Deep freeze ruby objects [![Gem Version](https://badge.fury.io/rb/ice_nine.svg)][gem] [![Build Status](https://github.com/dkubb/ice_nine/actions/workflows/ci.yml/badge.svg)][ci] -[![Code Climate](https://codeclimate.com/github/dkubb/ice_nine.png)][codeclimate] -[![Inline docs](http://inch-ci.org/github/dkubb/ice_nine.svg?branch=master)][inch] [gem]: https://rubygems.org/gems/ice_nine [ci]: https://github.com/dkubb/ice_nine/actions/ -[travis]: https://travis-ci.org/dkubb/ice_nine -[gemnasium]: https://gemnasium.com/dkubb/ice_nine -[codeclimate]: https://codeclimate.com/github/dkubb/ice_nine -[inch]: http://inch-ci.org/github/dkubb/ice_nine Examples -------- @@ -40,6 +34,25 @@ object = Object.new object.deep_freeze ``` +Requirements +------------ + +ice_nine requires Ruby 3.3 or newer, and is tested against Ruby 3.3, 3.4 +and 4.0. + +Development +----------- + +```shell +bundle install +bundle exec rake # runs the spec suite and RuboCop +bundle exec rspec # spec suite only +bundle exec rubocop # lint only +``` + +Set `COVERAGE=true` when running the spec suite to generate a SimpleCov +report under `coverage/`; the suite enforces 100% line and branch coverage. + Contributing ------------ diff --git a/Rakefile b/Rakefile index b4ca397..50845e9 100644 --- a/Rakefile +++ b/Rakefile @@ -1,3 +1,15 @@ -# encoding: utf-8 +# frozen_string_literal: true -Rake.application.load_imports +require 'bundler/gem_tasks' +require 'rspec/core/rake_task' + +RSpec::Core::RakeTask.new(:spec) + +begin + require 'rubocop/rake_task' + RuboCop::RakeTask.new(:rubocop) +rescue LoadError + nil +end + +task default: %i[spec rubocop] diff --git a/benchmarks/speed.rb b/benchmarks/speed.rb index 2a00c32..d760962 100755 --- a/benchmarks/speed.rb +++ b/benchmarks/speed.rb @@ -1,16 +1,15 @@ #!/usr/bin/env ruby - -# encoding: utf-8 +# frozen_string_literal: true # benchmark speed of deep freeze -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) -require 'rbench' +require 'benchmark' require 'ice_nine' # @return [Hash] -def self.nested(depth, width, array_length) +def nested(depth, width, array_length) hash = {} 1.upto(width) do |n| @@ -18,17 +17,17 @@ def self.nested(depth, width, array_length) end unless depth == 1 - hash[(width - 1).to_s] = array_length.times.map { nested(depth - 1, width, array_length) } + hash[(width - 1).to_s] = Array.new(array_length) { nested(depth - 1, width, array_length) } hash[width.to_s] = nested(depth - 1, width, array_length) end hash end -hash = nested(3, 5, 500) +hash = nested(3, 5, 500) hash2 = nested(3, 5, 500) -RBench.run do - report('deep_freeze') { IceNine.deep_freeze(hash) } - report('deep_freeze!') { IceNine.deep_freeze!(hash2) } +Benchmark.bmbm do |x| + x.report('deep_freeze') { IceNine.deep_freeze(hash) } + x.report('deep_freeze!') { IceNine.deep_freeze!(hash2) } end diff --git a/config/devtools.yml b/config/devtools.yml deleted file mode 100644 index dbdc79a..0000000 --- a/config/devtools.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -unit_test_timeout: 0.1 diff --git a/config/flay.yml b/config/flay.yml deleted file mode 100644 index 50ae2d5..0000000 --- a/config/flay.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -threshold: 8 -total_score: 52 diff --git a/config/flog.yml b/config/flog.yml deleted file mode 100644 index aa98167..0000000 --- a/config/flog.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -threshold: 5.5 diff --git a/config/mutant.yml b/config/mutant.yml deleted file mode 100644 index 54be0c4..0000000 --- a/config/mutant.yml +++ /dev/null @@ -1,12 +0,0 @@ ---- -integration: - name: rspec -requires: - - ice_nine -matcher: - subjects: - - IceNine* -mutation: - timeout: 1.0 -coverage_criteria: - timeout: true diff --git a/config/reek.yml b/config/reek.yml deleted file mode 100644 index ef42f14..0000000 --- a/config/reek.yml +++ /dev/null @@ -1,105 +0,0 @@ ---- -Attribute: - enabled: true - exclude: [] -BooleanParameter: - enabled: true - exclude: [] -ClassVariable: - enabled: true - exclude: [] -ControlParameter: - enabled: true - exclude: [] -DataClump: - enabled: true - exclude: [] - max_copies: 2 - min_clump_size: 2 -DuplicateMethodCall: - enabled: true - exclude: [] - max_calls: 1 - allow_calls: [] -FeatureEnvy: - enabled: true - exclude: - - IceNine::RecursionGuard::Frozen#guard -IrresponsibleModule: - enabled: true - exclude: [] -LongParameterList: - enabled: true - exclude: [] - max_params: 2 - overrides: - initialize: - max_params: 3 -LongYieldList: - enabled: true - exclude: [] - max_params: 2 -NestedIterators: - enabled: true - exclude: [] - max_allowed_nesting: 1 - ignore_iterators: [] -NilCheck: - enabled: true - exclude: [] -RepeatedConditional: - enabled: true - exclude: [] - max_ifs: 1 -TooManyInstanceVariables: - enabled: true - exclude: [] - max_instance_variables: 3 -TooManyMethods: - enabled: true - exclude: [] - max_methods: 10 -TooManyStatements: - enabled: true - exclude: - - each - max_statements: 5 -UncommunicativeMethodName: - enabled: true - exclude: [] - reject: - - !ruby/regexp /^[a-z]$/ - - !ruby/regexp /[0-9]$/ - - !ruby/regexp /[A-Z]/ - accept: [] -UncommunicativeModuleName: - enabled: true - exclude: [] - reject: - - !ruby/regexp /^.$/ - - !ruby/regexp /[0-9]$/ - accept: [] -UncommunicativeParameterName: - enabled: true - exclude: [] - reject: - - !ruby/regexp /^.$/ - - !ruby/regexp /[0-9]$/ - - !ruby/regexp /[A-Z]/ - accept: [] -UncommunicativeVariableName: - enabled: true - exclude: [] - reject: - - !ruby/regexp /^.$/ - - !ruby/regexp /[0-9]$/ - - !ruby/regexp /[A-Z]/ - accept: [] -UnusedParameters: - enabled: true - exclude: [] -UtilityFunction: - enabled: true - exclude: - - IceNine::RecursionGuard::Frozen#guard - max_helper_calls: 0 diff --git a/config/roodi.yml b/config/roodi.yml deleted file mode 100644 index 242e8be..0000000 --- a/config/roodi.yml +++ /dev/null @@ -1,16 +0,0 @@ ---- -AbcMetricMethodCheck: { score: 1 } -AssignmentInConditionalCheck: { } -CaseMissingElseCheck: { } -ClassLineCountCheck: { line_count: 88 } -ClassNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' } -ClassVariableCheck: { } -CyclomaticComplexityBlockCheck: { complexity: 3 } -CyclomaticComplexityMethodCheck: { complexity: 1 } -EmptyRescueBodyCheck: { } -ForLoopCheck: { } -MethodLineCountCheck: { line_count: 1 } -MethodNameCheck: { pattern: !ruby/regexp '/\A(?:[a-z\d](?:_?[a-z\d])+[?!=]?|\[\]=?|==|<=>|<<|[+*&|-])\z/' } -ModuleLineCountCheck: { line_count: 92 } -ModuleNameCheck: { pattern: !ruby/regexp '/\A(?:[A-Z]+|[A-Z][a-z](?:[A-Z]?[a-z])+)\z/' } -ParameterNumberCheck: { parameter_count: 0 } diff --git a/config/rubocop.yml b/config/rubocop.yml deleted file mode 100644 index 18eeafd..0000000 --- a/config/rubocop.yml +++ /dev/null @@ -1,114 +0,0 @@ -inherit_from: ../.rubocop.yml - -# Avoid parameter lists longer than five parameters. -ParameterLists: - Max: 3 - CountKeywordArgs: true - -# Avoid more than `Max` levels of nesting. -BlockNesting: - Max: 3 - -# Align with the style guide. -CollectionMethods: - PreferredMethods: - collect: 'map' - inject: 'reduce' - find: 'detect' - find_all: 'select' - -# Do not force public/protected/private keyword to be indented at the same -# level as the def keyword. My personal preference is to outdent these keywords -# because I think when scanning code it makes it easier to identify the -# sections of code and visually separate them. When the keyword is at the same -# level I think it sort of blends in with the def keywords and makes it harder -# to scan the code and see where the sections are. -AccessModifierIndentation: - Enabled: false - -# Limit line length -LineLength: - Max: 79 - -# Disable documentation checking until a class needs to be documented once -Documentation: - Enabled: false - -# Do not always use &&/|| instead of and/or. -AndOr: - Enabled: false - -# Do not favor modifier if/unless usage when you have a single-line body -IfUnlessModifier: - Enabled: false - -# Allow case equality operator (in limited use within the specs) -CaseEquality: - Enabled: false - -# Constants do not always have to use SCREAMING_SNAKE_CASE -ConstantName: - Enabled: false - -# Not all trivial readers/writers can be defined with attr_* methods -TrivialAccessors: - Enabled: false - -# Allow empty lines around class body -EmptyLinesAroundClassBody: - Enabled: false - -# Allow empty lines around module body -EmptyLinesAroundModuleBody: - Enabled: false - -# Allow multiple line operations to not require indentation -MultilineOperationIndentation: - Enabled: false - -# Prefer String#% over Kernel#sprintf -FormatString: - Enabled: false - -# Use square brackets for literal Array objects -PercentLiteralDelimiters: - PreferredDelimiters: - '%': () - '%i': '[]' - '%q': () - '%Q': () - '%r': '{}' - '%s': () - '%w': '[]' - '%W': '[]' - '%x': () - -# Align if/else blocks with the variable assignment -EndAlignment: - AlignWith: variable - -# Do not always align parameters when it is easier to read -AlignParameters: - Exclude: - - spec/**/*_spec.rb - -# Prefer #kind_of? over #is_a? -ClassCheck: - EnforcedStyle: kind_of? - -# Do not prefer double quotes to be used when %q or %Q is more appropriate -UnneededPercentQ: - Enabled: false - -# Allow a maximum ABC score -Metrics/AbcSize: - Max: 6.08 - -# Allow modules to be qualified with a "::" prefix -ClassAndModuleChildren: - Exclude: - - spec/**/*_spec.rb - -# Allow additional spaces -ExtraSpacing: - Enabled: false diff --git a/config/yardstick.yml b/config/yardstick.yml deleted file mode 100644 index a6b63e8..0000000 --- a/config/yardstick.yml +++ /dev/null @@ -1,2 +0,0 @@ ---- -threshold: 100 diff --git a/ice_nine.gemspec b/ice_nine.gemspec index fcb0c57..8a9bcfe 100644 --- a/ice_nine.gemspec +++ b/ice_nine.gemspec @@ -1,6 +1,7 @@ -# encoding: utf-8 +# frozen_string_literal: true -require File.expand_path('../lib/ice_nine/version', __FILE__) +require 'English' +require_relative 'lib/ice_nine/version' Gem::Specification.new do |gem| gem.name = 'ice_nine' @@ -13,12 +14,13 @@ Gem::Specification.new do |gem| gem.license = 'MIT' gem.require_paths = %w[lib] - gem.files = `git ls-files`.split($/) - gem.test_files = `git ls-files -- spec/{unit,integration}`.split($/) + gem.files = `git ls-files -- lib LICENSE README.md TODO`.split($INPUT_RECORD_SEPARATOR) gem.extra_rdoc_files = %w[LICENSE README.md TODO] - gem.required_ruby_version = '>= 2.7.3' + gem.required_ruby_version = '>= 3.3' - gem.add_development_dependency('bundler', '~> 2.2', '>= 2.2.33') - gem.add_development_dependency('rake', '~> 13.0', '>= 13.0.6') + gem.metadata['rubygems_mfa_required'] = 'true' + gem.metadata['changelog_uri'] = "#{gem.homepage}/blob/master/README.md" + gem.metadata['source_code_uri'] = gem.homepage + gem.metadata['bug_tracker_uri'] = "#{gem.homepage}/issues" end diff --git a/lib/ice_nine.rb b/lib/ice_nine.rb index a659785..72a5f8b 100644 --- a/lib/ice_nine.rb +++ b/lib/ice_nine.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'ice_nine/support/recursion_guard' @@ -20,7 +20,6 @@ # Base IceNine module module IceNine - # Deep Freeze an object # # @example @@ -55,5 +54,4 @@ def self.deep_freeze(object) def self.deep_freeze!(object) Freezer.deep_freeze!(object) end - -end # IceNine +end diff --git a/lib/ice_nine/core_ext/object.rb b/lib/ice_nine/core_ext/object.rb index 7e541fd..1ff5b7e 100644 --- a/lib/ice_nine/core_ext/object.rb +++ b/lib/ice_nine/core_ext/object.rb @@ -1,13 +1,10 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine - # Core Ruby extensions module CoreExt - # Extend Object with deep freezing module Object - # Deep freeze an object # # @example @@ -33,10 +30,9 @@ def deep_freeze def deep_freeze! IceNine.deep_freeze!(self) end - - end # Object - end # CoreExt -end # IceNine + end + end +end # Add Object#deep_freeze Object.instance_eval { include IceNine::CoreExt::Object } diff --git a/lib/ice_nine/freezer.rb b/lib/ice_nine/freezer.rb index 035e928..80aeb99 100644 --- a/lib/ice_nine/freezer.rb +++ b/lib/ice_nine/freezer.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine - # The default class that handles freezing objects class Freezer - # Cache the Freezer classes returned for each type @freezer_cache = Hash.new do |cache, mod| freezer = nil @@ -68,7 +66,7 @@ def self.find(name) freezer = name.split('::').reduce(self) do |mod, const| mod.const_lookup(const) or break mod end - freezer if freezer < self # only return a descendant freezer + freezer if freezer < self # only return a descendant freezer end private_class_method :find @@ -104,6 +102,5 @@ def self.guarded_deep_freeze(object, recursion_guard) class << self protected :const_lookup, :guarded_deep_freeze end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/array.rb b/lib/ice_nine/freezer/array.rb index e8d7d16..c155fb5 100644 --- a/lib/ice_nine/freezer/array.rb +++ b/lib/ice_nine/freezer/array.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # A freezer class for handling Array objects class Array < Object - # Deep Freeze an Array # # @example @@ -22,7 +20,6 @@ def self.guarded_deep_freeze(array, recursion_guard) Freezer.guarded_deep_freeze(entry, recursion_guard) end end - - end # Array - end # Freezer -end # IceNine + end + end +end diff --git a/lib/ice_nine/freezer/false_class.rb b/lib/ice_nine/freezer/false_class.rb index f5774db..ff64daa 100644 --- a/lib/ice_nine/freezer/false_class.rb +++ b/lib/ice_nine/freezer/false_class.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing false objects class FalseClass < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/hash.rb b/lib/ice_nine/freezer/hash.rb index d180284..ce5e126 100644 --- a/lib/ice_nine/freezer/hash.rb +++ b/lib/ice_nine/freezer/hash.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # A freezer class for handling Hash objects class Hash < Object - # Deep Freeze a Hash # # @example @@ -40,7 +38,6 @@ def self.freeze_key_value_pairs(hash, recursion_guard) end private_class_method :freeze_key_value_pairs - - end # Hash - end # Freezer -end # IceNine + end + end +end diff --git a/lib/ice_nine/freezer/module.rb b/lib/ice_nine/freezer/module.rb index 2674f5f..4969f8f 100644 --- a/lib/ice_nine/freezer/module.rb +++ b/lib/ice_nine/freezer/module.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing Module objects class Module < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/nil_class.rb b/lib/ice_nine/freezer/nil_class.rb index d95f442..29550b8 100644 --- a/lib/ice_nine/freezer/nil_class.rb +++ b/lib/ice_nine/freezer/nil_class.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing nil objects class NilClass < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/no_freeze.rb b/lib/ice_nine/freezer/no_freeze.rb index cfc8b79..4af6108 100644 --- a/lib/ice_nine/freezer/no_freeze.rb +++ b/lib/ice_nine/freezer/no_freeze.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # A freezer class that does not freeze anything class NoFreeze < self - # Pass through the object without freezing it # # @example @@ -19,7 +17,6 @@ class NoFreeze < self def self.guarded_deep_freeze(object, _recursion_guard) object end - - end # NoFreeze - end # Freezer -end # IceNine + end + end +end diff --git a/lib/ice_nine/freezer/numeric.rb b/lib/ice_nine/freezer/numeric.rb index f5dbdac..efad1a8 100644 --- a/lib/ice_nine/freezer/numeric.rb +++ b/lib/ice_nine/freezer/numeric.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing Numeric objects class Numeric < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/object.rb b/lib/ice_nine/freezer/object.rb index 2e4a5b7..3d961ac 100644 --- a/lib/ice_nine/freezer/object.rb +++ b/lib/ice_nine/freezer/object.rb @@ -1,11 +1,9 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # A freezer class for handling Object instances class Object < self - # Deep Freeze an object # # @example @@ -41,9 +39,11 @@ def self.freeze_instance_variables(object, recursion_guard) end private_class_method :freeze_instance_variables + end - end # Object - + # Freeze BasicObject instances using the same strategy as Object + # + # @api private BasicObject = Object - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/struct.rb b/lib/ice_nine/freezer/struct.rb index a40c4b4..e0bc3e4 100644 --- a/lib/ice_nine/freezer/struct.rb +++ b/lib/ice_nine/freezer/struct.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # A freezer class for handling Struct objects class Struct < Array; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/symbol.rb b/lib/ice_nine/freezer/symbol.rb index 2dadc7e..37c5ec7 100644 --- a/lib/ice_nine/freezer/symbol.rb +++ b/lib/ice_nine/freezer/symbol.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing Symbol objects class Symbol < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/freezer/true_class.rb b/lib/ice_nine/freezer/true_class.rb index e612d0c..ad2dfce 100644 --- a/lib/ice_nine/freezer/true_class.rb +++ b/lib/ice_nine/freezer/true_class.rb @@ -1,10 +1,8 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine class Freezer - # Skip freezing true objects class TrueClass < NoFreeze; end - - end # Freezer -end # IceNine + end +end diff --git a/lib/ice_nine/support/recursion_guard.rb b/lib/ice_nine/support/recursion_guard.rb index 3d71da9..d14fa5b 100644 --- a/lib/ice_nine/support/recursion_guard.rb +++ b/lib/ice_nine/support/recursion_guard.rb @@ -1,20 +1,18 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine - # Protect against infinite recursion # # @private class RecursionGuard - # Protects against infinite recursion by never yielding with the same # object more than once. class ObjectSet < self - # Initialize a recursion guard # # @return [undefined] def initialize + super @object_ids = {} end @@ -32,15 +30,14 @@ def initialize def guard(object) caller_object_id = object.__id__ return object if @object_ids.key?(caller_object_id) + @object_ids[caller_object_id] = nil yield end - - end # ObjectSet + end # Protects against infinite recursion by not yielding with frozen objects class Frozen < self - # Guard against recursively calling a block with the same frozen object # # @param [Object] object @@ -48,10 +45,9 @@ class Frozen < self # @return [Object] def guard(object) return object if object.frozen? + yield end - - end # Frozen - - end # RecursionGuard -end # IceNine + end + end +end diff --git a/lib/ice_nine/version.rb b/lib/ice_nine/version.rb index 02afb43..000f21a 100644 --- a/lib/ice_nine/version.rb +++ b/lib/ice_nine/version.rb @@ -1,8 +1,6 @@ -# encoding: utf-8 +# frozen_string_literal: true module IceNine - # Gem version - VERSION = '0.11.2'.freeze - -end # IceNine + VERSION = '0.11.2' +end diff --git a/spec/integration/ice_nine/class_methods/deep_freeze_bang_spec.rb b/spec/integration/ice_nine/class_methods/deep_freeze_bang_spec.rb index a7fc922..cc1ceb0 100644 --- a/spec/integration/ice_nine/class_methods/deep_freeze_bang_spec.rb +++ b/spec/integration/ice_nine/class_methods/deep_freeze_bang_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -7,15 +7,15 @@ describe IceNine, '.deep_freeze!' do subject { object.deep_freeze!(value) } - let(:object) { IceNine } + let(:object) { described_class } context 'with a shallowly frozen value' do - let(:value) { %w[a b].freeze } + let(:value) { [+'a', +'b'].freeze } it 'does not deep freeze' do expect(subject.select(&:frozen?)).to be_empty end end - it_should_behave_like 'IceNine.deep_freeze' + it_behaves_like 'IceNine.deep_freeze' end diff --git a/spec/integration/ice_nine/class_methods/deep_freeze_spec.rb b/spec/integration/ice_nine/class_methods/deep_freeze_spec.rb index 479339d..a5f778c 100644 --- a/spec/integration/ice_nine/class_methods/deep_freeze_spec.rb +++ b/spec/integration/ice_nine/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -7,7 +7,7 @@ describe IceNine, '.deep_freeze' do subject { object.deep_freeze(value) } - let(:object) { IceNine } + let(:object) { described_class } context 'with a shallowly frozen value' do let(:value) { ['a', %w[b c]].freeze } @@ -17,5 +17,5 @@ end end - it_should_behave_like 'IceNine.deep_freeze' + it_behaves_like 'IceNine.deep_freeze' end diff --git a/spec/shared/array_deep_freeze.rb b/spec/shared/array_deep_freeze.rb index b93b0d0..4bbd438 100644 --- a/spec/shared/array_deep_freeze.rb +++ b/spec/shared/array_deep_freeze.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine::Freezer::Array.deep_freeze' do it_behaves_like 'IceNine::Freezer::Object.deep_freeze' diff --git a/spec/shared/hash_deep_freeze.rb b/spec/shared/hash_deep_freeze.rb index e1b84ed..3422882 100644 --- a/spec/shared/hash_deep_freeze.rb +++ b/spec/shared/hash_deep_freeze.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine::Freezer::Hash.deep_freeze' do it_behaves_like 'IceNine::Freezer::Object.deep_freeze' @@ -13,11 +13,11 @@ if RUBY_VERSION >= '1.9' && RUBY_ENGINE == 'rbx' it 'does not freeze the state' do - expect(subject.instance_variable_get(:@state)).to_not be_frozen + expect(subject.instance_variable_get(:@state)).not_to be_frozen end it 'does not freeze the entries' do - expect(subject.instance_variable_get(:@entries)).to_not be_frozen + expect(subject.instance_variable_get(:@entries)).not_to be_frozen end end end diff --git a/spec/shared/ice_nine_deep_freeze.rb b/spec/shared/ice_nine_deep_freeze.rb index 3957b95..6f7fc15 100644 --- a/spec/shared/ice_nine_deep_freeze.rb +++ b/spec/shared/ice_nine_deep_freeze.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine.deep_freeze' do context 'with an Object' do @@ -9,7 +9,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -26,7 +26,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -43,7 +43,7 @@ let(:value) { %w[a] } it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -60,7 +60,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -77,7 +77,7 @@ let(:value) { { Object.new => Object.new } } it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -98,7 +98,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -116,14 +116,14 @@ end context 'with a String' do - let(:value) { '' } + let(:value) { +'' } before do value.instance_eval { @a = '1' } end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -140,7 +140,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -154,11 +154,11 @@ end context 'with a Struct' do - let(:value) { klass.new(%w[ 1 2 ]) } - let(:klass) { Struct.new(:a) } + let(:value) { klass.new(%w[1 2]) } + let(:klass) { Struct.new(:a) } it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -175,7 +175,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -196,7 +196,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -213,7 +213,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do @@ -231,11 +231,11 @@ let(:value) { value } it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'does not freeze the object' do - expect { subject }.to_not change(value, :frozen?).from(value.frozen?) + expect { subject }.not_to change(value, :frozen?).from(value.frozen?) end end end diff --git a/spec/shared/no_freeze_deep_freeze.rb b/spec/shared/no_freeze_deep_freeze.rb index 24b8fcf..8383c51 100644 --- a/spec/shared/no_freeze_deep_freeze.rb +++ b/spec/shared/no_freeze_deep_freeze.rb @@ -1,21 +1,21 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine::Freezer::NoFreeze.deep_freeze' do before do - value.instance_eval { @a = '1' } unless value.frozen? + value.instance_eval { @a = +'1' } unless value.frozen? end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'does not freeze the object' do - expect { subject }.to_not change(value, :frozen?).from(value.frozen?) + expect { subject }.not_to change(value, :frozen?).from(value.frozen?) end it 'does not freeze instance variables' do if subject.instance_variable_defined?(:@a) - expect(subject.instance_variable_get(:@a)).to_not be_frozen + expect(subject.instance_variable_get(:@a)).not_to be_frozen end end end diff --git a/spec/shared/object_deep_freeze.rb b/spec/shared/object_deep_freeze.rb index 1fe4d9f..9a54ea5 100644 --- a/spec/shared/object_deep_freeze.rb +++ b/spec/shared/object_deep_freeze.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine::Freezer::Object.deep_freeze' do before do @@ -6,7 +6,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'freezes the object' do diff --git a/spec/shared/range_deep_freeze.rb b/spec/shared/range_deep_freeze.rb index feb19f9..a7e6ffa 100644 --- a/spec/shared/range_deep_freeze.rb +++ b/spec/shared/range_deep_freeze.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true shared_examples 'IceNine::Freezer::Range.deep_freeze' do it_behaves_like 'IceNine::Freezer::Object.deep_freeze' diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1329542..ebe0f87 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,26 +1,25 @@ -# encoding: utf-8 +# frozen_string_literal: true if ENV['COVERAGE'] == 'true' require 'simplecov' - SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ - SimpleCov::Formatter::HTMLFormatter, - ] + SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new( + [SimpleCov::Formatter::HTMLFormatter] + ) SimpleCov.start do command_name 'spec:unit' + enable_coverage :branch - add_filter 'config' add_filter 'spec' - add_filter 'vendor' - minimum_coverage 100 + minimum_coverage line: 100, branch: 100 end end require 'ice_nine' -Dir[Pathname(__dir__).join('shared/**/*.rb')].each(&Kernel.method(:require)) +Dir[Pathname(__dir__).join('shared/**/*.rb')].each { |file| require file } RSpec.configure do |config| config.expect_with :rspec do |expect_with| diff --git a/spec/support/config_alias.rb b/spec/support/config_alias.rb deleted file mode 100644 index 9c3f42f..0000000 --- a/spec/support/config_alias.rb +++ /dev/null @@ -1,5 +0,0 @@ -# encoding: utf-8 - -require 'rbconfig' - -::Config = RbConfig unless defined?(::Config) diff --git a/spec/unit/ice_nine/class_methods/deep_freeze_bang_spec.rb b/spec/unit/ice_nine/class_methods/deep_freeze_bang_spec.rb index a9f75b9..e92762a 100644 --- a/spec/unit/ice_nine/class_methods/deep_freeze_bang_spec.rb +++ b/spec/unit/ice_nine/class_methods/deep_freeze_bang_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -6,7 +6,7 @@ describe IceNine, '.deep_freeze!' do subject { object.deep_freeze!(value) } - let(:object) { IceNine } + let(:object) { described_class } let(:value) { Object.new } context 'when the object is not frozen' do @@ -15,7 +15,7 @@ context 'when the object is frozen' do before do - value.instance_eval { @a = '1' } + value.instance_eval { @a = +'1' } value.freeze end diff --git a/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb index a811fa8..dbf2c0a 100644 --- a/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -6,7 +6,7 @@ describe IceNine, '.deep_freeze' do subject { object.deep_freeze(value) } - let(:object) { IceNine } + let(:object) { described_class } let(:value) { Object.new } context 'when the object is not frozen' do @@ -20,7 +20,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'leaves the object frozen' do diff --git a/spec/unit/ice_nine/core_ext/object/deep_freeze_bang_spec.rb b/spec/unit/ice_nine/core_ext/object/deep_freeze_bang_spec.rb index e14c356..5e05fab 100644 --- a/spec/unit/ice_nine/core_ext/object/deep_freeze_bang_spec.rb +++ b/spec/unit/ice_nine/core_ext/object/deep_freeze_bang_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -7,7 +7,7 @@ describe IceNine::CoreExt::Object, '#deep_freeze!' do subject { value.deep_freeze! } - let(:value) { Object.new.extend(IceNine::CoreExt::Object) } + let(:value) { Object.new.extend(described_class) } context 'when the object is not frozen' do it_behaves_like 'IceNine::Freezer::Object.deep_freeze' @@ -15,7 +15,7 @@ context 'when the object is frozen' do before do - value.instance_eval { @a = '1' } + value.instance_eval { @a = +'1' } value.freeze end diff --git a/spec/unit/ice_nine/core_ext/object/deep_freeze_spec.rb b/spec/unit/ice_nine/core_ext/object/deep_freeze_spec.rb index 3b6a57c..00739c1 100644 --- a/spec/unit/ice_nine/core_ext/object/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/core_ext/object/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -7,7 +7,7 @@ describe IceNine::CoreExt::Object, '#deep_freeze' do subject { value.deep_freeze } - let(:value) { Object.new.extend(IceNine::CoreExt::Object) } + let(:value) { Object.new.extend(described_class) } it_behaves_like 'IceNine::Freezer::Object.deep_freeze' end diff --git a/spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb index 62df85b..d0906e8 100644 --- a/spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/array/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' diff --git a/spec/unit/ice_nine/freezer/class_methods/deep_freeze_bang_spec.rb b/spec/unit/ice_nine/freezer/class_methods/deep_freeze_bang_spec.rb index 450d467..45fefab 100644 --- a/spec/unit/ice_nine/freezer/class_methods/deep_freeze_bang_spec.rb +++ b/spec/unit/ice_nine/freezer/class_methods/deep_freeze_bang_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -6,7 +6,7 @@ describe IceNine::Freezer, '.deep_freeze!' do subject { object.deep_freeze!(value) } - let(:object) { IceNine::Freezer } + let(:object) { described_class } let(:value) { Object.new } context 'when the object is not frozen' do @@ -15,7 +15,7 @@ context 'when the object is frozen' do before do - value.instance_eval { @a = '1' } + value.instance_eval { @a = +'1' } value.freeze end diff --git a/spec/unit/ice_nine/freezer/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/class_methods/deep_freeze_spec.rb index e64b939..8bec2e3 100644 --- a/spec/unit/ice_nine/freezer/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -6,7 +6,7 @@ describe IceNine::Freezer, '.deep_freeze' do subject { object.deep_freeze(value) } - let(:object) { IceNine::Freezer } + let(:object) { described_class } let(:value) { Object.new } context 'when the object is not frozen' do @@ -20,7 +20,7 @@ end it 'returns the object' do - should be(value) + expect(subject).to be(value) end it 'leaves the object frozen' do diff --git a/spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb b/spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb index cb67562..f0f9690 100644 --- a/spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb +++ b/spec/unit/ice_nine/freezer/class_methods/element_reader_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' @@ -25,7 +25,7 @@ end it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -41,7 +41,7 @@ class User; end end after :all do - ::Application.send(:remove_const, :User) + Application.send(:remove_const, :User) Object.send(:remove_const, :Application) end @@ -56,7 +56,7 @@ class User; end end it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -65,7 +65,7 @@ class User; end let(:freezer) { IceNine::Freezer::Struct } it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -73,7 +73,7 @@ class User; end let(:mod) { Object } it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -81,7 +81,7 @@ class User; end let(:mod) { Class.new } it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -89,7 +89,7 @@ class User; end let(:mod) { Module.new } it 'returns the freezer' do - should be_nil + expect(subject).to be_nil end end @@ -104,7 +104,7 @@ class Hash::Test; end end it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end @@ -119,7 +119,7 @@ class State; end end after :all do - ::Mash.send(:remove_const, :State) + Mash.send(:remove_const, :State) Object.send(:remove_const, :Mash) end @@ -132,7 +132,7 @@ class State; end end it 'returns the freezer' do - should be(freezer) + expect(subject).to be(freezer) end end end diff --git a/spec/unit/ice_nine/freezer/false_class/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/false_class/class_methods/deep_freeze_spec.rb index 0424682..68f9d5d 100644 --- a/spec/unit/ice_nine/freezer/false_class/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/false_class/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb index 4a89ce5..09e04c8 100644 --- a/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/hash/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' @@ -10,6 +10,7 @@ context 'with a Hash object having a default proc' do let(:value) do + # rubocop:disable-next Lint/EmptyBlock -- only the Proc's frozen state is under test Hash.new {}.update(Object.new => Object.new) end @@ -22,7 +23,7 @@ context 'with a Hash object having a default value' do let(:value) do - Hash.new('').update(Object.new => Object.new) + Hash.new(+'').update(Object.new => Object.new) end it_behaves_like 'IceNine::Freezer::Hash.deep_freeze' @@ -31,7 +32,7 @@ expect(subject.default).to be_frozen end - context 'that is a circular reference' do + context 'with a default value that is a circular reference' do before { value.default = value } it_behaves_like 'IceNine::Freezer::Hash.deep_freeze' diff --git a/spec/unit/ice_nine/freezer/module/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/module/class_methods/deep_freeze_spec.rb index 0a316a5..052a99c 100644 --- a/spec/unit/ice_nine/freezer/module/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/module/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/freezer/nil_class/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/nil_class/class_methods/deep_freeze_spec.rb index 6eff10f..2189b84 100644 --- a/spec/unit/ice_nine/freezer/nil_class/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/nil_class/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/freezer/no_freeze/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/no_freeze/class_methods/deep_freeze_spec.rb index c749926..67dd355 100644 --- a/spec/unit/ice_nine/freezer/no_freeze/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/no_freeze/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer/no_freeze' diff --git a/spec/unit/ice_nine/freezer/numeric/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/numeric/class_methods/deep_freeze_spec.rb index 32b407b..cec123a 100644 --- a/spec/unit/ice_nine/freezer/numeric/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/numeric/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/freezer/object/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/object/class_methods/deep_freeze_spec.rb index 31b72d4..15e6e69 100644 --- a/spec/unit/ice_nine/freezer/object/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/object/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' diff --git a/spec/unit/ice_nine/freezer/struct/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/struct/class_methods/deep_freeze_spec.rb index cd1eeae..420f85b 100644 --- a/spec/unit/ice_nine/freezer/struct/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/struct/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine' diff --git a/spec/unit/ice_nine/freezer/symbol/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/symbol/class_methods/deep_freeze_spec.rb index 1ac38c4..efbc863 100644 --- a/spec/unit/ice_nine/freezer/symbol/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/symbol/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/freezer/true_class/class_methods/deep_freeze_spec.rb b/spec/unit/ice_nine/freezer/true_class/class_methods/deep_freeze_spec.rb index 39b27a0..3461ecd 100644 --- a/spec/unit/ice_nine/freezer/true_class/class_methods/deep_freeze_spec.rb +++ b/spec/unit/ice_nine/freezer/true_class/class_methods/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/freezer' diff --git a/spec/unit/ice_nine/recursion_guard/frozen/guard_spec.rb b/spec/unit/ice_nine/recursion_guard/frozen/guard_spec.rb index a856a34..683d93e 100644 --- a/spec/unit/ice_nine/recursion_guard/frozen/guard_spec.rb +++ b/spec/unit/ice_nine/recursion_guard/frozen/guard_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/support/recursion_guard' @@ -6,13 +6,13 @@ describe IceNine::RecursionGuard::Frozen, '#guard' do subject { object.guard(object_arg) { return_value } } - let(:object) { IceNine::RecursionGuard::Frozen.new } + let(:object) { described_class.new } let(:object_arg) { Object.new } let(:return_value) { double('return_value') } context 'when the object_arg is not frozen' do it 'returns the expected value' do - should be(return_value) + expect(subject).to be(return_value) end end @@ -22,7 +22,7 @@ end it 'returns the expected value' do - should be(object_arg) + expect(subject).to be(object_arg) end end end diff --git a/spec/unit/ice_nine/recursion_guard/object_set/guard_spec.rb b/spec/unit/ice_nine/recursion_guard/object_set/guard_spec.rb index f899c7e..9a12af2 100644 --- a/spec/unit/ice_nine/recursion_guard/object_set/guard_spec.rb +++ b/spec/unit/ice_nine/recursion_guard/object_set/guard_spec.rb @@ -1,39 +1,39 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine/support/recursion_guard' describe IceNine::RecursionGuard::ObjectSet, '#guard' do - let(:object) { IceNine::RecursionGuard::ObjectSet.new } - let(:object_arg1) { 'similar_but_not_equal_id' } - let(:object_arg2) { 'similar_but_not_equal_id' } - let(:return_value) { double('return_value') } + let(:object) { described_class.new } + let(:first_object_arg) { +'similar_but_not_equal_id' } + let(:second_object_arg) { +'similar_but_not_equal_id' } + let(:return_value) { double('return_value') } context 'when the block is not recursive' do subject do - object.guard(object_arg1) { return_value } - object.guard(object_arg2) { return_value } + object.guard(first_object_arg) { return_value } + object.guard(second_object_arg) { return_value } end it 'returns the expected value' do - should be(return_value) + expect(subject).to be(return_value) end end context 'when the block is recursive' do subject do - object.guard(object_arg1) do - object.guard(object_arg2) do - expect(subject).to be(object_arg1) + object.guard(first_object_arg) do + object.guard(second_object_arg) do + expect(subject).to be(first_object_arg) return_value end - expect(subject).to be(object_arg1) + expect(subject).to be(first_object_arg) return_value end end it 'returns the expected value' do - should be(return_value) + expect(subject).to be(return_value) end end end diff --git a/spec/unit/object/deep_freeze_spec.rb b/spec/unit/object/deep_freeze_spec.rb index 4368b78..93448cb 100644 --- a/spec/unit/object/deep_freeze_spec.rb +++ b/spec/unit/object/deep_freeze_spec.rb @@ -1,4 +1,4 @@ -# encoding: utf-8 +# frozen_string_literal: true require 'spec_helper' require 'ice_nine'