rspec-rails 2.99.0 → 3.1.0

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.
Files changed (80) hide show
  1. checksums.yaml +6 -14
  2. checksums.yaml.gz.sig +1 -0
  3. data/.yardopts +1 -1
  4. data/Capybara.md +1 -3
  5. data/Changelog.md +148 -11
  6. data/License.txt +1 -0
  7. data/README.md +202 -105
  8. data/lib/generators/rspec/controller/controller_generator.rb +1 -0
  9. data/lib/generators/rspec/controller/templates/controller_spec.rb +5 -5
  10. data/lib/generators/rspec/controller/templates/view_spec.rb +2 -2
  11. data/lib/generators/rspec/feature/feature_generator.rb +16 -0
  12. data/lib/generators/rspec/feature/templates/feature_spec.rb +5 -0
  13. data/lib/generators/rspec/helper/helper_generator.rb +1 -0
  14. data/lib/generators/rspec/helper/templates/helper_spec.rb +2 -2
  15. data/lib/generators/rspec/install/install_generator.rb +44 -5
  16. data/lib/generators/rspec/install/templates/spec/{spec_helper.rb.tt → rails_helper.rb} +19 -28
  17. data/lib/generators/rspec/integration/integration_generator.rb +1 -12
  18. data/lib/generators/rspec/integration/templates/request_spec.rb +3 -8
  19. data/lib/generators/rspec/job/job_generator.rb +12 -0
  20. data/lib/generators/rspec/job/templates/job_spec.rb.erb +7 -0
  21. data/lib/generators/rspec/mailer/mailer_generator.rb +1 -0
  22. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +6 -6
  23. data/lib/generators/rspec/model/model_generator.rb +19 -5
  24. data/lib/generators/rspec/model/templates/fixtures.yml +1 -1
  25. data/lib/generators/rspec/model/templates/model_spec.rb +2 -2
  26. data/lib/generators/rspec/observer/observer_generator.rb +1 -0
  27. data/lib/generators/rspec/observer/templates/observer_spec.rb +2 -2
  28. data/lib/generators/rspec/scaffold/scaffold_generator.rb +108 -135
  29. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +34 -39
  30. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +5 -13
  31. data/lib/generators/rspec/scaffold/templates/index_spec.rb +3 -10
  32. data/lib/generators/rspec/scaffold/templates/new_spec.rb +6 -14
  33. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +9 -9
  34. data/lib/generators/rspec/scaffold/templates/show_spec.rb +4 -11
  35. data/lib/generators/rspec/view/templates/view_spec.rb +2 -2
  36. data/lib/generators/rspec/view/view_generator.rb +1 -0
  37. data/lib/generators/rspec.rb +16 -6
  38. data/lib/rspec/rails/adapters.rb +33 -35
  39. data/lib/rspec/rails/configuration.rb +97 -0
  40. data/lib/rspec/rails/example/controller_example_group.rb +173 -159
  41. data/lib/rspec/rails/example/feature_example_group.rb +25 -20
  42. data/lib/rspec/rails/example/helper_example_group.rb +27 -26
  43. data/lib/rspec/rails/example/mailer_example_group.rb +29 -14
  44. data/lib/rspec/rails/example/model_example_group.rb +7 -7
  45. data/lib/rspec/rails/example/rails_example_group.rb +1 -0
  46. data/lib/rspec/rails/example/request_example_group.rb +19 -17
  47. data/lib/rspec/rails/example/routing_example_group.rb +40 -39
  48. data/lib/rspec/rails/example/view_example_group.rb +140 -137
  49. data/lib/rspec/rails/example.rb +0 -33
  50. data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
  51. data/lib/rspec/rails/extensions.rb +0 -1
  52. data/lib/rspec/rails/feature_check.rb +35 -0
  53. data/lib/rspec/rails/fixture_support.rb +5 -12
  54. data/lib/rspec/rails/matchers/be_a_new.rb +67 -62
  55. data/lib/rspec/rails/matchers/be_new_record.rb +23 -21
  56. data/lib/rspec/rails/matchers/be_valid.rb +41 -33
  57. data/lib/rspec/rails/matchers/have_http_status.rb +361 -0
  58. data/lib/rspec/rails/matchers/have_rendered.rb +35 -31
  59. data/lib/rspec/rails/matchers/redirect_to.rb +30 -29
  60. data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
  61. data/lib/rspec/rails/matchers/routing_matchers.rb +104 -94
  62. data/lib/rspec/rails/matchers.rb +7 -4
  63. data/lib/rspec/rails/tasks/rspec.rake +1 -1
  64. data/lib/rspec/rails/vendor/capybara.rb +2 -33
  65. data/lib/rspec/rails/version.rb +3 -1
  66. data/lib/rspec/rails/view_assigns.rb +18 -18
  67. data/lib/rspec/rails/view_rendering.rb +20 -45
  68. data/lib/rspec/rails.rb +2 -13
  69. data/lib/rspec-rails.rb +4 -1
  70. data.tar.gz.sig +0 -0
  71. metadata +80 -99
  72. metadata.gz.sig +3 -0
  73. data/lib/autotest/rails_rspec2.rb +0 -91
  74. data/lib/generators/rspec/install/templates/.rspec +0 -1
  75. data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
  76. data/lib/rspec/rails/infer_type_configuration.rb +0 -26
  77. data/lib/rspec/rails/matchers/have_extension.rb +0 -36
  78. data/lib/rspec/rails/mocks.rb +0 -284
  79. data/lib/rspec/rails/module_inclusion.rb +0 -19
  80. data/lib/rspec/rails/vendor/webrat.rb +0 -33
