hanami-rspec 2.2.1 → 2.3.0.beta1

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: 545929e2a6c13aa7f5052858fe8fba43163558c730c512ba3a7ff9764f8ad6f8
4
- data.tar.gz: 26be07463cb1646c6111d32dbcd208ce44e1cc7cb319787fdb92ad9f914d4380
3
+ metadata.gz: 47867e59208a120e7f584b7df9f4c5c75616d5d25d98c7c142d7e59724a036cb
4
+ data.tar.gz: b9a3751317444dffc651cec5a849d5dfcefdbf08a339205bfa720dd00eaf3427
5
5
  SHA512:
6
- metadata.gz: 84de26024f511da7b7a741852f657f7f5c27f17faa3948d499a605abf6a18f57b7f0047aeeee2beeebba58796120f4dc6e972f12b355bef620bad9952966bf40
7
- data.tar.gz: b9484baf4dbd6a3cf9bed838de729f3aa033d60a488661f738f7dcb1f662c995bbe490a9dd20e5b3245f0b73af77c78b8e9464c40aaab99508498da874afd835
6
+ metadata.gz: 8ad71b96324dbf80cb0834a3c8c1a4977a479e4c415cf77b0cfbc813f6cf819a30bc678bebdad6a662f246e76207d05f60f14344594ca82115337dc717543790
7
+ data.tar.gz: 48c531c0bed9b553fea85d7848a059bc4b64de7135651bd035f5e8c98106a3f4a60cad9bc0a789f5a60a9feaeaeffa6bcf2ccaf35c31f2910b7027f9d7679fa1
@@ -14,6 +14,7 @@ jobs:
14
14
  fail-fast: false
15
15
  matrix:
16
16
  ruby:
17
+ - "3.4"
17
18
  - "3.3"
18
19
  - "3.2"
19
20
  - "3.1"
data/.rubocop.yml CHANGED
@@ -16,6 +16,8 @@ Style/BlockDelimiters:
16
16
  Enabled: false
17
17
  Style/CommentedKeyword:
18
18
  Enabled: false
19
+ Style/HashSyntax:
20
+ EnforcedShorthandSyntax: either_consistent
19
21
  Style/LambdaCall:
20
22
  Enabled: false
21
23
  Style/TrailingCommaInArguments:
data/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  RSpec support for Hanami
4
4
 
