hanami-rspec 2.1.0.beta1 → 2.1.0.rc1

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: 269b1419c457289578dcba75f394d7063c4ae93c508e7cef167c6e539909cda2
4
- data.tar.gz: 3878122758804f81133387645f8f3f2e8ec0471793f6ecebce95ee83e1fe5f74
3
+ metadata.gz: dbf21d5b7746adf7037bf9028868a3e0e101696f2d2a6b943683ca7e0243b37e
4
+ data.tar.gz: 8239bea8a08ac6e60aa45681a5979bbe5a72da970c3ac06a125b7cfb1360918a
5
5
  SHA512:
6
- metadata.gz: a76436f24498e5ac580014a30e509fc6595267392a7425ac470514c0cc04a4cd8b1aeaf1bd7ff1357b791947c0c81a0f5ae10763475a6d9f8b7427a261a21a68
7
- data.tar.gz: 39c5b148b7062e6892a31979eeade944e3f88274d8a58a1d5473649581b38eca1228449755b73fb9aed6db69c15a30286941c889d472e4cf5d1ba01cd0d097a7
6
+ metadata.gz: 4a4fe2ff34cdb0599c2352db2d2ff068ee414b199758d1bf2133b4442bf06917e5918cb41b8d3c83fdaa6baa8b9ab9b851235295dbc574bc64fbd0592e3ee7a3
7
+ data.tar.gz: 955846cdaefbec231159dcdf96d2424a2449afda08bc650b33d68c7d6f5410b16026f1047781bdff3c36646e66e02467cbcaa457e480f4b009d31a254f45cd10
data/CHANGELOG.md CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  RSpec support for Hanami
4
4
 
5
+ ## v2.1.0.rc1 - 2023-11-01
6
+
7
+ ### Added
8
+
9
+ - [Luca Guidi] Generate spec for `hanami generate part` command
10
+
11
+ ### Changed
12
+
13
+ - [Luca Guidi] Default request spec to expect 404, now that `hanami new` doesn't generate a default root route anymore
14
+
5
15
  ## v2.1.0.beta1 - 2023-06-29
6
16
 
7
17
  ## v2.0.1 - 2022-12-25
@@ -99,6 +99,21 @@ module Hanami
99
99
  generator.call(app.namespace, slice, controller, action)
100
100
  end
101
101
  end
102
+
103
+ # @since 2.1.0
104
+ # @api private
105
+ class Part < Hanami::CLI::Commands::App::Command
106
+ # @since 2.1.0
107
+ # @api private
108
+ def call(options, **)
109
+ # FIXME: dry-cli kwargs aren't correctly forwarded in Ruby 3
110
+ slice = inflector.underscore(Shellwords.shellescape(options[:slice])) if options[:slice]
111
+ name = inflector.underscore(Shellwords.shellescape(options[:name]))
112
+
113
+ generator = Generators::Part.new(fs: fs, inflector: inflector)
114
+ generator.call(app.namespace, slice, name)
115
+ end
116
+ end
102
117
  end
103
118
  end