@@ -1,40 +1,44 @@
1
- module RSpec::Rails::Matchers
2
- module RenderTemplate
3
- class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matcher for template rendering.
5
+ module RenderTemplate
6
+ # @private
7
+ class RenderTemplateMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ def initialize(scope, expected, message = nil)
9
+ @expected = Symbol === expected ? expected.to_s : expected
10
+ @message = message
11
+ @scope = scope
12
+ end
4
13
 
5
- def initialize(scope, expected, message=nil)
6
- @expected = Symbol === expected ? expected.to_s : expected
7
- @message = message
8
- @scope = scope
9
- end
14
+ # @api private
15
+ def matches?(*)
16
+ match_unless_raises ActiveSupport::TestCase::Assertion do
17
+ @scope.assert_template expected, @message
18
+ end
19
+ end
20
+
21
+ # @api private
22
+ def failure_message
23
+ rescued_exception.message
24
+ end
10
25
 
11
- # @api private
12
- def matches?(*)
13
- match_unless_raises ActiveSupport::TestCase::Assertion do
14
- @scope.assert_template expected, @message
26
+ # @api private
27
+ def failure_message_when_negated
28
+ "expected not to render #{expected.inspect}, but did"
29
+ end
15
30
  end
16
- end
17
31
 
18
- # @api private
19
- def failure_message_for_should
20
- rescued_exception.message
21
- end
32
+ # Delegates to `assert_template`.
33
+ #
34
+ # @example
35
+ # expect(response).to have_rendered("new")
36
+ def have_rendered(options, message = nil)
37
+ RenderTemplateMatcher.new(self, options, message)
38
+ end
22
39
 
23
- # @api private
24
- def failure_message_for_should_not
25
- "expected not to render #{expected.inspect}, but did"
40
+ alias_method :render_template, :have_rendered
26
41
  end
27
42
  end
28
-
29
- # Delegates to `assert_template`
30
- #
31
- # @example
32
- #
33
- # response.should have_rendered("new")
34
- def have_rendered(options, message=nil)
35
- RenderTemplateMatcher.new(self, options, message)
36
- end
37
-
38
- alias_method :render_template, :have_rendered
39
43
  end
40
44
  end
@@ -1,37 +1,38 @@
1
- module RSpec::Rails::Matchers
2
- module RedirectTo
3
- class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matcher for redirects.
5
+ module RedirectTo
6
+ # @private
7
+ class RedirectTo < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ def initialize(scope, expected)
9
+ @expected = expected
10
+ @scope = scope
11
+ end
4
12
 
