rspec-rails 2.14.2 → 3.9.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 +4 -2
- data/Capybara.md +2 -4
- data/Changelog.md +592 -34
- data/{License.txt → LICENSE.md} +5 -2
- data/README.md +290 -369
- data/lib/generators/rspec/controller/controller_generator.rb +1 -0
- data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
- 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/generators/generator_generator.rb +24 -0
- data/lib/generators/rspec/generators/templates/generator_spec.rb +6 -0
- data/lib/generators/rspec/helper/helper_generator.rb +1 -0
- 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 +78 -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/job/templates/job_spec.rb.erb +7 -0
- data/lib/generators/rspec/mailer/mailer_generator.rb +7 -0
- 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 +19 -5
- 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/observer/observer_generator.rb +1 -0
- data/lib/generators/rspec/observer/templates/observer_spec.rb +2 -2
- data/lib/generators/rspec/request/request_generator.rb +10 -0
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +68 -138
- data/lib/generators/rspec/scaffold/templates/api_controller_spec.rb +165 -0
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +98 -73
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +9 -13
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -10
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +10 -14
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +21 -12
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +4 -11
- 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 +1 -0
- data/lib/generators/rspec.rb +20 -6
- data/lib/rspec/rails/active_record.rb +25 -0
- data/lib/rspec/rails/adapters.rb +104 -37
- data/lib/rspec/rails/configuration.rb +148 -0
- data/lib/rspec/rails/example/controller_example_group.rb +188 -138
- data/lib/rspec/rails/example/feature_example_group.rb +63 -20
- data/lib/rspec/rails/example/helper_example_group.rb +35 -26
- data/lib/rspec/rails/example/job_example_group.rb +23 -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 +3 -1
- 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 +108 -0
- data/lib/rspec/rails/example/view_example_group.rb +168 -135
- data/lib/rspec/rails/example.rb +2 -33
- data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +64 -0
- data/lib/rspec/rails/file_fixture_support.rb +17 -0
- data/lib/rspec/rails/fixture_file_upload_support.rb +40 -0
- data/lib/rspec/rails/fixture_support.rb +32 -13
- data/lib/rspec/rails/matchers/active_job.rb +317 -0
- data/lib/rspec/rails/matchers/base_matcher.rb +184 -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 +174 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +381 -0
- data/lib/rspec/rails/matchers/have_rendered.rb +54 -31
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +107 -93
- data/lib/rspec/rails/matchers.rb +13 -14
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +10 -4
- 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 +89 -63
- data/lib/rspec/rails/view_spec_methods.rb +56 -0
- data/lib/rspec/rails.rb +10 -10
- data/lib/rspec-rails.rb +66 -1
- data.tar.gz.sig +0 -0
- metadata +92 -77
- 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/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,23 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container module for job spec functionality. It is only available if
|
5
|
+
# ActiveJob has been loaded before it.
|
6
|
+
module JobExampleGroup
|
7
|
+
# This blank module is only necessary for YARD processing. It doesn't
|
8
|
+
# handle the conditional `defined?` check below very well.
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
if defined?(ActiveJob)
|
14
|
+
module RSpec
|
15
|
+
module Rails
|
16
|
+
# Container module for job spec functionality.
|
17
|
+
module JobExampleGroup
|
18
|
+
extend ActiveSupport::Concern
|
19
|
+
include RSpec::Rails::RailsExampleGroup
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,20 +1,36 @@
|
|
1
|
-
|
2
|
-
module
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container module for mailer spec functionality. It is only available if
|
5
|
+
# ActionMailer has been loaded before it.
|
3
6
|
module MailerExampleGroup
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
+
# This blank module is only necessary for YARD processing. It doesn't
|
8
|
+
# handle the conditional `defined?` check below very well.
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
7
12
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
if defined?(ActionMailer)
|
14
|
+
module RSpec
|
15
|
+
module Rails
|
16
|
+
# Container module for mailer spec functionality.
|
17
|
+
module MailerExampleGroup
|
18
|
+
extend ActiveSupport::Concern
|
19
|
+
include RSpec::Rails::RailsExampleGroup
|
20
|
+
include ActionMailer::TestCase::Behavior
|
21
|
+
|
22
|
+
included do
|
23
|
+
include ::Rails.application.routes.url_helpers
|
24
|
+
options = ::Rails.configuration.action_mailer.default_url_options
|
25
|
+
options.each { |key, value| default_url_options[key] = value } if options
|
26
|
+
end
|
14
27
|
|
15
|
-
|
16
|
-
|
17
|
-
described_class
|
28
|
+
# Class-level DSL for mailer specs.
|
29
|
+
module ClassMethods
|
30
|
+
# Alias for `described_class`.
|
31
|
+
def mailer_class
|
32
|
+
described_class
|
33
|
+
end
|
18
34
|
end
|
19
35
|
end
|
20
36
|
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container class for model spec functionality. Does not provide anything
|
5
|
+
# special over the common RailsExampleGroup currently.
|
6
|
+
module ModelExampleGroup
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
@@ -4,12 +4,14 @@ require 'rspec/rails/matchers'
|
|
4
4
|
|
5
5
|
module RSpec
|
6
6
|
module Rails
|
7
|
+
# @api public
|
8
|
+
# Common rails example functionality.
|
7
9
|
module RailsExampleGroup
|
8
10
|
extend ActiveSupport::Concern
|
9
11
|
include RSpec::Rails::SetupAndTeardownAdapter
|
10
12
|
include RSpec::Rails::MinitestLifecycleAdapter if ::Rails::VERSION::STRING >= '4'
|
11
13
|
include RSpec::Rails::MinitestAssertionAdapter
|
12
|
-
include RSpec::Rails::
|
14
|
+
include RSpec::Rails::FixtureSupport
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,22 +1,29 @@
|
|
1
|
-
module RSpec
|
2
|
-
module
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container class for request spec functionality.
|
5
|
+
module RequestExampleGroup
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include RSpec::Rails::RailsExampleGroup
|
8
|
+
include ActionDispatch::Integration::Runner
|
9
|
+
include ActionDispatch::Assertions
|
10
|
+
include RSpec::Rails::Matchers::RedirectTo
|
11
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
12
|
+
include ActionController::TemplateAssertions
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
if ActionPack::VERSION::MAJOR >= 5
|
15
|
+
include ActionDispatch::IntegrationTest::Behavior
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
|
18
|
+
# Delegates to `Rails.application`.
|
19
|
+
def app
|
20
|
+
::Rails.application
|
21
|
+
end
|
17
22
|
|
18
|
-
|
19
|
-
|
23
|
+
included do
|
24
|
+
before do
|
25
|
+
@routes = ::Rails.application.routes
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
22
29
|
end
|
@@ -1,54 +1,63 @@
|
|
1
1
|
require "action_dispatch/testing/assertions/routing"
|
2
2
|
|
3
|
-
module RSpec
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
module
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
#
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# @private
|
6
|
+
RoutingAssertionDelegator = RSpec::Rails::AssertionDelegator.new(
|
7
|
+
ActionDispatch::Assertions::RoutingAssertions
|
8
|
+
)
|
9
|
+
|
10
|
+
# @api public
|
11
|
+
# Container module for routing spec functionality.
|
12
|
+
module RoutingExampleGroup
|
13
|
+
extend ActiveSupport::Concern
|
14
|
+
include RSpec::Rails::RailsExampleGroup
|
15
|
+
include RSpec::Rails::Matchers::RoutingMatchers
|
16
|
+
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
|
17
|
+
include RSpec::Rails::RoutingAssertionDelegator
|
18
|
+
|
19
|
+
# Class-level DSL for route specs.
|
20
|
+
module ClassMethods
|
21
|
+
# Specifies the routeset that will be used for the example group. This
|
22
|
+
# is most useful when testing Rails engines.
|
23
|
+
#
|
24
|
+
# @example
|
25
|
+
# describe MyEngine::PostsController do
|
26
|
+
# routes { MyEngine::Engine.routes }
|
27
|
+
#
|
28
|
+
# it "routes posts#index" do
|
29
|
+
# expect(:get => "/posts").to
|
30
|
+
# route_to(:controller => "my_engine/posts", :action => "index")
|
31
|
+
# end
|
32
|
+
# end
|
33
|
+
def routes
|
34
|
+
before do
|
35
|
+
self.routes = yield
|
36
|
+
end
|
28
37
|
end
|
29
38
|
end
|
30
|
-
end
|
31
|
-
|
32
|
-
included do
|
33
|
-
metadata[:type] = :routing
|
34
39
|
|
35
|
-
|
36
|
-
|
40
|
+
included do
|
41
|
+
before do
|
42
|
+
self.routes = ::Rails.application.routes
|
43
|
+
end
|
37
44
|
end
|
38
|
-
end
|
39
45
|
|
40
|
-
|
46
|
+
# @!attribute [r]
|
47
|
+
# @private
|
48
|
+
attr_reader :routes
|
41
49
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
50
|
+
# @private
|
51
|
+
def routes=(routes)
|
52
|
+
@routes = routes
|
53
|
+
assertion_instance.instance_variable_set(:@routes, routes)
|
54
|
+
end
|
47
55
|
|
48
56
|
private
|
49
57
|
|
50
|
-
|
51
|
-
|
58
|
+
def method_missing(m, *args, &block)
|
59
|
+
routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
|
60
|
+
end
|
52
61
|
end
|
53
62
|
end
|
54
63
|
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# @api public
|
4
|
+
# Container class for system tests
|
5
|
+
module SystemExampleGroup
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include RSpec::Rails::RailsExampleGroup
|
8
|
+
include RSpec::Rails::Matchers::RedirectTo
|
9
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
10
|
+
include ActionDispatch::Integration::Runner
|
11
|
+
include ActionDispatch::Assertions
|
12
|
+
include ActionController::TemplateAssertions
|
13
|
+
|
14
|
+
# Special characters to translate into underscores for #method_name
|
15
|
+
CHARS_TO_TRANSLATE = ['/', '.', ':', ',', "'", '"', " "].freeze
|
16
|
+
|
17
|
+
# @private
|
18
|
+
module BlowAwayAfterTeardownHook
|
19
|
+
# @private
|
20
|
+
def after_teardown
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# for the SystemTesting Screenshot situation
|
25
|
+
def passed?
|
26
|
+
return false if RSpec.current_example.exception
|
27
|
+
return true unless defined?(::RSpec::Expectations::FailureAggregator)
|
28
|
+
|
29
|
+
failure_notifier = ::RSpec::Support.failure_notifier
|
30
|
+
return true unless failure_notifier.is_a?(::RSpec::Expectations::FailureAggregator)
|
31
|
+
|
32
|
+
failure_notifier.failures.empty? && failure_notifier.other_errors.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
# @private
|
36
|
+
def method_name
|
37
|
+
@method_name ||= [
|
38
|
+
self.class.name.underscore,
|
39
|
+
RSpec.current_example.description.underscore
|
40
|
+
].join("_").tr(CHARS_TO_TRANSLATE.join, "_")[0...200] + "_#{rand(1000)}"
|
41
|
+
end
|
42
|
+
|
43
|
+
# Delegates to `Rails.application`.
|
44
|
+
def app
|
45
|
+
::Rails.application
|
46
|
+
end
|
47
|
+
|
48
|
+
included do |other|
|
49
|
+
begin
|
50
|
+
require 'capybara'
|
51
|
+
require 'action_dispatch/system_test_case'
|
52
|
+
# rubocop:disable Lint/HandleExceptions
|
53
|
+
rescue LoadError => e
|
54
|
+
# rubocop:enable Lint/HandleExceptions
|
55
|
+
abort """
|
56
|
+
LoadError: #{e.message}
|
57
|
+
System test integration requires Rails >= 5.1 and has a hard
|
58
|
+
dependency on a webserver and `capybara`, please add capybara to
|
59
|
+
your Gemfile and configure a webserver (e.g. `Capybara.server =
|
60
|
+
:webrick`) before attempting to use system specs.
|
61
|
+
""".gsub(/\s+/, ' ').strip
|
62
|
+
end
|
63
|
+
|
64
|
+
original_after_teardown =
|
65
|
+
::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown.instance_method(:after_teardown)
|
66
|
+
|
67
|
+
other.include ActionDispatch::IntegrationTest::Behavior
|
68
|
+
other.include ::ActionDispatch::SystemTesting::TestHelpers::SetupAndTeardown
|
69
|
+
other.include ::ActionDispatch::SystemTesting::TestHelpers::ScreenshotHelper
|
70
|
+
other.include BlowAwayAfterTeardownHook
|
71
|
+
|
72
|
+
attr_reader :driver
|
73
|
+
|
74
|
+
if ActionDispatch::SystemTesting::Server.respond_to?(:silence_puma=)
|
75
|
+
ActionDispatch::SystemTesting::Server.silence_puma = true
|
76
|
+
end
|
77
|
+
|
78
|
+
def initialize(*args, &blk)
|
79
|
+
super(*args, &blk)
|
80
|
+
@driver = nil
|
81
|
+
end
|
82
|
+
|
83
|
+
def driven_by(*args, &blk)
|
84
|
+
@driver = ::ActionDispatch::SystemTestCase.driven_by(*args, &blk).tap(&:use)
|
85
|
+
end
|
86
|
+
|
87
|
+
before do
|
88
|
+
# A user may have already set the driver, so only default if driver
|
89
|
+
# is not set
|
90
|
+
driven_by(:selenium) unless @driver
|
91
|
+
@routes = ::Rails.application.routes
|
92
|
+
end
|
93
|
+
|
94
|
+
after do
|
95
|
+
orig_stdout = $stdout
|
96
|
+
$stdout = StringIO.new
|
97
|
+
begin
|
98
|
+
original_after_teardown.bind(self).call
|
99
|
+
ensure
|
100
|
+
myio = $stdout
|
101
|
+
RSpec.current_example.metadata[:extra_failure_lines] = myio.string
|
102
|
+
$stdout = orig_stdout
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|