mocha 3.0.2 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44d35f56fc0395b34a514c91a44a914ac782a500a4426db9e7c00aea8ae66c96
4
- data.tar.gz: 2be9168ce81c71de23b3ba15593184274098938bdad1108226231c3a70fdb172
3
+ metadata.gz: 12216e23b807fb2f1fd151d8f68ddd8fbbad2927a444cc563b192fe560ba0433
4
+ data.tar.gz: f5c3575c50f7a16d94fbb2c29b65de160c29cb3a84b460d84b0244a721028628
5
5
  SHA512:
6
- metadata.gz: d2fe09345542097c73fdc4594ed43d6d737b5927dd29672b79e1d94fce9550ab580c38d0855524eb193eed9b7969078e6e2ad62f11a78156e48288d27b907c78
7
- data.tar.gz: f17bfeb0fdc2ba83a65e69f515094c00da41b25de979b5bd75767b235fd9cc0e086673a7807d0b895474792a4760e81283b3bc0ba980e67899870f84c9dd638c
6
+ metadata.gz: e13297ea4d191863ddd889c7d64dccf0cd652734b46cbd1d04fec4c09c896923aba9fe09f15ce0c50982eb0ef22d892086ad5b8f661283f54ee9913d6c2cfa1e
7
+ data.tar.gz: ef2a1fafc1af00f43033742ebf2aff3870495bac17e0347607606026d3fa5e9cce961921371601cc0752e11501a7fbbf083d65a1743a318b873d7e2455fb4d2c
data/RELEASE.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Release Notes
2
2
 
