hanami-rspec 2.1.0.beta1 → 2.1.0.rc2

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: 213e19981cb640eec5aca246cafc481ad481731099a0c58b391fcb41a17300c7
4
+ data.tar.gz: a67b4291aa541a722e5460bf403aa9f203d770476c3b3a0b823c7cb056f676e0
5
5
  SHA512:
6
- metadata.gz: a76436f24498e5ac580014a30e509fc6595267392a7425ac470514c0cc04a4cd8b1aeaf1bd7ff1357b791947c0c81a0f5ae10763475a6d9f8b7427a261a21a68
7
- data.tar.gz: 39c5b148b7062e6892a31979eeade944e3f88274d8a58a1d5473649581b38eca1228449755b73fb9aed6db69c15a30286941c889d472e4cf5d1ba01cd0d097a7
6
+ metadata.gz: 4c4d92b324e878aa771f045e592b1e35e6bb80f375dba7b9ac80bab120d29cb1ac06e036006dfe3ab504510b437f6ab99af94aed2d8b949ea0289f4e5bbbf604
7
+ data.tar.gz: 984fe9016a17887063c2e4e1545cf9b5344fb3faa7ce42cc22516912cdd1753c6f33cb99d72c33f264855df804266f81925c73b5e09b13b3bac64a850fdd1f00
data/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  RSpec support for Hanami
4
4
 
5
+ ## v2.1.0.rc2 - 2023-11-08
6
+
7
+ ### Added
8
+
9
+ - [Tim Riley] Skip generating tests for `hanami generate` when `--skip-tests` CLI option is given.
10
+ - [Tim Riley] Install Capybara and generate `spec/support/capybara.rb` in `hanami install` hook.
11
+
12
+ ### Changed
13
+
14
+ - [Tim Riley] Add explanatory code comments to `spec/support/rspec.rb` generated in `hanami install` hook.
15
+
16
+ ## v2.1.0.rc1 - 2023-11-01
17
+
18
+ ### Added
19
+
20
+ - [Luca Guidi] Generate spec for `hanami generate part` command
21
+
22
+ ### Changed
23
+
24
+ - [Luca Guidi] Default request spec to expect 404, now that `hanami new` doesn't generate a default root route anymore
25
+
5
26
  ## v2.1.0.beta1 - 2023-06-29
6
27
 
7
28
  ## v2.0.1 - 2022-12-25
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.0"
32
+ spec.add_dependency "hanami-cli", "~> 2.1.rc"
33
33
  spec.add_dependency "rspec", "~> 3.12"
34
34
  spec.add_dependency "rake", "~> 13.0"
35
35
  spec.add_dependency "zeitwerk", "~> 2.6"
@@ -14,9 +14,11 @@ module Hanami
14
14
  # @api private
15
15
  def call(*, **)
16
16
  append_gemfile
17
+ append_gitignore
17
18
  copy_dotrspec
18
19
  copy_spec_helper
19
20
  copy_support_rspec
21
+ copy_support_features
20
22
  copy_support_requests
21
23
 
22
24
  generate_request_spec
@@ -27,9 +29,14 @@ module Hanami
27
29
  def append_gemfile
28
30
  fs.append(
29
31
  fs.expand_path("Gemfile"),
30
- fs.read(
31
- fs.expand_path(fs.join("generators", "gemfile"), __dir__)
32
- ),
32
+ fs.read(fs.expand_path(fs.join("generators", "gemfile"), __dir__))
33
+ )
34
+ end
35
+
36
+ def append_gitignore
37
+ fs.append(
38
+ fs.expand_path(".gitignore"),
39
+ fs.read(fs.expand_path(fs.join("generators", "gitignore"), __dir__))
33
40
  )
34
41
  end
35
42
 
@@ -54,6 +61,13 @@ module Hanami
54
61
  )
55
62
  end
56
63
 
64
+ def copy_support_features
65
+ fs.cp(
66
+ fs.expand_path(fs.join("generators", "support_features.rb"), __dir__),
67
+ fs.expand_path(fs.join("spec", "support", "features.rb"))
68
+ )
69
+ end
70
+
57
71
  def copy_support_requests