104
119
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe <%= camelized_app_name %>::Views::Part do
4
+ <%- if ruby_omit_hash_values? -%>
5
+ subject { described_class.new(value:) }
6
+ <%- else -%>
7
+ subject { described_class.new(value: value) }
8
+ <%- end -%>
9
+ let(:value) { double("value") }
10
+
11
+ it "works" do
12
+ expect(subject).to be_kind_of(described_class)
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe <%= camelized_slice_name %>::Views::Part do
4
+ <%- if ruby_omit_hash_values? -%>
5
+ subject { described_class.new(value:) }
6
+ <%- else -%>
7
+ subject { described_class.new(value: value) }
8
+ <%- end -%>
9
+ let(:value) { double("value") }
10
+
11
+ it "works" do
12
+ expect(subject).to be_kind_of(described_class)
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe <%= camelized_slice_name %>::Views::Parts::<%= camelized_name %> do
4
+ <%- if ruby_omit_hash_values? -%>
5
+ subject { described_class.new(value:) }
6
+ <%- else -%>
7
+ subject { described_class.new(value: value) }
8
+ <%- end -%>
9
+ let(:value) { double("<%= underscored_name %>") }
10
+
11
+ it "works" do
12
+ expect(subject).to be_kind_of(described_class)
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe <%= camelized_app_name %>::Views::Parts::<%= camelized_name %> do
4
+ <%- if ruby_omit_hash_values? -%>
5
+ subject { described_class.new(value:) }
6
+ <%- else -%>
7
+ subject { described_class.new(value: value) }
8
+ <%- end -%>
9
+ let(:value) { double("<%= underscored_name %>") }
10
+
11
+ it "works" do
12
+ expect(subject).to be_kind_of(described_class)
13
+ end
14
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+
5
+ module Hanami
6
+ module RSpec
7
+ module Generators
8
+ # @since 2.1.0
9
+ # @api private
10
+ class Part
11
+ # @since 2.1.0
12
+ # @api private
13
+ def initialize(fs:, inflector:)
14
+ @fs = fs
15
+ @inflector = inflector
16
+ end
17
+
18
+ # @since 2.1.0
19
+ # @api private
20
+ def call(app, slice, name, context: Hanami::CLI::Generators::App::PartContext.new(inflector, app, slice, name))
21
+ if slice
22
+ generate_for_slice(slice, context)
23
+ else
24
+ generate_for_app(context)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ # @since 2.1.0
31
+ # @api private
32
+ def generate_for_slice(slice, context)
33
+ generate_base_part_for_app(context)
34
+ generate_base_part_for_slice(context, slice)
35
+
36
+ fs.write(
37
+ "spec/slices/#{slice}/views/parts/#{context.underscored_name}_spec.rb",
38
+ t("part_slice_spec.erb", context)
39
+ )
40
+ end
41
+
42
+ # @since 2.1.0
43
+ # @api private
44
+ def generate_for_app(context)
45
+ generate_base_part_for_app(context)
46
+
47
+ fs.write(
48
+ "spec/views/parts/#{context.underscored_name}_spec.rb",
49
+ t("part_spec.erb", context)
50
+ )
51
+ end
52
+
53
+ # @since 2.1.0
54
+ # @api private
55
+ def generate_base_part_for_app(context)
56
+ path = fs.join("spec", "views", "part_spec.rb")
57
+ return if fs.exist?(path)
58
+
59
+ fs.write(
60
+ path,
61
+ t("part_base_spec.erb", context)
62
+ )
63
+ end
64
+
65
+ # @since 2.1.0
66
+ # @api private
67
+ def generate_base_part_for_slice(context, slice)
68
+ path = "spec/slices/#{slice}/views/part_spec.rb"
69
+ return if fs.exist?(path)
70
+
71
+ fs.write(
72
+ path,
73
+ t("part_slice_base_spec.erb", context)
74
+ )
75
+ end
76
+
77
+ # @since 2.1.0
78
+ # @api private
79
+ attr_reader :fs
80
+
81
+ # @since 2.1.0
82
+ # @api private
83
+ attr_reader :inflector
84
+
85
+ # @since 2.1.0
86
+ # @api private
87
+ def template(path, context)
88
+ require "erb"
89
+
90
+ ERB.new(
91
+ File.read(__dir__ + "/part/#{path}"),
92
+ trim_mode: "-"
93
+ ).result(context.ctx)
94
+ end
95
+
96
+ # @since 2.1.0
97
+ # @api private
98
+ alias_method :t, :template
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.describe "Root", type: :request do
4
- it "is successful" do
4
+ it "is not found" do
5
5
  get "/"
6
6
 
7
- # Find me in `config/routes.rb`
8
- expect(last_response).to be_successful
9
- expect(last_response.body).to eq("Hello from Hanami")
7
+ # Generate new action via:
8
+ # `bundle exec hanami generate action home.index --url=/`
9
+ expect(last_response.status).to be(404)
10
10
  end
11
11
  end
@@ -6,6 +6,6 @@ module Hanami
6
6
  #
7
7
  # @since 2.0.0
8
8
  # @api public
9
- VERSION = "2.1.0.beta1"
9
+ VERSION = "2.1.0.rc1"
10
10
  end
11
11
  end
data/lib/hanami/rspec.rb CHANGED
@@ -35,6 +35,7 @@ module Hanami
35
35
  Hanami::CLI.after "install", Commands::Install
36
36
  Hanami::CLI.after "generate slice", Commands::Generate::Slice
37
37
  Hanami::CLI.after "generate action", Commands::Generate::Action
38
+ Hanami::CLI.after "generate part", Commands::Generate::Part
38
39
  end
39
40
  end
40
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.beta1
4
+ version: 2.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-29 00:00:00.000000000 Z
11
+ date: 2023-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-cli
@@ -109,6 +109,11 @@ files:
109
109
  - lib/hanami/rspec/generators/dotrspec
110
110
  - lib/hanami/rspec/generators/gemfile
111
111
  - lib/hanami/rspec/generators/helper.rb
112
+ - lib/hanami/rspec/generators/part.rb
113
+ - lib/hanami/rspec/generators/part/part_base_spec.erb
114
+ - lib/hanami/rspec/generators/part/part_slice_base_spec.erb
115
+ - lib/hanami/rspec/generators/part/part_slice_spec.erb
116
+ - lib/hanami/rspec/generators/part/part_spec.erb
112
117
  - lib/hanami/rspec/generators/request.rb
113
118
  - lib/hanami/rspec/generators/slice.rb
114
119
  - lib/hanami/rspec/generators/slice/action_spec.erb