rspec-rails 2.12.2 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,18 @@
1
+ ### 2.13.0 / 2013-02-23
2
+ [full changelog](http://github.com/rspec/rspec-rails/compare/v2.12.2...v2.13.0)
3
+
4
+ Enhancements
5
+
6
+ * `be_valid` matcher includes validation error messages. (Tom Scott)
7
+ * Adds cucumber scenario showing how to invoke an anonymous controller's
8
+ non-resourceful actions. (Paulo Luis Franchini Casaretto)
9
+ * Null template handler is used when views are stubbed. (Daniel Schierbeck)
10
+ * The generated `spec_helper.rb` in Rails 4 includes a check for pending
11
+ migrations. (Andy Lindeman)
12
+ * Adds `rake spec:features` task. (itzki)
13
+ * Rake tasks are automatically generated for each spec/ directory.
14
+ (Rudolf Schmidt)
15
+
1
16
  ### 2.12.2 / 2013-01-12
2
17
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.12.1...v2.12.2)
3
18
 
@@ -7,6 +22,8 @@ Bug fixes
7
22
  to support testing of redirection and generation of URLs from other contexts.
8
23
  The implementation ended up breaking the ability to refer to non-anonymous
9
24
  routes in the context of the controller under test.
25
+ * Uses `assert_select` correctly in view specs generated by scaffolding. (Andy
26
+ Lindeman)
10
27
 
11
28
  ### 2.12.1 / 2013-01-07