5
- def initialize(scope, expected)
6
- @expected = expected
7
- @scope = scope
8
- end
13
+ def matches?(_)
14
+ match_unless_raises ActiveSupport::TestCase::Assertion do
15
+ @scope.assert_redirected_to(@expected)
16
+ end
17
+ end
9
18
 
10
- # @api private
11
- def matches?(_)
12
- match_unless_raises ActiveSupport::TestCase::Assertion do
13
- @scope.assert_redirected_to(@expected)
14
- end
15
- end
19
+ def failure_message
20
+ rescued_exception.message
21
+ end
16
22
 
17
- # @api private
18
- def failure_message_for_should
19
- rescued_exception.message
20
- end
23
+ def failure_message_when_negated
24
+ "expected not to redirect to #{@expected.inspect}, but did"
25
+ end
26
+ end
21
27
 
22
- # @api private
23
- def failure_message_for_should_not
24
- "expected not to redirect to #{@expected.inspect}, but did"
28
+ # Delegates to `assert_redirected_to`.
29
+ #
30
+ # @example
31
+ # expect(response).to redirect_to(:action => "new")
32
+ def redirect_to(target)
33
+ RedirectTo.new(self, target)
34
+ end
25
35
  end
26
36
  end
27
-
28
- # Delegates to `assert_redirected_to`
29
- #
30
- # @example
31
- #
32
- # response.should redirect_to(:action => "new")
33
- def redirect_to(target)
34
- RedirectTo.new(self, target)
35
- end
36
37
  end
37
38
  end
@@ -1,3 +1,3 @@
1
1
  if defined?(ActiveRecord::Relation)
2
- RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::MatchArray)
2
+ RSpec::Matchers::BuiltIn::OperatorMatcher.register(ActiveRecord::Relation, '=~', RSpec::Matchers::BuiltIn::ContainExactly)
3
3
  end
@@ -1,109 +1,119 @@
1
- module RSpec::Rails::Matchers
2
- module RoutingMatchers
3
- extend RSpec::Matchers::DSL
1
+ module RSpec
2
+ module Rails
3
+ module Matchers
4
+ # Matchers to help with specs for routing code.
5
+ module RoutingMatchers
6
+ extend RSpec::Matchers::DSL
4
7
 
5
- class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
8
+ # @private
9
+ class RouteToMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
10
+ def initialize(scope, *expected)
11
+ @scope = scope
12
+ @expected = expected[1] || {}
13
+ if Hash === expected[0]
14
+ @expected.merge!(expected[0])
15
+ else
16
+ controller, action = expected[0].split('#')
17
+ @expected.merge!(:controller => controller, :action => action)
18
+ end
19
+ end
6
20
 
7
- def initialize(scope, *expected)
8
- @scope = scope
9
- @expected = expected[1] || {}
10
- if Hash === expected[0]
11
- @expected.merge!(expected[0])
12
- else
13
- controller, action = expected[0].split('#')
14
- @expected.merge!(:controller => controller, :action => action)
15
- end
16
- end
17
-
18
- # @api private
19
- def matches?(verb_to_path_map)
20
- @actual = @verb_to_path_map = verb_to_path_map
21
- # assert_recognizes does not consider ActionController::RoutingError an
22
- # assertion failure, so we have to capture that and Assertion here.
23
- match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
24
- path, query = *verb_to_path_map.values.first.split('?')
25
- @scope.assert_recognizes(
26
- @expected,
27
- {:method => verb_to_path_map.keys.first, :path => path},
28
- Rack::Utils::parse_query(query)
29
- )
30
- end
31
- end
21
+ def matches?(verb_to_path_map)
22
+ @actual = @verb_to_path_map = verb_to_path_map
23
+ # assert_recognizes does not consider ActionController::RoutingError an
24
+ # assertion failure, so we have to capture that and Assertion here.
25
+ match_unless_raises ActiveSupport::TestCase::Assertion, ActionController::RoutingError do
26
+ path, query = *verb_to_path_map.values.first.split('?')
27
+ @scope.assert_recognizes(
28
+ @expected,
29
+ { :method => verb_to_path_map.keys.first, :path => path },
30
+ Rack::Utils.parse_nested_query(query)
31
+ )
32
+ end
33
+ end
32
34
 
