rspec-rails 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +17 -0
- data/README.md +7 -7
- data/lib/generators/rspec.rb +10 -6
- data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +19 -2
- data/lib/generators/rspec/install/templates/spec/rails_helper.rb +13 -4
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- 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/model/model_generator.rb +18 -5
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +107 -100
- data/lib/rspec-rails.rb +1 -1
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec/rails/adapters.rb +9 -7
- data/lib/rspec/rails/configuration.rb +2 -3
- data/lib/rspec/rails/example/controller_example_group.rb +172 -149
- data/lib/rspec/rails/example/feature_example_group.rb +25 -23
- data/lib/rspec/rails/example/helper_example_group.rb +27 -25
- data/lib/rspec/rails/example/mailer_example_group.rb +26 -22
- data/lib/rspec/rails/example/model_example_group.rb +8 -6
- data/lib/rspec/rails/example/request_example_group.rb +19 -17
- data/lib/rspec/rails/example/routing_example_group.rb +40 -38
- data/lib/rspec/rails/example/view_example_group.rb +140 -137
- data/lib/rspec/rails/extensions/active_record/proxy.rb +0 -1
- data/lib/rspec/rails/feature_check.rb +35 -0
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/matchers.rb +5 -2
- data/lib/rspec/rails/matchers/be_a_new.rb +68 -64
- data/lib/rspec/rails/matchers/be_new_record.rb +24 -20
- data/lib/rspec/rails/matchers/be_valid.rb +38 -34
- data/lib/rspec/rails/matchers/have_http_status.rb +340 -334
- data/lib/rspec/rails/matchers/have_rendered.rb +35 -32
- data/lib/rspec/rails/matchers/redirect_to.rb +30 -27
- data/lib/rspec/rails/matchers/routing_matchers.rb +103 -101
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +1 -2
- data/lib/rspec/rails/view_rendering.rb +6 -8
- metadata +16 -13
- metadata.gz.sig +3 -2
@@ -1,38 +1,40 @@
|
|
1
1
|
require 'rspec/rails/view_assigns'
|
2
2
|
|
3
|
-
module RSpec
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# Container module for helper specs.
|
6
|
+
module HelperExampleGroup
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
9
|
+
include ActionView::TestCase::Behavior
|
10
|
+
include RSpec::Rails::ViewAssigns
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
# @private
|
13
|
+
module ClassMethods
|
14
|
+
def determine_default_helper_class(_ignore)
|
15
|
+
described_class
|
16
|
+
end
|
15
17
|
end
|
16
|
-
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
# Returns an instance of ActionView::Base with the helper being specified
|
20
|
+
# mixed in, along with any of the built-in rails helpers.
|
21
|
+
def helper
|
22
|
+
_view.tap do |v|
|
23
|
+
v.extend(ApplicationHelper) if defined?(ApplicationHelper)
|
24
|
+
v.assign(view_assigns)
|
25
|
+
end
|
24
26
|
end
|
25
|
-
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def _controller_path(example)
|
31
|
+
example.example_group.described_class.to_s.sub(/Helper/, '').underscore
|
32
|
+
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
included do
|
35
|
+
before do |example|
|
36
|
+
controller.controller_path = _controller_path(example)
|
37
|
+
end
|
36
38
|
end
|
37
39
|
end
|
38
40
|
end
|
@@ -1,31 +1,35 @@
|
|
1
|
-
module RSpec
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# Container module for mailer spec functionality. It is only available if
|
4
|
+
# ActionMailer has been loaded before it.
|
5
|
+
module MailerExampleGroup
|
6
|
+
# This blank module is only necessary for YARD processing. It doesn't
|
7
|
+
# handle the conditional `defined?` check below very well.
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
9
11
|
|
10
12
|
if defined?(ActionMailer)
|
11
|
-
module RSpec
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
module RSpec
|
14
|
+
module Rails
|
15
|
+
# Container module for mailer spec functionality.
|
16
|
+
module MailerExampleGroup
|
17
|
+
extend ActiveSupport::Concern
|
18
|
+
include RSpec::Rails::RailsExampleGroup
|
19
|
+
include ActionMailer::TestCase::Behavior
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
included do
|
22
|
+
include ::Rails.application.routes.url_helpers
|
23
|
+
options = ::Rails.configuration.action_mailer.default_url_options
|
24
|
+
options.each { |key, value| default_url_options[key] = value } if options
|
25
|
+
end
|
23
26
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
# Class-level DSL for mailer specs.
|
28
|
+
module ClassMethods
|
29
|
+
# Alias for `described_class`.
|
30
|
+
def mailer_class
|
31
|
+
described_class
|
32
|
+
end
|
29
33
|
end
|
30
34
|
end
|
31
35
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
module RSpec
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# Container class for model spec functionality. Does not provide anything
|
4
|
+
# special over the common RailsExampleGroup currently.
|
5
|
+
module ModelExampleGroup
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
include RSpec::Rails::RailsExampleGroup
|
8
|
+
end
|
7
9
|
end
|
8
10
|
end
|
@@ -1,22 +1,24 @@
|
|
1
|
-
module RSpec
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
module RSpec
|
2
|
+
module Rails
|
3
|
+
# Container class for request spec functionality.
|
4
|
+
module RequestExampleGroup
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
include RSpec::Rails::RailsExampleGroup
|
7
|
+
include ActionDispatch::Integration::Runner
|
8
|
+
include ActionDispatch::Assertions
|
9
|
+
include RSpec::Rails::Matchers::RedirectTo
|
10
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
11
|
+
include ActionController::TemplateAssertions
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
# Delegates to `Rails.application`.
|
14
|
+
def app
|
15
|
+
::Rails.application
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
18
|
+
included do
|
19
|
+
before do
|
20
|
+
@routes = ::Rails.application.routes
|
21
|
+
end
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
@@ -1,53 +1,55 @@
|
|
1
1
|
require "action_dispatch/testing/assertions/routing"
|
2
2
|
|
3
|
-
module RSpec
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# Container module for routing spec functionality.
|
6
|
+
module RoutingExampleGroup
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
9
|
+
include RSpec::Rails::Matchers::RoutingMatchers
|
10
|
+
include RSpec::Rails::Matchers::RoutingMatchers::RouteHelpers
|
11
|
+
include RSpec::Rails::AssertionDelegator.new(ActionDispatch::Assertions::RoutingAssertions)
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
13
|
+
# Class-level DSL for route specs.
|
14
|
+
module ClassMethods
|
15
|
+
# Specifies the routeset that will be used for the example group. This
|
16
|
+
# is most useful when testing Rails engines.
|
17
|
+
#
|
18
|
+
# @example
|
19
|
+
# describe MyEngine::PostsController do
|
20
|
+
# routes { MyEngine::Engine.routes }
|
21
|
+
#
|
22
|
+
# it "routes posts#index" do
|
23
|
+
# expect(:get => "/posts").to
|
24
|
+
# route_to(:controller => "my_engine/posts", :action => "index")
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
def routes(&blk)
|
28
|
+
before do
|
29
|
+
self.routes = blk.call
|
30
|
+
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
end
|
32
33
|
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
included do
|
35
|
+
before do
|
36
|
+
self.routes = ::Rails.application.routes
|
37
|
+
end
|
36
38
|
end
|
37
|
-
end
|
38
39
|
|
39
|
-
|
40
|
+
attr_reader :routes
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
# @private
|
43
|
+
def routes=(routes)
|
44
|
+
@routes = routes
|
45
|
+
assertion_instance.instance_variable_set(:@routes, routes)
|
46
|
+
end
|
46
47
|
|
47
48
|
private
|
48
49
|
|
49
|
-
|
50
|
-
|
50
|
+
def method_missing(m, *args, &block)
|
51
|
+
routes.url_helpers.respond_to?(m) ? routes.url_helpers.send(m, *args) : super
|
52
|
+
end
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
@@ -1,169 +1,172 @@
|
|
1
1
|
require 'rspec/rails/view_assigns'
|
2
2
|
|
3
|
-
module RSpec
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
def _default_helpers
|
22
|
-
helpers = [_default_helper].compact
|
23
|
-
helpers << ApplicationHelper if Object.const_defined?('ApplicationHelper')
|
24
|
-
helpers
|
25
|
-
end
|
26
|
-
end
|
3
|
+
module RSpec
|
4
|
+
module Rails
|
5
|
+
# Container class for view spec functionality.
|
6
|
+
module ViewExampleGroup
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
include RSpec::Rails::RailsExampleGroup
|
9
|
+
include ActionView::TestCase::Behavior
|
10
|
+
include RSpec::Rails::ViewAssigns
|
11
|
+
include RSpec::Rails::Matchers::RenderTemplate
|
12
|
+
|
13
|
+
# @private
|
14
|
+
module ClassMethods
|
15
|
+
def _default_helper
|
16
|
+
base = metadata[:description].split('/')[0..-2].join('/')
|
17
|
+
(base.camelize + 'Helper').constantize if base
|
18
|
+
rescue NameError
|
19
|
+
nil
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
# @overload render({:partial => path_to_file}, {... locals ...}) do ... end
|
34
|
-
#
|
35
|
-
# Delegates to ActionView::Base#render, so see documentation on that
|
36
|
-
# for more info.
|
37
|
-
#
|
38
|
-
# The only addition is that you can call render with no arguments, and RSpec
|
39
|
-
# will pass the top level description to render:
|
40
|
-
#
|
41
|
-
# describe "widgets/new.html.erb" do
|
42
|
-
# it "shows all the widgets" do
|
43
|
-
# render # => view.render(:file => "widgets/new.html.erb")
|
44
|
-
# # ...
|
45
|
-
# end
|
46
|
-
# end
|
47
|
-
def render(options={}, local_assigns={}, &block)
|
48
|
-
options = _default_render_options if Hash === options and options.empty?
|
49
|
-
super(options, local_assigns, &block)
|
22
|
+
def _default_helpers
|
23
|
+
helpers = [_default_helper].compact
|
24
|
+
helpers << ApplicationHelper if Object.const_defined?('ApplicationHelper')
|
25
|
+
helpers
|
26
|
+
end
|
50
27
|
end
|
51
28
|
|
52
|
-
#
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
29
|
+
# DSL exposed to view specs.
|
30
|
+
module ExampleMethods
|
31
|
+
# @overload render
|
32
|
+
# @overload render({:partial => path_to_file})
|
33
|
+
# @overload render({:partial => path_to_file}, {... locals ...})
|
34
|
+
# @overload render({:partial => path_to_file}, {... locals ...}) do ... end
|
35
|
+
#
|
36
|
+
# Delegates to ActionView::Base#render, so see documentation on that
|
37
|
+
# for more info.
|
38
|
+
#
|
39
|
+
# The only addition is that you can call render with no arguments, and
|
40
|
+
# RSpec will pass the top level description to render:
|
41
|
+
#
|
42
|
+
# describe "widgets/new.html.erb" do
|
43
|
+
# it "shows all the widgets" do
|
44
|
+
# render # => view.render(:file => "widgets/new.html.erb")
|
45
|
+
# # ...
|
46
|
+
# end
|
47
|
+
# end
|
48
|
+
def render(options = {}, local_assigns = {}, &block)
|
49
|
+
options = _default_render_options if Hash === options && options.empty?
|
50
|
+
super(options, local_assigns, &block)
|
51
|
+
end
|
65
52
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
53
|
+
# The instance of `ActionView::Base` that is used to render the template.
|
54
|
+
# Use this to stub methods _before_ calling `render`.
|
55
|
+
#
|
56
|
+
# describe "widgets/new.html.erb" do
|
57
|
+
# it "shows all the widgets" do
|
58
|
+
# view.stub(:foo) { "foo" }
|
59
|
+
# render
|
60
|
+
# # ...
|
61
|
+
# end
|
62
|
+
# end
|
63
|
+
def view
|
64
|
+
_view
|
65
|
+
end
|
75
66
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
67
|
+
# Simulates the presence of a template on the file system by adding a
|
68
|
+
# Rails' FixtureResolver to the front of the view_paths list. Designed to
|
69
|
+
# help isolate view examples from partials rendered by the view template
|
70
|
+
# that is the subject of the example.
|
71
|
+
#
|
72
|
+
# stub_template("widgets/_widget.html.erb" => "This content.")
|
73
|
+
def stub_template(hash)
|
74
|
+
view.view_paths.unshift(ActionView::FixtureResolver.new(hash))
|
75
|
+
end
|
83
76
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
77
|
+
# Provides access to the params hash that will be available within the
|
78
|
+
# view.
|
79
|
+
#
|
80
|
+
# params[:foo] = 'bar'
|
81
|
+
def params
|
82
|
+
controller.params
|
83
|
+
end
|
89
84
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
# For backwards compatibility, we use #response as an alias for
|
95
|
-
# #rendered, but it needs to implement #body to avoid `assert_template`
|
96
|
-
# raising a `NoMethodError`.
|
97
|
-
unless rendered.respond_to?(:body)
|
98
|
-
def rendered.body; self; end;
|
85
|
+
# @deprecated Use `view` instead.
|
86
|
+
def template
|
87
|
+
RSpec.deprecate("template", :replacement => "view")
|
88
|
+
view
|
99
89
|
end
|
100
90
|
|
101
|
-
rendered
|
102
|
-
|
91
|
+
# @deprecated Use `rendered` instead.
|
92
|
+
def response
|
93
|
+
# `assert_template` expects `response` to implement a #body method
|
94
|
+
# like an `ActionDispatch::Response` does to force the view to
|
95
|
+
# render. For backwards compatibility, we use #response as an alias
|
96
|
+
# for #rendered, but it needs to implement #body to avoid
|
97
|
+
# `assert_template` raising a `NoMethodError`.
|
98
|
+
unless rendered.respond_to?(:body)
|
99
|
+
def rendered.body
|
100
|
+
self
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
rendered
|
105
|
+
end
|
103
106
|
|
104
|
-
|
107
|
+
private
|
105
108
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
109
|
+
def _default_render_options
|
110
|
+
if ::Rails::VERSION::STRING >= '3.2'
|
111
|
+
# pluck the handler, format, and locale out of, eg, posts/index.de.html.haml
|
112
|
+
template, *components = _default_file_to_render.split('.')
|
113
|
+
handler, format, locale = *components.reverse
|
111
114
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
115
|
+
render_options = { :template => template }
|
116
|
+
render_options[:handlers] = [handler] if handler
|
117
|
+
render_options[:formats] = [format] if format
|
118
|
+
render_options[:locales] = [locale] if locale
|
116
119
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
+
render_options
|
121
|
+
else
|
122
|
+
{ :template => _default_file_to_render }
|
123
|
+
end
|
120
124
|
end
|
121
|
-
end
|
122
125
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
+
def _path_parts
|
127
|
+
_default_file_to_render.split("/")
|
128
|
+
end
|
126
129
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
+
def _controller_path
|
131
|
+
_path_parts[0..-2].join("/")
|
132
|
+
end
|
130
133
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
+
def _inferred_action
|
135
|
+
_path_parts.last.split(".").first
|
136
|
+
end
|
134
137
|
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
138
|
+
def _include_controller_helpers
|
139
|
+
helpers = controller._helpers
|
140
|
+
view.singleton_class.class_exec do
|
141
|
+
include helpers unless included_modules.include?(helpers)
|
142
|
+
end
|
139
143
|
end
|
140
144
|
end
|
141
|
-
end
|
142
145
|
|
143
|
-
|
144
|
-
|
146
|
+
included do
|
147
|
+
include ExampleMethods
|
145
148
|
|
146
|
-
|
149
|
+
helper(*_default_helpers)
|
147
150
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
151
|
+
before do
|
152
|
+
_include_controller_helpers
|
153
|
+
if view.lookup_context.respond_to?(:prefixes)
|
154
|
+
# rails 3.1
|
155
|
+
view.lookup_context.prefixes << _controller_path
|
156
|
+
end
|
154
157
|
|
155
|
-
|
156
|
-
|
158
|
+
# fixes bug with differing formats
|
159
|
+
view.lookup_context.view_paths.each(&:clear_cache)
|
157
160
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
161
|
+
controller.controller_path = _controller_path
|
162
|
+
controller.request.path_parameters[:controller] = _controller_path
|
163
|
+
controller.request.path_parameters[:action] = _inferred_action unless _inferred_action =~ /^_/
|
164
|
+
end
|
162
165
|
|
163
|
-
|
164
|
-
|
166
|
+
let(:_default_file_to_render) do |example|
|
167
|
+
example.example_group.top_level_description
|
168
|
+
end
|
165
169
|
end
|
166
170
|
end
|
167
171
|
end
|
168
172
|
end
|
169
|
-
|