5
+ ## v2.3.0.beta1 - 2025-10-03
6
+
7
+ ## Changed
8
+
9
+ - [Aaron Allen] Change shared context name in generated `spec/support/requests.rb` to avoid a RuboCop RSpec offense (#40)
10
+
5
11
  ## v2.2.1 - 2024-11-12
6
12
 
7
13
  ### Changed
data/Gemfile CHANGED
@@ -8,10 +8,6 @@ unless ENV["CI"]
8
8
  gem "yard"
9
9
  end
10
10
 
11
- gem "dry-files", github: "dry-rb/dry-files", branch: "main"
12
- gem "dry-logger", github: "dry-rb/dry-logger", branch: "main"
13
- gem "dry-system", github: "dry-rb/dry-system", branch: "main"
14
-
15
11
  gem "hanami-utils", github: "hanami/utils", branch: "main"
16
12
  gem "hanami-cli", github: "hanami/cli", branch: "main"
17
13
  gem "hanami", github: "hanami/hanami", branch: "main"
data/hanami-rspec.gemspec CHANGED
@@ -29,7 +29,7 @@ Gem::Specification.new do |spec|
29
29
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
30
  spec.require_paths = ["lib"]
31
31
 
32
- spec.add_dependency "hanami-cli", "~> 2.2"
32
+ spec.add_dependency "hanami-cli", "~> 2.3.0.beta1"
33
33
  spec.add_dependency "rspec", "~> 3.12"
34
34
  spec.add_dependency "rake", "~> 13.0"
35
35
  spec.add_dependency "zeitwerk", "~> 2.6"
@@ -134,11 +134,13 @@ module Hanami
134
134
  return if options[:skip_tests]
135
135
 
136
136
  slice = inflector.underscore(Shellwords.shellescape(options[:slice])) if options[:slice]
137
- name = inflector.underscore(Shellwords.shellescape(options[:name]))
138
- *controller, action = name.split(ACTION_SEPARATOR)
137
+ key = inflector.underscore(Shellwords.shellescape(options[:name]))
138
+
139
+ namespace = slice ? inflector.camelize(slice) : app.namespace
140
+ base_path = slice ? "spec/slices/#{slice}" : "spec"
139
141
 
140
- generator = Generators::Action.new(fs: fs, inflector: inflector)
141
- generator.call(app.namespace, slice, controller, action)
142
+ generator = Generators::Action.new(fs:, inflector:)
143
+ generator.call(key:, namespace:, base_path:)
142
144
  end
143
145
  end
144
146
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "erb"
3
+ require "hanami/cli/generators/app/ruby_class_file"
4
4
 
5
5
  module Hanami
6
6
  module RSpec
@@ -17,41 +17,43 @@ module Hanami
17
17
 
18
18
  # @since 2.0.0
19
19
  # @api private
20
- def call(app, slice, controller, action, context: Hanami::CLI::Generators::App::ActionContext.new(inflector, app, slice, controller, action)) # rubocop:disable Layout/LineLength
21
- if slice
22
- fs.write(
23
- "spec/slices/#{slice}/actions/#{controller_directory(controller)}/#{action}_spec.rb",
24
- t("action_slice_spec.erb", context)
25
- )
26
- else
27
- fs.write(
28
- "spec/actions/#{controller_directory(controller)}/#{action}_spec.rb",
29
- t("action_spec.erb", context)
30
- )
31
- end
20
+ def call(key:, namespace:, base_path:)
21
+ ruby_class_file = action_ruby_class_file(key: key, namespace: namespace, base_path: base_path)
22
+ spec_file_path = ruby_class_file.path.gsub(/\.rb$/, "_spec.rb")
23
+ action_class_name = ruby_class_file.fully_qualified_name
24
+
25
+ fs.write(spec_file_path, spec_content(action_class_name))
32
26
  end
33
27
 
34
28
  private
35
29
 
36
- attr_reader :fs
37
-
38
- attr_reader :inflector
39
-
40
- # @api private
41
- # @param controller [Array<String>]
42
- def controller_directory(controller)
43
- fs.join(controller)
30
+ attr_reader :fs, :inflector
31
+
32
+ def action_ruby_class_file(key:, namespace:, base_path:)
33
+ Hanami::CLI::Generators::App::RubyClassFile.new(
34
+ fs: fs,
35
+ inflector: inflector,
36
+ namespace: namespace,
37
+ key: inflector.underscore(key),
38
+ base_path: base_path,
39
+ extra_namespace: "Actions",
40
+ )
44
41
  end
45
42
 
46
- def template(path, context)
47
- require "erb"
43
+ def spec_content(class_name)
44
+ <<~RUBY
45
+ # frozen_string_literal: true
48
46
 
49
- ERB.new(
50
- File.read(__dir__ + "/action/#{path}")
51
- ).result(context.ctx)
52
- end
47
+ RSpec.describe #{class_name} do
48
+ let(:params) { Hash[] }
53
49
 
54
- alias_method :t, :template
50
+ it "works" do
51
+ response = subject.call(params)
52
+ expect(response).to be_successful
53
+ end
54
+ end
55
+ RUBY
56
+ end
55
57
  end
56
58
  end
57
59
  end
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe <%= camelized_app_name %>::Views::Part do
4
- <%- if ruby_omit_hash_values? -%>
5
4
  subject { described_class.new(value:) }
6
- <%- else -%>
7
- subject { described_class.new(value: value) }
8
- <%- end -%>
9
5
  let(:value) { double("value") }
10
6
 
11
7
  it "works" do
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe <%= camelized_slice_name %>::Views::Part do
4
- <%- if ruby_omit_hash_values? -%>
5
4
  subject { described_class.new(value:) }
6
- <%- else -%>
7
- subject { described_class.new(value: value) }
8
- <%- end -%>
9
5
  let(:value) { double("value") }
10
6
 
11
7
  it "works" do
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe <%= camelized_slice_name %>::Views::Parts::<%= camelized_name %> do
4
- <%- if ruby_omit_hash_values? -%>
5
4
  subject { described_class.new(value:) }
6
- <%- else -%>
7
- subject { described_class.new(value: value) }
8
- <%- end -%>
9
5
  let(:value) { double("<%= underscored_name %>") }
10
6
 
11
7
  it "works" do
@@ -1,11 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe <%= camelized_app_name %>::Views::Parts::<%= camelized_name %> do
4
- <%- if ruby_omit_hash_values? -%>
5
4
  subject { described_class.new(value:) }
6
- <%- else -%>
7
- subject { described_class.new(value: value) }
8
- <%- end -%>
9
5
  let(:value) { double("<%= underscored_name %>") }
10
6
 
11
7
  it "works" do
@@ -17,7 +17,19 @@ module Hanami
17
17
 
18
18
  # @since 2.1.0
19
19
  # @api private
20
- def call(app, slice, name, context: Hanami::CLI::Generators::App::PartContext.new(inflector, app, slice, name))
20
+ def call(app, slice, name)
21
+ context = Struct.new(
22
+ :camelized_app_name,
23
+ :camelized_slice_name,
24
+ :camelized_name,
25
+ :underscored_name
26
+ ).new(
27
+ inflector.camelize(app),
28
+ slice ? inflector.camelize(slice) : nil,
29
+ inflector.camelize(name),
30
+ inflector.underscore(name)
31
+ )
32
+
21
33
  if slice
22
34
  generate_for_slice(slice, context)
23
35
  else
@@ -90,7 +102,7 @@ module Hanami
90
102
  ERB.new(
91
103
  File.read(__dir__ + "/part/#{path}"),
92
104
  trim_mode: "-"
93
- ).result(context.ctx)
105
+ ).result(context.instance_eval { binding })
94
106
  end