33
- # @api private
34
- def failure_message_for_should
35
- rescued_exception.message
36
- end
35
+ def failure_message
36
+ rescued_exception.message
37
+ end
37
38
 
38
- def failure_message_for_should_not
39
- "expected #{@actual.inspect} not to route to #{@expected.inspect}"
40
- end
39
+ def failure_message_when_negated
40
+ "expected #{@actual.inspect} not to route to #{@expected.inspect}"
41
+ end
41
42
 
42
- def description
43
- "route #{@actual.inspect} to #{@expected.inspect}"
44
- end
45
- end
46
-
47
- # Delegates to `assert_recognizes`. Supports short-hand controller/action
48
- # declarations (e.g. `"controller#action"`).
49
- #
50
- # @example
51
- #
52
- # { :get => "/things/special" }.should route_to(
53
- # :controller => "things",
54
- # :action => "special"
55
- # )
56
- #
57
- # { :get => "/things/special" }.should route_to("things#special")
58
- #
59
- # @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
60
- def route_to(*expected)
61
- RouteToMatcher.new(self, *expected)
62
- end
43
+ def description
44
+ "route #{@actual.inspect} to #{@expected.inspect}"
45
+ end
46
+ end
63
47
 
64
- class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
48
+ # Delegates to `assert_recognizes`. Supports short-hand controller/action
49
+ # declarations (e.g. `"controller#action"`).
50
+ #
51
+ # @example
52
+ #
53
+ # expect(:get => "/things/special").to route_to(
54
+ # :controller => "things",
55
+ # :action => "special"
56
+ # )
57
+ #
58
+ # expect(:get => "/things/special").to route_to("things#special")
59
+ #
60
+ # @see http://api.rubyonrails.org/classes/ActionDispatch/Assertions/RoutingAssertions.html#method-i-assert_recognizes
61
+ def route_to(*expected)
62
+ RouteToMatcher.new(self, *expected)
63
+ end
65
64
 
66
- def initialize(scope)
67
- @scope = scope
68
- end
65
+ # @private
66
+ class BeRoutableMatcher < RSpec::Matchers::BuiltIn::BaseMatcher
67
+ def initialize(scope)
68
+ @scope = scope
69
+ end
69
70
 
70
- # @api private
71
- def matches?(path)
72
- @actual = path
73
- match_unless_raises ActionController::RoutingError do
74
- @routing_options = @scope.routes.recognize_path(
75
- path.values.first, :method => path.keys.first
76
- )
77
- end
78
- end
71
+ def matches?(path)
72
+ @actual = path
73
+ match_unless_raises ActionController::RoutingError do
74
+ @routing_options = @scope.routes.recognize_path(
75
+ path.values.first, :method => path.keys.first
76
+ )
77
+ end
78
+ end
79
79
 
80
- def failure_message_for_should
81
- "expected #{@actual.inspect} to be routable"
82
- end
80
+ def failure_message
81
+ "expected #{@actual.inspect} to be routable"
82
+ end
83
83
 
84
- def failure_message_for_should_not
85
- "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
86
- end
87
- end
84
+ def failure_message_when_negated
85
+ "expected #{@actual.inspect} not to be routable, but it routes to #{@routing_options.inspect}"
86
+ end
87
+ end
88
88
 
89
- # Passes if the route expression is recognized by the Rails router based on
90
- # the declarations in `config/routes.rb`. Delegates to
91
- # `RouteSet#recognize_path`.
92
- #
93
- # @example
94
- #
95
- # You can use route helpers provided by rspec-rails.
96
- # {:get => "/a/path"}.should be_routable
97
- # {:post => "/another/path"}.should be_routable
98
- # {:put => "/yet/another/path"}.should_not be_routable
99
- def be_routable
100
- BeRoutableMatcher.new(self)
101
- end
89
+ # Passes if the route expression is recognized by the Rails router based on
90
+ # the declarations in `config/routes.rb`. Delegates to
91
+ # `RouteSet#recognize_path`.
92
+ #
93
+ # @example You can use route helpers provided by rspec-rails.
94
+ # expect(:get => "/a/path").to be_routable
95
+ # expect(:post => "/another/path").to be_routable
96
+ # expect(:put => "/yet/another/path").to be_routable
97
+ def be_routable
98
+ BeRoutableMatcher.new(self)
99
+ end
102
100
 