3
+ ## 3.1.0
4
+
5
+ ### External changes
6
+
7
+ * Format warnings consistently and include source location (#794)
8
+
9
+ ### Internal changes
10
+
11
+ * Fix `Style/OneClassPerFile` violations (#796)
12
+ * Remove `mise.toml` which was added accidentally (6c5f84db)
13
+ * Add `.ruby-version` to `.gitignore` (8516ccc1)
14
+
3
15
  ## 3.0.2
4
16
 
5
17
  ### External changes
@@ -9,7 +9,17 @@ module Mocha
9
9
  end
10
10
 
11
11
  def filtered(backtrace)
12
- backtrace.reject { |location| File.expand_path(location).start_with?(@lib_directory) }
12
+ backtrace.reject { |line| exclude?(line) }
13
+ end
14
+
15
+ def filtered_locations(locations)
16
+ locations.reject { |location| exclude?(location.path) }
17
+ end
18
+
19
+ private
20
+
21
+ def exclude?(path)
22
+ File.expand_path(path).start_with?(@lib_directory)
13
23
  end
14
24
  end
15
25
  end
@@ -1,26 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/backtrace_filter'
3
+ require 'mocha/logger'
4
4
 
5
5
  module Mocha
6
6
  class Deprecation
7
- class Logger
8
- def call(message)
9
- filter = BacktraceFilter.new
10
- location = filter.filtered(caller)[0]
11
- warn "Mocha deprecation warning at #{location}: #{message}"
12
- end
13
- end
14
-
15
7
  class << self
16
- attr_writer :logger
17
-
18
8
  def warning(message)
19
- logger.call(message)
20
- end
21
-
22
- def logger
23
- @logger ||= Logger.new
9
+ Logger.warning(message, category: :deprecation)
24
10
  end
25
11
  end
26
12
  end
@@ -646,10 +646,10 @@ module Mocha
646
646
  end
647
647
 
648
648
  # @private
649
- attr_reader :backtrace
649
+ attr_reader :backtrace_locations
650
650
 
651
651
  # @private
652
- def initialize(mock, expected_method_name, backtrace = nil)
652
+ def initialize(mock, expected_method_name, backtrace_locations = nil)
653
653
  @mock = mock
654
654
  @method_matcher = MethodMatcher.new(expected_method_name.to_sym)
655
655
  @parameters_matcher = ParametersMatcher.new
@@ -659,7 +659,7 @@ module Mocha
659
659
  @cardinality = Cardinality.new.exactly(1)
660
660
  @return_values = ReturnValues.new
661
661
  @yield_parameters = YieldParameters.new
662
- @backtrace = backtrace || caller
662
+ @backtrace_locations = backtrace_locations || caller_locations
663
663
  end
664
664
 
665
665
  # @private
@@ -760,10 +760,16 @@ module Mocha
760
760
  strings.join
761
761
  end
762
762
 
763
+ # @private
764
+ def backtrace
765
+ backtrace_locations.map(&:to_s)
766
+ end
767
+
763
768
  # @private
764
769
  def definition_location
765
770
  filter = BacktraceFilter.new
766
- filter.filtered(backtrace)[0]
771
+ location = filter.filtered_locations(backtrace_locations)[0]
772
+ "#{location.path}:#{location.lineno}"
767
773
  end
768
774
  end
769
775
  end
data/lib/mocha/inspect.rb CHANGED
@@ -52,22 +52,12 @@ module Mocha
52
52
  end
53
53
  end
54
54
 
55
- class Object
56
- include Mocha::Inspect::ObjectMethods
57
- end
55
+ Object.include(Mocha::Inspect::ObjectMethods)
58
56
 
59
- class Array
60
- include Mocha::Inspect::ArrayMethods
61
- end
57
+ Array.include(Mocha::Inspect::ArrayMethods)
62
58
 
63
- class Hash
64
- include Mocha::Inspect::HashMethods
65
- end
59
+ Hash.include(Mocha::Inspect::HashMethods)
66
60
 
67
- class Time
68
- include Mocha::Inspect::TimeMethods
69
- end
61
+ Time.include(Mocha::Inspect::TimeMethods)
70
62
 
71
- class Date
72
- include Mocha::Inspect::DateMethods
73
- end
63
+ Date.include(Mocha::Inspect::DateMethods)
data/lib/mocha/logger.rb CHANGED
@@ -1,13 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'mocha/backtrace_filter'
4
+
3
5
  module Mocha
4
6
  class Logger
5
- def initialize(io)
6
- @io = io
7
+ class << self
8
+ attr_writer :logger
9
+
10
+ def warning(*args, **kwargs)
11
+ logger.warning(*args, **kwargs)
12
+ end
13
+
14
+ def logger
15
+ @logger ||= new
16
+ end
7
17
  end
8
18
 
9
- def warn(message)
10
- @io.puts "WARNING: #{message}"
19
+ def warning(message, category: nil)
20
+ filter = BacktraceFilter.new
21
+ location = filter.filtered_locations(caller_locations)[0]
22
+ prefix = ['Mocha', category, 'warning'].compact.join(' ')
23
+ warn("#{prefix}: #{message} (at #{location.path}:#{location.lineno})")
11
24
  end
12
25
  end
13
26
  end
data/lib/mocha/mockery.rb CHANGED
@@ -49,7 +49,6 @@ module Mocha
49
49
  def setup(assertion_counter)
50
50
  @instances ||= []
51
51
  mockery = new(assertion_counter)
52
- mockery.logger = instance.logger unless @instances.empty?
53
52
  @instances.push(mockery)
54
53
  end
55
54
 
@@ -149,12 +148,6 @@ module Mocha
149
148
  check(:stubbing_method_on_non_mock_object, 'method on non-mock object', signature_proc)
150
149
  end
151
150
 
152
- attr_writer :logger
153
-
154
- def logger
155
- @logger ||= Logger.new($stderr)
156
- end
157
-
158
151
  private
159
152
 
160
153
  def check(action, description, signature_proc, backtrace = caller)
@@ -165,7 +158,7 @@ module Mocha
165
158
  message = "stubbing #{description}: #{method_signature}"
166
159
  raise StubbingError.new(message, backtrace) if treatment == :prevent
167
160
 
168
- logger.warn(message) if treatment == :warn
161
+ Logger.warning(message) if treatment == :warn
169
162
  end
170
163
 
171
164
  def expectations
@@ -23,6 +23,6 @@ module Mocha
23
23
  end
24
24
 
25
25
  # @private
26
- class Object
26
+ class Object # rubocop:disable Style/OneClassPerFile
27
27
  include Mocha::ParameterMatchers::InstanceMethods
28
28
  end
data/lib/mocha/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Mocha
4
- VERSION = '3.0.2'
4
+ VERSION = '3.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
@@ -132,7 +132,6 @@ files:
132
132
  - lib/mocha/thrown_object.rb
133
133
  - lib/mocha/version.rb
134
134
  - lib/mocha/yield_parameters.rb
135
- - mise.toml
136
135
  - mocha.gemspec
137
136
  homepage: https://mocha.jamesmead.org
138
137
  licenses:
data/mise.toml DELETED
@@ -1,2 +0,0 @@
1
- [tools]
2
- ruby = "4.0.0"