magic-support 0.1.0 → 0.2.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: 9f7037e20104047261af68821013d1bc6b2bb56fdd45b6f598d3cd59cf0eac11
4
- data.tar.gz: c03b20aa6bf855ea037ec6779cb7c396705c7daed59a44fff7b515b82c63b6a9
3
+ metadata.gz: fa812d41502d5c332298c520006236fb6c6535e8403e0beb253354712f7694e8
4
+ data.tar.gz: 2029e9de5202d7c451264ae71ef471d76723e89451556b3db6c511b51102f05d
5
5
  SHA512:
6
- metadata.gz: 9b8d8c4f7b1af05776084e0a87839b357e9653267cac8c00a0fcd6f27e975e84f2b0b581ad3bbceecb1d5c45433334c0afbb6e11cd86c676a28593f6b3354673
7
- data.tar.gz: 6bac701a2559fa55207d088da2d004b2d7e0cc012007f352e6c9d45fdcd577aa094fb71b1afbae1b7ade2be7706a1cc4846cfe45cdfa55299156b52028d8b6f7
6
+ metadata.gz: 987615bca255fc3fe46178003bcea2e96df7ce8b55ae07f3b73551c8631209ddb0dea1da5931bc48396b1c983538507b96c185ebde57cbbcab40e828366753fc
7
+ data.tar.gz: 4cce946f3b7dc0211041516e9d9fa5ab083b6610af51fd63e9f2f062bbedd5d383bb4039d4e6c7f02a0009272f938fe826480b782f9229c6a1b22308a82e5499
data/.rubocop.yml CHANGED
@@ -2,6 +2,6 @@ inherit_from:
2
2
  - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop.yml
3
3
  - https://github.com/Alexander-Senko/Alexander-Senko/raw/refs/heads/main/.rubocop-rspec.yml
4
4
 
5
- require:
5
+ plugins:
6
6
  - rubocop-rspec
7
7
  - rubocop-rake
data/CHANGELOG.md CHANGED
@@ -1,3 +1,19 @@
1
+ ## [0.2.0] — 2025-05-13
2
+
3
+ ### RSpec
4
+
5
+ #### Method specs
6
+
7
+ ##### Added
8
+
9
+ - Receiver objects are exposed via `receiver`.
10
+ - Emit warnings on missing methods.
11
+
12
+ ##### Fixed
13
+
14
+ - Don’t swallow unrelated name errors.
15
+
16
+
1
17
  ## [0.1.0] — 2024-11-28
2
18
 
3
19
  ### Added