103
- module RouteHelpers
104
- %w(get post put patch delete options head).each do |method|
105
- define_method method do |path|
106
- { method.to_sym => path }
101
+ # Helpers for matching different route types.
102
+ module RouteHelpers
103
+ # @!method get
104
+ # @!method post
105
+ # @!method put
106
+ # @!method patch
107
+ # @!method delete
108
+ # @!method options
109
+ # @!method head
110
+ #
111
+ # Shorthand method for matching this type of route.
112
+ %w[get post put patch delete options head].each do |method|
113
+ define_method method do |path|
114
+ { method.to_sym => path }
115
+ end
116
+ end
107
117
  end
108
118
  end
109
119
  end
@@ -1,8 +1,11 @@
1
- require 'rspec/core/deprecation'
1
+ require 'rspec/core/warnings'
2
2
  require 'rspec/expectations'
3
3
 
4
- module RSpec::Rails
5
- module Matchers
4
+ module RSpec
5
+ module Rails
6
+ # Container module for Rails specific matchers.
7
+ module Matchers
8
+ end
6
9
  end
7
10
  end
8
11
 
@@ -22,6 +25,6 @@ require 'rspec/rails/matchers/redirect_to'
22
25
  require 'rspec/rails/matchers/routing_matchers'
23
26
  require 'rspec/rails/matchers/be_new_record'
24
27
  require 'rspec/rails/matchers/be_a_new'
25
- require 'rspec/rails/matchers/have_extension'
26
28
  require 'rspec/rails/matchers/relation_match_array'
27
29
  require 'rspec/rails/matchers/be_valid'
30
+ require 'rspec/rails/matchers/have_http_status'
@@ -22,7 +22,7 @@ namespace :spec do
22
22
  task :prepare do
23
23
  ENV['RACK_ENV'] = ENV['RAILS_ENV'] = 'test'
24
24
  if Rails.configuration.generators.options[:rails][:orm] == :active_record
25
- if ::Rails::VERSION::STRING.to_f < 4.1
25
+ if Rake::Task.task_defined?("test:prepare")
26
26
  Rake::Task["test:prepare"].invoke
27
27
  end
28
28
  end
@@ -9,42 +9,11 @@ rescue LoadError
9
9
  end
10
10
 
11
11
  if defined?(Capybara)
12
- module RSpec::Rails::DeprecatedCapybaraDSL
13
- include ::Capybara::DSL
14
-
15
- def self.included(mod)
16
- mod.extend(ClassMethods)
17
- super
18
- end
19
-
20
- module ClassMethods
21
- def include(mod)
22
- if mod == ::Capybara::DSL
23
- class_variable_set(:@@_rspec_capybara_included_explicitly, true)
24
- end
25
-
26
- super
27
- end
28
- end
29
-
30
- ::Capybara::DSL.instance_methods(false).each do |method|
31
- # capybara internally calls `page`, skip to avoid a duplicate
32
- # deprecation warning
33
- next if method.to_s == 'page'
34
-
35
- define_method method do |*args, &blk|
36
- unless self.class.class_variable_defined?(:@@_rspec_capybara_included_explicitly)
37
- RSpec.deprecate "Using the capybara method `#{method}` in controller specs",
38
- :replacement => "feature specs (spec/features)"
39
- end
40
- super(*args, &blk)
41
- end
42
- end
43
- end
12
+ require 'rspec/support/version_checker'
13
+ RSpec::Support::VersionChecker.new('capybara', Capybara::VERSION, '2.2.0').check_version!
44
14
 
45
15
  RSpec.configure do |c|
46
16
  if defined?(Capybara::DSL)