58
72
  fs.cp(
59
73
  fs.expand_path(fs.join("generators", "support_requests.rb"), __dir__),
@@ -91,6 +105,9 @@ module Hanami
91
105
  # @api private
92
106
  def call(options, **)
93
107
  # FIXME: dry-cli kwargs aren't correctly forwarded in Ruby 3
108
+
109
+ return if options[:skip_tests]
110
+
94
111
  slice = inflector.underscore(Shellwords.shellescape(options[:slice])) if options[:slice]
95
112
  name = inflector.underscore(Shellwords.shellescape(options[:name]))
96
113
  *controller, action = name.split(ACTION_SEPARATOR)
@@ -99,6 +116,24 @@ module Hanami
99
116
  generator.call(app.namespace, slice, controller, action)
100
117
  end
101
118
  end
119
+
120
+ # @since 2.1.0
121
+ # @api private
122
+ class Part < Hanami::CLI::Commands::App::Command
123
+ # @since 2.1.0
124
+ # @api private
125
+ def call(options, **)
126
+ # FIXME: dry-cli kwargs aren't correctly forwarded in Ruby 3
127
+
128
+ return if options[:skip_tests]
129
+
130
+ slice = inflector.underscore(Shellwords.shellescape(options[:slice])) if options[:slice]
131
+ name = inflector.underscore(Shellwords.shellescape(options[:name]))
132
+
133
+ generator = Generators::Part.new(fs: fs, inflector: inflector)
134
+ generator.call(app.namespace, slice, name)
135
+ end
136
+ end
102
137
  end
103
138
  end
104
139
  end
@@ -1,4 +1,5 @@
1
1
 
2
2
  group :test do
3
+ gem "capybara"
3
4
  gem "rack-test"
4
5
  end
@@ -0,0 +1 @@
1
+ spec/examples.txt
@@ -7,4 +7,5 @@ ENV["HANAMI_ENV"] ||= "test"
7
7
  require "hanami/prepare"
8
8
 
9
9
  require_relative "support/rspec"
10
+ require_relative "support/features"
10
11
  require_relative "support/requests"
@@ -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
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "capybara/rspec"
4
+
5
+ Capybara.app = Hanami.app
@@ -2,11 +2,12 @@
2
2
 
3
3
  require "rack/test"
4
4
 
5
- RSpec.shared_context "Hanami app" do
5
+ RSpec.shared_context "Rack::Test" do
6
+ # Define the app for Rack::Test requests
6
7
  let(:app) { Hanami.app }
7
8
  end
8
9
 
9
10
  RSpec.configure do |config|
10
11
  config.include Rack::Test::Methods, type: :request
11
- config.include_context "Hanami app", type: :request
12
+ config.include_context "Rack::Test", type: :request
12
13
  end
@@ -1,27 +1,61 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
+ # Use the recommended non-monkey patched syntax.
5
+ config.disable_monkey_patching!
6
+
7
+ # Use and configure rspec-expectations.
4
8
  config.expect_with :rspec do |expectations|
9
+ # This option will default to `true` in RSpec 4.
5
10
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
11
  end
7
12
 
13
+ # Use and configure rspec-mocks.
8
14
  config.mock_with :rspec do |mocks|
15
+ # Prevents you from mocking or stubbing a method that does not exist on a
16
+ # real object.
9
17
  mocks.verify_partial_doubles = true
10
18
  end
11
19
 
20
+ # This option will default to `:apply_to_host_groups` in RSpec 4.
12
21
  config.shared_context_metadata_behavior = :apply_to_host_groups
13
22
 
23
+ # Limit a spec run to individual examples or groups you care about by tagging
24
+ # them with `:focus` metadata. When nothing is tagged with `:focus`, all
25
+ # examples get run.
26
+ #
27
+ # RSpec also provides aliases for `it`, `describe`, and `context` that include
28
+ # `:focus` metadata: `fit`, `fdescribe` and `fcontext`, respectively.
14
29
  config.filter_run_when_matching :focus
15
30
 
16
- config.disable_monkey_patching!
17
- config.warnings = true
31
+ # Allow RSpec to persist some state between runs in order to support the
32
+ # `--only-failures` and `--next-failure` CLI options. We recommend you
33
+ # configure your source control system to ignore this file.
34
+ config.example_status_persistence_file_path = "spec/examples.txt"
18
35
 
36
+ # Uncomment this to enable warnings. This is recommended, but in some cases
37
+ # may be too noisy due to issues in dependencies.
38
+ # config.warnings = true
39
+
40
+ # Show more verbose output when running an individual spec file.
19
41
  if config.files_to_run.one?
20
42
  config.default_formatter = "doc"
21
43
  end
22
44
 
45
+ # Print the 10 slowest examples and example groups at the end of the spec run,
46
+ # to help surface which specs are running particularly slow.
23
47
  config.profile_examples = 10
24
48
 
49
+ # Run specs in random order to surface order dependencies. If you find an
50
+ # order dependency and want to debug it, you can fix the order by providing
51
+ # the seed, which is printed after each run:
52
+ #
53
+ # --seed 1234
25
54
  config.order = :random
55
+
56
+ # Seed global randomization in this process using the `--seed` CLI option.
57
+ # This allows you to use `--seed` to deterministically reproduce test failures
58
+ # related to randomization by passing the same `--seed` value as the one that
59
+ # triggered the failure.
26
60
  Kernel.srand config.seed
27
61
  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.rc2"
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.rc2
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-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hanami-cli
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: 2.1.rc
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: 2.1.rc
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -108,13 +108,20 @@ files:
108
108
  - lib/hanami/rspec/generators/action/action_spec.erb
109
109
  - lib/hanami/rspec/generators/dotrspec
110
110
  - lib/hanami/rspec/generators/gemfile
111
+ - lib/hanami/rspec/generators/gitignore
111
112
  - lib/hanami/rspec/generators/helper.rb
113
+ - lib/hanami/rspec/generators/part.rb
114
+ - lib/hanami/rspec/generators/part/part_base_spec.erb
115
+ - lib/hanami/rspec/generators/part/part_slice_base_spec.erb
116
+ - lib/hanami/rspec/generators/part/part_slice_spec.erb
117
+ - lib/hanami/rspec/generators/part/part_spec.erb
112
118
  - lib/hanami/rspec/generators/request.rb
113
119
  - lib/hanami/rspec/generators/slice.rb
114
120
  - lib/hanami/rspec/generators/slice/action_spec.erb
115
121
  - lib/hanami/rspec/generators/slice/keep.erb
116
122
  - lib/hanami/rspec/generators/slice/repository_spec.erb
117
123
  - lib/hanami/rspec/generators/slice/view_spec.erb
124
+ - lib/hanami/rspec/generators/support_features.rb
118
125
  - lib/hanami/rspec/generators/support_requests.rb
119
126
  - lib/hanami/rspec/generators/support_rspec.rb
120
127
  - lib/hanami/rspec/rake_tasks.rb
@@ -143,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
143
150
  - !ruby/object:Gem::Version
144
151
  version: 1.3.1
145
152
  requirements: []
146
- rubygems_version: 3.4.13
153
+ rubygems_version: 3.4.21
147
154
  signing_key:
148
155
  specification_version: 4
149
156
  summary: Hanami RSpec