hanami-rspec 2.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5c81e6f4992dc09e1e1ecc6aac46e01f26b959ead78dbc5666f4186354e1d5d4
4
+ data.tar.gz: 72a5a8fc775f49caeaf9c35a3c09115f6bd7ff1deb6c6042147f8d843617afe9
5
+ SHA512:
6
+ metadata.gz: 37269746fea506a5606e6512d80a28afa2447146066adc267f8bc9f887dc33aed3c34e327ff8dd491562b512dbb5607eb679688780a631e089ba59b24af75008
7
+ data.tar.gz: 6b2c09d813b91ae8fce7adad538059e2a71c6a087c5657bd7f81e78acad974fce27962d4df2c233c3c39b06e6fbc5717640e100323b945e7ed57b97d9dad8479
@@ -0,0 +1,50 @@
1
+ name: ci
2
+
3
+ 'on':
4
+ push:
5
+ paths:
6
+ - '.github/workflows/ci.yml'
7
+ - 'lib/**'
8
+ - '*.gemspec'
9
+ - 'spec/**'
10
+ - 'Rakefile'
11
+ - 'Gemfile'
12
+ - '.rubocop.yml'
13
+ pull_request:
14
+ branches:
15
+ - main
16
+ schedule:
17
+ - cron: '30 4 * * *'
18
+ create:
19
+
20
+ jobs:
21
+ tests:
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ fail-fast: false
25
+ matrix:
26
+ ruby:
27
+ - '3.1'
28
+ - '3.0'
29
+ steps:
30
+ - uses: ravsamhq/notify-slack-action@v1
31
+ if: always()
32
+ with:
33
+ status: ${{ job.status }}
34
+ notify_when: 'failure'
35
+ env:
36
+ SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
37
+ - uses: actions/checkout@v1
38
+ - name: Install package dependencies
39
+ run: '[ -e $APT_DEPS ] || sudo apt-get install -y --no-install-recommends $APT_DEPS'
40
+ - name: Set up Ruby
41
+ uses: ruby/setup-ruby@v1
42
+ with:
43
+ ruby-version: ${{matrix.ruby}}
44
+ - name: Install latest bundler
45
+ run: |
46
+ gem install bundler --no-document
47
+ - name: Bundle install
48
+ run: bundle install --jobs 4 --retry 3
49
+ - name: Run all tests
50
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ .rubocop-*
10
+ Gemfile.lock
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,26 @@
1
+ # Please keep AllCops, Bundler, Style, Metrics groups and then order cops
2
+ # alphabetically
3
+ inherit_from:
4
+ - https://raw.githubusercontent.com/hanami/devtools/main/.rubocop.yml
5
+ Layout/LineLength:
6
+ Exclude:
7
+ - Gemfile
8
+ Naming/MethodParameterName:
9
+ AllowedNames:
10
+ - fs
11
+ Naming/HeredocDelimiterNaming:
12
+ Enabled: false
13
+ Style/AccessorGrouping:
14
+ Enabled: false
15
+ Style/BlockDelimiters:
16
+ Enabled: false
17
+ Style/CommentedKeyword:
18
+ Enabled: false
19
+ Style/LambdaCall:
20
+ Enabled: false
21
+ Style/TrailingCommaInArguments:
22
+ Enabled: false
23
+ Style/TrailingCommaInArrayLiteral:
24
+ Enabled: false
25
+ Style/TrailingCommaInHashLiteral:
26
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,30 @@
1
+ ## v2.0.0.rc1 - 2022-11-08
2
+
3
+ ## Changed
4
+
5
+ - [Luca Guidi] Follow `hanami` versioning
6
+
7
+ ## v3.11.0.beta4 - 2022-10-24
8
+
9
+ ## Changed
10
+
11
+ - [Luca Guidi] Generate slice specs under `spec/slices/[slice_name]/` (#9)
12
+
13
+ ## v3.11.0.beta3 - 2022-09-21
14
+
15
+ ### Added
16
+
17
+ - [Luca Guidi] Hook into `hanami new` and `hanami generate` to respect name pluralization
18
+ - [Luca Guidi] Hook into `hanami generate action` to generate action specs
19
+
20
+ ## v3.11.0.beta2 - 2022-08-16
21
+
22
+ ### Added
23
+
24
+ - [Luca Guidi] Hook into `hanami generate slice` to generate a slice directory in spec/ along with a placeholder base action spec [#5]
25
+
26
+ ## v3.11.0.beta1 - 2022-07-20
27
+
28
+ ### Added
29
+
30
+ - [Luca Guidi] Hook into `hanami install` to setup RSpec + Rack::Test
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at me@lucaguidi.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+ gemspec
5
+
6
+ unless ENV["CI"]
7
+ gem "byebug", require: false, platforms: :mri
8
+ gem "yard", require: false
9
+ end
10
+
11
+ gem "dry-files", require: false, git: "https://github.com/dry-rb/dry-files.git", branch: "main"
12
+ gem "dry-logger", require: false, git: "https://github.com/dry-rb/dry-logger.git", branch: "main"
13
+ gem "hanami-utils", require: false, git: "https://github.com/hanami/utils.git", branch: "main"
14
+ gem "hanami-cli", require: false, git: "https://github.com/hanami/cli.git", branch: "main"
15
+ gem "hanami", require: false, git: "https://github.com/hanami/hanami.git", branch: "main"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
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.
data/README.md ADDED
@@ -0,0 +1,60 @@
1
+ # Hanami::RSpec
2
+
3
+ RSpec and testing support for [full-stack Hanami applications](`https://github.com/hanami/hanami`).
4
+
5
+ ## Status
6
+
7
+ [![Gem Version](https://badge.fury.io/rb/hanami-rspec.svg)](https://badge.fury.io/rb/hanami-rspec)
8
+ [![CI](https://github.com/hanami/rspec/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/rspec/actions?query=workflow%3Aci+branch%3Amain)
9
+ [![Depfu](https://badges.depfu.com/badges/a8545fb67cf32a2c75b6227bc0821027/overview.svg)](https://depfu.com/github/hanami/rspec?project=Bundler)
10
+
11
+ ## Contact
12
+
13
+ - Home page: http://hanamirb.org
14
+ - Mailing List: http://hanamirb.org/mailing-list
15
+ - Bugs/Issues: https://github.com/hanami/rspec/issues
16
+ - Support: http://stackoverflow.com/questions/tagged/hanami
17
+ - Chat: http://chat.hanamirb.org
18
+
19
+ ## Rubies
20
+
21
+ **Hanami::RSpec** supports Ruby (MRI) 3.0+
22
+
23
+ ## Installation
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ group :cli, :development, :test do
29
+ gem "hanami-rspec"
30
+ end
31
+ ```
32
+
33
+ And then execute:
34
+
35
+ $ bundle install
36
+ $ bundle exec hanami setup
37
+
38
+ ## Usage
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+
44
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+
46
+ ## Contributing
47
+
48
+ Bug reports and pull requests are welcome on GitHub at https://github.com/hanami/rspec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/hanami/rspec/blob/main/CODE_OF_CONDUCT.md).
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
53
+
54
+ ## Code of Conduct
55
+
56
+ Everyone interacting in the `Hanami::RSpec` project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/hanami/rspec/blob/main/CODE_OF_CONDUCT.md).
57
+
58
+ ## Copyright
59
+
60
+ Copyright © 2014-2022 Hanami Team – Released under MIT License
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "hanami/rspec"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/hanami/rspec/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "hanami-rspec"
7
+ spec.version = Hanami::RSpec::VERSION
8
+ spec.authors = ["Luca Guidi"]
9
+ spec.email = ["me@lucaguidi.com"]
10
+
11
+ spec.summary = "Hanami RSpec"
12
+ spec.description = "Hanami RSpec generators and Rake tasks"
13
+ spec.homepage = "https://hanamirb.org"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 3.0.0")
16
+
17
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/hanami/rspec"
21
+ spec.metadata["changelog_uri"] = "https://github.com/hanami/rspec/blob/master/CHANGELOG.md"
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency "hanami-cli", "~> 2.0.0.rc1"
33
+ spec.add_dependency "rspec", "~> 3.11"
34
+ spec.add_dependency "rake", "~> 13.0"
35
+
36
+ spec.add_development_dependency "rubocop", "~> 1.11"
37
+ spec.metadata["rubygems_mfa_required"] = "true"
38
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli"
4
+ require "shellwords"
5
+ require "hanami/cli/commands/app/command"
6
+ require "hanami/cli/generators/context"
7
+ require_relative "./generators"
8
+
9
+ module Hanami
10
+ module RSpec
11
+ module Commands
12
+ class Install < Hanami::CLI::Command
13
+ def call(*, **)
14
+ append_gemfile
15
+ copy_dotrspec
16
+ copy_spec_helper
17
+ copy_support_rspec
18
+ copy_support_requests
19
+
20
+ generate_request_spec
21
+ end
22
+
23
+ private
24
+
25
+ def append_gemfile
26
+ fs.append(
27
+ fs.expand_path("Gemfile"),
28
+ fs.read(
29
+ fs.expand_path(fs.join("generators", "gemfile"), __dir__)
30
+ ),
31
+ )
32
+ end
33
+
34
+ def copy_dotrspec
35
+ fs.cp(
36
+ fs.expand_path(fs.join("generators", "dotrspec"), __dir__),
37
+ fs.expand_path(fs.join(".rspec")),
38
+ )
39
+ end
40
+
41
+ def copy_spec_helper
42
+ fs.cp(
43
+ fs.expand_path(fs.join("generators", "helper.rb"), __dir__),
44
+ fs.expand_path(fs.join("spec", "spec_helper.rb"))
45
+ )
46
+ end
47
+
48
+ def copy_support_rspec
49
+ fs.cp(
50
+ fs.expand_path(fs.join("generators", "support_rspec.rb"), __dir__),
51
+ fs.expand_path(fs.join("spec", "support", "rspec.rb"))
52
+ )
53
+ end
54
+
55
+ def copy_support_requests
56
+ fs.cp(
57
+ fs.expand_path(fs.join("generators", "support_requests.rb"), __dir__),
58
+ fs.expand_path(fs.join("spec", "support", "requests.rb"))
59
+ )
60
+ end
61
+
62
+ def generate_request_spec
63
+ fs.cp(
64
+ fs.expand_path(fs.join("generators", "request.rb"), __dir__),
65
+ fs.expand_path(fs.join("spec", "requests", "root_spec.rb"))
66
+ )
67
+ end
68
+ end
69
+
70
+ module Generate
71
+ class Slice < Hanami::CLI::Command
72
+ # FIXME: dry-cli kwargs aren't correctly forwarded in Ruby 3
73
+ def call(options, **)
74
+ slice = inflector.underscore(Shellwords.shellescape(options[:name]))
75
+
76
+ generator = Generators::Slice.new(fs: fs, inflector: inflector)
77
+ generator.call(slice)
78
+ end
79
+ end
80
+
81
+ class Action < Hanami::CLI::Commands::App::Command
82
+ # FIXME: dry-cli kwargs aren't correctly forwarded in Ruby 3
83
+ def call(options, **)
84
+ slice = inflector.underscore(Shellwords.shellescape(options[:slice])) if options[:slice]
85
+ name = inflector.underscore(Shellwords.shellescape(options[:name]))
86
+ *controller, action = name.split(ACTION_SEPARATOR)
87
+
88
+ generator = Generators::Action.new(fs: fs, inflector: inflector)
89
+ generator.call(app.namespace, slice, controller, action)
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ if Hanami::CLI.within_hanami_app?
98
+ Hanami::CLI.after "install", Hanami::RSpec::Commands::Install
99
+ Hanami::CLI.after "generate slice", Hanami::RSpec::Commands::Generate::Slice
100
+ Hanami::CLI.after "generate action", Hanami::RSpec::Commands::Generate::Action
101
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module RSpec
5
+ class Error < StandardError
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "hanami/cli/generators/app/action_context"
5
+
6
+ module Hanami
7
+ module RSpec
8
+ module Generators
9
+ class Action
10
+ def initialize(fs:, inflector:)
11
+ @fs = fs
12
+ @inflector = inflector
13
+ end
14
+
15
+ def call(app, slice, controller, action, context: Hanami::CLI::Generators::App::ActionContext.new(inflector, app, slice, controller, action)) # rubocop:disable Layout/LineLength
16
+ if slice
17
+ fs.write(
18
+ "spec/slices/#{slice}/actions/#{controller_directory(controller)}/#{action}_spec.rb",
19
+ t("action_slice_spec.erb", context)
20
+ )
21
+ else
22
+ fs.write(
23
+ "spec/actions/#{controller_directory(controller)}/#{action}_spec.rb",
24
+ t("action_spec.erb", context)
25
+ )
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :fs
32
+
33
+ attr_reader :inflector
34
+
35
+ # @api private
36
+ # @param controller [Array<String>]
37
+ def controller_directory(controller)
38
+ fs.join(controller)
39
+ end
40
+
41
+ def template(path, context)
42
+ require "erb"
43
+
44
+ ERB.new(
45
+ File.read(__dir__ + "/action/#{path}")
46
+ ).result(context.ctx)
47
+ end
48
+
49
+ alias_method :t, :template
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ --require spec_helper
@@ -0,0 +1,4 @@
1
+
2
+ group :test do
3
+ gem "rack-test"
4
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ SPEC_ROOT = Pathname(__dir__).realpath.freeze
5
+
6
+ ENV["HANAMI_ENV"] ||= "test"
7
+ require "hanami/prepare"
8
+
9
+ require_relative "support/rspec"
10
+ require_relative "support/requests"
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe "Root", type: :request do
4
+ it "is successful" do
5
+ get "/"
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")
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.describe <%= camelized_slice_name %>::Action do
4
+ xit "works"
5
+ end
File without changes
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "slices/<%= underscored_slice_name %>/repository"
4
+
5
+ RSpec.describe <%= camelized_slice_name %>::Repository do
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "slices/<%= underscored_slice_name %>/view"
4
+
5
+ RSpec.describe <%= camelized_slice_name %>::View do
6
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "erb"
4
+ require "hanami/cli/generators/app/slice_context"
5
+
6
+ module Hanami
7
+ module RSpec
8
+ module Generators
9
+ class Slice
10
+ def initialize(fs:, inflector:)
11
+ @fs = fs
12
+ @inflector = inflector
13
+ end
14
+
15
+ def call(slice, context: Hanami::CLI::Generators::App::SliceContext.new(inflector, nil, slice, nil))
16
+ fs.write("spec/slices/#{slice}/action_spec.rb", t("action_spec.erb", context))
17
+ # fs.write("spec/slices/#{slice}/view_spec.rb", t("view_spec.erb", context))
18
+ # fs.write("spec/slices/#{slice}/repository_spec.rb", t("repository_spec.erb", context))
19
+
20
+ fs.write("spec/slices/#{slice}/actions/.keep", t("keep.erb", context))
21
+ # fs.write("spec/slices/#{slice}/views/.keep", t("keep.erb", context))
22
+ # fs.write("spec/slices/#{slice}/templates/.keep", t("keep.erb", context))
23
+ # fs.write("spec/slices/#{slice}/templates/layouts/.keep", t("keep.erb", context))
24
+ # fs.write("spec/slices/#{slice}/entities/.keep", t("keep.erb", context))
25
+ # fs.write("spec/slices/#{slice}/repositories/.keep", t("keep.erb", context))
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :fs
31
+
32
+ attr_reader :inflector
33
+
34
+ def template(path, context)
35
+ require "erb"
36
+
37
+ ERB.new(
38
+ File.read(__dir__ + "/slice/#{path}")
39
+ ).result(context.ctx)
40
+ end
41
+
42
+ alias_method :t, :template
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rack/test"
4
+
5
+ RSpec.shared_context "Hanami app" do
6
+ let(:app) { Hanami.app }
7
+ end
8
+
9
+ RSpec.configure do |config|
10
+ config.include Rack::Test::Methods, type: :request
11
+ config.include_context "Hanami app", type: :request
12
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |expectations|
5
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
6
+ end
7
+
8
+ config.mock_with :rspec do |mocks|
9
+ mocks.verify_partial_doubles = true
10
+ end
11
+
12
+ config.shared_context_metadata_behavior = :apply_to_host_groups
13
+
14
+ config.filter_run_when_matching :focus
15
+
16
+ config.disable_monkey_patching!
17
+ config.warnings = true
18
+
19
+ if config.files_to_run.one?
20
+ config.default_formatter = "doc"
21
+ end
22
+
23
+ config.profile_examples = 10
24
+
25
+ config.order = :random
26
+ Kernel.srand config.seed
27
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module RSpec
5
+ module Generators
6
+ require_relative "./generators/slice"
7
+ require_relative "./generators/action"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "hanami/cli/rake_tasks"
4
+
5
+ Hanami::CLI::RakeTasks.register_tasks do
6
+ require "rspec/core/rake_task"
7
+ ::RSpec::Core::RakeTask.new(:spec)
8
+
9
+ task default: :spec
10
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module RSpec
5
+ VERSION = "2.0.0.rc1"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module RSpec
5
+ require_relative "rspec/version"
6
+ require_relative "rspec/error"
7
+ require_relative "rspec/commands"
8
+ require_relative "rspec/rake_tasks"
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "./hanami/rspec"
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hanami-rspec
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0.rc1
5
+ platform: ruby
6
+ authors:
7
+ - Luca Guidi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-11-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: hanami-cli
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0.rc1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.0.rc1
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '13.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.11'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.11'
69
+ description: Hanami RSpec generators and Rake tasks
70
+ email:
71
+ - me@lucaguidi.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/workflows/ci.yml"
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".rubocop.yml"
80
+ - CHANGELOG.md
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - hanami-rspec.gemspec
89
+ - lib/hanami-rspec.rb
90
+ - lib/hanami/rspec.rb
91
+ - lib/hanami/rspec/commands.rb
92
+ - lib/hanami/rspec/error.rb
93
+ - lib/hanami/rspec/generators.rb
94
+ - lib/hanami/rspec/generators/action.rb
95
+ - lib/hanami/rspec/generators/action/action_slice_spec.erb
96
+ - lib/hanami/rspec/generators/action/action_spec.erb
97
+ - lib/hanami/rspec/generators/dotrspec
98
+ - lib/hanami/rspec/generators/gemfile
99
+ - lib/hanami/rspec/generators/helper.rb
100
+ - lib/hanami/rspec/generators/request.rb
101
+ - lib/hanami/rspec/generators/slice.rb
102
+ - lib/hanami/rspec/generators/slice/action_spec.erb
103
+ - lib/hanami/rspec/generators/slice/keep.erb
104
+ - lib/hanami/rspec/generators/slice/repository_spec.erb
105
+ - lib/hanami/rspec/generators/slice/view_spec.erb
106
+ - lib/hanami/rspec/generators/support_requests.rb
107
+ - lib/hanami/rspec/generators/support_rspec.rb
108
+ - lib/hanami/rspec/rake_tasks.rb
109
+ - lib/hanami/rspec/version.rb
110
+ homepage: https://hanamirb.org
111
+ licenses:
112
+ - MIT
113
+ metadata:
114
+ allowed_push_host: https://rubygems.org
115
+ homepage_uri: https://hanamirb.org
116
+ source_code_uri: https://github.com/hanami/rspec
117
+ changelog_uri: https://github.com/hanami/rspec/blob/master/CHANGELOG.md
118
+ rubygems_mfa_required: 'true'
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 3.0.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">"
131
+ - !ruby/object:Gem::Version
132
+ version: 1.3.1
133
+ requirements: []
134
+ rubygems_version: 3.3.3
135
+ signing_key:
136
+ specification_version: 4
137
+ summary: Hanami RSpec
138
+ test_files: []