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,284 +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
- RSpec.deprecate("`mock_model`", :replacement => "the `rspec-activemodel-mocks` gem")
91
- if String === string_or_model_class
92
- if Object.const_defined?(string_or_model_class)
93
- model_class = Object.const_get(string_or_model_class)
94
- else
95
- model_class = Object.const_set(string_or_model_class, Class.new do
96
- extend ::ActiveModel::Naming
97
- def self.primary_key; :id; end
98
- end)
99
- end
100
- else
101
- model_class = string_or_model_class
102
- end
103
-
104
- unless model_class.kind_of? ::ActiveModel::Naming
105
- raise ArgumentError.new <<-EOM
106
- The mock_model method can only accept as its first argument:
107
- * A String representing a Class that does not exist
108
- * A String representing a Class that extends ActiveModel::Naming
109
- * A Class that extends ActiveModel::Naming
110
-
111
- It received #{model_class.inspect}
112
- EOM
113
- end
114
-
115
- stubs = stubs.reverse_merge(:id => next_id)
116
- stubs = stubs.reverse_merge(:persisted? => !!stubs[:id],
117
- :destroyed? => false,
118
- :marked_for_destruction? => false,
119
- :valid? => true,
120
- :blank? => false)
121
-
122
- double("#{model_class.name}_#{stubs[:id]}", stubs).tap do |m|
123
- m.singleton_class.class_eval do
124
- include ActiveModelInstanceMethods
125
- include ActiveRecordInstanceMethods if defined?(ActiveRecord)
126
- include ::ActiveModel::Conversion
127
- include ::ActiveModel::Validations
128
- end
129
- if defined?(ActiveRecord)
130
- [:save, :update_attributes, :update].each do |key|
131
- if stubs[key] == false
132
- RSpec::Mocks.allow_message(m.errors, :empty?).and_return(false)
133
- end
134
- end
135
- end
136
- m.__send__(:__mock_proxy).instance_eval(<<-CODE, __FILE__, __LINE__)
137
- def @object.is_a?(other)
138
- #{model_class}.ancestors.include?(other)
139
- end unless #{stubs.has_key?(:is_a?)}
140
-
141
- def @object.kind_of?(other)
142
- #{model_class}.ancestors.include?(other)
143
- end unless #{stubs.has_key?(:kind_of?)}
144
-
145
- def @object.instance_of?(other)
146
- other == #{model_class}
147
- end unless #{stubs.has_key?(:instance_of?)}
148
-
149
- def @object.__model_class_has_column?(method_name)
150
- #{model_class}.respond_to?(:column_names) && #{model_class}.column_names.include?(method_name.to_s)
151
- end
152
-
153
- def @object.has_attribute?(attr_name)
154
- __model_class_has_column?(attr_name)
155
- end unless #{stubs.has_key?(:has_attribute?)}
156
-
157
- def @object.respond_to?(method_name, include_private=false)
158
- __model_class_has_column?(method_name) ? true : super
159
- end unless #{stubs.has_key?(:respond_to?)}
160
-
161
- def @object.method_missing(m, *a, &b)
162
- respond_to?(m) ? null_object? ? self : nil : super
163
- end
164
-
165
- def @object.class
166
- #{model_class}
167
- end unless #{stubs.has_key?(:class)}
168
-
169
- def @object.to_s
170
- "#{model_class.name}_#{to_param}"
171
- end unless #{stubs.has_key?(:to_s)}
172
- CODE
173
- yield m if block_given?
174
- end
175
- end
176
-
177
- module ActiveModelStubExtensions
178
- # Stubs `persisted` to return false and `id` to return nil
179
- def as_new_record
180
- RSpec::Mocks.allow_message(self, :persisted?).and_return(false)
181
- RSpec::Mocks.allow_message(self, :id).and_return(nil)
182
- self
183
- end
184
-
185
- # Returns `true` by default. Override with a stub.
186
- def persisted?
187
- true
188
- end
189
- end
190
-
191
- module ActiveRecordStubExtensions
192
- # Stubs `id` (or other primary key method) to return nil
193
- def as_new_record
194
- self.__send__("#{self.class.primary_key}=", nil)
195
- super
196
- end
197
-
198
- # Returns the opposite of `persisted?`.
199
- def new_record?
200
- !persisted?
201
- end
202
-
203
- # Raises an IllegalDataAccessException (stubbed models are not allowed to access the database)
204
- # @raises IllegalDataAccessException
205
- def connection
206
- raise RSpec::Rails::IllegalDataAccessException.new("stubbed models are not allowed to access the database")
207
- end
208
- end
209
-
210
- # Creates an instance of `Model` with `to_param` stubbed using a
211
- # generated value that is unique to each object. If `Model` is an
212
- # `ActiveRecord` model, it is prohibited from accessing the database*.
213
- #
214
- # For each key in `stubs`, if the model has a matching attribute
215
- # (determined by `respond_to?`) it is simply assigned the submitted values.
216
- # If the model does not have a matching attribute, the key/value pair is
217
- # assigned as a stub return value using RSpec's mocking/stubbing
218
- # framework.
219
- #
220
- # <tt>persisted?</tt> is overridden to return the result of !id.nil?
221
- # This means that by default persisted? will return true. If you want
222
- # the object to behave as a new record, sending it `as_new_record` will
223
- # set the id to nil. You can also explicitly set :id => nil, in which
224
- # case persisted? will return false, but using `as_new_record` makes the
225
- # example a bit more descriptive.
226
- #
227
- # While you can use stub_model in any example (model, view, controller,
228
- # helper), it is especially useful in view examples, which are
229
- # inherently more state-based than interaction-based.
230
- #
231
- # @example
232
- #
233
- # stub_model(Person)
234
- # stub_model(Person).as_new_record
235
- # stub_model(Person, :to_param => 37)
236
- # stub_model(Person) {|person| person.first_name = "David"}
237
- def stub_model(model_class, stubs={})
238
- RSpec.deprecate("`stub_model`", :replacement => "the `rspec-activemodel-mocks` gem")
239
- model_class.new.tap do |m|
240
- m.extend ActiveModelStubExtensions
241
- if defined?(ActiveRecord) && model_class < ActiveRecord::Base
242
- m.extend ActiveRecordStubExtensions
243
- primary_key = model_class.primary_key.to_sym
244
- stubs = stubs.reverse_merge(primary_key => next_id)
245
- stubs = stubs.reverse_merge(:persisted? => !!stubs[primary_key])
246
- else
247
- stubs = stubs.reverse_merge(:id => next_id)
248
- stubs = stubs.reverse_merge(:persisted? => !!stubs[:id])
249
- end
250
- stubs = stubs.reverse_merge(:blank? => false)
251
-
252
- stubs.each do |message, return_value|
253
- if m.respond_to?("#{message}=")
254
- m.__send__("#{message}=", return_value)
255
- else
256
- RSpec::Mocks.allow_message(m, message).and_return(return_value)
257
- end
258
- end
259
-
260
- yield m if block_given?
261
- end
262
- end
263
-
264
- private
265
-
266
- @@model_id = 1000
267
-
268
- def next_id
269
- @@model_id += 1
270
- end
271
-
272
- end
273
- end
274
- end
275
-
276
- # We need to check if rspec-activemodel-mocks is in use on this side due
277
- # to Rails defaults. Because rspec-activemodel-mocks does not depend on
278
- # rspec-rails, bundler is likely to require rspec-activemodel-mocks before
279
- # rspec-rails when Bundler.require is performed. This will result in the
280
- # user still getting a deprecation message even when they are doing
281
- # everything right.
282
- unless defined?(RSpec::ActiveModel::Mocks::Mocks)
283
- RSpec.configuration.include RSpec::Rails::Mocks
284
- end
@@ -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