47
- c.include ::RSpec::Rails::DeprecatedCapybaraDSL, :type => :controller
48
17
  c.include Capybara::DSL, :type => :feature
49
18
  end
50
19
 
@@ -1,7 +1,9 @@
1
1
  module RSpec
2
2
  module Rails
3
+ # Version information for RSpec Rails.
3
4
  module Version
4
- STRING = '2.99.0'
5
+ # Current version of RSpec Rails, in semantic versioning format.
6
+ STRING = '3.1.0'
5
7
  end
6
8
  end
7
9
  end
@@ -1,5 +1,6 @@
1
1
  module RSpec
2
2
  module Rails
3
+ # Helpers for making instance variables available to views.
3
4
  module ViewAssigns
4
5
  # Assigns a value to an instance variable in the scope of the
5
6
  # view being rendered.
@@ -11,35 +12,34 @@ module RSpec
11
12
  _encapsulated_assigns[key] = value
12
13
  end
13
14
 
15
+ # Compat-shim for AbstractController::Rendering#view_assigns
16
+ #
17
+ # _assigns was deprecated in favor of view_assigns after
18
+ # Rails-3.0.0 was released. Since we are not able to predict when
19
+ # the _assigns/view_assigns patch will be released (I thought it
20
+ # would have been in 3.0.1, but 3.0.1 bypassed this change for a
21
+ # security fix), this bit ensures that we do the right thing without
22
+ # knowing anything about the Rails version we are dealing with.
23
+ #
24
+ # Once that change _is_ released, this can be changed to something
25
+ # that checks for the Rails version when the module is being
26
+ # interpreted, as it was before commit dd0095.
14
27
  def view_assigns
15
- begin
16
- # TODO: _assigns was deprecated in favor of view_assigns after
17
- # Rails-3.0.0 was released. Since we are not able to predict when
18
- # the _assigns/view_assigns patch will be released (I thought it
19
- # would have been in 3.0.1, but 3.0.1 bypassed this change for a
20
- # security fix), this bit ensures that we do the right thing without
21
- # knowing anything about the Rails version we are dealing with.
22
- #
23
- # Once that change _is_ released, this can be changed to something
24
- # that checks for the Rails version when the module is being
25
- # interpreted, as it was before commit dd0095.
26
- super.merge(_encapsulated_assigns)
27
- rescue
28
- _assigns
29
- end
28
+ super.merge(_encapsulated_assigns)
29
+ rescue
30
+ _assigns
30
31
  end
31
32
 
32
- # @api private
33
+ # @private
33
34
  def _assigns
34
35
  super.merge(_encapsulated_assigns)
35
36
  end
36
37
 
37
- private
38
+ private
38
39
 
39
40
  def _encapsulated_assigns
40
41
  @_encapsulated_assigns ||= {}
41
42
  end
42
-
43
43
  end
44
44
  end
45
45
  end
@@ -1,53 +1,27 @@
1
1
  require 'action_view/testing/resolvers'
2
2
 
3
- RSpec.configure do |config|
4
- # This allows us to expose `render_views` as a config option even though it
5
- # breaks the convention of other options by using `render_views` as a
6
- # command (i.e. render_views = true), where it would normally be used as a
7
- # getter. This makes it easier for rspec-rails users because we use
8
- # `render_views` directly in example groups, so this aligns the two APIs,
9
- # but requires this workaround:
10
- config.add_setting :rendering_views, :default => false
11
-
12
- def config.render_views=(val)
13
- self.rendering_views = val
14
- end
15
-
16
- def config.render_views
17
- self.rendering_views = true
18
- end
19
-
20
- def config.render_views?
21
- rendering_views
22
- end
23
- end
24
-
25
3
  module RSpec
26
4
  module Rails
5
+ # Helpers for optionally rendering views in controller specs.
27
6
  module ViewRendering
28
7
  extend ActiveSupport::Concern
29
8
 
30
9
  attr_accessor :controller
31
10
 
11
+ # DSL methods
32
12
  module ClassMethods
