rspec-rails 3.8.2 → 7.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Capybara.md +5 -54
- data/Changelog.md +440 -76
- data/README.md +281 -500
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → channel/templates/channel_spec.rb.erb} +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +24 -7
- data/lib/generators/rspec/controller/templates/request_spec.rb +19 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +3 -3
- data/lib/generators/rspec/generator/generator_generator.rb +24 -0
- data/lib/generators/rspec/generator/templates/generator_spec.rb +5 -0
- data/lib/generators/rspec/helper/helper_generator.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +23 -6
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +32 -17
- data/lib/generators/rspec/job/job_generator.rb +2 -1
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +1 -1
- data/lib/generators/rspec/mailbox/mailbox_generator.rb +14 -0
- data/lib/generators/rspec/mailbox/templates/mailbox_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +7 -4
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +4 -4
- data/lib/generators/rspec/model/model_generator.rb +8 -7
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +10 -3
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +36 -22
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +13 -49
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +14 -62
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -9
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -6
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +8 -10
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/system/system_generator.rb +24 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/view_generator.rb +4 -4
- data/lib/generators/rspec.rb +16 -5
- data/lib/rspec/rails/adapters.rb +22 -76
- data/lib/rspec/rails/configuration.rb +112 -38
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +5 -4
- data/lib/rspec/rails/example/feature_example_group.rb +6 -26
- data/lib/rspec/rails/example/helper_example_group.rb +2 -9
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +2 -2
- data/lib/rspec/rails/example/rails_example_group.rb +7 -1
- data/lib/rspec/rails/example/request_example_group.rb +1 -4
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/system_example_group.rb +88 -16
- data/lib/rspec/rails/example/view_example_group.rb +40 -28
- data/lib/rspec/rails/example.rb +2 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -10
- data/lib/rspec/rails/feature_check.rb +16 -29
- data/lib/rspec/rails/file_fixture_support.rb +11 -10
- data/lib/rspec/rails/fixture_file_upload_support.rb +20 -15
- data/lib/rspec/rails/fixture_support.rb +64 -34
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +173 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +65 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +224 -24
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +258 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +23 -32
- data/lib/rspec/rails/matchers/have_rendered.rb +2 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +13 -13
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +12 -0
- data/lib/rspec/rails/tasks/rspec.rake +9 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -17
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +0 -18
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +20 -7
- data/lib/rspec-rails.rb +36 -18
- data.tar.gz.sig +0 -0
- metadata +55 -37
- metadata.gz.sig +0 -0
- data/lib/generators/rspec/integration/integration_generator.rb +0 -22
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
- /data/lib/generators/rspec/{integration → request}/templates/request_spec.rb +0 -0
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class ChannelGenerator < Base
|
7
|
+
def create_channel_spec
|
8
|
+
template 'channel_spec.rb.erb', target_path('channels', class_path, "#{file_name}_channel_spec.rb")
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= class_name %>
|
4
|
+
RSpec.describe <%= class_name %>Channel, <%= type_metatag(:channel) %> do
|
5
5
|
pending "add some examples to (or delete) #{__FILE__}"
|
6
6
|
end
|
7
7
|
<% end -%>
|
@@ -4,21 +4,30 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class ControllerGenerator < Base
|
7
|
-
argument :actions, :
|
7
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
8
8
|
|
9
|
-
class_option :template_engine,
|
10
|
-
class_option :
|
11
|
-
class_option :
|
9
|
+
class_option :template_engine, desc: "Template engine to generate view files"
|
10
|
+
class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
|
11
|
+
class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
|
12
|
+
class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
|
13
|
+
class_option :routing_specs, type: :boolean, default: false, desc: "Generate routing specs"
|
14
|
+
|
15
|
+
def generate_request_spec
|
16
|
+
return unless options[:request_specs]
|
17
|
+
|
18
|
+
template 'request_spec.rb',
|
19
|
+
target_path('requests', class_path, "#{file_name}_spec.rb")
|
20
|
+
end
|
12
21
|
|
13
22
|
def generate_controller_spec
|
14
23
|
return unless options[:controller_specs]
|
15
24
|
|
16
25
|
template 'controller_spec.rb',
|
17
|
-
|
26
|
+
target_path('controllers', class_path, "#{file_name}_controller_spec.rb")
|
18
27
|
end
|
19
28
|
|
20
29
|
def generate_view_specs
|
21
|
-
return if actions.empty?
|
30
|
+
return if actions.empty? && behavior == :invoke
|
22
31
|
return unless options[:view_specs] && options[:template_engine]
|
23
32
|
|
24
33
|
empty_directory File.join("spec", "views", file_path)
|
@@ -26,9 +35,17 @@ module Rspec
|
|
26
35
|
actions.each do |action|
|
27
36
|
@action = action
|
28
37
|
template 'view_spec.rb',
|
29
|
-
|
38
|
+
target_path('views', file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
30
39
|
end
|
31
40
|
end
|
41
|
+
|
42
|
+
def generate_routing_spec
|
43
|
+
return if actions.empty?
|
44
|
+
return unless options[:routing_specs]
|
45
|
+
|
46
|
+
template 'routing_spec.rb',
|
47
|
+
target_path('routing', class_path, "#{file_name}_routing_spec.rb")
|
48
|
+
end
|
32
49
|
end
|
33
50
|
end
|
34
51
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
+
<% namespaced_path = regular_class_path.join('/') -%>
|
5
|
+
<% if actions.empty? -%>
|
6
|
+
describe "GET /index" do
|
7
|
+
pending "add some examples (or delete) #{__FILE__}"
|
8
|
+
end
|
9
|
+
<% end -%>
|
10
|
+
<% for action in actions -%>
|
11
|
+
describe "GET /<%= action %>" do
|
12
|
+
it "returns http success" do
|
13
|
+
get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
|
14
|
+
expect(response).to have_http_status(:success)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
<% end -%>
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
<% module_namespacing do -%>
|
4
|
+
RSpec.describe '<%= class_name %>Controller', <%= type_metatag(:routing) %> do
|
5
|
+
describe 'routing' do
|
6
|
+
<% for action in actions -%>
|
7
|
+
it 'routes to #<%= action %>' do
|
8
|
+
expect(get: "/<%= class_name.underscore %>/<%= action %>").to route_to("<%= class_name.underscore %>#<%= action %>")
|
9
|
+
end
|
10
|
+
<% end -%>
|
11
|
+
end
|
12
|
+
end
|
13
|
+
<% end -%>
|
@@ -4,13 +4,13 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class FeatureGenerator < Base
|
7
|
-
class_option :feature_specs, :
|
8
|
-
class_option :singularize, :
|
7
|
+
class_option :feature_specs, type: :boolean, default: true, desc: "Generate feature specs"
|
8
|
+
class_option :singularize, type: :boolean, default: false, desc: "Singularize the generated feature"
|
9
9
|
|
10
10
|
def generate_feature_spec
|
11
11
|
return unless options[:feature_specs]
|
12
12
|
|
13
|
-
template template_name,
|
13
|
+
template template_name, target_path('features', class_path, filename)
|
14
14
|
end
|
15
15
|
|
16
16
|
def template_name
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class GeneratorGenerator < Base
|
7
|
+
class_option :generator_specs, type: :boolean, default: true, desc: 'Generate generator specs'
|
8
|
+
|
9
|
+
def generate_generator_spec
|
10
|
+
return unless options[:generator_specs]
|
11
|
+
|
12
|
+
template template_name, target_path('generator', class_path, filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
def template_name
|
16
|
+
'generator_spec.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def filename
|
20
|
+
"#{file_name}_generator_spec.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,12 +4,12 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class HelperGenerator < Base
|
7
|
-
class_option :helper_specs, :
|
7
|
+
class_option :helper_specs, type: :boolean, default: true
|
8
8
|
|
9
9
|
def generate_helper_spec
|
10
10
|
return unless options[:helper_specs]
|
11
11
|
|
12
|
-
template 'helper_spec.rb',
|
12
|
+
template 'helper_spec.rb', target_path('helpers', class_path, "#{file_name}_helper_spec.rb")
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
@@ -12,6 +12,8 @@ Description:
|
|
12
12
|
Copy rspec files to your application.
|
13
13
|
DESC
|
14
14
|
|
15
|
+
class_option :default_path, type: :string, default: 'spec'
|
16
|
+
|
15
17
|
def self.source_root
|
16
18
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
17
19
|
end
|
@@ -20,20 +22,20 @@ DESC
|
|
20
22
|
Dir.mktmpdir do |dir|
|
21
23
|
generate_rspec_init dir
|
22
24
|
template File.join(dir, '.rspec'), '.rspec'
|
23
|
-
directory File.join(dir, 'spec'),
|
25
|
+
directory File.join(dir, 'spec'), default_path
|
24
26
|
end
|
25
27
|
end
|
26
28
|
|
27
29
|
def copy_rails_files
|
28
|
-
template 'spec/rails_helper.rb'
|
30
|
+
template 'spec/rails_helper.rb', "#{default_path}/rails_helper.rb"
|
29
31
|
end
|
30
32
|
|
31
33
|
private
|
32
34
|
|
33
35
|
def generate_rspec_init(tmpdir)
|
34
36
|
initializer = ::RSpec::Core::ProjectInitializer.new(
|
35
|
-
:
|
36
|
-
:
|
37
|
+
destination: tmpdir,
|
38
|
+
report_stream: StringIO.new
|
37
39
|
)
|
38
40
|
initializer.run
|
39
41
|
|
@@ -41,13 +43,19 @@ DESC
|
|
41
43
|
|
42
44
|
replace_generator_command(spec_helper_path)
|
43
45
|
remove_warnings_configuration(spec_helper_path)
|
46
|
+
|
47
|
+
unless default_path == "spec"
|
48
|
+
dot_rspec_path = File.join(tmpdir, '.rspec')
|
49
|
+
|
50
|
+
append_default_path(dot_rspec_path)
|
51
|
+
end
|
44
52
|
end
|
45
53
|
|
46
54
|
def replace_generator_command(spec_helper_path)
|
47
55
|
gsub_file spec_helper_path,
|
48
56
|
'rspec --init',
|
49
57
|
'rails generate rspec:install',
|
50
|
-
:
|
58
|
+
verbose: false
|
51
59
|
end
|
52
60
|
|
53
61
|
def remove_warnings_configuration(spec_helper_path)
|
@@ -56,7 +64,16 @@ DESC
|
|
56
64
|
gsub_file spec_helper_path,
|
57
65
|
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
|
58
66
|
'',
|
59
|
-
:
|
67
|
+
verbose: false
|
68
|
+
end
|
69
|
+
|
70
|
+
def append_default_path(dot_rspec_path)
|
71
|
+
append_to_file dot_rspec_path,
|
72
|
+
"--default-path #{default_path}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def default_path
|
76
|
+
options[:default_path]
|
60
77
|
end
|
61
78
|
end
|
62
79
|
end
|
@@ -1,9 +1,14 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
2
|
require 'spec_helper'
|
3
3
|
ENV['RAILS_ENV'] ||= 'test'
|
4
|
-
|
4
|
+
require_relative '../config/environment'
|
5
5
|
# Prevent database truncation if the environment is production
|
6
6
|
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
7
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
8
|
+
# Uncomment the line below in case you have `--require rails_helper` in the `.rspec` file
|
9
|
+
# that will avoid rails generators crashing because migrations haven't been run yet
|
10
|
+
# return unless Rails.env.test?
|
11
|
+
<% end -%>
|
7
12
|
require 'rspec/rails'
|
8
13
|
# Add additional requires below this line. Rails is not loaded until this point!
|
9
14
|
|
@@ -20,37 +25,47 @@ require 'rspec/rails'
|
|
20
25
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
26
|
# require only the support files necessary.
|
22
27
|
#
|
23
|
-
#
|
28
|
+
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
24
29
|
|
25
|
-
<% if RSpec::Rails::FeatureCheck.
|
30
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
26
31
|
# Checks for pending migrations and applies them before tests are run.
|
27
32
|
# If you are not using ActiveRecord, you can remove these lines.
|
28
33
|
begin
|
29
34
|
ActiveRecord::Migration.maintain_test_schema!
|
30
35
|
rescue ActiveRecord::PendingMigrationError => e
|
31
|
-
|
32
|
-
exit 1
|
33
|
-
end
|
34
|
-
<% elsif RSpec::Rails::FeatureCheck.can_check_pending_migrations? -%>
|
35
|
-
# Checks for pending migrations before tests are run.
|
36
|
-
# If you are not using ActiveRecord, you can remove these lines.
|
37
|
-
begin
|
38
|
-
ActiveRecord::Migration.check_pending!
|
39
|
-
rescue ActiveRecord::PendingMigrationError => e
|
40
|
-
puts e.to_s.strip
|
41
|
-
exit 1
|
36
|
+
abort e.to_s.strip
|
42
37
|
end
|
43
38
|
<% end -%>
|
44
39
|
RSpec.configure do |config|
|
45
40
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
46
41
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
47
|
-
|
42
|
+
<% if ::Rails::VERSION::STRING < "7.1.0" -%>
|
43
|
+
config.fixture_path = Rails.root.join('spec/fixtures')
|
44
|
+
<% else -%>
|
45
|
+
config.fixture_paths = [
|
46
|
+
Rails.root.join('spec/fixtures')
|
47
|
+
]
|
48
|
+
<% end -%>
|
48
49
|
|
49
50
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
50
51
|
# examples within a transaction, remove the following line or assign false
|
51
52
|
# instead of true.
|
52
53
|
config.use_transactional_fixtures = true
|
53
54
|
|
55
|
+
# You can uncomment this line to turn off ActiveRecord support entirely.
|
56
|
+
# config.use_active_record = false
|
57
|
+
|
58
|
+
<% else -%>
|
59
|
+
# Remove this line to enable support for ActiveRecord
|
60
|
+
config.use_active_record = false
|
61
|
+
|
62
|
+
# If you enable ActiveRecord support you should uncomment these lines,
|
63
|
+
# note if you'd prefer not to run each example within a transaction, you
|
64
|
+
# should set use_transactional_fixtures to false.
|
65
|
+
#
|
66
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
67
|
+
# config.use_transactional_fixtures = true
|
68
|
+
|
54
69
|
<% end -%>
|
55
70
|
# RSpec Rails can automatically mix in different behaviours to your tests
|
56
71
|
# based on their file location, for example enabling you to call `get` and
|
@@ -59,12 +74,12 @@ RSpec.configure do |config|
|
|
59
74
|
# You can disable this behaviour by removing the line below, and instead
|
60
75
|
# explicitly tag your specs with their type, e.g.:
|
61
76
|
#
|
62
|
-
# RSpec.describe UsersController, :
|
77
|
+
# RSpec.describe UsersController, type: :controller do
|
63
78
|
# # ...
|
64
79
|
# end
|
65
80
|
#
|
66
81
|
# The different available types are documented in the features, such as in
|
67
|
-
# https://
|
82
|
+
# https://rspec.info/features/7-0/rspec-rails
|
68
83
|
config.infer_spec_type_from_file_location!
|
69
84
|
|
70
85
|
# Filter lines from Rails gems in backtraces.
|
@@ -5,7 +5,8 @@ module Rspec
|
|
5
5
|
# @private
|
6
6
|
class JobGenerator < Base
|
7
7
|
def create_job_spec
|
8
|
-
|
8
|
+
file_suffix = file_name.end_with?('job') ? 'spec.rb' : 'job_spec.rb'
|
9
|
+
template 'job_spec.rb.erb', target_path('jobs', class_path, [file_name, file_suffix].join('_'))
|
9
10
|
end
|
10
11
|
end
|
11
12
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= class_name
|
4
|
+
RSpec.describe <%= class_name %><%= "Job" unless class_name.end_with?("Job")%>, <%= type_metatag(:job) %> do
|
5
5
|
pending "add some examples to (or delete) #{__FILE__}"
|
6
6
|
end
|
7
7
|
<% end -%>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class MailboxGenerator < Base
|
7
|
+
def create_mailbox_spec
|
8
|
+
template('mailbox_spec.rb.erb',
|
9
|
+
target_path('mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -5,22 +5,25 @@ module Rspec
|
|
5
5
|
module Generators
|
6
6
|
# @private
|
7
7
|
class MailerGenerator < Base
|
8
|
-
argument :actions, :
|
8
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
9
9
|
|
10
10
|
def generate_mailer_spec
|
11
|
-
|
11
|
+
file_suffix = file_name.end_with?('mailer') ? 'spec.rb' : 'mailer_spec.rb'
|
12
|
+
template "mailer_spec.rb", target_path('mailers', class_path, [file_name, file_suffix].join('_'))
|
12
13
|
end
|
13
14
|
|
14
15
|
def generate_fixtures_files
|
15
16
|
actions.each do |action|
|
16
17
|
@action, @path = action, File.join(file_path, action)
|
17
|
-
template "fixture",
|
18
|
+
template "fixture", target_path("fixtures", @path)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def generate_preview_files
|
22
23
|
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
|
-
|
24
|
+
|
25
|
+
file_suffix = file_name.end_with?('mailer') ? 'preview.rb' : 'mailer_preview.rb'
|
26
|
+
template "preview.rb", target_path("mailers/previews", class_path, [file_name, file_suffix].join('_'))
|
24
27
|
end
|
25
28
|
end
|
26
29
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%=
|
4
|
+
RSpec.describe <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>, <%= type_metatag(:mailer) %> do
|
5
5
|
<% for action in actions -%>
|
6
6
|
describe "<%= action %>" do
|
7
|
-
let(:mail) { <%=
|
7
|
+
let(:mail) { <%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %> }
|
8
8
|
|
9
9
|
it "renders the headers" do
|
10
10
|
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
<% module_namespacing do -%>
|
2
|
-
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>
|
3
|
-
class <%= class_name %>Preview < ActionMailer::Preview
|
2
|
+
# Preview all emails at http://localhost:3000/rails/mailers/<%= file_path %>_mailer
|
3
|
+
class <%= class_name %><%= 'Mailer' unless class_name.end_with?('Mailer') %>Preview < ActionMailer::Preview
|
4
4
|
<% actions.each do |action| -%>
|
5
5
|
|
6
|
-
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path
|
6
|
+
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>_mailer/<%= action %>
|
7
7
|
def <%= action %>
|
8
|
-
<%=
|
8
|
+
<%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
|
9
9
|
end
|
10
10
|
<% end -%>
|
11
11
|
|
@@ -5,14 +5,14 @@ module Rspec
|
|
5
5
|
# @private
|
6
6
|
class ModelGenerator < Base
|
7
7
|
argument :attributes,
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
class_option :fixture, :
|
8
|
+
type: :array,
|
9
|
+
default: [],
|
10
|
+
banner: "field:type field:type"
|
11
|
+
class_option :fixture, type: :boolean
|
12
12
|
|
13
13
|
def create_model_spec
|
14
|
-
template_file =
|
15
|
-
'
|
14
|
+
template_file = target_path(
|
15
|
+
'models',
|
16
16
|
class_path,
|
17
17
|
"#{file_name}_spec.rb"
|
18
18
|
)
|
@@ -23,7 +23,8 @@ module Rspec
|
|
23
23
|
|
24
24
|
def create_fixture_file
|
25
25
|
return unless missing_fixture_replacement?
|
26
|
-
|
26
|
+
|
27
|
+
template 'fixtures.yml', target_path('fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
@@ -1,10 +1,17 @@
|
|
1
|
-
require 'generators/rspec
|
1
|
+
require 'generators/rspec'
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
|
-
class RequestGenerator <
|
7
|
-
|
6
|
+
class RequestGenerator < Base
|
7
|
+
class_option :request_specs, type: :boolean, default: true, desc: 'Generate request specs'
|
8
|
+
|
9
|
+
def generate_request_spec
|
10
|
+
return unless options[:request_specs]
|
11
|
+
|
12
|
+
template 'request_spec.rb',
|
13
|
+
target_path('requests', "#{name.underscore.pluralize}_spec.rb")
|
14
|
+
end
|
8
15
|
end
|
9
16
|
end
|
10
17
|
end
|
@@ -6,18 +6,19 @@ module Rspec
|
|
6
6
|
# @private
|
7
7
|
class ScaffoldGenerator < Base
|
8
8
|
include ::Rails::Generators::ResourceHelpers
|
9
|
-
source_paths << File.expand_path(
|
10
|
-
argument :attributes, :
|
9
|
+
source_paths << File.expand_path('../helper/templates', __dir__)
|
10
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
11
11
|
|
12
|
-
class_option :orm, :
|
13
|
-
class_option :template_engine, :
|
14
|
-
class_option :singleton, :
|
15
|
-
class_option :api, :
|
12
|
+
class_option :orm, desc: "ORM used to generate the controller"
|
13
|
+
class_option :template_engine, desc: "Template engine to generate view files"
|
14
|
+
class_option :singleton, type: :boolean, desc: "Supply to create a singleton controller"
|
15
|
+
class_option :api, type: :boolean, desc: "Skip specs unnecessary for API-only apps"
|
16
16
|
|
17
|
-
class_option :controller_specs, :
|
18
|
-
class_option :
|
19
|
-
class_option :
|
20
|
-
class_option :
|
17
|
+
class_option :controller_specs, type: :boolean, default: false, desc: "Generate controller specs"
|
18
|
+
class_option :request_specs, type: :boolean, default: true, desc: "Generate request specs"
|
19
|
+
class_option :view_specs, type: :boolean, default: true, desc: "Generate view specs"
|
20
|
+
class_option :helper_specs, type: :boolean, default: true, desc: "Generate helper specs"
|
21
|
+
class_option :routing_specs, type: :boolean, default: true, desc: "Generate routing specs"
|
21
22
|
|
22
23
|
def initialize(*args, &blk)
|
23
24
|
@generator_args = args.first
|
@@ -27,15 +28,20 @@ module Rspec
|
|
27
28
|
def generate_controller_spec
|
28
29
|
return unless options[:controller_specs]
|
29
30
|
|
30
|
-
template_file = File.join(
|
31
|
-
'spec/controllers',
|
32
|
-
controller_class_path,
|
33
|
-
"#{controller_file_name}_controller_spec.rb"
|
34
|
-
)
|
35
31
|
if options[:api]
|
36
|
-
template 'api_controller_spec.rb', template_file
|
32
|
+
template 'api_controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
|
33
|
+
else
|
34
|
+
template 'controller_spec.rb', template_file(folder: 'controllers', suffix: '_controller')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def generate_request_spec
|
39
|
+
return unless options[:request_specs]
|
40
|
+
|
41
|
+
if options[:api]
|
42
|
+
template 'api_request_spec.rb', template_file(folder: 'requests')
|
37
43
|
else
|
38
|
-
template '
|
44
|
+
template 'request_spec.rb', template_file(folder: 'requests')
|
39
45
|
end
|
40
46
|
end
|
41
47
|
|
@@ -52,34 +58,34 @@ module Rspec
|
|
52
58
|
def generate_routing_spec
|
53
59
|
return unless options[:routing_specs]
|
54
60
|
|
55
|
-
template_file =
|
56
|
-
'
|
61
|
+
template_file = target_path(
|
62
|
+
'routing',
|
57
63
|
controller_class_path,
|
58
64
|
"#{controller_file_name}_routing_spec.rb"
|
59
65
|
)
|
60
66
|
template 'routing_spec.rb', template_file
|
61
67
|
end
|
62
68
|
|
63
|
-
hook_for :integration_tool, :as => :integration
|
64
|
-
|
65
69
|
protected
|
66
70
|
|
67
71
|
attr_reader :generator_args
|
68
72
|
|
69
73
|
def copy_view(view)
|
70
74
|
template "#{view}_spec.rb",
|
71
|
-
|
75
|
+
target_path("views", controller_file_path, "#{view}.html.#{options[:template_engine]}_spec.rb")
|
72
76
|
end
|
73
77
|
|
74
78
|
# support for namespaced-resources
|
75
79
|
def ns_file_name
|
76
80
|
return file_name if ns_parts.empty?
|
81
|
+
|
77
82
|
"#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}"
|
78
83
|
end
|
79
84
|
|
80
85
|
# support for namespaced-resources
|
81
86
|
def ns_table_name
|
82
87
|
return table_name if ns_parts.empty?
|
88
|
+
|
83
89
|
"#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}"
|
84
90
|
end
|
85
91
|
|
@@ -114,9 +120,17 @@ module Rspec
|
|
114
120
|
end
|
115
121
|
end
|
116
122
|
|
123
|
+
def template_file(folder:, suffix: '')
|
124
|
+
target_path(folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
|
125
|
+
end
|
126
|
+
|
117
127
|
def banner
|
118
128
|
self.class.banner
|
119
129
|
end
|
130
|
+
|
131
|
+
def show_helper(resource_name = file_name)
|
132
|
+
"#{singular_route_name}_url(#{resource_name})"
|
133
|
+
end
|
120
134
|
end
|
121
135
|
end
|
122
136
|
end
|