95
107
 
96
108
  # @since 2.1.0
@@ -17,7 +17,12 @@ module Hanami
17
17
 
18
18
  # @since 2.0.0
19
19
  # @api private
20
- def call(slice, context: Hanami::CLI::Generators::App::SliceContext.new(inflector, nil, slice, nil))
20
+ def call(slice)
21
+ context = Struct.new(:slice, :camelized_slice_name).new(
22
+ slice,
23
+ inflector.camelize(slice)
24
+ )
25
+
21
26
  fs.write("spec/slices/#{slice}/action_spec.rb", t("action_spec.erb", context))
22
27
  # fs.write("spec/slices/#{slice}/view_spec.rb", t("view_spec.erb", context))
23
28
  # fs.write("spec/slices/#{slice}/repository_spec.rb", t("repository_spec.erb", context))
@@ -41,7 +46,7 @@ module Hanami
41
46
 
42
47
  ERB.new(
43
48
  File.read(__dir__ + "/slice/#{path}")
44
- ).result(context.ctx)
49
+ ).result(context.instance_eval { binding })
45
50
  end
46
51
 
47
52
  alias_method :t, :template
@@ -2,12 +2,12 @@
2
2
 
3
3
  require "rack/test"
4
4
 
5
- RSpec.shared_context "Rack::Test" do
5
+ RSpec.shared_context "with Rack::Test" do
6
6
  # Define the app for Rack::Test requests
7
7
  let(:app) { Hanami.app }
8
8
  end
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.include Rack::Test::Methods, type: :request
12
- config.include_context "Rack::Test", type: :request
12
+ config.include_context "with Rack::Test", type: :request
13
13
  end
@@ -6,6 +6,6 @@ module Hanami
6
6
  #
7
7
  # @since 2.0.0
8
8
  # @api public
9
- VERSION = "2.2.1"
9
+ VERSION = "2.3.0.beta1"
10
10
  end
11
11
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2024-11-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: hanami-cli
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '2.2'
18
+ version: 2.3.0.beta1
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '2.2'
25
+ version: 2.3.0.beta1
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rspec
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -104,8 +103,6 @@ files:
104
103
  - lib/hanami/rspec.rb
105
104
  - lib/hanami/rspec/commands.rb
106
105
  - lib/hanami/rspec/generators/action.rb
107
- - lib/hanami/rspec/generators/action/action_slice_spec.erb
108
- - lib/hanami/rspec/generators/action/action_spec.erb
109
106
  - lib/hanami/rspec/generators/dotrspec
110
107
  - lib/hanami/rspec/generators/gemfile
111
108
  - lib/hanami/rspec/generators/gemfile_db
@@ -139,7 +136,6 @@ metadata:
139
136
  source_code_uri: https://github.com/hanami/rspec
140
137
  changelog_uri: https://github.com/hanami/rspec/blob/master/CHANGELOG.md
141
138
  rubygems_mfa_required: 'true'
142
- post_install_message:
143
139
  rdoc_options: []
144
140
  require_paths:
145
141
  - lib
@@ -154,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
150
  - !ruby/object:Gem::Version
155
151
  version: '0'
156
152
  requirements: []
157
- rubygems_version: 3.5.22
158
- signing_key:
153
+ rubygems_version: 3.6.9
159
154
  specification_version: 4
160
155
  summary: Hanami RSpec
161
156
  test_files: []
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe <%= camelized_slice_name %>::Actions::<%= camelized_controller_name %>::<%= camelized_action_name %> do
4
- let(:params) { Hash[] }
5
-
6
- it "works" do
7
- response = subject.call(params)
8
- expect(response).to be_successful
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe <%= camelized_app_name %>::Actions::<%= camelized_controller_name %>::<%= camelized_action_name %> do
4
- let(:params) { Hash[] }
5
-
6
- it "works" do
7
- response = subject.call(params)
8
- expect(response).to be_successful
9
- end
10
- end