rspec-rails 3.0.2 → 7.1.1
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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +3 -1
- data/Capybara.md +6 -55
- data/Changelog.md +805 -47
- data/{License.txt → LICENSE.md} +5 -3
- data/README.md +278 -444
- 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/controller_spec.rb +3 -3
- 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/controller/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/feature/feature_generator.rb +15 -2
- data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
- 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/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +41 -7
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +63 -22
- data/lib/generators/rspec/job/job_generator.rb +13 -0
- data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
- 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 +12 -3
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +2 -2
- data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
- data/lib/generators/rspec/model/model_generator.rb +20 -6
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/request/request_generator.rb +17 -0
- data/lib/generators/rspec/request/templates/request_spec.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +90 -113
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +129 -0
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +46 -64
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +11 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +4 -3
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +138 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +18 -11
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +3 -3
- 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/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +4 -4
- data/lib/generators/rspec.rb +30 -11
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +46 -29
- data/lib/rspec/rails/configuration.rb +165 -41
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +185 -149
- data/lib/rspec/rails/example/feature_example_group.rb +43 -23
- data/lib/rspec/rails/example/helper_example_group.rb +28 -25
- data/lib/rspec/rails/example/job_example_group.rb +23 -0
- data/lib/rspec/rails/example/mailbox_example_group.rb +80 -0
- data/lib/rspec/rails/example/mailer_example_group.rb +27 -22
- data/lib/rspec/rails/example/model_example_group.rb +9 -6
- data/lib/rspec/rails/example/rails_example_group.rb +9 -2
- data/lib/rspec/rails/example/request_example_group.rb +21 -17
- data/lib/rspec/rails/example/routing_example_group.rb +47 -39
- data/lib/rspec/rails/example/system_example_group.rb +180 -0
- data/lib/rspec/rails/example/view_example_group.rb +179 -134
- data/lib/rspec/rails/example.rb +4 -0
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -11
- data/lib/rspec/rails/feature_check.rb +51 -0
- data/lib/rspec/rails/file_fixture_support.rb +18 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +45 -0
- data/lib/rspec/rails/fixture_support.rb +70 -14
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +180 -0
- data/lib/rspec/rails/matchers/action_cable/have_streams.rb +58 -0
- data/lib/rspec/rails/matchers/action_cable.rb +70 -0
- data/lib/rspec/rails/matchers/action_mailbox.rb +73 -0
- data/lib/rspec/rails/matchers/active_job.rb +526 -0
- data/lib/rspec/rails/matchers/base_matcher.rb +179 -0
- data/lib/rspec/rails/matchers/be_a_new.rb +70 -64
- data/lib/rspec/rails/matchers/be_new_record.rb +25 -20
- data/lib/rspec/rails/matchers/be_valid.rb +39 -34
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +259 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +359 -333
- data/lib/rspec/rails/matchers/have_rendered.rb +55 -32
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -27
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -101
- data/lib/rspec/rails/matchers/send_email.rb +122 -0
- data/lib/rspec/rails/matchers.rb +21 -12
- data/lib/rspec/rails/tasks/rspec.rake +9 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -11
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +1 -20
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +89 -27
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +9 -1
- data/lib/rspec-rails.rb +83 -3
- data.tar.gz.sig +0 -0
- metadata +108 -78
- metadata.gz.sig +3 -2
- data/lib/generators/rspec/integration/integration_generator.rb +0 -17
- data/lib/generators/rspec/integration/templates/request_spec.rb +0 -10
- data/lib/generators/rspec/observer/observer_generator.rb +0 -13
@@ -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
|
@@ -1,13 +1,13 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= class_name %>Controller,
|
4
|
+
RSpec.describe <%= class_name %>Controller, <%= type_metatag(:controller) %> do
|
5
5
|
|
6
6
|
<% for action in actions -%>
|
7
|
-
describe "GET
|
7
|
+
describe "GET #<%= action %>" do
|
8
8
|
it "returns http success" do
|
9
9
|
get :<%= action %>
|
10
|
-
expect(response).to
|
10
|
+
expect(response).to have_http_status(:success)
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -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 -%>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>",
|
3
|
+
RSpec.describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>", <%= type_metatag(:view) %> do
|
4
4
|
pending "add some examples to (or delete) #{__FILE__}"
|
5
5
|
end
|
@@ -4,12 +4,25 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class FeatureGenerator < Base
|
7
|
-
class_option :feature_specs, :
|
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"
|
8
9
|
|
9
10
|
def generate_feature_spec
|
10
11
|
return unless options[:feature_specs]
|
11
12
|
|
12
|
-
template
|
13
|
+
template template_name, target_path('features', class_path, filename)
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_name
|
17
|
+
options[:singularize] ? 'feature_singular_spec.rb' : 'feature_spec.rb'
|
18
|
+
end
|
19
|
+
|
20
|
+
def filename
|
21
|
+
if options[:singularize]
|
22
|
+
"#{file_name.singularize}_spec.rb"
|
23
|
+
else
|
24
|
+
"#{file_name}_spec.rb"
|
25
|
+
end
|
13
26
|
end
|
14
27
|
end
|
15
28
|
end
|
@@ -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
|
@@ -11,7 +11,7 @@ require 'rails_helper'
|
|
11
11
|
# end
|
12
12
|
# end
|
13
13
|
<% module_namespacing do -%>
|
14
|
-
RSpec.describe <%= class_name %>Helper,
|
14
|
+
RSpec.describe <%= class_name %>Helper, <%= type_metatag(:helper) %> do
|
15
15
|
pending "add some examples to (or delete) #{__FILE__}"
|
16
16
|
end
|
17
17
|
<% end -%>
|
@@ -1,17 +1,19 @@
|
|
1
1
|
require "rspec/support"
|
2
2
|
require "rspec/core"
|
3
3
|
RSpec::Support.require_rspec_core "project_initializer"
|
4
|
+
require "rspec/rails/feature_check"
|
4
5
|
|
5
6
|
module Rspec
|
6
7
|
module Generators
|
7
8
|
# @private
|
8
9
|
class InstallGenerator < ::Rails::Generators::Base
|
9
|
-
|
10
10
|
desc <<DESC
|
11
11
|
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,26 +22,58 @@ 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
|
+
|
42
|
+
spec_helper_path = File.join(tmpdir, 'spec', 'spec_helper.rb')
|
43
|
+
|
44
|
+
replace_generator_command(spec_helper_path)
|
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
|
52
|
+
end
|
53
|
+
|
54
|
+
def replace_generator_command(spec_helper_path)
|
55
|
+
gsub_file spec_helper_path,
|
40
56
|
'rspec --init',
|
41
57
|
'rails generate rspec:install',
|
42
|
-
:
|
58
|
+
verbose: false
|
59
|
+
end
|
60
|
+
|
61
|
+
def remove_warnings_configuration(spec_helper_path)
|
62
|
+
empty_line = '^\n'
|
63
|
+
comment_line = '^\s*#.+\n'
|
64
|
+
gsub_file spec_helper_path,
|
65
|
+
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
|
66
|
+
'',
|
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]
|
43
77
|
end
|
44
78
|
end
|
45
79
|
end
|
@@ -1,8 +1,16 @@
|
|
1
1
|
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
-
ENV["RAILS_ENV"] ||= 'test'
|
3
2
|
require 'spec_helper'
|
4
|
-
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
require_relative '../config/environment'
|
5
|
+
# Prevent database truncation if the environment is production
|
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 -%>
|
5
12
|
require 'rspec/rails'
|
13
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
6
14
|
|
7
15
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
16
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
@@ -11,40 +19,73 @@ require 'rspec/rails'
|
|
11
19
|
# run twice. It is recommended that you do not name files matching this glob to
|
12
20
|
# end with _spec.rb. You can configure this pattern with the --pattern
|
13
21
|
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
#
|
18
|
-
#
|
19
|
-
|
20
|
-
|
21
|
-
<% elsif ::Rails::VERSION::STRING >= '4' -%>
|
22
|
-
# Checks for pending migrations before tests are run.
|
23
|
-
# If you are not using ActiveRecord, you can remove this line.
|
24
|
-
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
|
22
|
+
#
|
23
|
+
# The following line is provided for convenience purposes. It has the downside
|
24
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
25
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
26
|
+
# require only the support files necessary.
|
27
|
+
#
|
28
|
+
# Rails.root.glob('spec/support/**/*.rb').sort_by(&:to_s).each { |f| require f }
|
25
29
|
|
30
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
31
|
+
# Checks for pending migrations and applies them before tests are run.
|
32
|
+
# If you are not using ActiveRecord, you can remove these lines.
|
33
|
+
begin
|
34
|
+
ActiveRecord::Migration.maintain_test_schema!
|
35
|
+
rescue ActiveRecord::PendingMigrationError => e
|
36
|
+
abort e.to_s.strip
|
37
|
+
end
|
26
38
|
<% end -%>
|
27
39
|
RSpec.configure do |config|
|
40
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
28
41
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
29
|
-
|
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 -%>
|
30
49
|
|
31
50
|
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
32
51
|
# examples within a transaction, remove the following line or assign false
|
33
52
|
# instead of true.
|
34
53
|
config.use_transactional_fixtures = true
|
35
54
|
|
36
|
-
#
|
37
|
-
#
|
38
|
-
|
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.
|
39
65
|
#
|
40
|
-
#
|
41
|
-
#
|
66
|
+
# config.fixture_path = Rails.root.join('spec/fixtures')
|
67
|
+
# config.use_transactional_fixtures = true
|
68
|
+
|
69
|
+
<% end -%>
|
70
|
+
# RSpec Rails uses metadata to mix in different behaviours to your tests,
|
71
|
+
# for example enabling you to call `get` and `post` in request specs. e.g.:
|
42
72
|
#
|
43
|
-
# RSpec.describe UsersController, :
|
73
|
+
# RSpec.describe UsersController, type: :request do
|
44
74
|
# # ...
|
45
75
|
# end
|
46
76
|
#
|
47
77
|
# The different available types are documented in the features, such as in
|
48
|
-
# https://
|
49
|
-
|
78
|
+
# https://rspec.info/features/7-1/rspec-rails
|
79
|
+
#
|
80
|
+
# You can also this infer these behaviours automatically by location, e.g.
|
81
|
+
# /spec/models would pull in the same behaviour as `type: :model` but this
|
82
|
+
# behaviour is considered legacy and will be removed in a future version.
|
83
|
+
#
|
84
|
+
# To enable this behaviour uncomment the line below.
|
85
|
+
# config.infer_spec_type_from_file_location!
|
86
|
+
|
87
|
+
# Filter lines from Rails gems in backtraces.
|
88
|
+
config.filter_rails_from_backtrace!
|
89
|
+
# arbitrary gems may also be filtered via:
|
90
|
+
# config.filter_gems_from_backtrace("gem name")
|
50
91
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class JobGenerator < Base
|
7
|
+
def create_job_spec
|
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('_'))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
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
|
@@ -1,21 +1,30 @@
|
|
1
1
|
require 'generators/rspec'
|
2
|
+
require "rspec/rails/feature_check"
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Generators
|
5
6
|
# @private
|
6
7
|
class MailerGenerator < Base
|
7
|
-
argument :actions, :
|
8
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
8
9
|
|
9
10
|
def generate_mailer_spec
|
10
|
-
|
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('_'))
|
11
13
|
end
|
12
14
|
|
13
15
|
def generate_fixtures_files
|
14
16
|
actions.each do |action|
|
15
17
|
@action, @path = action, File.join(file_path, action)
|
16
|
-
template "fixture",
|
18
|
+
template "fixture", target_path("fixtures", @path)
|
17
19
|
end
|
18
20
|
end
|
21
|
+
|
22
|
+
def generate_preview_files
|
23
|
+
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
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('_'))
|
27
|
+
end
|
19
28
|
end
|
20
29
|
end
|
21
30
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
RSpec.describe <%= class_name %>,
|
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) { <%= class_name %>.<%= action %> }
|
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 %>)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<% module_namespacing do -%>
|
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
|
+
<% actions.each do |action| -%>
|
5
|
+
|
6
|
+
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>_mailer/<%= action %>
|
7
|
+
def <%= action %>
|
8
|
+
<%= class_name.sub(/(Mailer)?$/, 'Mailer') %>.<%= action %>
|
9
|
+
end
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
end
|
13
|
+
<% end -%>
|
@@ -4,19 +4,33 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class ModelGenerator < Base
|
7
|
-
argument :attributes,
|
8
|
-
|
7
|
+
argument :attributes,
|
8
|
+
type: :array,
|
9
|
+
default: [],
|
10
|
+
banner: "field:type field:type"
|
11
|
+
class_option :fixture, type: :boolean
|
9
12
|
|
10
13
|
def create_model_spec
|
11
|
-
|
14
|
+
template_file = target_path(
|
15
|
+
'models',
|
16
|
+
class_path,
|
17
|
+
"#{file_name}_spec.rb"
|
18
|
+
)
|
19
|
+
template 'model_spec.rb', template_file
|
12
20
|
end
|
13
21
|
|
14
22
|
hook_for :fixture_replacement
|
15
23
|
|
16
24
|
def create_fixture_file
|
17
|
-
|
18
|
-
|
19
|
-
|
25
|
+
return unless missing_fixture_replacement?
|
26
|
+
|
27
|
+
template 'fixtures.yml', target_path('fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def missing_fixture_replacement?
|
33
|
+
options[:fixture] && options[:fixture_replacement].nil?
|
20
34
|
end
|
21
35
|
end
|
22
36
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
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
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
+
describe "GET /<%= name.underscore.pluralize %>" do
|
5
|
+
it "works! (now write some real specs)" do
|
6
|
+
get <%= index_helper %>_path
|
7
|
+
expect(response).to have_http_status(200)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|