Skip to content

Commit

Permalink
Merge pull request #722 from freerange/freeze-string-literals
Browse files Browse the repository at this point in the history
Freeze string literals
  • Loading branch information
floehopper authored Jan 1, 2025
2 parents 01809ba + de4013e commit 1c5dda3
Show file tree
Hide file tree
Showing 217 changed files with 452 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ jobs:
type: string
docker:
- image: << parameters.docker-image >>
environment:
RUBYOPT=--enable-frozen-string-literal
steps:
- checkout
- run: ruby --version
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha.rb
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# frozen_string_literal: true

require 'mocha/version'
2 changes: 2 additions & 0 deletions lib/mocha/any_instance_method.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/stubbed_method'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/api.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/ruby_version'
require 'mocha/parameter_matchers'
require 'mocha/hooks'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/argument_iterator.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class ArgumentIterator
def initialize(argument)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/backtrace_filter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class BacktraceFilter
LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), '..')) + File::SEPARATOR
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/block_matcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
module BlockMatchers
class OptionalBlock
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/cardinality.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class Cardinality
INFINITY = 1 / 0.0
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/central.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class Central
class Null < self
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/change_state_side_effect.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class ChangeStateSideEffect
def initialize(state)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/class_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/mockery'
require 'mocha/any_instance_method'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/ruby_version'
require 'mocha/deprecation'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/deprecation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/backtrace_filter'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/detection/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
module Detection
module Minitest
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/detection/test_unit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
module Detection
module TestUnit
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/error_with_filtered_backtrace.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/backtrace_filter'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/exception_raiser.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class ExceptionRaiser
def initialize(exception, message)
Expand Down
16 changes: 9 additions & 7 deletions lib/mocha/expectation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'ruby2_keywords'
require 'mocha/method_matcher'
require 'mocha/parameters_matcher'
Expand Down Expand Up @@ -744,19 +746,19 @@ def inspect

# @private
def mocha_inspect
message = "#{@cardinality.anticipated_times}, #{@cardinality.invoked_times}: #{method_signature}"
message << "; #{@ordering_constraints.map(&:mocha_inspect).join('; ')}" unless @ordering_constraints.empty?
strings = ["#{@cardinality.anticipated_times}, #{@cardinality.invoked_times}: #{method_signature}"]
strings << "; #{@ordering_constraints.map(&:mocha_inspect).join('; ')}" unless @ordering_constraints.empty?
if Mocha.configuration.display_matching_invocations_on_failure?
message << @cardinality.actual_invocations
strings << @cardinality.actual_invocations
end
message
strings.join
end

# @private
def method_signature
signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
signature << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
signature
strings = ["#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"]
strings << " #{@block_matcher.mocha_inspect}" if @block_matcher.mocha_inspect
strings.join
end

# @private
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/expectation_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
# Default exception class raised when an unexpected invocation or an unsatisfied expectation occurs.
#
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/expectation_error_factory.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/backtrace_filter'
require 'mocha/expectation_error'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/expectation_list.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class ExpectationList
def initialize(expectations = [])
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/hooks.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/mockery'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/in_state_ordering_constraint.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class InStateOrderingConstraint
def initialize(state_predicate)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/inspect.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'date'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/instance_method.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/stubbed_method'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/assertion_counter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
module Integration
class AssertionCounter
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/detection/minitest'
require 'mocha/integration/minitest/adapter'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/minitest/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/api'
require 'mocha/integration/assertion_counter'
require 'mocha/expectation_error_factory'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/minitest/exception_translation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/expectation_error'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/monkey_patcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/api'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/test_unit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/detection/test_unit'
require 'mocha/integration/test_unit/adapter'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/integration/test_unit/adapter.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/api'
require 'mocha/integration/assertion_counter'
require 'mocha/expectation_error'
Expand Down
14 changes: 8 additions & 6 deletions lib/mocha/invocation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameters_matcher'
require 'mocha/raised_exception'
require 'mocha/return_values'
Expand Down Expand Up @@ -44,19 +46,19 @@ def arguments
end

def call_description
description = "#{@mock.mocha_inspect}.#{@method_name}#{argument_description}"
description << ' { ... }' unless @block.nil?
description
strings = ["#{@mock.mocha_inspect}.#{@method_name}#{argument_description}"]
strings << ' { ... }' unless @block.nil?
strings.join
end

def short_call_description
"#{@method_name}(#{@arguments.join(', ')})"
end

def result_description
desc = "# => #{@result.mocha_inspect}"
desc << " after yielding #{@yields.map(&:mocha_inspect).join(', then ')}" if @yields.any?
desc
strings = ["# => #{@result.mocha_inspect}"]
strings << " after yielding #{@yields.map(&:mocha_inspect).join(', then ')}" if @yields.any?
strings.join
end

def full_description
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/is_a.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class Object
# :stopdoc:

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/logger.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class Logger
def initialize(io)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/macos_version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
MACOS = /darwin/.match(RUBY_PLATFORM)
MACOS_VERSION = MACOS && /darwin(\d+)/.match(RUBY_PLATFORM)[1].to_i
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/method_matcher.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class MethodMatcher
attr_reader :expected_method_name
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/minitest.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/ruby_version'
require 'mocha/integration/minitest'

Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/mock.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'ruby2_keywords'
require 'mocha/expectation'
require 'mocha/expectation_list'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/mockery.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/central'
require 'mocha/mock'
require 'mocha/names'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/names.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
class ImpersonatingName
def initialize(object)
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/not_initialized_error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/error_with_filtered_backtrace'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/object_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/mockery'
require 'mocha/instance_method'
require 'mocha/argument_iterator'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
# Used as parameters for {Expectation#with} to restrict the parameter values which will match the expectation. Can be nested.
module ParameterMatchers; end
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/all_of.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/any_of.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/any_parameters.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/anything.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/base.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Mocha
module ParameterMatchers
# @abstract Subclass and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {#equals}.
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/equals.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/equivalent_uri.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'
require 'uri'
require 'cgi'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/has_entries.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'
require 'mocha/parameter_matchers/all_of'
require 'mocha/parameter_matchers/has_entry'
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/has_entry.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/has_key.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/has_keys.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/has_value.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/base'

module Mocha
Expand Down
2 changes: 2 additions & 0 deletions lib/mocha/parameter_matchers/includes.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mocha/parameter_matchers/all_of'
require 'mocha/parameter_matchers/base'

Expand Down
Loading

0 comments on commit 1c5dda3

Please sign in to comment.