hanami-rspec 3.0.0 → 3.11.0.beta2
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.
Potentially problematic release.
This version of hanami-rspec might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +40 -0
- data/.gitignore +13 -0
- data/.rspec +1 -0
- data/.rubocop.yml +26 -0
- data/CHANGELOG.md +4 -212
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -17
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/hanami-rspec.gemspec +26 -26
- data/lib/hanami/rspec/commands.rb +15 -113
- data/lib/hanami/rspec/error.rb +8 -0
- data/lib/hanami/rspec/generators/gemfile +0 -2
- data/lib/hanami/rspec/generators/helper.rb +2 -1
- data/lib/hanami/rspec/generators/request.rb +4 -4
- data/lib/hanami/rspec/generators/slice/action_spec.erb +1 -1
- data/lib/hanami/rspec/generators/slice/repository_spec.erb +1 -1
- data/lib/hanami/rspec/generators/slice/view_spec.erb +1 -1
- data/lib/hanami/rspec/generators/slice.rb +13 -23
- data/lib/hanami/rspec/generators/support_requests.rb +2 -3
- data/lib/hanami/rspec/generators/support_rspec.rb +2 -36
- data/lib/hanami/rspec/generators.rb +9 -0
- data/lib/hanami/rspec/rake_tasks.rb +2 -0
- data/lib/hanami/rspec/version.rb +1 -4
- data/lib/hanami/rspec.rb +2 -47
- data/lib/hanami-rspec.rb +1 -1
- metadata +39 -42
- data/LICENSE +0 -20
- data/lib/hanami/rspec/generators/action.rb +0 -60
- data/lib/hanami/rspec/generators/gemfile_db +0 -9
- data/lib/hanami/rspec/generators/gitignore +0 -1
- data/lib/hanami/rspec/generators/mailer.rb +0 -60
- data/lib/hanami/rspec/generators/operation.rb +0 -59
- data/lib/hanami/rspec/generators/part/part_base_spec.erb +0 -10
- data/lib/hanami/rspec/generators/part/part_slice_base_spec.erb +0 -10
- data/lib/hanami/rspec/generators/part/part_slice_spec.erb +0 -10
- data/lib/hanami/rspec/generators/part/part_spec.erb +0 -10
- data/lib/hanami/rspec/generators/part.rb +0 -114
- data/lib/hanami/rspec/generators/support_db.rb +0 -10
- data/lib/hanami/rspec/generators/support_db_cleaning.rb +0 -40
- data/lib/hanami/rspec/generators/support_features.rb +0 -5
- data/lib/hanami/rspec/generators/support_mailers.rb +0 -20
- data/lib/hanami/rspec/generators/support_operations.rb +0 -9
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli/generators/app/ruby_class_file"
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
module RSpec
|
|
7
|
-
module Generators
|
|
8
|
-
# @since 2.0.0
|
|
9
|
-
# @api private
|
|
10
|
-
class Action
|
|
11
|
-
# @since 2.0.0
|
|
12
|
-
# @api private
|
|
13
|
-
def initialize(fs:, inflector:)
|
|
14
|
-
@fs = fs
|
|
15
|
-
@inflector = inflector
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @since 2.0.0
|
|
19
|
-
# @api private
|
|
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))
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
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
|
-
)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def spec_content(class_name)
|
|
44
|
-
<<~RUBY
|
|
45
|
-
# frozen_string_literal: true
|
|
46
|
-
|
|
47
|
-
RSpec.describe #{class_name} do
|
|
48
|
-
let(:params) { Hash[] }
|
|
49
|
-
|
|
50
|
-
it "works" do
|
|
51
|
-
response = subject.call(params)
|
|
52
|
-
expect(response).to be_successful
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
RUBY
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
spec/examples.txt
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli/generators/app/ruby_class_file"
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
module RSpec
|
|
7
|
-
module Generators
|
|
8
|
-
# @api private
|
|
9
|
-
class Mailer
|
|
10
|
-
attr_reader :fs, :inflector
|
|
11
|
-
|
|
12
|
-
def initialize(fs:, inflector:)
|
|
13
|
-
@fs = fs
|
|
14
|
-
@inflector = inflector
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def call(key:, namespace:, base_path:)
|
|
18
|
-
mailer_class_file = mailer_class_file(key:, namespace:, base_path:)
|
|
19
|
-
spec_file_path = mailer_class_file.path.gsub(/\.rb$/, "_spec.rb")
|
|
20
|
-
mailer_class_name = mailer_class_file.fully_qualified_name
|
|
21
|
-
|
|
22
|
-
fs.write(spec_file_path, spec_content(mailer_class_name))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def mailer_class_file(key:, namespace:, base_path:)
|
|
28
|
-
Hanami::CLI::Generators::App::RubyClassFile.new(
|
|
29
|
-
fs:, inflector:, namespace:,
|
|
30
|
-
key: inflector.underscore(key),
|
|
31
|
-
base_path: base_path,
|
|
32
|
-
extra_namespace: "Mailers"
|
|
33
|
-
)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def spec_content(class_name)
|
|
37
|
-
<<~RUBY
|
|
38
|
-
# frozen_string_literal: true
|
|
39
|
-
|
|
40
|
-
RSpec.describe #{class_name}, :mailers do
|
|
41
|
-
subject(:mailer) { described_class.new }
|
|
42
|
-
|
|
43
|
-
# Inspect the delivered message to set expectations on its contents:
|
|
44
|
-
#
|
|
45
|
-
# expect(result.message.to).to eq(["recipient@example.com"])
|
|
46
|
-
# expect(result.message.subject).to eq("Welcome")
|
|
47
|
-
# expect(result.message.html_body).to include("...")
|
|
48
|
-
|
|
49
|
-
xit "delivers" do
|
|
50
|
-
result = mailer.deliver
|
|
51
|
-
|
|
52
|
-
expect(result).to be_success
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
RUBY
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
end
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli/generators/app/ruby_class_file"
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
module RSpec
|
|
7
|
-
module Generators
|
|
8
|
-
# @api private
|
|
9
|
-
class Operation
|
|
10
|
-
attr_reader :fs, :inflector
|
|
11
|
-
|
|
12
|
-
def initialize(fs:, inflector:)
|
|
13
|
-
@fs = fs
|
|
14
|
-
@inflector = inflector
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def call(key:, namespace:, base_path:)
|
|
18
|
-
operation_class_file = operation_class_file(key:, namespace:, base_path:)
|
|
19
|
-
spec_file_path = operation_class_file.path.gsub(/\.rb$/, "_spec.rb")
|
|
20
|
-
operation_class_name = operation_class_file.fully_qualified_name
|
|
21
|
-
|
|
22
|
-
fs.write(spec_file_path, spec_content(operation_class_name))
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
private
|
|
26
|
-
|
|
27
|
-
def operation_class_file(key:, namespace:, base_path:)
|
|
28
|
-
Hanami::CLI::Generators::App::RubyClassFile.new(
|
|
29
|
-
fs:, inflector:, namespace:,
|
|
30
|
-
key: inflector.underscore(key),
|
|
31
|
-
base_path: base_path
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def spec_content(class_name)
|
|
36
|
-
<<~RUBY
|
|
37
|
-
# frozen_string_literal: true
|
|
38
|
-
|
|
39
|
-
RSpec.describe #{class_name} do
|
|
40
|
-
subject(:operation) { described_class.new }
|
|
41
|
-
|
|
42
|
-
# Use `be_success` and `be_failure` (from spec/support/operations.rb) to set expectations on an
|
|
43
|
-
# operation's result:
|
|
44
|
-
#
|
|
45
|
-
# expect(result).to be_success(expected_value)
|
|
46
|
-
# expect(result).to be_failure(:some_error)
|
|
47
|
-
|
|
48
|
-
xit "succeeds" do
|
|
49
|
-
result = operation.call
|
|
50
|
-
|
|
51
|
-
expect(result).to be_success
|
|
52
|
-
end
|
|
53
|
-
end
|
|
54
|
-
RUBY
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe <%= camelized_slice_name %>::Views::Parts::<%= camelized_name %> do
|
|
4
|
-
subject { described_class.new(value:) }
|
|
5
|
-
let(:value) { double("<%= underscored_name %>") }
|
|
6
|
-
|
|
7
|
-
it "works" do
|
|
8
|
-
expect(subject).to be_kind_of(described_class)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
RSpec.describe <%= camelized_app_name %>::Views::Parts::<%= camelized_name %> do
|
|
4
|
-
subject { described_class.new(value:) }
|
|
5
|
-
let(:value) { double("<%= underscored_name %>") }
|
|
6
|
-
|
|
7
|
-
it "works" do
|
|
8
|
-
expect(subject).to be_kind_of(described_class)
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,114 +0,0 @@
|
|
|
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)
|
|
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
|
-
|
|
33
|
-
if slice
|
|
34
|
-
generate_for_slice(slice, context)
|
|
35
|
-
else
|
|
36
|
-
generate_for_app(context)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
private
|
|
41
|
-
|
|
42
|
-
# @since 2.1.0
|
|
43
|
-
# @api private
|
|
44
|
-
def generate_for_slice(slice, context)
|
|
45
|
-
generate_base_part_for_app(context)
|
|
46
|
-
generate_base_part_for_slice(context, slice)
|
|
47
|
-
|
|
48
|
-
fs.write(
|
|
49
|
-
"spec/slices/#{slice}/views/parts/#{context.underscored_name}_spec.rb",
|
|
50
|
-
t("part_slice_spec.erb", context)
|
|
51
|
-
)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
# @since 2.1.0
|
|
55
|
-
# @api private
|
|
56
|
-
def generate_for_app(context)
|
|
57
|
-
generate_base_part_for_app(context)
|
|
58
|
-
|
|
59
|
-
fs.write(
|
|
60
|
-
"spec/views/parts/#{context.underscored_name}_spec.rb",
|
|
61
|
-
t("part_spec.erb", context)
|
|
62
|
-
)
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
# @since 2.1.0
|
|
66
|
-
# @api private
|
|
67
|
-
def generate_base_part_for_app(context)
|
|
68
|
-
path = fs.join("spec", "views", "part_spec.rb")
|
|
69
|
-
return if fs.exist?(path)
|
|
70
|
-
|
|
71
|
-
fs.write(
|
|
72
|
-
path,
|
|
73
|
-
t("part_base_spec.erb", context)
|
|
74
|
-
)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
# @since 2.1.0
|
|
78
|
-
# @api private
|
|
79
|
-
def generate_base_part_for_slice(context, slice)
|
|
80
|
-
path = "spec/slices/#{slice}/views/part_spec.rb"
|
|
81
|
-
return if fs.exist?(path)
|
|
82
|
-
|
|
83
|
-
fs.write(
|
|
84
|
-
path,
|
|
85
|
-
t("part_slice_base_spec.erb", context)
|
|
86
|
-
)
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
# @since 2.1.0
|
|
90
|
-
# @api private
|
|
91
|
-
attr_reader :fs
|
|
92
|
-
|
|
93
|
-
# @since 2.1.0
|
|
94
|
-
# @api private
|
|
95
|
-
attr_reader :inflector
|
|
96
|
-
|
|
97
|
-
# @since 2.1.0
|
|
98
|
-
# @api private
|
|
99
|
-
def template(path, context)
|
|
100
|
-
require "erb"
|
|
101
|
-
|
|
102
|
-
ERB.new(
|
|
103
|
-
File.read(__dir__ + "/part/#{path}"),
|
|
104
|
-
trim_mode: "-"
|
|
105
|
-
).result(context.instance_eval { binding })
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# @since 2.1.0
|
|
109
|
-
# @api private
|
|
110
|
-
alias_method :t, :template
|
|
111
|
-
end
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Tag feature spec examples as `:db`
|
|
4
|
-
#
|
|
5
|
-
# See support/db/cleaning.rb for how the database is cleaned around these `:db` examples.
|
|
6
|
-
RSpec.configure do |config|
|
|
7
|
-
config.define_derived_metadata(type: :feature) do |metadata|
|
|
8
|
-
metadata[:db] = true
|
|
9
|
-
end
|
|
10
|
-
end
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "database_cleaner/sequel"
|
|
4
|
-
|
|
5
|
-
# Clean the databases between tests tagged as `:db`
|
|
6
|
-
RSpec.configure do |config|
|
|
7
|
-
# Returns all the configured databases across the app and its slices.
|
|
8
|
-
#
|
|
9
|
-
# Used in the before/after hooks below to ensure each database is cleaned between examples.
|
|
10
|
-
#
|
|
11
|
-
# Modify this proc (or any code below) if you only need specific databases cleaned.
|
|
12
|
-
all_databases = -> {
|
|
13
|
-
Hanami.app.with_slices.each_with_object([]) { |slice, dbs|
|
|
14
|
-
next unless slice.key?("db.rom")
|
|
15
|
-
|
|
16
|
-
dbs.concat slice["db.rom"].gateways.values.map(&:connection)
|
|
17
|
-
}.uniq
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
config.before :suite do
|
|
21
|
-
all_databases.call.each do |db|
|
|
22
|
-
DatabaseCleaner[:sequel, db: db].clean_with :truncation, except: ["schema_migrations"]
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
config.prepend_before :each, :db do |example|
|
|
27
|
-
strategy = example.metadata[:js] ? :truncation : :transaction
|
|
28
|
-
|
|
29
|
-
all_databases.call.each do |db|
|
|
30
|
-
DatabaseCleaner[:sequel, db: db].strategy = strategy
|
|
31
|
-
DatabaseCleaner[:sequel, db: db].start
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
config.after :each, :db do
|
|
36
|
-
all_databases.call.each do |db|
|
|
37
|
-
DatabaseCleaner[:sequel, db: db].clean
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Reset recorded mail deliveries between examples tagged `:mailers`
|
|
4
|
-
#
|
|
5
|
-
# In the test env, mail is delivered via a shared test delivery method, so recorded deliveries
|
|
6
|
-
# accumulate across examples. Tag any example that sends mail with `:mailers` to start with a clean
|
|
7
|
-
# slate:
|
|
8
|
-
#
|
|
9
|
-
# RSpec.describe Mailers::Welcome, :mailers do
|
|
10
|
-
# # ...
|
|
11
|
-
# end
|
|
12
|
-
RSpec.configure do |config|
|
|
13
|
-
config.prepend_before :each, :mailers do
|
|
14
|
-
Hanami.app.with_slices.each do |slice|
|
|
15
|
-
next unless slice.key?("mailers.delivery_method")
|
|
16
|
-
|
|
17
|
-
slice["mailers.delivery_method"].clear
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
end
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/monads"
|
|
4
|
-
|
|
5
|
-
# Load Dry Monads' RSpec extension.
|
|
6
|
-
#
|
|
7
|
-
# This provides `be_success` and `be_failure` matchers for operation results, along with `Success`
|
|
8
|
-
# and `Failure` constructors for use within your examples.
|
|
9
|
-
Dry::Monads.load_extensions(:rspec)
|