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
data/lib/rspec/rails/mocks.rb
DELETED
@@ -1,274 +0,0 @@
|
|
1
|
-
require 'active_support'
|
2
|
-
require 'active_support/deprecation'
|
3
|
-
require 'active_support/core_ext'
|
4
|
-
require 'active_model'
|
5
|
-
|
6
|
-
module RSpec
|
7
|
-
module Rails
|
8
|
-
|
9
|
-
class IllegalDataAccessException < StandardError; end
|
10
|
-
|
11
|
-
module Mocks
|
12
|
-
|
13
|
-
module ActiveModelInstanceMethods
|
14
|
-
# Stubs `persisted?` to return false and `id` to return nil
|
15
|
-
# @return self
|
16
|
-
def as_new_record
|
17
|
-
RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
|
18
|
-
RSpec::Mocks.allow_message(self, :id).and_return(nil)
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
# Returns true by default. Override with a stub.
|
23
|
-
def persisted?
|
24
|
-
true
|
25
|
-
end
|
26
|
-
|
27
|
-
# Returns false for names matching <tt>/_before_type_cast$/</tt>,
|
28
|
-
# otherwise delegates to super.
|
29
|
-
def respond_to?(message, include_private=false)
|
30
|
-
message.to_s =~ /_before_type_cast$/ ? false : super
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
# Starting with Rails 4.1, ActiveRecord associations are inversible
|
35
|
-
# by default. This class represents an association from the mocked
|
36
|
-
# model's perspective.
|
37
|
-
#
|
38
|
-
# @private
|
39
|
-
class Association
|
40
|
-
attr_accessor :target, :inversed
|
41
|
-
|
42
|
-
def initialize(association_name)
|
43
|
-
@association_name = association_name
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
module ActiveRecordInstanceMethods
|
48
|
-
# Stubs `persisted?` to return `false` and `id` to return `nil`.
|
49
|
-
def destroy
|
50
|
-
RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
|
51
|
-
RSpec::Mocks.allow_message(self, :id).and_return(nil)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Transforms the key to a method and calls it.
|
55
|
-
def [](key)
|
56
|
-
send(key)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Returns the opposite of `persisted?`
|
60
|
-
def new_record?
|
61
|
-
!persisted?
|
62
|
-
end
|
63
|
-
|
64
|
-
# Returns an object representing an association from the mocked
|
65
|
-
# model's perspective. For use by Rails internally only.
|
66
|
-
def association(association_name)
|
67
|
-
@associations ||= Hash.new { |h, k| h[k] = Association.new(k) }
|
68
|
-
@associations[association_name]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Creates a test double representing `string_or_model_class` with common
|
73
|
-
# ActiveModel methods stubbed out. Additional methods may be easily
|
74
|
-
# stubbed (via add_stubs) if `stubs` is passed. This is most useful for
|
75
|
-
# impersonating models that don't exist yet.
|
76
|
-
#
|
77
|
-
# NOTE that only ActiveModel's methods, plus <tt>new_record?</tt>, are
|
78
|
-
# stubbed out implicitly. <tt>new_record?</tt> returns the inverse of
|
79
|
-
# <tt>persisted?</tt>, and is present only for compatibility with
|
80
|
-
# extension frameworks that have yet to update themselves to the
|
81
|
-
# ActiveModel API (which declares <tt>persisted?</tt>, not
|
82
|
-
# <tt>new_record?</tt>).
|
83
|
-
#
|
84
|
-
# `string_or_model_class` can be any of:
|
85
|
-
#
|
86
|
-
# * A String representing a Class that does not exist
|
87
|
-
# * A String representing a Class that extends ActiveModel::Naming
|
88
|
-
# * A Class that extends ActiveModel::Naming
|
89
|
-
def mock_model(string_or_model_class, stubs = {})
|
90
|
-
if String === string_or_model_class
|
91
|
-
if Object.const_defined?(string_or_model_class)
|
92
|
-
model_class = Object.const_get(string_or_model_class)
|
93
|
-
else
|
94
|
-
model_class = Object.const_set(string_or_model_class, Class.new do
|
95
|
-
extend ActiveModel::Naming
|
96
|
-
def self.primary_key; :id; end
|
97
|
-
end)
|
98
|
-
end
|
99
|
-
else
|
100
|
-
model_class = string_or_model_class
|
101
|
-
end
|
102
|
-
|
103
|
-
unless model_class.kind_of? ActiveModel::Naming
|
104
|
-
raise ArgumentError.new <<-EOM
|
105
|
-
The mock_model method can only accept as its first argument:
|
106
|
-
* A String representing a Class that does not exist
|
107
|
-
* A String representing a Class that extends ActiveModel::Naming
|
108
|
-
* A Class that extends ActiveModel::Naming
|
109
|
-
|
110
|
-
It received #{model_class.inspect}
|
111
|
-
EOM
|
112
|
-
end
|
113
|
-
|
114
|
-
stubs = stubs.reverse_merge(:id => next_id)
|
115
|
-
stubs = stubs.reverse_merge(:persisted? => !!stubs[:id],
|
116
|
-
:destroyed? => false,
|
117
|
-
:marked_for_destruction? => false,
|
118
|
-
:valid? => true,
|
119
|
-
:blank? => false)
|
120
|
-
|
121
|
-
double("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
|
122
|
-
m.singleton_class.class_eval do
|
123
|
-
include ActiveModelInstanceMethods
|
124
|
-
include ActiveRecordInstanceMethods if defined?(ActiveRecord)
|
125
|
-
include ActiveModel::Conversion
|
126
|
-
include ActiveModel::Validations
|
127
|
-
end
|
128
|
-
if defined?(ActiveRecord)
|
129
|
-
[:save, :update_attributes, :update].each do |key|
|
130
|
-
if stubs[key] == false
|
131
|
-
RSpec::Mocks.allow_message(m.errors, :empty?).and_return(false)
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
m.__send__(:__mock_proxy).instance_eval(<<-CODE, __FILE__, __LINE__)
|
136
|
-
def @object.is_a?(other)
|
137
|
-
#{model_class}.ancestors.include?(other)
|
138
|
-
end unless #{stubs.has_key?(:is_a?)}
|
139
|
-
|
140
|
-
def @object.kind_of?(other)
|
141
|
-
#{model_class}.ancestors.include?(other)
|
142
|
-
end unless #{stubs.has_key?(:kind_of?)}
|
143
|
-
|
144
|
-
def @object.instance_of?(other)
|
145
|
-
other == #{model_class}
|
146
|
-
end unless #{stubs.has_key?(:instance_of?)}
|
147
|
-
|
148
|
-
def @object.__model_class_has_column?(method_name)
|
149
|
-
#{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s)
|
150
|
-
end
|
151
|
-
|
152
|
-
def @object.has_attribute?(attr_name)
|
153
|
-
__model_class_has_column?(attr_name)
|
154
|
-
end unless #{stubs.has_key?(:has_attribute?)}
|
155
|
-
|
156
|
-
def @object.respond_to?(method_name, include_private=false)
|
157
|
-
__model_class_has_column?(method_name) ? true : super
|
158
|
-
end unless #{stubs.has_key?(:respond_to?)}
|
159
|
-
|
160
|
-
def @object.method_missing(m, *a, &b)
|
161
|
-
respond_to?(m) ? null_object? ? self : nil : super
|
162
|
-
end
|
163
|
-
|
164
|
-
def @object.class
|
165
|
-
#{model_class}
|
166
|
-
end unless #{stubs.has_key?(:class)}
|
167
|
-
|
168
|
-
def @object.to_s
|
169
|
-
"#{model_class.name}_#{to_param}"
|
170
|
-
end unless #{stubs.has_key?(:to_s)}
|
171
|
-
CODE
|
172
|
-
yield m if block_given?
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
module ActiveModelStubExtensions
|
177
|
-
# Stubs `persisted` to return false and `id` to return nil
|
178
|
-
def as_new_record
|
179
|
-
RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
|
180
|
-
RSpec::Mocks.allow_message(self, :id).and_return(nil)
|
181
|
-
self
|
182
|
-
end
|
183
|
-
|
184
|
-
# Returns `true` by default. Override with a stub.
|
185
|
-
def persisted?
|
186
|
-
true
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
module ActiveRecordStubExtensions
|
191
|
-
# Stubs `id` (or other primary key method) to return nil
|
192
|
-
def as_new_record
|
193
|
-
self.__send__("#{self.class.primary_key}=", nil)
|
194
|
-
super
|
195
|
-
end
|
196
|
-
|
197
|
-
# Returns the opposite of `persisted?`.
|
198
|
-
def new_record?
|
199
|
-
!persisted?
|
200
|
-
end
|
201
|
-
|
202
|
-
# Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)
|
203
|
-
# @raises IllegalDataAccessException
|
204
|
-
def connection
|
205
|
-
raise RSpec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
# Creates an instance of `Model` with `to_param` stubbed using a
|
210
|
-
# generated value that is unique to each object. If `Model` is an
|
211
|
-
# `ActiveRecord` model, it is prohibited from accessing the database*.
|
212
|
-
#
|
213
|
-
# For each key in `stubs`, if the model has a matching attribute
|
214
|
-
# (determined by `respond_to?`) it is simply assigned the submitted values.
|
215
|
-
# If the model does not have a matching attribute, the key/value pair is
|
216
|
-
# assigned as a stub return value using RSpec's mocking/stubbing
|
217
|
-
# framework.
|
218
|
-
#
|
219
|
-
# <tt>persisted?</tt> is overridden to return the result of !id.nil?
|
220
|
-
# This means that by default persisted? will return true. If you want
|
221
|
-
# the object to behave as a new record, sending it `as_new_record` will
|
222
|
-
# set the id to nil. You can also explicitly set :id => nil, in which
|
223
|
-
# case persisted? will return false, but using `as_new_record` makes the
|
224
|
-
# example a bit more descriptive.
|
225
|
-
#
|
226
|
-
# While you can use stub_model in any example (model, view, controller,
|
227
|
-
# helper), it is especially useful in view examples, which are
|
228
|
-
# inherently more state-based than interaction-based.
|
229
|
-
#
|
230
|
-
# @example
|
231
|
-
#
|
232
|
-
# stub_model(Person)
|
233
|
-
# stub_model(Person).as_new_record
|
234
|
-
# stub_model(Person, :to_param => 37)
|
235
|
-
# stub_model(Person) {|person| person.first_name = "David"}
|
236
|
-
def stub_model(model_class, stubs={})
|
237
|
-
model_class.new.tap do |m|
|
238
|
-
m.extend ActiveModelStubExtensions
|
239
|
-
if defined?(ActiveRecord) && model_class < ActiveRecord::Base
|
240
|
-
m.extend ActiveRecordStubExtensions
|
241
|
-
primary_key = model_class.primary_key.to_sym
|
242
|
-
stubs = stubs.reverse_merge(primary_key => next_id)
|
243
|
-
stubs = stubs.reverse_merge(:persisted? => !!stubs[primary_key])
|
244
|
-
else
|
245
|
-
stubs = stubs.reverse_merge(:id => next_id)
|
246
|
-
stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
|
247
|
-
end
|
248
|
-
stubs = stubs.reverse_merge(:blank? => false)
|
249
|
-
|
250
|
-
stubs.each do |message, return_value|
|
251
|
-
if m.respond_to?("#{message}=")
|
252
|
-
m.__send__("#{message}=", return_value)
|
253
|
-
else
|
254
|
-
RSpec::Mocks.allow_message(m, message).and_return(return_value)
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
yield m if block_given?
|
259
|
-
end
|
260
|
-
end
|
261
|
-
|
262
|
-
private
|
263
|
-
|
264
|
-
@@model_id = 1000
|
265
|
-
|
266
|
-
def next_id
|
267
|
-
@@model_id += 1
|
268
|
-
end
|
269
|
-
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
RSpec.configuration.include RSpec::Rails::Mocks
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module RSpec::Rails
|
2
|
-
module ModuleInclusion
|
3
|
-
# @deprecated No replacement.
|
4
|
-
#
|
5
|
-
# Will be removed from rspec-rails-3.0
|
6
|
-
#
|
7
|
-
# This was never intended to be a public API and is no longer needed
|
8
|
-
# internally. As it happens, there are a few blog posts citing its use, so
|
9
|
-
# I'm leaving it here, but deprecated.
|
10
|
-
def include_self_when_dir_matches(*path_parts)
|
11
|
-
lambda do |c|
|
12
|
-
RSpec.deprecate('include_self_when_dir_matches')
|
13
|
-
c.include self, :example_group => {
|
14
|
-
:file_path => Regexp.compile(path_parts.join('[\\\/]'))
|
15
|
-
}
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
begin
|
2
|
-
require 'webrat'
|
3
|
-
rescue LoadError
|
4
|
-
end
|
5
|
-
|
6
|
-
RSpec.configure do |c|
|
7
|
-
if defined?(Webrat)
|
8
|
-
c.include Webrat::Matchers, :type => :request
|
9
|
-
c.include Webrat::Matchers, :type => :controller
|
10
|
-
c.include Webrat::Matchers, :type => :view
|
11
|
-
c.include Webrat::Matchers, :type => :helper
|
12
|
-
c.include Webrat::Matchers, :type => :mailer
|
13
|
-
|
14
|
-
c.include Webrat::Methods, :type => :request
|
15
|
-
c.include Webrat::Methods, :type => :controller
|
16
|
-
|
17
|
-
module RequestInstanceMethods
|
18
|
-
def last_response
|
19
|
-
@response
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
c.include RequestInstanceMethods, :type => :request
|
24
|
-
|
25
|
-
c.before :type => :controller do
|
26
|
-
Webrat.configure {|w| w.mode = :rails}
|
27
|
-
end
|
28
|
-
|
29
|
-
c.before :type => :request do
|
30
|
-
Webrat.configure {|w| w.mode = :rack}
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|