rspec-rails 2.13.0 → 2.13.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 +7 -0
- data/Capybara.md +1 -3
- data/Changelog.md +14 -0
- data/README.md +46 -16
- data/features/Transactions.md +2 -2
- data/features/Upgrade.md +4 -0
- data/features/controller_specs/Cookies.md +1 -1
- data/features/controller_specs/README.md +9 -9
- data/features/controller_specs/controller_spec.feature +1 -1
- data/features/controller_specs/engine_routes.feature +51 -0
- data/features/helper_specs/helper_spec.feature +26 -0
- data/features/matchers/README.md +3 -3
- data/features/model_specs/errors_on.feature +1 -1
- data/features/routing_specs/README.md +6 -7
- data/features/routing_specs/engine_routes.feature +38 -0
- data/features/support/rails_versions.rb +4 -0
- data/lib/generators/rspec.rb +2 -1
- data/lib/generators/rspec/controller/controller_generator.rb +1 -1
- data/lib/generators/rspec/install/install_generator.rb +2 -0
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +2 -2
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +4 -8
- data/lib/rspec/rails.rb +1 -0
- data/lib/rspec/rails/adapters.rb +30 -1
- data/lib/rspec/rails/example/controller_example_group.rb +43 -6
- data/lib/rspec/rails/example/rails_example_group.rb +2 -0
- data/lib/rspec/rails/example/routing_example_group.rb +28 -2
- data/lib/rspec/rails/example/view_example_group.rb +1 -1
- data/lib/rspec/rails/fixture_support.rb +1 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
- data/lib/rspec/rails/mocks.rb +1 -1
- data/lib/rspec/rails/rails_version.rb +17 -0
- data/lib/rspec/rails/tasks/rspec.rake +8 -6
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/generators/rspec/controller/controller_generator_spec.rb +11 -0
- data/spec/generators/rspec/install/install_generator_spec.rb +1 -1
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +23 -0
- data/spec/rspec/rails/assertion_delegator_spec.rb +13 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +1 -1
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +3 -3
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +1 -1
- data/spec/rspec/rails/matchers/route_to_spec.rb +9 -10
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +22 -0
- data/spec/rspec/rails/rails_version_spec.rb +29 -0
- data/spec/support/null_object.rb +6 -0
- metadata +67 -86
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b2867278a722c089dbb2bd8f6063ecb479760f05
|
4
|
+
data.tar.gz: bb564009cc97a8fb65e1088e71d3c0d0538bebd3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e030efde0376019bc0f8397c361c73aebf1ce81ba9e62412ef702c56e74c1f3145a43feb7b41e9dcc482e2cd1bd8c1b831c7620348c83bae9e844dffda224fd4
|
7
|
+
data.tar.gz: 8397abcbfdf655a2c8c9daa3891b03e4a4cf38ff1f60b6106cdf8b7240d29ff496883360ea16ee4c74a48fb61f89599b1cad36157402d33a7380c7a6bb304f5e
|
data/Capybara.md
CHANGED
@@ -3,8 +3,6 @@ its Capybara::DSL (visit/page) and Capybara::RSpecMatchers to the
|
|
3
3
|
examples in the applicable directories, which differ slightly between
|
4
4
|
Capybara 1.x and Capybara >= 2.x.
|
5
5
|
|
6
|
-
Note that you need to require "capybara/rspec" for this integration to work.
|
7
|
-
|
8
6
|
## Capybara::DSL
|
9
7
|
|
10
8
|
Adds the `visit` and `page` methods, which work together to simulate a
|
@@ -12,7 +10,7 @@ GET request and provide access to the result (via `page`).
|
|
12
10
|
|
13
11
|
## Capybara::RSpecMatchers
|
14
12
|
|
15
|
-
Exposes matchers used to specify expected HTML content (e.g. `have_selector`).
|
13
|
+
Exposes matchers used to specify expected HTML content (e.g. `should_not have_selector` will work correctly).
|
16
14
|
|
17
15
|
## Capybara 1.x
|
18
16
|
|
data/Changelog.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
### 2.13.1
|
2
|
+
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.13.0...v2.13.1)
|
3
|
+
|
4
|
+
Bug fixes
|
5
|
+
|
6
|
+
* View specs are no longer generated if no template engine is specified (Kevin
|
7
|
+
Glowacz)
|
8
|
+
* `ActionController::Base.allow_forgery_protection` is set to its original
|
9
|
+
value after each example. (Mark Dimas)
|
10
|
+
* `patch` is supported in routing specs. (Chris Your)
|
11
|
+
* Routing assertions are supported in controller specs in Rails 4. (Andy
|
12
|
+
Lindeman)
|
13
|
+
* Fix spacing in the install generator template (Taiki ONO)
|
14
|
+
|
1
15
|
### 2.13.0 / 2013-02-23
|
2
16
|
[full changelog](http://github.com/rspec/rspec-rails/compare/v2.12.2...v2.13.0)
|
3
17
|
|
data/README.md
CHANGED
@@ -1,34 +1,58 @@
|
|
1
1
|
# rspec-rails [](http://travis-ci.org/rspec/rspec-rails) [](https://codeclimate.com/github/rspec/rspec-rails)
|
2
2
|
|
3
|
-
**rspec-rails
|
3
|
+
**rspec-rails** is a testing framework for Rails 3.x and 4.x.
|
4
4
|
|
5
|
-
Use **[rspec-rails 1](http://github.com/dchelimsky/rspec-rails)** for Rails
|
5
|
+
Use **[rspec-rails 1.x](http://github.com/dchelimsky/rspec-rails)** for Rails
|
6
|
+
2.x.
|
6
7
|
|
7
|
-
##
|
8
|
+
## Installation
|
8
9
|
|
9
|
-
Add `rspec-rails` to the `:
|
10
|
+
Add `rspec-rails` to **both** the `:development` and `:test` groups in the
|
11
|
+
`Gemfile`:
|
10
12
|
|
11
13
|
```ruby
|
12
|
-
group :
|
13
|
-
gem
|
14
|
+
group :development, :test do
|
15
|
+
gem 'rspec-rails', '~> 2.0'
|
14
16
|
end
|
15
17
|
```
|
16
18
|
|
17
|
-
|
18
|
-
tasks without having to type `RAILS_ENV=test`.
|
19
|
+
Download and install by running:
|
19
20
|
|
20
|
-
|
21
|
+
```
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
Initialize the `spec/` directory (where specs will reside) with:
|
21
26
|
|
22
27
|
```
|
23
28
|
rails generate rspec:install
|
24
29
|
```
|
25
30
|
|
26
|
-
|
27
|
-
|
31
|
+
To run your specs, use the `rspec` command:
|
32
|
+
|
33
|
+
```
|
34
|
+
bundle exec rspec
|
35
|
+
|
36
|
+
# Run only model specs
|
37
|
+
bundle exec rspec spec/models
|
38
|
+
|
39
|
+
# Run only specs for AccountsController
|
40
|
+
bundle exec rspec spec/controllers/accounts_controller_spec.rb
|
41
|
+
```
|
42
|
+
|
43
|
+
Specs can also be run via `rake spec`, though this command may be slower to
|
44
|
+
start than the `rspec` command.
|
45
|
+
|
46
|
+
In Rails 4, you may want to create a binstub for the `rspec` command so it can
|
47
|
+
be run via `bin/rspec`:
|
48
|
+
|
49
|
+
```
|
50
|
+
bundle binstubs rspec-core
|
51
|
+
```
|
28
52
|
|
29
53
|
### Generators
|
30
54
|
|
31
|
-
Once installed, RSpec will generate spec
|
55
|
+
Once installed, RSpec will generate spec files instead of Test::Unit test files
|
32
56
|
when commands like `rails generate model` and `rails generate controller` are
|
33
57
|
used.
|
34
58
|
|
@@ -67,7 +91,7 @@ describe PostsController do
|
|
67
91
|
it "responds successfully with an HTTP 200 status code" do
|
68
92
|
get :index
|
69
93
|
expect(response).to be_success
|
70
|
-
expect(response.
|
94
|
+
expect(response.status).to eq(200)
|
71
95
|
end
|
72
96
|
|
73
97
|
it "renders the index template" do
|
@@ -97,7 +121,8 @@ spec](#feature-specs).
|
|
97
121
|
|
98
122
|
## <a id="request-spec"></a>Request Specs
|
99
123
|
|
100
|
-
Request specs live in spec/requests, spec/
|
124
|
+
Request specs live in spec/requests, spec/features, spec/api and
|
125
|
+
spec/integration, and mix in behavior
|
101
126
|
[ActionDispatch::Integration::Runner](http://api.rubyonrails.org/classes/ActionDispatch/Integration/Runner.html),
|
102
127
|
which is the basis for [Rails' integration
|
103
128
|
tests](http://guides.rubyonrails.org/testing.html#integration-testing). The
|
@@ -123,7 +148,9 @@ end
|
|
123
148
|
```
|
124
149
|
|
125
150
|
This example uses only standard Rails and RSpec API's, but many RSpec/Rails
|
126
|
-
users like to use extension libraries like
|
151
|
+
users like to use extension libraries like
|
152
|
+
[FactoryGirl](https://github.com/thoughtbot/factory_girl) and
|
153
|
+
[Capybara](https://github.com/jnicklas/capybara):
|
127
154
|
|
128
155
|
```ruby
|
129
156
|
require 'spec_helper'
|
@@ -145,7 +172,10 @@ which can be encoded into the underlying factory definition without requiring
|
|
145
172
|
changes to this example.
|
146
173
|
|
147
174
|
Among other benefits, Capybara binds the form post to the generated HTML, which
|
148
|
-
means we don't need to specify them separately.
|
175
|
+
means we don't need to specify them separately. Note that Capybara's DSL as
|
176
|
+
shown is, by default, only available in specs in the spec/features directory.
|
177
|
+
For more information, see the [Capybara integration
|
178
|
+
docs](http://rubydoc.info/gems/rspec-rails/file/Capybara.md).
|
149
179
|
|
150
180
|
There are several other Ruby libs that implement the factory pattern or provide
|
151
181
|
a DSL for request specs (a.k.a. acceptance or integration specs), but
|
data/features/Transactions.md
CHANGED
@@ -36,11 +36,11 @@ already ran. For example:
|
|
36
36
|
end
|
37
37
|
|
38
38
|
it "does something" do
|
39
|
-
@widget.
|
39
|
+
expect(@widget).to do_something
|
40
40
|
end
|
41
41
|
|
42
42
|
it "does something else" do
|
43
|
-
@widget.
|
43
|
+
expect(@widget).to do_something_else
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/features/Upgrade.md
CHANGED
@@ -60,6 +60,10 @@ This needs to move from before the action to after. For example:
|
|
60
60
|
get :edit, :id => "37"
|
61
61
|
response.should render_template("edit")
|
62
62
|
|
63
|
+
# rspec-rails-2 with expect syntax
|
64
|
+
get :edit, :id => "37"
|
65
|
+
expect(response).to render_template("edit")
|
66
|
+
|
63
67
|
rspec-1 had to monkey patch Rails to get render_template to work before the
|
64
68
|
action, and this broke a couple of times with Rails releases (requiring urgent
|
65
69
|
fix releases in RSpec). Part of the philosophy of rspec-rails-2 is to rely on
|
@@ -12,15 +12,15 @@ specify expected outcomes such as:
|
|
12
12
|
* cookies sent back with the response
|
13
13
|
|
14
14
|
To specify outcomes, you can use:
|
15
|
-
|
16
|
-
* standard rspec matchers (`response.
|
17
|
-
* standard test/unit assertions (`assert_equal 200, response.
|
15
|
+
|
16
|
+
* standard rspec matchers (`expect(response.status).to eq(200)`)
|
17
|
+
* standard test/unit assertions (`assert_equal 200, response.status`)
|
18
18
|
* rails assertions (`assert_response 200`)
|
19
19
|
* rails-specific matchers:
|
20
|
-
* `response.
|
21
|
-
* `response.
|
22
|
-
* `assigns(:widget).
|
23
|
-
|
20
|
+
* `expect(response).to render_template(wraps assert_template)`
|
21
|
+
* `expect(response).to redirect_to(wraps assert_redirected_to)`
|
22
|
+
* `expect(assigns(:widget)).to be_a_new(Widget)`
|
23
|
+
|
24
24
|
## Examples
|
25
25
|
|
26
26
|
describe TeamsController do
|
@@ -28,12 +28,12 @@ To specify outcomes, you can use:
|
|
28
28
|
it "assigns @teams" do
|
29
29
|
team = Team.create
|
30
30
|
get :index
|
31
|
-
assigns(:teams).
|
31
|
+
expect(assigns(:teams)).to eq([team])
|
32
32
|
end
|
33
33
|
|
34
34
|
it "renders the index template" do
|
35
35
|
get :index
|
36
|
-
response.
|
36
|
+
expect(response).to render_template("index")
|
37
37
|
end
|
38
38
|
end
|
39
39
|
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: engine routes for controllers
|
2
|
+
|
3
|
+
Controller specs can specify the routeset that will be used for the example
|
4
|
+
group. This is most useful when testing Rails engines.
|
5
|
+
|
6
|
+
@unsupported-on-rails-3-0
|
7
|
+
Scenario: specify engine route
|
8
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
9
|
+
"""ruby
|
10
|
+
require "spec_helper"
|
11
|
+
|
12
|
+
# A very simple Rails engine
|
13
|
+
module MyEngine
|
14
|
+
class Engine < ::Rails::Engine
|
15
|
+
isolate_namespace MyEngine
|
16
|
+
end
|
17
|
+
|
18
|
+
Engine.routes.draw do
|
19
|
+
resources :widgets, :only => [:show] do
|
20
|
+
get :random, :on => :collection
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class WidgetsController < ::ActionController::Base
|
25
|
+
def random
|
26
|
+
@random_widget = Widget.all.shuffle.first
|
27
|
+
redirect_to widget_path(@random_widget)
|
28
|
+
end
|
29
|
+
|
30
|
+
def show
|
31
|
+
@widget = Widget.find(params[:id])
|
32
|
+
render :text => @widget.name
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe MyEngine::WidgetsController do
|
38
|
+
routes { MyEngine::Engine.routes }
|
39
|
+
|
40
|
+
it "redirects to a random widget" do
|
41
|
+
widget1 = Widget.create!(:name => "Widget 1")
|
42
|
+
widget2 = Widget.create!(:name => "Widget 2")
|
43
|
+
|
44
|
+
get :random
|
45
|
+
expect(response).to be_redirect
|
46
|
+
expect(response).to redirect_to(assigns(:random_widget))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
When I run `rspec spec`
|
51
|
+
Then the examples should all pass
|
@@ -94,3 +94,29 @@ Feature: helper spec
|
|
94
94
|
"""
|
95
95
|
When I run `rspec spec/helpers/widgets_helper_spec.rb`
|
96
96
|
Then the examples should all pass
|
97
|
+
|
98
|
+
Scenario: url helpers are defined
|
99
|
+
Given a file named "spec/helpers/widgets_helper_spec.rb" with:
|
100
|
+
"""ruby
|
101
|
+
require "spec_helper"
|
102
|
+
|
103
|
+
describe WidgetsHelper do
|
104
|
+
describe "#link_to_widget" do
|
105
|
+
it "links to a widget using its name" do
|
106
|
+
widget = Widget.create!(:name => "This Widget")
|
107
|
+
expect(helper.link_to_widget(widget)).to include("This Widget")
|
108
|
+
expect(helper.link_to_widget(widget)).to include(widget_path(widget))
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
"""
|
113
|
+
And a file named "app/helpers/widgets_helper.rb" with:
|
114
|
+
"""ruby
|
115
|
+
module WidgetsHelper
|
116
|
+
def link_to_widget(widget)
|
117
|
+
link_to(widget.name, widget_path(widget))
|
118
|
+
end
|
119
|
+
end
|
120
|
+
"""
|
121
|
+
When I run `rspec spec/helpers/widgets_helper_spec.rb`
|
122
|
+
Then the examples should all pass
|
data/features/matchers/README.md
CHANGED
@@ -4,15 +4,15 @@ rspec-compatible wrappers for Rails' assertions.
|
|
4
4
|
### redirects
|
5
5
|
|
6
6
|
# delegates to assert_redirected_to
|
7
|
-
response.
|
7
|
+
expect(response).to redirect_to(path)
|
8
8
|
|
9
9
|
### templates
|
10
10
|
|
11
11
|
# delegates to assert_template
|
12
|
-
response.
|
12
|
+
expect(response).to render_template(template_name)
|
13
13
|
|
14
14
|
### assigned objects
|
15
15
|
|
16
16
|
# passes if assigns(:widget) is an instance of Widget
|
17
17
|
# and it is not persisted
|
18
|
-
assigns(:widget).
|
18
|
+
expect(assigns(:widget)).to be_a_new(Widget)
|
@@ -10,7 +10,7 @@ Feature: errors_on
|
|
10
10
|
validates_presence_of :name
|
11
11
|
|
12
12
|
# In Rails 4, mass assignment protection is implemented on controllers
|
13
|
-
attr_accessible :name if Rails.
|
13
|
+
attr_accessible :name if RSpec::Rails.rails_version_satisfied_by?('< 4.0.0.beta1')
|
14
14
|
|
15
15
|
validates_length_of :name, :minimum => 10, :on => :publication
|
16
16
|
end
|
@@ -5,13 +5,12 @@ Simple apps with nothing but standard RESTful routes won't get much value from
|
|
5
5
|
routing specs, but they can provide significant value when used to specify
|
6
6
|
customized routes, like vanity links, slugs, etc.
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
)
|
8
|
+
expect(:get => "/articles/2012/11/when-to-use-routing-specs").to route_to(
|
9
|
+
:controller => "articles",
|
10
|
+
:month => "2012-11",
|
11
|
+
:slug => "when-to-use-routing-specs"
|
12
|
+
)
|
14
13
|
|
15
14
|
They are also valuable for routes that should not be available:
|
16
15
|
|
17
|
-
|
16
|
+
expect(:delete => "/accounts/37").not_to be_routable
|
@@ -0,0 +1,38 @@
|
|
1
|
+
Feature: engine routes
|
2
|
+
|
3
|
+
Routing specs can specify the routeset that will be used for the example
|
4
|
+
group. This is most useful when testing Rails engines.
|
5
|
+
|
6
|
+
@unsupported-on-rails-3-0
|
7
|
+
Scenario: specify engine route
|
8
|
+
Given a file named "spec/routing/engine_routes_spec.rb" with:
|
9
|
+
"""ruby
|
10
|
+
require "spec_helper"
|
11
|
+
|
12
|
+
# A very simple Rails engine
|
13
|
+
module MyEngine
|
14
|
+
class Engine < ::Rails::Engine
|
15
|
+
isolate_namespace MyEngine
|
16
|
+
end
|
17
|
+
|
18
|
+
Engine.routes.draw do
|
19
|
+
resources :widgets, :only => [:index]
|
20
|
+
end
|
21
|
+
|
22
|
+
class WidgetsController < ::ActionController::Base
|
23
|
+
def index
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe MyEngine::WidgetsController do
|
29
|
+
routes { MyEngine::Engine.routes }
|
30
|
+
|
31
|
+
it "routes to the list of all widgets" do
|
32
|
+
expect(:get => widgets_path).
|
33
|
+
to route_to(:controller => "my_engine/widgets", :action => "index")
|
34
|
+
end
|
35
|
+
end
|
36
|
+
"""
|
37
|
+
When I run `rspec spec`
|
38
|
+
Then the examples should all pass
|
data/lib/generators/rspec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rails/generators/named_base'
|
2
|
+
require 'rspec/rails/rails_version'
|
2
3
|
|
3
4
|
module Rspec
|
4
5
|
module Generators
|
@@ -7,7 +8,7 @@ module Rspec
|
|
7
8
|
@_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
8
9
|
end
|
9
10
|
|
10
|
-
if ::Rails.
|
11
|
+
if RSpec::Rails.rails_version_satisfied_by?('< 3.1')
|
11
12
|
def module_namespacing
|
12
13
|
yield if block_given?
|
13
14
|
end
|