rspec-rails 3.7.0 → 4.0.0
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/Capybara.md +5 -54
- data/Changelog.md +259 -70
- data/README.md +265 -496
- 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 +21 -4
- data/lib/generators/rspec/controller/templates/request_spec.rb +14 -0
- data/lib/generators/rspec/controller/templates/routing_spec.rb +13 -0
- data/lib/generators/rspec/feature/feature_generator.rb +4 -4
- 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/install/install_generator.rb +4 -4
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +25 -12
- data/lib/generators/rspec/integration/integration_generator.rb +4 -4
- data/lib/generators/rspec/integration/templates/request_spec.rb +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 +2 -1
- data/lib/generators/rspec/mailer/templates/preview.rb +1 -1
- data/lib/generators/rspec/model/model_generator.rb +6 -5
- data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
- data/lib/generators/rspec/request/request_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +43 -23
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +2 -38
- data/lib/generators/rspec/scaffold/templates/api_request_spec.rb +131 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +17 -17
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/request_spec.rb +133 -0
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +10 -13
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +1 -1
- 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/view_generator.rb +2 -2
- data/lib/generators/rspec.rb +0 -6
- data/lib/rspec/rails/adapters.rb +11 -76
- data/lib/rspec/rails/configuration.rb +47 -36
- data/lib/rspec/rails/example/channel_example_group.rb +93 -0
- data/lib/rspec/rails/example/controller_example_group.rb +4 -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 +1 -1
- data/lib/rspec/rails/example/rails_example_group.rb +1 -1
- data/lib/rspec/rails/example/system_example_group.rb +96 -60
- data/lib/rspec/rails/example/view_example_group.rb +47 -28
- data/lib/rspec/rails/example.rb +3 -3
- data/lib/rspec/rails/extensions/active_record/proxy.rb +1 -9
- data/lib/rspec/rails/feature_check.rb +12 -29
- data/lib/rspec/rails/fixture_file_upload_support.rb +40 -0
- data/lib/rspec/rails/fixture_support.rb +37 -31
- 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 +180 -22
- 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 +198 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +34 -13
- 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/routing_matchers.rb +14 -14
- data/lib/rspec/rails/matchers.rb +11 -0
- data/lib/rspec/rails/tasks/rspec.rake +7 -17
- data/lib/rspec/rails/vendor/capybara.rb +10 -15
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_path_builder.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +16 -5
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec-rails.rb +13 -10
- data.tar.gz.sig +0 -0
- metadata +55 -33
- 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}_request_spec.rb")
|
20
|
+
end
|
12
21
|
|
13
22
|
def generate_controller_spec
|
14
23
|
return unless options[:controller_specs]
|
@@ -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
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
+
<% namespaced_path = regular_class_path.join('/') %>
|
5
|
+
<% for action in actions -%>
|
6
|
+
describe "GET /<%= action %>" do
|
7
|
+
it "returns http success" do
|
8
|
+
get "<%= "/#{namespaced_path}" if namespaced_path != '' %>/<%= file_name %>/<%= action %>"
|
9
|
+
expect(response).to have_http_status(:success)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
<% end -%>
|
14
|
+
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,8 +4,8 @@ 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]
|
@@ -19,9 +19,9 @@ module Rspec
|
|
19
19
|
|
20
20
|
def filename
|
21
21
|
if options[:singularize]
|
22
|
-
"#{
|
22
|
+
"#{file_name.singularize}_spec.rb"
|
23
23
|
else
|
24
|
-
"#{
|
24
|
+
"#{file_name}_spec.rb"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
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]
|
@@ -32,8 +32,8 @@ 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
|
|
@@ -47,7 +47,7 @@ DESC
|
|
47
47
|
gsub_file spec_helper_path,
|
48
48
|
'rspec --init',
|
49
49
|
'rails generate rspec:install',
|
50
|
-
:
|
50
|
+
verbose: false
|
51
51
|
end
|
52
52
|
|
53
53
|
def remove_warnings_configuration(spec_helper_path)
|
@@ -56,7 +56,7 @@ DESC
|
|
56
56
|
gsub_file spec_helper_path,
|
57
57
|
/#{empty_line}(#{comment_line})+\s+config\.warnings = true\n/,
|
58
58
|
'',
|
59
|
-
:
|
59
|
+
verbose: false
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
@@ -1,7 +1,7 @@
|
|
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
|
-
require File.expand_path('
|
4
|
+
require File.expand_path('../config/environment', __dir__)
|
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
7
|
require 'rspec/rails'
|
@@ -20,18 +20,17 @@ require 'rspec/rails'
|
|
20
20
|
# directory. Alternatively, in the individual `*_spec.rb` files, manually
|
21
21
|
# require only the support files necessary.
|
22
22
|
#
|
23
|
-
# Dir[Rails.root.join('spec
|
23
|
+
# Dir[Rails.root.join('spec', 'support', '**', '*.rb')].sort.each { |f| require f }
|
24
24
|
|
25
|
-
<% if RSpec::Rails::FeatureCheck.
|
25
|
+
<% if RSpec::Rails::FeatureCheck.has_active_record_migration? -%>
|
26
26
|
# Checks for pending migrations and applies them before tests are run.
|
27
|
-
# If you are not using ActiveRecord, you can remove
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
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
|
35
34
|
<% end -%>
|
36
35
|
RSpec.configure do |config|
|
37
36
|
<% if RSpec::Rails::FeatureCheck.has_active_record? -%>
|
@@ -43,6 +42,20 @@ RSpec.configure do |config|
|
|
43
42
|
# instead of true.
|
44
43
|
config.use_transactional_fixtures = true
|
45
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
|
+
|
46
59
|
<% end -%>
|
47
60
|
# RSpec Rails can automatically mix in different behaviours to your tests
|
48
61
|
# based on their file location, for example enabling you to call `get` and
|
@@ -51,7 +64,7 @@ RSpec.configure do |config|
|
|
51
64
|
# You can disable this behaviour by removing the line below, and instead
|
52
65
|
# explicitly tag your specs with their type, e.g.:
|
53
66
|
#
|
54
|
-
# RSpec.describe UsersController, :
|
67
|
+
# RSpec.describe UsersController, type: :controller do
|
55
68
|
# # ...
|
56
69
|
# end
|
57
70
|
#
|
@@ -7,15 +7,15 @@ module Rspec
|
|
7
7
|
# Add a deprecation for this class, before rspec-rails 4, to use the
|
8
8
|
# `RequestGenerator` instead
|
9
9
|
class_option :request_specs,
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:
|
10
|
+
type: :boolean,
|
11
|
+
default: true,
|
12
|
+
desc: "Generate request specs"
|
13
13
|
|
14
14
|
def generate_request_spec
|
15
15
|
return unless options[:request_specs]
|
16
16
|
|
17
17
|
template 'request_spec.rb',
|
18
|
-
File.join('spec/requests',
|
18
|
+
File.join('spec/requests', "#{name.underscore.pluralize}_spec.rb")
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rails_helper'
|
2
2
|
|
3
3
|
RSpec.describe "<%= class_name.pluralize %>", <%= type_metatag(:request) %> do
|
4
|
-
describe "GET /<%=
|
4
|
+
describe "GET /<%= name.underscore.pluralize %>" do
|
5
5
|
it "works! (now write some real specs)" do
|
6
6
|
get <%= index_helper %>_path
|
7
7
|
expect(response).to have_http_status(200)
|
@@ -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
|
@@ -5,7 +5,7 @@ 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
|
template "mailer_spec.rb", File.join('spec/mailers', class_path, "#{file_name}_spec.rb")
|
@@ -20,6 +20,7 @@ module Rspec
|
|
20
20
|
|
21
21
|
def generate_preview_files
|
22
22
|
return unless RSpec::Rails::FeatureCheck.has_action_mailer_preview?
|
23
|
+
|
23
24
|
template "preview.rb", File.join("spec/mailers/previews", class_path, "#{file_name}_preview.rb")
|
24
25
|
end
|
25
26
|
end
|
@@ -5,7 +5,7 @@ class <%= class_name %>Preview < ActionMailer::Preview
|
|
5
5
|
|
6
6
|
# Preview this email at http://localhost:3000/rails/mailers/<%= file_path %>/<%= action %>
|
7
7
|
def <%= action %>
|
8
|
-
<%=
|
8
|
+
<%= Rails.version.to_f >= 5.0 ? class_name.sub(/(Mailer)?$/, 'Mailer') : class_name %>.<%= action %>
|
9
9
|
end
|
10
10
|
<% end -%>
|
11
11
|
|
@@ -5,10 +5,10 @@ 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
14
|
template_file = File.join(
|
@@ -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', File.join('spec/fixtures', class_path, "#{(pluralize_table_names? ? plural_file_name : file_name)}.yml")
|
27
28
|
end
|
28
29
|
|
29
30
|
private
|
@@ -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
|
|
@@ -60,8 +66,6 @@ module Rspec
|
|
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
|
@@ -73,21 +77,33 @@ module Rspec
|
|
73
77
|
|
74
78
|
# support for namespaced-resources
|
75
79
|
def ns_file_name
|
76
|
-
|
80
|
+
return file_name if ns_parts.empty?
|
81
|
+
|
82
|
+
"#{ns_prefix.map(&:underscore).join('/')}_#{ns_suffix.singularize.underscore}"
|
77
83
|
end
|
78
84
|
|
79
85
|
# support for namespaced-resources
|
80
86
|
def ns_table_name
|
81
|
-
|
87
|
+
return table_name if ns_parts.empty?
|
88
|
+
|
89
|
+
"#{ns_prefix.map(&:underscore).join('/')}/#{ns_suffix.tableize}"
|
82
90
|
end
|
83
91
|
|
84
92
|
def ns_parts
|
85
93
|
@ns_parts ||= begin
|
86
|
-
|
87
|
-
|
94
|
+
parts = generator_args[0].split(/\/|::/)
|
95
|
+
parts.size > 1 ? parts : []
|
88
96
|
end
|
89
97
|
end
|
90
98
|
|
99
|
+
def ns_prefix
|
100
|
+
@ns_prefix ||= ns_parts[0..-2]
|
101
|
+
end
|
102
|
+
|
103
|
+
def ns_suffix
|
104
|
+
@ns_suffix ||= ns_parts[-1]
|
105
|
+
end
|
106
|
+
|
91
107
|
def value_for(attribute)
|
92
108
|
raw_value_for(attribute).inspect
|
93
109
|
end
|
@@ -104,6 +120,10 @@ module Rspec
|
|
104
120
|
end
|
105
121
|
end
|
106
122
|
|
123
|
+
def template_file(folder:, suffix: '')
|
124
|
+
File.join('spec', folder, controller_class_path, "#{controller_file_name}#{suffix}_spec.rb")
|
125
|
+
end
|
126
|
+
|
107
127
|
def banner
|
108
128
|
self.class.banner
|
109
129
|
end
|
@@ -46,12 +46,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
46
46
|
describe "GET #index" do
|
47
47
|
it "returns a success response" do
|
48
48
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
49
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
50
|
-
get :index, {}, valid_session
|
51
|
-
<% else -%>
|
52
49
|
get :index, params: {}, session: valid_session
|
53
|
-
|
54
|
-
expect(response).to be_success
|
50
|
+
expect(response).to be_successful
|
55
51
|
end
|
56
52
|
end
|
57
53
|
|
@@ -59,12 +55,8 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
59
55
|
describe "GET #show" do
|
60
56
|
it "returns a success response" do
|
61
57
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
62
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
63
|
-
get :show, {:id => <%= file_name %>.to_param}, valid_session
|
64
|
-
<% else -%>
|
65
58
|
get :show, params: {id: <%= file_name %>.to_param}, session: valid_session
|
66
|
-
|
67
|
-
expect(response).to be_success
|
59
|
+
expect(response).to be_successful
|
68
60
|
end
|
69
61
|
end
|
70
62
|
|
@@ -72,20 +64,12 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
72
64
|
context "with valid params" do
|
73
65
|
it "creates a new <%= class_name %>" do
|
74
66
|
expect {
|
75
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
76
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
77
|
-
<% else -%>
|
78
67
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
79
|
-
<% end -%>
|
80
68
|
}.to change(<%= class_name %>, :count).by(1)
|
81
69
|
end
|
82
70
|
|
83
71
|
it "renders a JSON response with the new <%= ns_file_name %>" do
|
84
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
85
|
-
post :create, {:<%= ns_file_name %> => valid_attributes}, valid_session
|
86
|
-
<% else %>
|
87
72
|
post :create, params: {<%= ns_file_name %>: valid_attributes}, session: valid_session
|
88
|
-
<% end -%>
|
89
73
|
expect(response).to have_http_status(:created)
|
90
74
|
expect(response.content_type).to eq('application/json')
|
91
75
|
expect(response.location).to eq(<%= ns_file_name %>_url(<%= class_name %>.last))
|
@@ -94,11 +78,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
94
78
|
|
95
79
|
context "with invalid params" do
|
96
80
|
it "renders a JSON response with errors for the new <%= ns_file_name %>" do
|
97
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
98
|
-
post :create, {:<%= ns_file_name %> => invalid_attributes}, valid_session
|
99
|
-
<% else %>
|
100
81
|
post :create, params: {<%= ns_file_name %>: invalid_attributes}, session: valid_session
|
101
|
-
<% end -%>
|
102
82
|
expect(response).to have_http_status(:unprocessable_entity)
|
103
83
|
expect(response.content_type).to eq('application/json')
|
104
84
|
end
|
@@ -113,22 +93,14 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
113
93
|
|
114
94
|
it "updates the requested <%= ns_file_name %>" do
|
115
95
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
116
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
117
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => new_attributes}, valid_session
|
118
|
-
<% else -%>
|
119
96
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: new_attributes}, session: valid_session
|
120
|
-
<% end -%>
|
121
97
|
<%= file_name %>.reload
|
122
98
|
skip("Add assertions for updated state")
|
123
99
|
end
|
124
100
|
|
125
101
|
it "renders a JSON response with the <%= ns_file_name %>" do
|
126
102
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
127
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
128
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => valid_attributes}, valid_session
|
129
|
-
<% else %>
|
130
103
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: valid_attributes}, session: valid_session
|
131
|
-
<% end -%>
|
132
104
|
expect(response).to have_http_status(:ok)
|
133
105
|
expect(response.content_type).to eq('application/json')
|
134
106
|
end
|
@@ -137,11 +109,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
137
109
|
context "with invalid params" do
|
138
110
|
it "renders a JSON response with errors for the <%= ns_file_name %>" do
|
139
111
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
140
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
141
|
-
put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => invalid_attributes}, valid_session
|
142
|
-
<% else %>
|
143
112
|
put :update, params: {id: <%= file_name %>.to_param, <%= ns_file_name %>: invalid_attributes}, session: valid_session
|
144
|
-
<% end -%>
|
145
113
|
expect(response).to have_http_status(:unprocessable_entity)
|
146
114
|
expect(response.content_type).to eq('application/json')
|
147
115
|
end
|
@@ -152,11 +120,7 @@ RSpec.describe <%= controller_class_name %>Controller, <%= type_metatag(:control
|
|
152
120
|
it "destroys the requested <%= ns_file_name %>" do
|
153
121
|
<%= file_name %> = <%= class_name %>.create! valid_attributes
|
154
122
|
expect {
|
155
|
-
<% if RUBY_VERSION < '1.9.3' -%>
|
156
|
-
delete :destroy, {:id => <%= file_name %>.to_param}, valid_session
|
157
|
-
<% else -%>
|
158
123
|
delete :destroy, params: {id: <%= file_name %>.to_param}, session: valid_session
|
159
|
-
<% end -%>
|
160
124
|
}.to change(<%= class_name %>, :count).by(-1)
|
161
125
|
end
|
162
126
|
end
|