hanami-rspec 2.0.1 → 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: d165f3b5190d2f5c4ca7b33f28570ce3fdd696bd14da89cabedb710d433a42b9
4
- data.tar.gz: 4ed2cde06e1a09a9d05679e184db40c8e5d578b3e259e3cecd151b433371c34c
3
+ metadata.gz: dbf21d5b7746adf7037bf9028868a3e0e101696f2d2a6b943683ca7e0243b37e
4
+ data.tar.gz: 8239bea8a08ac6e60aa45681a5979bbe5a72da970c3ac06a125b7cfb1360918a
5
5
  SHA512:
6
- metadata.gz: edd319a20e32f589479134941d0275a41e80305e3964f1247532075ba5f48809d0fa0a1d186759e0879548b580764807813fb4b7c8e02e7052201d2af5bce101
7
- data.tar.gz: 2f938a13f5a1fa2a13d76fc82c919e6d19fab5ea2140048e53a3083af4ff5766fac1f3020002b19144901f1a6f683da9829da1af614324eefc7e9c4bef6a1a71
6
+ metadata.gz: 4a4fe2ff34cdb0599c2352db2d2ff068ee414b199758d1bf2133b4442bf06917e5918cb41b8d3c83fdaa6baa8b9ab9b851235295dbc574bc64fbd0592e3ee7a3
7
+ data.tar.gz: 955846cdaefbec231159dcdf96d2424a2449afda08bc650b33d68c7d6f5410b16026f1047781bdff3c36646e66e02467cbcaa457e480f4b009d31a254f45cd10
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
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
+
15
+ ## v2.1.0.beta1 - 2023-06-29
16
+
5
17
  ## v2.0.1 - 2022-12-25
6
18
 
7
19
  ### Added
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright © 2014 Hanami Team
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -57,4 +57,4 @@ Everyone interacting in the `Hanami::RSpec` project's codebases, issue trackers,
57
57
 
58
58
  ## Copyright
59
59
 
60
- Copyright © 2014-2022 Hanami Team – Released under MIT License
60
+ Copyright © 2014 Hanami Team – Released under MIT License
@@ -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.0.1"
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.0.1
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: 2022-12-25 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
@@ -94,7 +94,7 @@ files:
94
94
  - CHANGELOG.md
95
95
  - CODE_OF_CONDUCT.md
96
96
  - Gemfile
97
- - LICENSE.txt
97
+ - LICENSE.md
98
98
  - README.md
99
99
  - Rakefile
100
100
  - bin/console
@@ -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
@@ -139,11 +144,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
139
144
  version: 3.0.0
140
145
  required_rubygems_version: !ruby/object:Gem::Requirement
141
146
  requirements:
142
- - - ">="
147
+ - - ">"
143
148
  - !ruby/object:Gem::Version
144
- version: '0'
149
+ version: 1.3.1
145
150
  requirements: []
146
- rubygems_version: 3.4.1
151
+ rubygems_version: 3.4.13
147
152
  signing_key:
148
153
  specification_version: 4
149
154
  summary: Hanami RSpec
data/LICENSE.txt DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2021 Luca Guidi
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.