rspec-rails 2.14.2 → 4.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 +4 -2
- data/Capybara.md +6 -57
- data/Changelog.md +715 -37
- data/{License.txt → LICENSE.md} +5 -2
- data/README.md +287 -362
- data/lib/generators/rspec/channel/channel_generator.rb +12 -0
- data/lib/generators/rspec/channel/templates/channel_spec.rb.erb +7 -0
- data/lib/generators/rspec/controller/controller_generator.rb +23 -5
- data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
- 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 +2 -2
- data/lib/generators/rspec/feature/feature_generator.rb +29 -0
- data/lib/generators/rspec/feature/templates/feature_singular_spec.rb +5 -0
- data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
- 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 +2 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +2 -2
- data/lib/generators/rspec/install/install_generator.rb +44 -5
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +79 -0
- data/lib/generators/rspec/integration/integration_generator.rb +8 -13
- data/lib/generators/rspec/integration/templates/request_spec.rb +4 -9
- data/lib/generators/rspec/job/job_generator.rb +12 -0
- data/lib/generators/rspec/{observer/templates/observer_spec.rb → job/templates/job_spec.rb.erb} +2 -2
- 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 +9 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +7 -7
- data/lib/generators/rspec/mailer/templates/preview.rb +13 -0
- data/lib/generators/rspec/model/model_generator.rb +21 -6
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +2 -2
- data/lib/generators/rspec/request/request_generator.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +88 -148
- 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 +105 -80
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +10 -14
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +5 -12
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +11 -15
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +137 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +19 -12
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +5 -12
- data/lib/generators/rspec/system/system_generator.rb +26 -0
- data/lib/generators/rspec/system/templates/system_spec.rb +9 -0
- data/lib/generators/rspec/view/templates/view_spec.rb +2 -2
- data/lib/generators/rspec/view/view_generator.rb +3 -2
- data/lib/generators/rspec.rb +18 -10
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +49 -47
- data/lib/rspec/rails/configuration.rb +194 -0
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +188 -138
- data/lib/rspec/rails/example/feature_example_group.rb +43 -20
- data/lib/rspec/rails/example/helper_example_group.rb +28 -26
- 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 +30 -14
- data/lib/rspec/rails/example/model_example_group.rb +8 -7
- data/lib/rspec/rails/example/rails_example_group.rb +4 -2
- data/lib/rspec/rails/example/request_example_group.rb +23 -16
- data/lib/rspec/rails/example/routing_example_group.rb +49 -40
- 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 -33
- data/lib/rspec/rails/extensions/active_record/proxy.rb +5 -11
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +47 -0
- data/lib/rspec/rails/file_fixture_support.rb +17 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +35 -0
- data/lib/rspec/rails/fixture_support.rb +54 -23
- 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 +64 -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 +69 -62
- data/lib/rspec/rails/matchers/be_new_record.rb +24 -21
- data/lib/rspec/rails/matchers/be_valid.rb +42 -33
- data/lib/rspec/rails/matchers/have_enqueued_mail.rb +198 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +385 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +55 -31
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
- data/lib/rspec/rails/matchers/relation_match_array.rb +2 -2
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -93
- data/lib/rspec/rails/matchers.rb +22 -14
- data/lib/rspec/rails/tasks/rspec.rake +8 -18
- data/lib/rspec/rails/vendor/capybara.rb +12 -11
- data/lib/rspec/rails/version.rb +3 -1
- data/lib/rspec/rails/view_assigns.rb +18 -18
- data/lib/rspec/rails/view_path_builder.rb +29 -0
- data/lib/rspec/rails/view_rendering.rb +100 -63
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +10 -10
- data/lib/rspec-rails.rb +67 -3
- data.tar.gz.sig +0 -0
- metadata +121 -94
- metadata.gz.sig +0 -0
- data/lib/autotest/rails_rspec2.rb +0 -85
- data/lib/generators/rspec/install/templates/.rspec +0 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +0 -49
- data/lib/generators/rspec/observer/observer_generator.rb +0 -12
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/mocks.rb +0 -274
- data/lib/rspec/rails/module_inclusion.rb +0 -19
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
@@ -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
|
@@ -2,12 +2,22 @@ require 'generators/rspec'
|
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
|
+
# @private
|
5
6
|
class ControllerGenerator < Base
|
6
|
-
argument :actions, :
|
7
|
+
argument :actions, type: :array, default: [], banner: "action action"
|
7
8
|
|
8
|
-
class_option :template_engine,
|
9
|
-
class_option :
|
10
|
-
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
|
11
21
|
|
12
22
|
def generate_controller_spec
|
13
23
|
return unless options[:controller_specs]
|
@@ -17,7 +27,7 @@ module Rspec
|
|
17
27
|
end
|
18
28
|
|
19
29
|
def generate_view_specs
|
20
|
-
return if actions.empty?
|
30
|
+
return if actions.empty? && behavior == :invoke
|
21
31
|
return unless options[:view_specs] && options[:template_engine]
|
22
32
|
|
23
33
|
empty_directory File.join("spec", "views", file_path)
|
@@ -28,6 +38,14 @@ module Rspec
|
|
28
38
|
File.join("spec", "views", file_path, "#{@action}.html.#{options[:template_engine]}_spec.rb")
|
29
39
|
end
|
30
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
|
31
49
|
end
|
32
50
|
end
|
33
51
|
end
|
@@ -1,13 +1,13 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
describe <%= class_name %>Controller do
|
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
|
-
get
|
10
|
-
response.
|
9
|
+
get :<%= action %>
|
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
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
|
-
describe "<%= file_name %>/<%= @action %>.html.<%= options[:template_engine] %>" do
|
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
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'generators/rspec'
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
module Generators
|
5
|
+
# @private
|
6
|
+
class FeatureGenerator < Base
|
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
|
+
|
10
|
+
def generate_feature_spec
|
11
|
+
return unless options[:feature_specs]
|
12
|
+
|
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
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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
|
@@ -2,8 +2,9 @@ require 'generators/rspec'
|
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
|
+
# @private
|
5
6
|
class HelperGenerator < Base
|
6
|
-
class_option :helper_specs, :
|
7
|
+
class_option :helper_specs, type: :boolean, default: true
|
7
8
|
|
8
9
|
def generate_helper_spec
|
9
10
|
return unless options[:helper_specs]
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
3
|
# Specs in this file have access to a helper object that includes
|
4
4
|
# the <%= class_name %>Helper. For example:
|
@@ -11,7 +11,7 @@ require 'spec_helper'
|
|
11
11
|
# end
|
12
12
|
# end
|
13
13
|
<% module_namespacing do -%>
|
14
|
-
describe <%= class_name %>Helper do
|
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,7 +1,12 @@
|
|
1
|
+
require "rspec/support"
|
2
|
+
require "rspec/core"
|
3
|
+
RSpec::Support.require_rspec_core "project_initializer"
|
4
|
+
require "rspec/rails/feature_check"
|
5
|
+
|
1
6
|
module Rspec
|
2
7
|
module Generators
|
8
|
+
# @private
|
3
9
|
class InstallGenerator < ::Rails::Generators::Base
|
4
|
-
|
5
10
|
desc <<DESC
|
6
11
|
Description:
|
7
12
|
Copy rspec files to your application.
|
@@ -11,14 +16,48 @@ DESC
|
|
11
16
|
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
|
12
17
|
end
|
13
18
|
|
14
|
-
def
|
15
|
-
|
19
|
+
def copy_spec_files
|
20
|
+
Dir.mktmpdir do |dir|
|
21
|
+
generate_rspec_init dir
|
22
|
+
template File.join(dir, '.rspec'), '.rspec'
|
23
|
+
directory File.join(dir, 'spec'), 'spec'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_rails_files
|
28
|
+
template 'spec/rails_helper.rb'
|
16
29
|
end
|
17
30
|
|
18
|
-
|
19
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def generate_rspec_init(tmpdir)
|
34
|
+
initializer = ::RSpec::Core::ProjectInitializer.new(
|
35
|
+
destination: tmpdir,
|
36
|
+
report_stream: StringIO.new
|
37
|
+
)
|
38
|
+
initializer.run
|
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)
|
20
44
|
end
|
21
45
|
|
46
|
+
def replace_generator_command(spec_helper_path)
|
47
|
+
gsub_file spec_helper_path,
|
48
|
+
'rspec --init',
|
49
|
+
'rails generate rspec:install',
|
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
|
60
|
+
end
|
22
61
|
end
|
23
62
|
end
|
24
63
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# This file is copied to spec/ when you run 'rails generate rspec:install'
|
2
|
+
require 'spec_helper'
|
3
|
+
ENV['RAILS_ENV'] ||= 'test'
|
4
|
+
require File.expand_path('../config/environment', __dir__)
|
5
|
+
# Prevent database truncation if the environment is production
|
6
|
+
abort("The Rails environment is running in production mode!") if Rails.env.production?
|
7
|
+
require 'rspec/rails'
|
8
|
+
# Add additional requires below this line. Rails is not loaded until this point!
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc, in
|
11
|
+
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
|
12
|
+
# run as spec files by default. This means that files in spec/support that end
|
13
|
+
# in _spec.rb will both be required and run as specs, causing the specs to be
|
14
|
+
# run twice. It is recommended that you do not name files matching this glob to
|
15
|
+
# end with _spec.rb. You can configure this pattern with the --pattern
|
16
|
+
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
|
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 }
|
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
|
34
|
+
<% end -%>
|
35
|
+
RSpec.configure do |config|
|
36
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
37
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
38
|
+
config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
39
|
+
|
40
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
41
|
+
# examples within a transaction, remove the following line or assign false
|
42
|
+
# instead of true.
|
43
|
+
config.use_transactional_fixtures = true
|
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 -%>
|
60
|
+
# RSpec Rails can automatically mix in different behaviours to your tests
|
61
|
+
# based on their file location, for example enabling you to call `get` and
|
62
|
+
# `post` in specs under `spec/controllers`.
|
63
|
+
#
|
64
|
+
# You can disable this behaviour by removing the line below, and instead
|
65
|
+
# explicitly tag your specs with their type, e.g.:
|
66
|
+
#
|
67
|
+
# RSpec.describe UsersController, type: :controller do
|
68
|
+
# # ...
|
69
|
+
# end
|
70
|
+
#
|
71
|
+
# The different available types are documented in the features, such as in
|
72
|
+
# https://relishapp.com/rspec/rspec-rails/docs
|
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")
|
79
|
+
end
|
@@ -2,26 +2,21 @@ require 'generators/rspec'
|
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
|
+
# @private
|
5
6
|
class IntegrationGenerator < Base
|
6
|
-
|
7
|
-
|
8
|
-
class_option :
|
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"
|
9
13
|
|
10
14
|
def generate_request_spec
|
11
15
|
return unless options[:request_specs]
|
12
16
|
|
13
17
|
template 'request_spec.rb',
|
14
|
-
File.join('spec/requests',
|
18
|
+
File.join('spec/requests', "#{name.underscore.pluralize}_spec.rb")
|
15
19
|
end
|
16
|
-
|
17
|
-
protected
|
18
|
-
|
19
|
-
# @deprecated Use `--webrat` instead.
|
20
|
-
def webrat?
|
21
|
-
RSpec.deprecate("the --webrat-matchers option", :replacement => "--webrat") if options[:webrat_matchers]
|
22
|
-
options[:webrat] || options[:webrat_matchers]
|
23
|
-
end
|
24
|
-
|
25
20
|
end
|
26
21
|
end
|
27
22
|
end
|
@@ -1,15 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'rails_helper'
|
2
2
|
|
3
|
-
describe "<%= class_name.pluralize %>" do
|
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
|
-
<% if webrat? -%>
|
7
|
-
visit <%= index_helper %>_path
|
8
|
-
<% else -%>
|
9
|
-
# Run the generator again with the --webrat flag if you want to use webrat methods/matchers
|
10
6
|
get <%= index_helper %>_path
|
11
|
-
|
12
|
-
response.status.should be(200)
|
7
|
+
expect(response).to have_http_status(200)
|
13
8
|
end
|
14
9
|
end
|
15
10
|
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,9 +1,11 @@
|
|
1
1
|
require 'generators/rspec'
|
2
|
+
require "rspec/rails/feature_check"
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Generators
|
6
|
+
# @private
|
5
7
|
class MailerGenerator < Base
|
6
|
-
argument :actions, :
|
8
|
+
argument :actions, type: :array, default: [], banner: "method method"
|
7
9
|
|
8
10
|
def generate_mailer_spec
|
9
11
|
template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
|
@@ -15,6 +17,12 @@ module Rspec
|
|
15
17
|
template "fixture", File.join("spec/fixtures", @path)
|
16
18
|
end
|
17
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
|
18
26
|
end
|
19
27
|
end
|
20
28
|
end
|
@@ -1,19 +1,19 @@
|
|
1
|
-
require "
|
1
|
+
require "rails_helper"
|
2
2
|
|
3
3
|
<% module_namespacing do -%>
|
4
|
-
describe <%= class_name %> do
|
4
|
+
RSpec.describe <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>, <%= type_metatag(:mailer) %> do
|
5
5
|
<% for action in actions -%>
|
6
6
|
describe "<%= action %>" do
|
7
|
-
let(:mail) { <%= class_name %>.<%= action %> }
|
7
|
+
let(:mail) { <%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %> }
|
8
8
|
|
9
9
|
it "renders the headers" do
|
10
|
-
mail.subject.
|
11
|
-
mail.to.
|
12
|
-
mail.from.
|
10
|
+
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)
|
11
|
+
expect(mail.to).to eq(["to@example.org"])
|
12
|
+
expect(mail.from).to eq(["from@example.com"])
|
13
13
|
end
|
14
14
|
|
15
15
|
it "renders the body" do
|
16
|
-
mail.body.encoded.
|
16
|
+
expect(mail.body.encoded).to match("Hi")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -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
|
+
<%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %>
|
9
|
+
end
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
end
|
13
|
+
<% end -%>
|
@@ -2,20 +2,35 @@ require 'generators/rspec'
|
|
2
2
|
|
3
3
|
module Rspec
|
4
4
|
module Generators
|
5
|
+
# @private
|
5
6
|
class ModelGenerator < Base
|
6
|
-
argument :attributes,
|
7
|
-
|
7
|
+
argument :attributes,
|
8
|
+
type: :array,
|
9
|
+
default: [],
|
10
|
+
banner: "field:type field:type"
|
11
|
+
class_option :fixture, type: :boolean
|
8
12
|
|
9
13
|
def create_model_spec
|
10
|
-
|
14
|
+
template_file = File.join(
|
15
|
+
'spec/models',
|
16
|
+
class_path,
|
17
|
+
"#{file_name}_spec.rb"
|
18
|
+
)
|
19
|
+
template 'model_spec.rb', template_file
|
11
20
|
end
|
12
21
|
|
13
22
|
hook_for :fixture_replacement
|
14
23
|
|
15
24
|
def create_fixture_file
|
16
|
-
|
17
|
-
|
18
|
-
|
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?
|
19
34
|
end
|
20
35
|
end
|
21
36
|
end
|