12
29
  [full changelog](http://github.com/rspec/rspec-rails/compare/v2.12.0...v2.12.1)
data/README.md CHANGED
@@ -1,26 +1,11 @@
1
- # rspec-rails-2 [![Build Status](https://secure.travis-ci.org/rspec/rspec-rails.png?branch=master)](http://travis-ci.org/rspec/rspec-rails) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/rspec/rspec-rails)
1
+ # rspec-rails [![Build Status](https://secure.travis-ci.org/rspec/rspec-rails.png?branch=master)](http://travis-ci.org/rspec/rspec-rails) [![Code Climate](https://codeclimate.com/github/rspec/rspec-rails.png)](https://codeclimate.com/github/rspec/rspec-rails)
2
2
 
3
- rspec-2 for rails-3 with lightweight extensions to each
3
+ **rspec-rails 2** is a testing framework for Rails 3.x and 4.x.
4
4
 
5
- Note: Use [rspec-rails-1.3](http://github.com/dchelimsky/rspec-rails) for rails-2.
5
+ Use **[rspec-rails 1](http://github.com/dchelimsky/rspec-rails)** for Rails 2.x.
6
6
 
7
7
  ## Install
8
8
 
9
- ```
10
- gem install rspec-rails
11
- ```
12
-
13
- This installs the following gems:
14
-
15
- ```
16
- rspec-core
17
- rspec-expectations
18
- rspec-mocks
19
- rspec-rails
20
- ```
21
-
22
- ## Configure
23
-
24
9
  Add `rspec-rails` to the `:test` and `:development` groups in the Gemfile:
25
10
 
26
11
  ```ruby
@@ -43,65 +28,74 @@ the "rake spec" task.
43
28
 
44
29
  ### Generators
45
30
 
46
- If you type `script/rails generate`, the only RSpec generator you'll actually
47
- see is `rspec:install`. That's because RSpec is registered with Rails as the
48
- test framework, so whenever you generate application components like models,
49
- controllers, etc, RSpec specs are generated instead of Test::Unit tests.
31
+ Once installed, RSpec will generate spec file instead of Test::Unit test files
32
+ when commands like `rails generate model` and `rails generate controller` are
33
+ used.
50
34
 
51
- Please note that the generators are there to help you get started, but they are
52
- no substitute for writing your own examples, and they are only guaranteed to
53
- work out of the box for the default scenario (`ActiveRecord` & `Webrat`).
54
35
 
55
- ### Webrat and Capybara
36
+ ## Model Specs
56
37
 
57
- You can choose between webrat or capybara for simulating a browser, automating
58
- a browser, or setting expectations using the matchers they supply. Just add
59
- your preference to the Gemfile:
38
+ Model specs reside in the `spec/models` folder. Use model specs to describe
39
+ behavior of models (usually ActiveRecord-based) in the application. For example:
60
40
 
61
41
  ```ruby
62
- gem "webrat"
63
- gem "capybara"
64
- ```
42
+ require "spec_helper"
65
43
 
66
- See [http://rubydoc.info/gems/rspec-rails/file/Capybara.md](http://rubydoc.info/gems/rspec-rails/file/Capybara.md)
67
- for more info on Capybara integration.
44
+ describe User do
45
+ it "orders by last name" do
46
+ lindeman = User.create!(first_name: "Andy", last_name: "Lindeman")
47
+ chelimsky = User.create!(first_name: "David", last_name: "Chelimsky")
68
48
 
49
+ expect(User.ordered_by_last_name).to eq([chelimsky, lindeman])
50
+ end
51
+ end
52
+ ```
53
+
54
+ For more information, see [cucumber scenarios for model
55
+ specs](https://www.relishapp.com/rspec/rspec-rails/docs/model-specs).
69
56
 
70
- ## Living on edge
57
+ ## Controller Specs
71
58
 
72
- Bundler makes it a snap to use the latest code for any gem your app depends on. For
73
- rspec-rails, you'll need to point bundler to the git repositories for `rspec-rails`
74
- and the other rspec related gems it depends on:
59
+ Controller specs reside in the `spec/controllers` folder. Use controller specs
60
+ to describe behavior of Rails controllers. For example:
75
61
 
76
62
  ```ruby
77
- gem "rspec-rails", :git => "git://github.com/rspec/rspec-rails.git"
78
- gem "rspec", :git => "git://github.com/rspec/rspec.git"
79
- gem "rspec-core", :git => "git://github.com/rspec/rspec-core.git"
80
- gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
81
- gem "rspec-mocks", :git => "git://github.com/rspec/rspec-mocks.git"
82
- ```
63
+ require "spec_helper"
83
64
 
84
- Run `bundle install` and you'll have whatever is in git right now. Any time you
85
- want to update to a newer head, just run `bundle update`.
65
+ describe PostsController do
66
+ describe "GET #index" do
67
+ it "responds successfully with an HTTP 200 status code" do
68
+ get :index
69
+ expect(response).to be_success
70
+ expect(response.code).to eq(200)
71
+ end
86
72
 
87
- Keep in mind that each of these codebases is under active development, which
88
- means that its entirely possible that you'll pull from these repos and they won't
89
- play nice together. If playing nice is important to you, stick to the published
90
- gems.
73
+ it "renders the index template" do
74
+ get :index
75
+ expect(response).to render_template("index")
76
+ end
91
77
 
92
- ## Backwards compatibility
78
+ it "loads all of the posts into @posts" do
79
+ post1, post2 = Post.create!, Post.create!
80
+ get :index
93
81
 
94
- This is a complete rewrite of the rspec-rails extension designed to work with
95
- rails-3.x and rspec-2.x. It will not work with older versions of either rspec
96
- or rails. Many of the APIs from rspec-rails-1 have been carried forward,
97
- however, so upgrading an app from rspec-1/rails-2, while not pain-free, should
98
- not send you to the doctor with a migraine.
82
+ expect(assigns(:posts)).to match_array([post1, post2])
83
+ end
84
+ end
85
+ end
86
+ ```
99
87
 
100
- ## Known issues
88
+ For more information, see [cucumber scenarios for controller
89
+ specs](https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs).
101
90
 
102
- See http://github.com/rspec/rspec-rails/issues
91
+ **Note:** To encourage more isolated testing, views are not rendered by default
92
+ in controller specs. If you wish to assert against the contents of the rendered
93
+ view in a controller spec, enable
94
+ [render\_views](https://www.relishapp.com/rspec/rspec-rails/docs/controller-specs/render-views)
95
+ or use a higher-level [request spec](#request-specs) or [feature
96
+ spec](#feature-specs).
103
97
 
104
- # Request Specs
98
+ ## <a id="request-spec"></a>Request Specs
105
99
 
106
100
  Request specs live in spec/requests, spec/api and spec/integration, and mix in behavior
107
101
  [ActionDispatch::Integration::Runner](http://api.rubyonrails.org/classes/ActionDispatch/Integration/Runner.html),
@@ -159,111 +153,6 @@ FactoryGirl and Capybara seem to be the most widely used. Whether you choose
159
153
  these or other libs, we strongly recommend using something for each of these
160
154
  roles.
161
155
 
162
- # Controller Specs
163
-
164
- Controller specs live in spec/controllers, and mix in
165
- ActionController::TestCase::Behavior, which is the basis for Rails' functional
166
- tests.
167
-
168
- ## with fixtures
169
-
170
- ```ruby
171
- require 'spec_helper'
172
- describe WidgetsController do
173
- describe "GET index" do
174
- fixtures :widgets
175
-
176
- it "assigns all widgets to @widgets" do
177
- get :index
178
- expect(assigns(:widgets)).to eq(Widget.all)
179
- end
180
- end
181
- end
182
- ```
183
-
184
- ## with a factory
185
-
186
- ```ruby
187
- require 'spec_helper'
188
- describe WidgetsController do
189
- describe "GET index" do
190
- it "assigns all widgets to @widgets" do
191
- widget = FactoryGirl.create(:widget)
192
- get :index
193
- expect(assigns(:widgets)).to eq([widget])
194
- end
195
- end
196
- end
197
- ```
198
-
199
- ## with stubs
200
-
201
- ```ruby
202
- require 'spec_helper'
203
- describe WidgetsController do
204
- describe "GET index" do
205
- it "assigns all widgets to @widgets" do
206
- widget = stub_model(Widget)
207
- Widget.stub(:all) { [widget] }
208
- get :index
209
- expect(assigns(:widgets)).to eq([widget])
210
- end
211
- end
212
- end
213
- ```
214
-
215
- ## matchers
216
-
217
- In addition to the stock matchers from rspec-expectations, controller
218
- specs add these matchers, which delegate to rails' assertions:
219
-
220
- ```ruby
221
- expect(response).to render_template(*args)
222
- # => delegates to assert_template(*args)
223
-
224
- expect(response).to redirect_to(destination)
225
- # => delegates to assert_redirected_to(destination)
226
- ```
227
-
228
- ## isolation from views
229
-
230
- RSpec's preferred approach to spec'ing controller behaviour is to isolate
231
- the controller from its collaborators. By default, therefore, controller
232
- example groups do not render the views in your app. Due to the way Rails
233
- searches for view templates, the template still needs to exist, but it
234
- won't actually be loaded.
235
-
236
- NOTE that this is different from rspec-rails-1 with rails-2, which did not
237
- require the presence of the file at all. Due to changes in rails-3, this
238
- was no longer feasible in rspec-rails-2.
239
-
240
- ## `render_views`
241
-
242
- If you prefer a more integrated approach, similar to that of Rails'
243
- functional tests, you can tell controller groups to render the views in the
244
- app with the `render_views` declaration:
245
-
246
- ```ruby
247
- require 'spec_helper'
248
- describe WidgetsController do
249
- render_views
250
- # ...
251
- ```
252
-
253
- ### Upgrade note
254
-
255
- `render_views` replaces `integrate_views` from rspec-rails-1.3
256
-
257
- ## `assigns`
258
-
259
- Use `assigns(key)` to express expectations about instance variables that a controller
260
- assigns to the view in the course of an action:
261
-
262
- ```ruby
263
- get :index
264
- expect(assigns(:widgets)).to eq(expected_value)
265
- ```
266
-
267
156
  # View specs
268
157
 
269
158
  View specs live in spec/views, and mix in ActionView::TestCase::Behavior.
@@ -369,32 +258,6 @@ render
369
258
  expect(rendered).to xxx
370
259
  ```
371
260
 
372
- # Model specs
373
-
374
- Model specs live in spec/models.
375
-
376
- ```ruby
377
- require 'spec_helper'
378
- describe Article do
379
- describe ".recent" do
380
- it "includes articles published less than one week ago" do
381
- article = Article.create!(:published_at => Date.today - 1.week + 1.second)
382
- expect(Article.recent).to eq([article])
383
- end
384
-
385
- it "excludes articles published at midnight one week ago" do
386
- article = Article.create!(:published_at => Date.today - 1.week)
387
- expect(Article.recent).to be_empty
388
- end
389
-
390
- it "excludes articles published more than one week ago" do
391
- article = Article.create!(:published_at => Date.today - 1.week - 1.second)
392
- expect(Article.recent).to be_empty
393
- end
394
- end
395
- end
396
- ```
397
-
398
261
  # Routing specs
399
262
 
400
263
  Routing specs live in spec/routing.
@@ -518,6 +381,21 @@ However, you must first clear the task that rspec-rails defined:
518
381
  task("spec").clear
519
382
  ```
520
383
 
384
+ ### Webrat and Capybara
385
+
386
+ You can choose between webrat or capybara for simulating a browser, automating
387
+ a browser, or setting expectations using the matchers they supply. Just add
388
+ your preference to the Gemfile:
389
+
390
+ ```ruby
391
+ gem "webrat"
392
+ # ... or ...
393
+ gem "capybara"
394
+ ```
395
+
396
+ See [http://rubydoc.info/gems/rspec-rails/file/Capybara.md](http://rubydoc.info/gems/rspec-rails/file/Capybara.md)
397
+ for more info on Capybara integration.
398
+
521
399
  # Contribute
522
400
 
523
401
  See [http://github.com/rspec/rspec-dev](http://github.com/rspec/rspec-dev).
@@ -531,3 +409,7 @@ For `rspec-rails`-specific development information, see
531
409
  * [http://github.com/rspec/rspec-core](http://github.com/rspec/rspec-core)
532
410
  * [http://github.com/rspec/rspec-expectations](http://github.com/rspec/rspec-expectations)
533
411
  * [http://github.com/rspec/rspec-mocks](http://github.com/rspec/rspec-mocks)
412
+
413
+ ## Feature Requests & Bugs
414
+
415
+ See <http://github.com/rspec/rspec-rails/issues>
@@ -351,3 +351,28 @@ Feature: anonymous controller
351
351
  """
352
352
  When I run `rspec spec`
353
353
  Then the examples should all pass
354
+
355
+ Scenario: refer to application routes in the controller under test
356
+ Given a file named "spec/controllers/application_controller_spec.rb" with:
357
+ """ruby
358
+ require "spec_helper"
359
+
360
+ Rails.application.routes.draw do
361
+ match "/login" => "sessions#new", :as => "login", :via => "get"
362
+ end
363
+
364
+ describe ApplicationController do
365
+ controller do
366
+ def index
367
+ redirect_to login_url
368
+ end
369
+ end
370
+
371
+ it "redirects to the login page" do
372
+ get :index
373
+ expect(response).to redirect_to("/login")
374
+ end
375
+ end
376
+ """
377
+ When I run `rspec spec`
378
+ Then the examples should all pass
@@ -11,11 +11,11 @@ behavior and expectations.
11
11
 
12
12
  describe Post do
13
13
  context "with 2 or more comments" do
14
- it "orders them in reverse" do
15
- post = Post.create
16
- comment1 = post.comment("first")
17
- comment2 = post.comment("second")
18
- post.reload.comments.should eq([comment2, comment1])
14
+ it "orders them in reverse chronologically" do
15
+ post = Post.create!
16
+ comment1 = post.comments.create!(:body => "first comment")
17
+ comment2 = post.comments.create!(:body => "second comment")
18
+ expect(post.reload.comments).to eq([comment2, comment1])
19
19
  end
20
20
  end
21
21
  end
@@ -8,6 +8,12 @@ require 'rspec/autorun'
8
8
  # in spec/support/ and its subdirectories.
9
9
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
10
10
 
11
+ <% if ::Rails.version >= '4' -%>
12
+ # Checks for pending migrations before tests are run.
13
+ # If you are not using ActiveRecord, you can remove this line.
14
+ ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
15
+
16
+ <% end -%>
11
17
  RSpec.configure do |config|
12
18
  # ## Mock Framework
13
19
  #
@@ -113,7 +113,11 @@ describe <%= controller_class_name %>Controller do
113
113
  # specifies that the <%= class_name %> created on the previous line
114
114
  # receives the :update_attributes message with whatever params are
115
115
  # submitted in the request.
116
+ <%- if Rails.version >= '4' -%>
117
+ <%= class_name %>.any_instance.should_receive(:update).with(<%= formatted_hash(example_params_for_update) %>)
118
+ <%- else -%>
116
119
  <%= class_name %>.any_instance.should_receive(:update_attributes).with(<%= formatted_hash(example_params_for_update) %>)
120
+ <%- end -%>
117
121
  put :update, {:id => <%= file_name %>.to_param, :<%= ns_file_name %> => <%= formatted_hash(example_params_for_update) %>}, valid_session
118
122
  end
119
123
 
@@ -21,9 +21,9 @@ describe "<%= ns_table_name %>/edit" do
21
21
  end
22
22
  <% else -%>
23
23
  # Run the generator again with the --webrat flag if you want to use webrat matchers
24
- assert_select "form", :action => <%= index_helper %>_path(@<%= ns_file_name %>), :method => "post" do
24
+ assert_select "form[action=?][method=?]", <%= ns_file_name %>_path(@<%= ns_file_name %>), "post" do
25
25
  <% for attribute in output_attributes -%>
26
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
26
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
27
27
  <% end -%>
28
28
  end
29
29
  <% end -%>
@@ -20,9 +20,9 @@ describe "<%= ns_table_name %>/new" do
20
20
  end
21
21
  <% else -%>
22
22
  # Run the generator again with the --webrat flag if you want to use webrat matchers
23
- assert_select "form", :action => <%= index_helper %>_path, :method => "post" do
23
+ assert_select "form[action=?][method=?]", <%= index_helper %>_path, "post" do
24
24
  <% for attribute in output_attributes -%>
25
- assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>", :name => "<%= ns_file_name %>[<%= attribute.name %>]"
25
+ assert_select "<%= attribute.input_type -%>#<%= ns_file_name %>_<%= attribute.name %>[name=?]", "<%= ns_file_name %>[<%= attribute.name %>]"
26
26
  <% end -%>
27
27
  end
28
28
  <% end -%>
@@ -24,3 +24,4 @@ require 'rspec/rails/matchers/be_new_record'
24
24
  require 'rspec/rails/matchers/be_a_new'
25
25
  require 'rspec/rails/matchers/have_extension'
26
26
  require 'rspec/rails/matchers/relation_match_array'
27
+ require 'rspec/rails/matchers/be_valid'
@@ -0,0 +1,40 @@
1
+ module RSpec::Rails::Matchers
2
+ class BeValid < RSpec::Matchers::BuiltIn::Be
3
+ def initialize(*args)
4
+ @args = args
5
+ end
6
+
7
+ # @api private
8
+ def matches?(actual)
9
+ @actual = actual
10
+ actual.valid?(*@args)
11
+ end
12
+
13
+ # @api private
14
+ def failure_message_for_should
15
+ message = "expected #{actual.inspect} to be valid"
16
+ if actual.respond_to?(:errors)
17
+ message << ", but got errors: #{actual.errors.full_messages.join(', ')}"
18
+ end
19
+
20
+ message
21
+ end
22
+
23
+ # @api private
24
+ def failure_message_for_should_not
25
+ "expected #{actual.inspect} not to be valid"
26
+ end
27
+ end
28
+
29
+ # Passes if the given model instance's `valid?` method is true, meaning all
30
+ # of the `ActiveModel::Validations` passed and no errors exist. If a message
31
+ # is not given, a default message is shown listing each error.
32
+ #
33
+ # @example
34
+ #
35
+ # thing = Thing.new
36
+ # thing.should be_valid
37
+ def be_valid(*args)
38
+ BeValid.new(*args)
39
+ end
40
+ end
@@ -104,7 +104,7 @@ EOM
104
104
  include ActiveModel::Validations
105
105
  end
106
106
  if defined?(ActiveRecord)
107
- [:save, :update_attributes].each do |key|
107
+ [:save, :update_attributes, :update].each do |key|
108
108
  if stubs[key] == false
109
109
  m.errors.stub(:empty? => false)
110
110
  end
@@ -3,12 +3,7 @@ if default = Rake.application.instance_variable_get('@tasks')['default']
3
3
  default.prerequisites.delete('test')
4
4
  end
5
5
 
6
- orm_setting = Rails.configuration.generators.options[:rails][:orm]
7
- spec_prereq = if(orm_setting == :active_record)
8
- Rails.configuration.active_record[:schema_format] == :sql ? "db:test:clone_structure" : "db:test:prepare"
9
- else
10
- :noop
11
- end
6
+ spec_prereq = Rails.configuration.generators.options[:rails][:orm] == :active_record ? "test:prepare" : :noop
12
7
  task :noop do; end
13
8
  task :default => :spec
14
9
 
@@ -18,10 +13,15 @@ desc "Run all specs in spec directory (excluding plugin specs)"
18
13
  RSpec::Core::RakeTask.new(:spec => spec_prereq)
19
14
 
20
15
  namespace :spec do
21
- [:requests, :models, :controllers, :views, :helpers, :mailers, :lib, :routing].each do |sub|
22
- desc "Run the code examples in spec/#{sub}"
23
- RSpec::Core::RakeTask.new(sub => spec_prereq) do |t|
24
- t.pattern = "./spec/#{sub}/**/*_spec.rb"
16
+ def types
17
+ dirs = Dir['./spec/**/*_spec.rb'].map { |f| f.sub(/^\.\/(spec\/\w+)\/.*/, '\\1') }.uniq
18
+ Hash[dirs.map { |d| [d.split('/').last, d] }]
19
+ end
20
+
21
+ types.each do |type, dir|
22
+ desc "Run the code examples in #{dir}"
23
+ RSpec::Core::RakeTask.new(type => spec_prereq) do |t|
24
+ t.pattern = "./#{dir}/**/*_spec.rb"
25
25
  end
26
26
  end
27
27
 
@@ -34,22 +34,12 @@ namespace :spec do
34
34
 
35
35
  task :statsetup do
36
36
  require 'rails/code_statistics'
37
- ::STATS_DIRECTORIES << %w(Model\ specs spec/models) if File.exist?('spec/models')
38
- ::STATS_DIRECTORIES << %w(View\ specs spec/views) if File.exist?('spec/views')
39
- ::STATS_DIRECTORIES << %w(Controller\ specs spec/controllers) if File.exist?('spec/controllers')
40
- ::STATS_DIRECTORIES << %w(Helper\ specs spec/helpers) if File.exist?('spec/helpers')
41
- ::STATS_DIRECTORIES << %w(Library\ specs spec/lib) if File.exist?('spec/lib')
42
- ::STATS_DIRECTORIES << %w(Mailer\ specs spec/mailers) if File.exist?('spec/mailers')
43
- ::STATS_DIRECTORIES << %w(Routing\ specs spec/routing) if File.exist?('spec/routing')
44
- ::STATS_DIRECTORIES << %w(Request\ specs spec/requests) if File.exist?('spec/requests')
45
- ::CodeStatistics::TEST_TYPES << "Model specs" if File.exist?('spec/models')
46
- ::CodeStatistics::TEST_TYPES << "View specs" if File.exist?('spec/views')
47
- ::CodeStatistics::TEST_TYPES << "Controller specs" if File.exist?('spec/controllers')
48
- ::CodeStatistics::TEST_TYPES << "Helper specs" if File.exist?('spec/helpers')
49
- ::CodeStatistics::TEST_TYPES << "Library specs" if File.exist?('spec/lib')
50
- ::CodeStatistics::TEST_TYPES << "Mailer specs" if File.exist?('spec/mailers')
51
- ::CodeStatistics::TEST_TYPES << "Routing specs" if File.exist?('spec/routing')
52
- ::CodeStatistics::TEST_TYPES << "Request specs" if File.exist?('spec/requests')
37
+ types.each do |type, dir|
38
+ name = type.singularize.capitalize
39
+
40
+ ::STATS_DIRECTORIES << ["#{name} specs", dir]
41
+ ::CodeStatistics::TEST_TYPES << "#{name} specs"
42
+ end
53
43
  end
54
44
  end
55
45
 
@@ -1,7 +1,7 @@
1
1
  module RSpec
2
2
  module Rails
3
3
  module Version
4
- STRING = '2.12.2'
4
+ STRING = '2.13.0'
5
5
  end
6
6
  end
7
7
  end
@@ -73,7 +73,7 @@ module RSpec
73
73
  ::ActionView::Template.new(
74
74
  "",
75
75
  template.identifier,
76
- template.handler,
76
+ EmptyTemplateHandler,
77
77
  {
78
78
  :virtual_path => template.virtual_path,
79
79
  :format => template.formats
@@ -83,6 +83,12 @@ module RSpec
83
83
  end
84
84
  end
85
85
 
86
+ class EmptyTemplateHandler
87
+ def self.call(template)
88
+ %("")
89
+ end
90
+ end
91
+
86
92
  module EmptyTemplates
87
93
  # @api private
88
94
  def prepend_view_path(new_path)
@@ -15,4 +15,16 @@ describe Rspec::Generators::InstallGenerator do
15
15
  run_generator
16
16
  File.read( file('spec/spec_helper.rb') ).should =~ /^require 'rspec\/autorun'$/m
17
17
  end
18
+
19
+ if ::Rails.version >= '4'
20
+ it "generates spec/spec_helper.rb with a check for pending migrations" do
21
+ run_generator
22
+ File.read( file('spec/spec_helper.rb') ).should =~ /ActiveRecord::Migration\.check_pending!/m
23
+ end
24
+ else
25
+ it "generates spec/spec_helper.rb without a check for pending migrations" do
26
+ run_generator
27
+ File.read( file('spec/spec_helper.rb') ).should_not =~ /ActiveRecord::Migration\.check_pending!/m
28
+ end
29
+ end
18
30
  end
@@ -5,12 +5,12 @@ module RSpec::Rails
5
5
  it { should be_included_in_files_in('./spec/features/') }
6
6
  it { should be_included_in_files_in('.\\spec\\features\\') }
7
7
 
8
- it "adds :type => :model to the metadata" do
8
+ it "adds :type => :feature to the metadata" do
9
9
  group = RSpec::Core::ExampleGroup.describe do
10
10
  include FeatureExampleGroup
11
11
  end
12
12
 
13
- expect(group.metadata[:type]).to eql(:feature)
13
+ expect(group.metadata[:type]).to eq(:feature)
14
14
  end
15
15
 
16
16
  it "includes Rails route helpers" do
@@ -22,8 +22,8 @@ module RSpec::Rails
22
22
  include FeatureExampleGroup
23
23
  end
24
24
 
25
- expect(group.new.foo_path).to eql("/foo")
26
- expect(group.new.foo_url).to eql("http://www.example.com/foo")
25
+ expect(group.new.foo_path).to eq("/foo")
26
+ expect(group.new.foo_url).to eq("http://www.example.com/foo")
27
27
  end
28
28
 
29
29
  describe "#visit" do
@@ -49,7 +49,7 @@ module RSpec::Rails
49
49
  include FeatureExampleGroup
50
50
  end
51
51
 
52
- expect(group.new.visit("/foo")).to eql("success: /foo")
52
+ expect(group.new.visit("/foo")).to eq("success: /foo")
53
53
  end
54
54
  end
55
55
  end
@@ -0,0 +1,44 @@
1
+ require "spec_helper"
2
+ require 'active_support/all'
3
+ require 'rspec/rails/matchers/be_valid'
4
+
5
+ describe "be_valid matcher" do
6
+ include RSpec::Rails::Matchers
7
+
8
+ class Post
9
+ include ActiveModel::Validations
10
+ attr_accessor :title
11
+ validates_presence_of :title
12
+ end
13
+
14
+ let(:post) { Post.new }
15
+
16
+ it "includes the error messages in the failure message" do
17
+ expect {
18
+ expect(post).to be_valid
19
+ }.to raise_exception(/Title can't be blank/)
20
+ end
21
+
22
+ it "includes a failure message for the negative case" do
23
+ post.stub(:valid?) { true }
24
+ expect {
25
+ expect(post).not_to be_valid
26
+ }.to raise_exception(/expected .* not to be valid/)
27
+ end
28
+
29
+ it "uses a custom failure message if provided" do
30
+ expect {
31
+ expect(post).to be_valid, "Post was not valid!"
32
+ }.to raise_exception(/Post was not valid!/)
33
+ end
34
+
35
+ it "includes the validation context if provided" do
36
+ post.should_receive(:valid?).with(:create) { true }
37
+ expect(post).to be_valid(:create)
38
+ end
39
+
40
+ it "does not include the validation context if not provided" do
41
+ post.should_receive(:valid?).with(no_args) { true }
42
+ expect(post).to be_valid
43
+ end
44
+ end
@@ -112,7 +112,7 @@ describe "stub_model" do
112
112
 
113
113
  describe "alternate primary key" do
114
114
  it "has the correct primary_key name" do
115
- stub_model(AlternatePrimaryKeyModel).class.primary_key.to_s.should eql('my_id')
115
+ stub_model(AlternatePrimaryKeyModel).class.primary_key.to_s.should eq('my_id')
116
116
  end
117
117
 
118
118
  it "has a primary_key" do
metadata CHANGED
@@ -2,206 +2,206 @@
2
2
  name: rspec-rails
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 2.12.2
5
+ version: 2.13.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Chelimsky
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-12 00:00:00.000000000 Z
12
+ date: 2013-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activesupport
16
15
  version_requirements: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ! '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '3.0'
22
- requirement: !ruby/object:Gem::Requirement
23
20
  none: false
21
+ prerelease: false
22
+ name: activesupport
23
+ requirement: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ! '>='
26
26
  - !ruby/object:Gem::Version
27
27
  version: '3.0'
28
- prerelease: false
28
+ none: false
29
29
  type: :runtime
30
30
  - !ruby/object:Gem::Dependency
31
- name: actionpack
32
31
  version_requirements: !ruby/object:Gem::Requirement
33
- none: false
34
32
  requirements:
35
33
  - - ! '>='
36
34
  - !ruby/object:Gem::Version
37
35
  version: '3.0'
38
- requirement: !ruby/object:Gem::Requirement
39
36
  none: false
37
+ prerelease: false
38
+ name: actionpack
39
+ requirement: !ruby/object:Gem::Requirement
40
40
  requirements:
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '3.0'
44
- prerelease: false
44
+ none: false
45
45
  type: :runtime
46
46
  - !ruby/object:Gem::Dependency
47
- name: railties
48
47
  version_requirements: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ! '>='
52
50
  - !ruby/object:Gem::Version
53
51
  version: '3.0'
54
- requirement: !ruby/object:Gem::Requirement
55
52
  none: false
53
+ prerelease: false
54
+ name: railties
55
+ requirement: !ruby/object:Gem::Requirement
56
56
  requirements:
57
57
  - - ! '>='
58
58
  - !ruby/object:Gem::Version
59
59
  version: '3.0'
60
- prerelease: false
60
+ none: false
61
61
  type: :runtime
62
62
  - !ruby/object:Gem::Dependency
63
- name: rspec-core
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
- none: false
66
64
  requirements:
67
65
  - - ~>
68
66
  - !ruby/object:Gem::Version
69
- version: 2.12.0
70
- requirement: !ruby/object:Gem::Requirement
67
+ version: 2.13.0
71
68
  none: false
69
+ prerelease: false
70
+ name: rspec-core
71
+ requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 2.12.0
76
- prerelease: false
75
+ version: 2.13.0
76
+ none: false
77
77
  type: :runtime
78
78
  - !ruby/object:Gem::Dependency
79
- name: rspec-expectations
80
79
  version_requirements: !ruby/object:Gem::Requirement
81
- none: false
82
80
  requirements:
83
81
  - - ~>
84
82
  - !ruby/object:Gem::Version
85
- version: 2.12.0
86
- requirement: !ruby/object:Gem::Requirement
83
+ version: 2.13.0
87
84
  none: false
85
+ prerelease: false
86
+ name: rspec-expectations
87
+ requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ~>
90
90
  - !ruby/object:Gem::Version
91
- version: 2.12.0
92
- prerelease: false
91
+ version: 2.13.0
92
+ none: false
93
93
  type: :runtime
94
94
  - !ruby/object:Gem::Dependency
95
- name: rspec-mocks
96
95
  version_requirements: !ruby/object:Gem::Requirement
97
- none: false
98
96
  requirements:
99
97
  - - ~>
100
98
  - !ruby/object:Gem::Version
101
- version: 2.12.0
102
- requirement: !ruby/object:Gem::Requirement
99
+ version: 2.13.0
103
100
  none: false
101
+ prerelease: false
102
+ name: rspec-mocks
103
+ requirement: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ~>
106
106
  - !ruby/object:Gem::Version
107
- version: 2.12.0
108
- prerelease: false
107
+ version: 2.13.0
108
+ none: false
109
109
  type: :runtime
110
110
  - !ruby/object:Gem::Dependency
111
- name: rake
112
111
  version_requirements: !ruby/object:Gem::Requirement
113
- none: false
114
112
  requirements:
115
113
  - - ~>
116
114
  - !ruby/object:Gem::Version
117
115
  version: 10.0.0
118
- requirement: !ruby/object:Gem::Requirement
119
116
  none: false
117
+ prerelease: false
118
+ name: rake
119
+ requirement: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - ~>
122
122
  - !ruby/object:Gem::Version
123
123
  version: 10.0.0
124
- prerelease: false
124
+ none: false
125
125
  type: :development
126
126
  - !ruby/object:Gem::Dependency
127
- name: cucumber
128
127
  version_requirements: !ruby/object:Gem::Requirement
129
- none: false
130
128
  requirements:
131
129
  - - ~>
132
130
  - !ruby/object:Gem::Version
133
131
  version: 1.1.9
134
- requirement: !ruby/object:Gem::Requirement
135
132
  none: false
133
+ prerelease: false
134
+ name: cucumber
135
+ requirement: !ruby/object:Gem::Requirement
136
136
  requirements:
137
137
  - - ~>
138
138
  - !ruby/object:Gem::Version
139
139
  version: 1.1.9
140
- prerelease: false
140
+ none: false
141
141
  type: :development
142
142
  - !ruby/object:Gem::Dependency
143
- name: aruba
144
143
  version_requirements: !ruby/object:Gem::Requirement
145
- none: false
146
144
  requirements:
147
145
  - - ~>
148
146
  - !ruby/object:Gem::Version
149
147
  version: 0.4.11
150
- requirement: !ruby/object:Gem::Requirement
151
148
  none: false
149
+ prerelease: false
150
+ name: aruba
151
+ requirement: !ruby/object:Gem::Requirement
152
152
  requirements:
153
153
  - - ~>
154
154
  - !ruby/object:Gem::Version
155
155
  version: 0.4.11
156
- prerelease: false
156
+ none: false
157
157
  type: :development
158
158
  - !ruby/object:Gem::Dependency
159
- name: ZenTest
160
159
  version_requirements: !ruby/object:Gem::Requirement
161
- none: false
162
160
  requirements:
163
161
  - - '='
164
162
  - !ruby/object:Gem::Version
165
163
  version: 4.6.2
166
- requirement: !ruby/object:Gem::Requirement
167
164
  none: false
165
+ prerelease: false
166
+ name: ZenTest
167
+ requirement: !ruby/object:Gem::Requirement
168
168
  requirements:
169
169
  - - '='
170
170
  - !ruby/object:Gem::Version
171
171
  version: 4.6.2
172
- prerelease: false
172
+ none: false
173
173
  type: :development
174
174
  - !ruby/object:Gem::Dependency
175
- name: ammeter
176
175
  version_requirements: !ruby/object:Gem::Requirement
177
- none: false
178
176
  requirements:
179
177
  - - '='
180
178
  - !ruby/object:Gem::Version
181
179
  version: 0.2.5
182
- requirement: !ruby/object:Gem::Requirement
183
180
  none: false
181
+ prerelease: false
182
+ name: ammeter
183
+ requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - '='
186
186
  - !ruby/object:Gem::Version
187
187
  version: 0.2.5
188
- prerelease: false
188
+ none: false
189
189
  type: :development
190
190
  - !ruby/object:Gem::Dependency
191
- name: capybara
192
191
  version_requirements: !ruby/object:Gem::Requirement
193
- none: false
194
192
  requirements:
195
193
  - - ! '>='
196
194
  - !ruby/object:Gem::Version
197
195
  version: 2.0.0.beta4
198
- requirement: !ruby/object:Gem::Requirement
199
196
  none: false
197
+ prerelease: false
198
+ name: capybara
199
+ requirement: !ruby/object:Gem::Requirement
200
200
  requirements:
201
201
  - - ! '>='
202
202
  - !ruby/object:Gem::Version
203
203
  version: 2.0.0.beta4
204
- prerelease: false
204
+ none: false
205
205
  type: :development
206
206
  description: RSpec for Rails
207
207
  email: rspec-users@rubyforge.org
@@ -218,7 +218,7 @@ files:
218
218
  - lib/generators/rspec/helper/templates/helper_spec.rb
219
219
  - lib/generators/rspec/install/install_generator.rb
220
220
  - lib/generators/rspec/install/templates/.rspec
221
- - lib/generators/rspec/install/templates/spec/spec_helper.rb
221
+ - lib/generators/rspec/install/templates/spec/spec_helper.rb.tt
222
222
  - lib/generators/rspec/integration/integration_generator.rb
223
223
  - lib/generators/rspec/integration/templates/request_spec.rb
224
224
  - lib/generators/rspec/mailer/mailer_generator.rb
@@ -258,6 +258,7 @@ files:
258
258
  - lib/rspec/rails/matchers.rb
259
259
  - lib/rspec/rails/matchers/be_a_new.rb
260
260
  - lib/rspec/rails/matchers/be_new_record.rb
261
+ - lib/rspec/rails/matchers/be_valid.rb
261
262
  - lib/rspec/rails/matchers/have_extension.rb
262
263
  - lib/rspec/rails/matchers/have_rendered.rb
263
264
  - lib/rspec/rails/matchers/redirect_to.rb
@@ -344,6 +345,7 @@ files:
344
345
  - spec/rspec/rails/matchers/be_a_new_spec.rb
345
346
  - spec/rspec/rails/matchers/be_new_record_spec.rb
346
347
  - spec/rspec/rails/matchers/be_routable_spec.rb
348
+ - spec/rspec/rails/matchers/be_valid_spec.rb
347
349
  - spec/rspec/rails/matchers/errors_on_spec.rb
348
350
  - spec/rspec/rails/matchers/has_spec.rb
349
351
  - spec/rspec/rails/matchers/have_rendered_spec.rb
@@ -367,29 +369,29 @@ rdoc_options:
367
369
  require_paths:
368
370
  - lib
369
371
  required_ruby_version: !ruby/object:Gem::Requirement
370
- none: false
371
372
  requirements:
372
373
  - - ! '>='
373
374
  - !ruby/object:Gem::Version
374
375
  version: '0'
375
- hash: 1572351758875073422
376
376
  segments:
377
377
  - 0
378
- required_rubygems_version: !ruby/object:Gem::Requirement
378
+ hash: 643908547844668422
379
379
  none: false
380
+ required_rubygems_version: !ruby/object:Gem::Requirement
380
381
  requirements:
381
382
  - - ! '>='
382
383
  - !ruby/object:Gem::Version
383
384
  version: '0'
384
- hash: 1572351758875073422
385
385
  segments:
386
386
  - 0
387
+ hash: 643908547844668422
388
+ none: false
387
389
  requirements: []
388
390
  rubyforge_project: rspec
389
391
  rubygems_version: 1.8.24
390
392
  signing_key:
391
393
  specification_version: 3
392
- summary: rspec-rails-2.12.2
394
+ summary: rspec-rails-2.13.0
393
395
  test_files:
394
396
  - features/Autotest.md
395
397
  - features/Generators.md
@@ -458,6 +460,7 @@ test_files:
458
460
  - spec/rspec/rails/matchers/be_a_new_spec.rb
459
461
  - spec/rspec/rails/matchers/be_new_record_spec.rb
460
462
  - spec/rspec/rails/matchers/be_routable_spec.rb
463
+ - spec/rspec/rails/matchers/be_valid_spec.rb
461
464
  - spec/rspec/rails/matchers/errors_on_spec.rb
462
465
  - spec/rspec/rails/matchers/has_spec.rb
463
466
  - spec/rspec/rails/matchers/have_rendered_spec.rb