rspec-rails 3.0.2 → 5.1.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +619 -43
- 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 +22 -5
- 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 +6 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +22 -5
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +43 -14
- data/lib/generators/rspec/integration/integration_generator.rb +7 -2
- data/lib/generators/rspec/integration/templates/request_spec.rb +3 -3
- 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 +8 -1
- 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 +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 +3 -3
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -3
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +3 -3
- 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 +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/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/view/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +12 -10
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +34 -28
- data/lib/rspec/rails/configuration.rb +135 -40
- 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 +3 -2
- data/lib/rspec/rails/example/request_example_group.rb +21 -17
- data/lib/rspec/rails/example/routing_example_group.rb +49 -39
- data/lib/rspec/rails/example/system_example_group.rb +125 -0
- data/lib/rspec/rails/example/view_example_group.rb +178 -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 +47 -0
- data/lib/rspec/rails/file_fixture_support.rb +15 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +56 -0
- data/lib/rspec/rails/fixture_support.rb +42 -13
- data/lib/rspec/rails/matchers/action_cable/have_broadcasted_to.rb +170 -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 +465 -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 +226 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +363 -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.rb +20 -12
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +12 -11
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +1 -2
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +87 -27
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +9 -1
- data/lib/rspec-rails.rb +62 -3
- data.tar.gz.sig +0 -0
- metadata +118 -72
- metadata.gz.sig +0 -0
- 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', File.join('spec/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,11 +4,20 @@ 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
|
+
File.join('spec/requests', class_path, "#{file_name}_spec.rb")
|
20
|
+
end
|
12
21
|
|
13
22
|
def generate_controller_spec
|
14
23
|
return unless options[:controller_specs]
|
@@ -18,7 +27,7 @@ module Rspec
|
|
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)
|
@@ -29,6 +38,14 @@ module Rspec
|
|
29
38
|
File.join("spec", "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
|
+
File.join('spec/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, File.join('spec/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, File.join('spec/generator', class_path, filename)
|
13
|
+
end
|
14
|
+
|
15
|
+
def template_name
|
16
|
+
'generator_spec.rb'
|
17
|
+
end
|
18
|
+
|
19
|
+
def filename
|
20
|
+
"#{table_name}_generator_spec.rb"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -4,7 +4,7 @@ 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,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,12 +1,12 @@
|
|
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.
|
@@ -32,14 +32,31 @@ DESC
|
|
32
32
|
|
33
33
|
def generate_rspec_init(tmpdir)
|
34
34
|
initializer = ::RSpec::Core::ProjectInitializer.new(
|
35
|
-
:
|
36
|
-
:
|
35
|
+
destination: tmpdir,
|
36
|
+
report_stream: StringIO.new
|
37
37
|
)
|
38
38
|
initializer.run
|
39
|
-
|
39
|
+
|
40
|
+
spec_helper_path = File.join(tmpdir, 'spec', 'spec_helper.rb')
|
41
|
+
|
42
|
+
replace_generator_command(spec_helper_path)
|
43
|
+
remove_warnings_configuration(spec_helper_path)
|
44
|
+
end
|
45
|
+
|
46
|
+
def replace_generator_command(spec_helper_path)
|
47
|
+
gsub_file spec_helper_path,
|
40
48
|
'rspec --init',
|
41
49
|
'rails generate rspec:install',
|
42
|
-
:
|
50
|
+
verbose: false
|
51
|
+
end
|
52
|
+
|
53
|
+
def remove_warnings_configuration(spec_helper_path)
|
54
|
+
empty_line = '^\n'
|
55
|
+
comment_line = '^\s*#.+\n'
|
56
|
+
gsub_file spec_helper_path,
|
57
|
+
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
|
58
|
+
'',
|
59
|
+
verbose: false
|
43
60
|
end
|
44
61
|
end
|
45
62
|
end
|
@@ -1,8 +1,11 @@
|
|
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?
|
5
7
|
require 'rspec/rails'
|
8
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
6
9
|
|
7
10
|
# Requires supporting ruby files with custom matchers and macros, etc, in
|
8
11
|
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
@@ -11,20 +14,26 @@ require 'rspec/rails'
|
|
11
14
|
# run twice. It is recommended that you do not name files matching this glob to
|
12
15
|
# end with _spec.rb. You can configure this pattern with the --pattern
|
13
16
|
# 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)
|
17
|
+
#
|
18
|
+
# The following line is provided for convenience purposes. It has the downside
|
19
|
+
# of increasing the boot-up time by auto-requiring all files in the support
|
20
|
+
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
|
+
# require only the support files necessary.
|
22
|
+
#
|
23
|
+
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
|
25
24
|
|
25
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
26
|
+
# Checks for pending migrations and applies them before tests are run.
|
27
|
+
# If you are not using ActiveRecord, you can remove these lines.
|
28
|
+
begin
|
29
|
+
ActiveRecord::Migration.maintain_test_schema!
|
30
|
+
rescue ActiveRecord::PendingMigrationError => e
|
31
|
+
puts e.to_s.strip
|
32
|
+
exit 1
|
33
|
+
end
|
26
34
|
<% end -%>
|
27
35
|
RSpec.configure do |config|
|
36
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
28
37
|
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
29
38
|
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
30
39
|
|
@@ -33,6 +42,21 @@ RSpec.configure do |config|
|
|
33
42
|
# instead of true.
|
34
43
|
config.use_transactional_fixtures = true
|
35
44
|
|
45
|
+
# You can uncomment this line to turn off ActiveRecord support entirely.
|
46
|
+
# config.use_active_record = false
|
47
|
+
|
48
|
+
<% else -%>
|
49
|
+
# Remove this line to enable support for ActiveRecord
|
50
|
+
config.use_active_record = false
|
51
|
+
|
52
|
+
# If you enable ActiveRecord support you should unncomment these lines,
|
53
|
+
# note if you'd prefer not to run each example within a transaction, you
|
54
|
+
# should set use_transactional_fixtures to false.
|
55
|
+
#
|
56
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
57
|
+
# config.use_transactional_fixtures = true
|
58
|
+
|
59
|
+
<% end -%>
|
36
60
|
# RSpec Rails can automatically mix in different behaviours to your tests
|
37
61
|
# based on their file location, for example enabling you to call `get` and
|
38
62
|
# `post` in specs under `spec/controllers`.
|
@@ -40,11 +64,16 @@ RSpec.configure do |config|
|
|
40
64
|
# You can disable this behaviour by removing the line below, and instead
|
41
65
|
# explicitly tag your specs with their type, e.g.:
|
42
66
|
#
|
43
|
-
# RSpec.describe UsersController, :
|
67
|
+
# RSpec.describe UsersController, type: :controller do
|
44
68
|
# # ...
|
45
69
|
# end
|
46
70
|
#
|
47
71
|
# The different available types are documented in the features, such as in
|
48
72
|
# https://relishapp.com/rspec/rspec-rails/docs
|
49
73
|
config.infer_spec_type_from_file_location!
|
74
|
+
|
75
|
+
# Filter lines from Rails gems in backtraces.
|
76
|
+
config.filter_rails_from_backtrace!
|
77
|
+
# arbitrary gems may also be filtered via:
|
78
|
+
# config.filter_gems_from_backtrace("gem name")
|
50
79
|
end
|
@@ -4,13 +4,18 @@ module Rspec
|
|
4
4
|
module Generators
|
5
5
|
# @private
|
6
6
|
class IntegrationGenerator < Base
|
7
|
-
|
7
|
+
# Add a deprecation for this class, before rspec-rails 4, to use the
|
8
|
+
# `RequestGenerator` instead
|
9
|
+
class_option :request_specs,
|
10
|
+
type: :boolean,
|
11
|
+
default: true,
|
12
|
+
desc: "Generate request specs"
|
8
13
|
|
9
14
|
def generate_request_spec
|
10
15
|
return unless options[:request_specs]
|
11
16
|
|
12
17
|
template 'request_spec.rb',
|
13
|
-
File.join('spec/requests',
|
18
|
+
File.join('spec/requests', "#{name.underscore.pluralize}_spec.rb")
|
14
19
|
end
|
15
20
|
end
|
16
21
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
|
-
RSpec.describe "<%= class_name.pluralize %>",
|
4
|
-
describe "GET /<%=
|
3
|
+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
+
describe "GET /<%= name.underscore.pluralize %>" do
|
5
5
|
it "works! (now write some real specs)" do
|
6
6
|
get <%= index_helper %>_path
|
7
|
-
expect(response
|
7
|
+
expect(response).to have_http_status(200)
|
8
8
|
end
|
9
9
|
end
|
10
10
|
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', File.join('spec/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
|
+
File.join('spec/mailboxes', class_path, "#{file_name}_mailbox_spec.rb")
|
10
|
+
)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -1,10 +1,11 @@
|
|
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
|
template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
|
@@ -16,6 +17,12 @@ module Rspec
|
|
16
17
|
template "fixture", File.join("spec/fixtures", @path)
|
17
18
|
end
|
18
19
|
end
|
20
|
+
|
21
|
+
def generate_preview_files
|
22
|
+
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
|
+
|
24
|
+
template "preview.rb", File.join("spec/mailers/previews", class_path, "#{file_name}_preview.rb")
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
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 %>
|
3
|
+
class <%= class_name %>Preview < ActionMailer::Preview
|
4
|
+
<% actions.each do |action| -%>
|
5
|
+
|
6
|
+
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= 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 = File.join(
|
15
|
+
'spec/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', File.join('spec/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
|