33
- def metadata_for_rspec_rails
34
- metadata[:rspec_rails] = metadata[:rspec_rails] ? metadata[:rspec_rails].dup : {}
35
- end
36
-
37
13
  # @see RSpec::Rails::ControllerExampleGroup
38
- def render_views(true_or_false=true)
39
- metadata_for_rspec_rails[:render_views] = true_or_false
40
- end
41
-
42
- # @deprecated Use `render_views` instead.
43
- def integrate_views
44
- RSpec.deprecate("integrate_views", :replacement => "render_views")
45
- render_views
14
+ def render_views(true_or_false = true)
15
+ @render_views = true_or_false
46
16
  end
47
17
 
48
18
  # @api private
49
19
  def render_views?
50
- metadata_for_rspec_rails.fetch(:render_views) do
20
+ return @render_views if defined?(@render_views)
21
+
22
+ if superclass.respond_to?(:render_views?)
23
+ superclass.render_views?
24
+ else
51
25
  RSpec.configuration.render_views?
52
26
  end
53
27
  end
@@ -60,6 +34,8 @@ module RSpec
60
34
 
61
35
  # Delegates find_all to the submitted path set and then returns templates
62
36
  # with modified source
37
+ #
38
+ # @private
63
39
  class EmptyTemplatePathSetDecorator < ::ActionView::Resolver
64
40
  attr_reader :original_path_set
65
41
 
@@ -67,40 +43,39 @@ module RSpec
67
43
  @original_path_set = original_path_set
68
44
  end
69
45
 
70
- # @api private
71
46
  def find_all(*args)
72
- original_path_set.find_all(*args).collect do |template|
47
+ original_path_set.find_all(*args).map do |template|
73
48
  ::ActionView::Template.new(
74
49
  "",
75
50
  template.identifier,
76
51
  EmptyTemplateHandler,
77
- {
78
- :virtual_path => template.virtual_path,
79
- :format => template.formats
80
- }
52
+ :virtual_path => template.virtual_path,
53
+ :format => template.formats
81
54
  )
82
55
  end
83
56
  end
84
57
  end
85
58
 
59
+ # @private
86
60
  class EmptyTemplateHandler
87
- def self.call(template)
61
+ def self.call(_template)
88
62
  %("")
89
63
  end
90
64
  end
91
65
 
66
+ # Used to null out view rendering in controller specs.
67
+ #
68
+ # @private
92
69
  module EmptyTemplates
93
- # @api private
94
70
  def prepend_view_path(new_path)
95
71
  lookup_context.view_paths.unshift(*_path_decorator(new_path))
96
72
  end
97
73
 
98
- # @api private
99
74
  def append_view_path(new_path)
100
75
  lookup_context.view_paths.push(*_path_decorator(new_path))
101
76
  end
102
77
 
103
- private
78
+ private
104
79
 
105
80
  def _path_decorator(path)
106
81
  EmptyTemplatePathSetDecorator.new(ActionView::PathSet.new(Array.wrap(path)))
data/lib/rspec/rails.rb CHANGED
@@ -1,22 +1,11 @@
1
1
  require 'rspec/core'
2
-
3
- RSpec::configure do |c|
4
- c.backtrace_exclusion_patterns << /vendor\//
5
- c.backtrace_exclusion_patterns << /lib\/rspec\/rails/
6
- end
7
-
8
2
  require 'rails/version'
9
3
  require 'rspec/rails/extensions'
10
4
  require 'rspec/rails/view_rendering'
11
5
  require 'rspec/rails/adapters'
12
6
  require 'rspec/rails/matchers'
13
7
  require 'rspec/rails/fixture_support'
14
-
15
- # Load rspec-activemodel-mocks if available; otherwise fall back
16
- # to the deprecated mock methods
17
- require 'rspec/rails/mocks'
18
- require 'rspec/rails/module_inclusion'
19
8
  require 'rspec/rails/example'
20
- require 'rspec/rails/infer_type_configuration'
21
9
  require 'rspec/rails/vendor/capybara'
22
- require 'rspec/rails/vendor/webrat'
10
+ require 'rspec/rails/configuration'
11
+ require 'rspec/rails/feature_check'