data/README.md CHANGED
@@ -19,18 +19,16 @@ It’s inspired by [Active Support](
19
19
 
20
20
  ## Installation
21
21
 
22
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
23
-
24
- Install the gem and add to the application's Gemfile by executing:
22
+ Install the gem and add to the application’s Gemfile by executing:
25
23
 
26
24
  ```bash
27
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
25
+ bundle add magic-support
28
26
  ```
29
27
 
30
- If bundler is not being used to manage dependencies, install the gem by executing:
28
+ If Bundler is not being used to manage dependencies, install the gem by executing:
31
29
 
32
30
  ```bash
33
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
31
+ gem install magic-support
34
32
  ```
35
33
 
36
34
  ## Core extensions
@@ -107,7 +105,7 @@ It holds authors info to be used primarily in gem specs.
107
105
  Pre-install Magic Support if you plan to use `Gem::Author` in your gemspec.
108
106
 
109
107
  ```bash
110
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
108
+ gem install magic-support
111
109
  ```
112
110
 
113
111
  #### Usage
@@ -186,6 +184,7 @@ In cases when the method couldn’t be found (e.g., due to delegation via `metho
186
184
  instead.
187
185
  Anyway, one may treat it as something _callable_.
188
186
 
187
+ A receiver object is exposed via `receiver`.
189
188
  A method name is exposed as a `Symbol` via `method_name`.
190
189
 
191
190
  > [!NOTE]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'magic/core_ext'
3
+ require_relative 'utils'
4
4
 
5
5
  Magic::CoreExt.kernel do
6
6
  # Yields self to the block and returns the result of the block if it’s
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Magic # :nodoc:
4
+ module CoreExt # :nodoc:
5
+ module Kernel
6
+ # Some classes copy Kernel methods on initialization instead of
7
+ # including Kernel itself. Thus, new methods should be defined
8
+ # explicitly for them.
9
+ MODULES = [ # classes/modules including Kernel methods
10
+ ::Kernel,
11
+ (Delegator if defined? Delegator),
12
+ ].compact.freeze
13
+ end
14
+
15
+ module_function
16
+
17
+ def kernel(&)
18
+ Module.new(&).tap do |kernel|
19
+ Kernel::MODULES.each { _1.include kernel }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,27 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'magic/core_ext'
3
+ require 'magic/loader'
4
4
 
5
- module Magic # :nodoc:
6
- module CoreExt # :nodoc:
7
- module Kernel
8
- # Some classes copy Kernel methods on initialization instead of
9
- # including Kernel itself. Thus, new methods should be defined
10
- # explicitly for them.
11
- MODULES = [ # classes/modules including Kernel methods
12
- ::Kernel,
13
- (Delegator if defined? Delegator),
14
- ].compact.freeze
15
- end
16
-
17
- module_function
18
-
19
- def kernel(&)
20
- Module.new(&).tap do |kernel|
21
- Kernel::MODULES.each { _1.include kernel }
22
- end
23
- end
24
- end
25
-
26
- CoreExt.require_all __FILE__
27
- end
5
+ Magic::Loader.require_all
@@ -1,17 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Magic # :nodoc:
4
- module CoreExt # :nodoc:
5
- module_function
3
+ require 'magic/loader'
6
4
 
7
- def require_all scope = __FILE__
8
- scope
9
- .delete_suffix('.rb')
10
- .then { Pathname _1 }
11
- .glob('*.rb')
12
- .each { require _1 }
13
- end
14
- end
15
-
16
- CoreExt.require_all
17
- end
5
+ Magic::Loader.require_all
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+
5
+ module Magic # :nodoc:
6
+ module Loader # :nodoc:
7
+ module_function
8
+
9
+ def require_all scope = caller_locations[0].path
10
+ Pathname(scope)
11
+ .sub_ext('')
12
+ .glob('*.rb')
13
+ .each { require _1 }
14
+ end
15
+ end
16
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Magic
4
4
  module Support
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
data/lib/rspec/method.rb CHANGED
@@ -30,22 +30,15 @@ module RSpec # :nodoc:
30
30
  subject_method = subject_method.super_method or break
31
31
  end
32
32
 
33
- define_method :subject do
34
- receiver =
35
- case [ scope, subject_method&.bind_call(self) || super() ]
36
- in '#', receiver
37
- receiver
38
- in '.', Module => receiver
39
- receiver
40
- in '.', receiver
41
- receiver.class
42
- end
43
-
44
- receiver.method name
45
- rescue NameError
46
- # TODO: emit a warning
47
-
48
- -> *args { receiver.send name, *args }
33
+ let :receiver do
34
+ case [ scope, subject_method&.bind_call(self) || super() ]
35
+ in '#', receiver
36
+ receiver
37
+ in '.', Module => receiver
38
+ receiver
39
+ in '.', receiver
40
+ receiver.class
41
+ end
49
42
  end
50
43
 
51
44
  let(:method_name) { name.to_sym }
@@ -62,6 +55,17 @@ module RSpec # :nodoc:
62
55
 
63
56
  def its_result(*args, &) = its(args, &)
64
57
  end
58
+
59
+ def subject
60
+ receiver.method method_name
61
+ rescue NameError => error
62
+ raise unless
63
+ (receiver.is_a? error.receiver rescue false)
64
+
65
+ warn "Testing #{error}"
66
+
67
+ -> *args { receiver.send method_name, *args }
68
+ end
65
69
  end
66
70
  end
67
71
 
@@ -1,7 +1,5 @@
1
1
  module Magic
2
2
  module CoreExt
3
- def require_all: (?String) -> Array[Pathname]
4
-
5
3
  def kernel: () { () -> void } -> Module
6
4
  end
7
5
  end
@@ -0,0 +1,5 @@
1
+ module Magic
2
+ module Loader
3
+ def require_all: (?(String | Pathname)) -> Array[Pathname]
4
+ end
5
+ end
data/sig/rspec/method.rbs CHANGED
@@ -1,5 +1,9 @@
1
1
  module RSpec
2
2
  module Method
3
3
  REFERENCE: Regexp
4
+
5
+ module ExampleGroup
6
+ def subject: () -> (::Method | Proc)
7
+ end
4
8
  end
5
9
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magic-support
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Senko
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2024-11-28 00:00:00.000000000 Z
10
+ date: 2025-05-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -40,6 +40,8 @@ files:
40
40
  - lib/magic/core_ext.rb
41
41
  - lib/magic/core_ext/kernel.rb
42
42
  - lib/magic/core_ext/kernel/optional.rb
43
+ - lib/magic/core_ext/kernel/utils.rb
44
+ - lib/magic/loader.rb
43
45
  - lib/magic/support.rb
44
46
  - lib/magic/support/authors.rb
45
47
  - lib/magic/support/version.rb
@@ -48,6 +50,7 @@ files:
48
50
  - sig/lib/magic/support/author.rbs
49
51
  - sig/magic/core_ext.rbs
50
52
  - sig/magic/core_ext/kernel.rbs
53
+ - sig/magic/loader.rbs
51
54
  - sig/magic/support.rbs
52
55
  - sig/rspec/method.rbs
53
56
  - sig/rubygems/author.rbs
@@ -56,7 +59,7 @@ licenses:
56
59
  - MIT
57
60
  metadata:
58
61
  source_code_uri: https://github.com/Alexander-Senko/magic-support
59
- changelog_uri: https://github.com/Alexander-Senko/magic-support/blob/v0.1.0/CHANGELOG.md
62
+ changelog_uri: https://github.com/Alexander-Senko/magic-support/blob/v0.2.0/CHANGELOG.md
60
63
  rdoc_options: []
61
64
  require_paths:
62
65
  - lib
@@ -71,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
74
  - !ruby/object:Gem::Version
72
75
  version: '0'
73
76
  requirements: []
74
- rubygems_version: 3.6.0.dev
77
+ rubygems_version: 3.6.5
75
78
  specification_version: 4
76
79
  summary: Active Support extended
77
80
  test_files: []