rspec-rails 2.14.2 → 2.99.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/Changelog.md +8 -10
- data/features/Autotest.md +24 -0
- data/features/Generators.md +24 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +56 -0
- data/features/RailsVersions.md +4 -0
- data/features/Transactions.md +84 -0
- data/features/Upgrade.md +121 -0
- data/features/controller_specs/Cookies.md +57 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +378 -0
- data/features/controller_specs/bypass_rescue.feature +75 -0
- data/features/controller_specs/controller_spec.feature +58 -0
- data/features/controller_specs/engine_routes.feature +51 -0
- data/features/controller_specs/isolation_from_views.feature +87 -0
- data/features/controller_specs/render_views.feature +114 -0
- data/features/feature_specs/feature_spec.feature +34 -0
- data/features/helper_specs/helper_spec.feature +122 -0
- data/features/mailer_specs/url_helpers.feature +38 -0
- data/features/matchers/README.md +18 -0
- data/features/matchers/new_record_matcher.feature +41 -0
- data/features/matchers/redirect_to_matcher.feature +40 -0
- data/features/matchers/relation_match_array.feature +27 -0
- data/features/matchers/render_template_matcher.feature +49 -0
- data/features/mocks/mock_model.feature +147 -0
- data/features/mocks/stub_model.feature +58 -0
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +51 -0
- data/features/model_specs/records.feature +27 -0
- data/features/model_specs/transactional_examples.feature +109 -0
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +16 -0
- data/features/routing_specs/be_routable_matcher.feature +80 -0
- data/features/routing_specs/engine_routes.feature +38 -0
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +90 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/step_definitions/model_steps.rb +3 -0
- data/features/support/env.rb +53 -0
- data/features/support/rails_versions.rb +4 -0
- data/features/support/rubinius.rb +6 -0
- data/features/view_specs/inferred_controller_path.feature +45 -0
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +206 -0
- data/lib/autotest/rails_rspec2.rb +81 -76
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +1 -6
- data/lib/rspec/rails/adapters.rb +5 -12
- data/lib/rspec/rails/example/controller_example_group.rb +1 -2
- data/lib/rspec/rails/example/helper_example_group.rb +3 -3
- data/lib/rspec/rails/example/view_example_group.rb +4 -7
- data/lib/rspec/rails/matchers/have_extension.rb +0 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +0 -4
- data/lib/rspec/rails/mocks.rb +0 -26
- data/lib/rspec/rails/tasks/rspec.rake +5 -12
- data/lib/rspec/rails/version.rb +1 -1
- data/spec/autotest/rails_rspec2_spec.rb +36 -0
- data/spec/generators/rspec/controller/controller_generator_spec.rb +97 -0
- data/spec/generators/rspec/helper/helper_generator_spec.rb +30 -0
- data/spec/generators/rspec/install/install_generator_spec.rb +30 -0
- data/spec/generators/rspec/integration/integration_generator_spec.rb +44 -0
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +48 -0
- data/spec/generators/rspec/model/model_generator_spec.rb +52 -0
- data/spec/generators/rspec/observer/observer_generator_spec.rb +21 -0
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +138 -0
- data/spec/generators/rspec/view/view_generator_spec.rb +41 -0
- data/spec/rspec/rails/assertion_adapter_spec.rb +28 -0
- data/spec/rspec/rails/assertion_delegator_spec.rb +43 -0
- data/spec/rspec/rails/configuration_spec.rb +26 -0
- data/spec/rspec/rails/deprecations_spec.rb +18 -0
- data/spec/rspec/rails/example/controller_example_group_spec.rb +100 -0
- data/spec/rspec/rails/example/feature_example_group_spec.rb +56 -0
- data/spec/rspec/rails/example/helper_example_group_spec.rb +66 -0
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +21 -0
- data/spec/rspec/rails/example/model_example_group_spec.rb +15 -0
- data/spec/rspec/rails/example/request_example_group_spec.rb +17 -0
- data/spec/rspec/rails/example/routing_example_group_spec.rb +32 -0
- data/spec/rspec/rails/example/view_example_group_spec.rb +220 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +42 -0
- data/spec/rspec/rails/fixture_support_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +142 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +33 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/be_valid_spec.rb +44 -0
- data/spec/rspec/rails/matchers/errors_on_spec.rb +38 -0
- data/spec/rspec/rails/matchers/has_spec.rb +29 -0
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +93 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +80 -0
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +31 -0
- data/spec/rspec/rails/matchers/route_to_spec.rb +151 -0
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +22 -0
- data/spec/rspec/rails/mocks/mock_model_spec.rb +378 -0
- data/spec/rspec/rails/mocks/stub_model_spec.rb +154 -0
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +32 -0
- data/spec/rspec/rails/view_rendering_spec.rb +111 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/ar_classes.rb +42 -0
- data/spec/support/helpers.rb +20 -0
- data/spec/support/matchers.rb +9 -0
- data/spec/support/null_object.rb +6 -0
- metadata +223 -47
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: errors_on
|
2
|
+
|
3
|
+
Scenario: with one validation error
|
4
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
5
|
+
"""ruby
|
6
|
+
require "spec_helper"
|
7
|
+
|
8
|
+
class ValidatingWidget < ActiveRecord::Base
|
9
|
+
self.table_name = :widgets
|
10
|
+
validates_presence_of :name
|
11
|
+
|
12
|
+
# In Rails 4, mass assignment protection is implemented on controllers
|
13
|
+
attr_accessible :name if ::ActiveRecord::VERSION::STRING < '4'
|
14
|
+
|
15
|
+
validates_length_of :name, :minimum => 10, :on => :publication
|
16
|
+
end
|
17
|
+
|
18
|
+
describe ValidatingWidget do
|
19
|
+
it "fails validation with no name (using error_on)" do
|
20
|
+
expect(ValidatingWidget.new).to have(1).error_on(:name)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "fails validation with no name (using errors_on)" do
|
24
|
+
expect(ValidatingWidget.new).to have(1).errors_on(:name)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "fails validation with no name expecting a specific message" do
|
28
|
+
expect(ValidatingWidget.new.errors_on(:name)).to include("can't be blank")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "fails validation with a short name (using a validation context)" do
|
32
|
+
expect(ValidatingWidget.new(:name => "too short")).
|
33
|
+
to have(1).errors_on(:name, :context => :publication)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "passes validation with a longer name (using a validation context)" do
|
37
|
+
expect(ValidatingWidget.new(:name => "a longer name")).
|
38
|
+
to have(0).errors_on(:name, :context => :publication)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "passes validation with a name (using 0)" do
|
42
|
+
expect(ValidatingWidget.new(:name => "liquid nitrogen")).to have(0).errors_on(:name)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "passes validation with a name (using :no)" do
|
46
|
+
expect(ValidatingWidget.new(:name => "liquid nitrogen")).to have(:no).errors_on(:name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
"""
|
50
|
+
When I run `rspec spec/models/widget_spec.rb`
|
51
|
+
Then the examples should all pass
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: records
|
2
|
+
|
3
|
+
Scenario: asserting number of records
|
4
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
5
|
+
"""ruby
|
6
|
+
require "spec_helper"
|
7
|
+
|
8
|
+
describe Widget do
|
9
|
+
it "has no widgets in the database" do
|
10
|
+
expect(Widget).to have(:no).records
|
11
|
+
expect(Widget).to have(0).records
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has one record" do
|
15
|
+
Widget.create!(:name => "Cog")
|
16
|
+
expect(Widget).to have(1).record
|
17
|
+
end
|
18
|
+
|
19
|
+
it "counts only records that match a query" do
|
20
|
+
Widget.create!(:name => "Cog")
|
21
|
+
expect(Widget.where(:name => "Cog")).to have(1).record
|
22
|
+
expect(Widget.where(:name => "Wheel")).to have(0).records
|
23
|
+
end
|
24
|
+
end
|
25
|
+
"""
|
26
|
+
When I run `rspec spec/models/widget_spec.rb`
|
27
|
+
Then the examples should all pass
|
@@ -0,0 +1,109 @@
|
|
1
|
+
Feature: transactional examples
|
2
|
+
|
3
|
+
By default rspec executes each individual example in a transaction.
|
4
|
+
|
5
|
+
You can also explicitly enable/disable transactions the configuration
|
6
|
+
property 'use_transactional_examples'.
|
7
|
+
|
8
|
+
Scenario: run in transactions (default)
|
9
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
10
|
+
"""ruby
|
11
|
+
require "spec_helper"
|
12
|
+
|
13
|
+
describe Widget do
|
14
|
+
it "has none to begin with" do
|
15
|
+
expect(Widget.count).to eq 0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "has one after adding one" do
|
19
|
+
Widget.create
|
20
|
+
expect(Widget.count).to eq 1
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has none after one was created in a previous example" do
|
24
|
+
expect(Widget.count).to eq 0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
"""
|
28
|
+
When I run `rspec spec/models/widget_spec.rb`
|
29
|
+
Then the examples should all pass
|
30
|
+
|
31
|
+
Scenario: run in transactions (explicit)
|
32
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
33
|
+
"""ruby
|
34
|
+
require "spec_helper"
|
35
|
+
|
36
|
+
RSpec.configure do |c|
|
37
|
+
c.use_transactional_examples = true
|
38
|
+
end
|
39
|
+
|
40
|
+
describe Widget do
|
41
|
+
it "has none to begin with" do
|
42
|
+
expect(Widget.count).to eq 0
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has one after adding one" do
|
46
|
+
Widget.create
|
47
|
+
expect(Widget.count).to eq 1
|
48
|
+
end
|
49
|
+
|
50
|
+
it "has none after one was created in a previous example" do
|
51
|
+
expect(Widget.count).to eq 0
|
52
|
+
end
|
53
|
+
end
|
54
|
+
"""
|
55
|
+
When I run `rspec spec/models/widget_spec.rb`
|
56
|
+
Then the examples should all pass
|
57
|
+
|
58
|
+
Scenario: disable transactions (explicit)
|
59
|
+
Given a file named "spec/models/widget_spec.rb" with:
|
60
|
+
"""ruby
|
61
|
+
require "spec_helper"
|
62
|
+
|
63
|
+
RSpec.configure do |c|
|
64
|
+
c.use_transactional_examples = false
|
65
|
+
c.order = "default"
|
66
|
+
end
|
67
|
+
|
68
|
+
describe Widget do
|
69
|
+
it "has none to begin with" do
|
70
|
+
expect(Widget.count).to eq 0
|
71
|
+
end
|
72
|
+
|
73
|
+
it "has one after adding one" do
|
74
|
+
Widget.create
|
75
|
+
expect(Widget.count).to eq 1
|
76
|
+
end
|
77
|
+
|
78
|
+
it "has one after one was created in a previous example" do
|
79
|
+
expect(Widget.count).to eq 1
|
80
|
+
end
|
81
|
+
|
82
|
+
after(:all) { Widget.destroy_all }
|
83
|
+
end
|
84
|
+
"""
|
85
|
+
When I run `rspec spec/models/widget_spec.rb`
|
86
|
+
Then the examples should all pass
|
87
|
+
|
88
|
+
Scenario: run in transactions with fixture
|
89
|
+
Given a file named "spec/models/thing_spec.rb" with:
|
90
|
+
"""ruby
|
91
|
+
require "spec_helper"
|
92
|
+
|
93
|
+
describe Thing do
|
94
|
+
fixtures :things
|
95
|
+
it "fixture method defined" do
|
96
|
+
things(:one)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
"""
|
100
|
+
Given a file named "spec/fixtures/things.yml" with:
|
101
|
+
"""
|
102
|
+
one:
|
103
|
+
name: MyString
|
104
|
+
"""
|
105
|
+
When I run `rspec spec/models/thing_spec.rb`
|
106
|
+
Then the examples should all pass
|
107
|
+
|
108
|
+
|
109
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
Feature: request spec
|
2
|
+
|
3
|
+
Request specs provide a thin wrapper around Rails' integration tests, and are
|
4
|
+
designed to drive behavior through the full stack, including routing
|
5
|
+
(provided by Rails) and without stubbing (that's up to you).
|
6
|
+
|
7
|
+
With request specs, you can:
|
8
|
+
|
9
|
+
* specify a single request
|
10
|
+
* specify multiple requests across multiple controllers
|
11
|
+
* specify multiple requests across multiple sessions
|
12
|
+
|
13
|
+
Check the rails documentation on integration tests for more information.
|
14
|
+
|
15
|
+
RSpec provides two matchers that delegate to Rails assertions:
|
16
|
+
|
17
|
+
render_template # delegates to assert_template
|
18
|
+
redirect_to # delegates to assert_redirected_to
|
19
|
+
|
20
|
+
Check the Rails docs for details on these methods as well.
|
21
|
+
|
22
|
+
[Capybara](http://github.com/jnicklas/capybara) is no longer supported in
|
23
|
+
request specs as of Capybara 2.0.0. The recommended way to use Capybara is
|
24
|
+
with [feature specs](../feature-specs/feature-spec).
|
25
|
+
|
26
|
+
Scenario: specify managing a Widget with Rails integration methods
|
27
|
+
Given a file named "spec/requests/widget_management_spec.rb" with:
|
28
|
+
"""ruby
|
29
|
+
require "spec_helper"
|
30
|
+
|
31
|
+
describe "Widget management" do
|
32
|
+
|
33
|
+
it "creates a Widget and redirects to the Widget's page" do
|
34
|
+
get "/widgets/new"
|
35
|
+
expect(response).to render_template(:new)
|
36
|
+
|
37
|
+
post "/widgets", :widget => {:name => "My Widget"}
|
38
|
+
|
39
|
+
expect(response).to redirect_to(assigns(:widget))
|
40
|
+
follow_redirect!
|
41
|
+
|
42
|
+
expect(response).to render_template(:show)
|
43
|
+
expect(response.body).to include("Widget was successfully created.")
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
"""
|
48
|
+
When I run `rspec spec/requests/widget_management_spec.rb`
|
49
|
+
Then the example should pass
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Routing specs live in the `spec/routing` directory, or any example group with
|
2
|
+
`:type => :routing`.
|
3
|
+
|
4
|
+
Simple apps with nothing but standard RESTful routes won't get much value from
|
5
|
+
routing specs, but they can provide significant value when used to specify
|
6
|
+
customized routes, like vanity links, slugs, etc.
|
7
|
+
|
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
|
+
)
|
13
|
+
|
14
|
+
They are also valuable for routes that should not be available:
|
15
|
+
|
16
|
+
expect(:delete => "/accounts/37").not_to be_routable
|
@@ -0,0 +1,80 @@
|
|
1
|
+
Feature: be_routable matcher
|
2
|
+
|
3
|
+
The `be_routable` matcher is best used with `should_not` to specify that a
|
4
|
+
given route should not be routable. It is available in routing specs (in
|
5
|
+
spec/routing) and controller specs (in spec/controllers).
|
6
|
+
|
7
|
+
Scenario: specify routeable route should not be routable (fails)
|
8
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
9
|
+
"""ruby
|
10
|
+
require "spec_helper"
|
11
|
+
|
12
|
+
describe "routes for Widgets" do
|
13
|
+
it "does not route to widgets" do
|
14
|
+
expect(:get => "/widgets").not_to be_routable
|
15
|
+
end
|
16
|
+
end
|
17
|
+
"""
|
18
|
+
|
19
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
20
|
+
Then the output should contain "1 example, 1 failure"
|
21
|
+
|
22
|
+
Scenario: specify non-routeable route should not be routable (passes)
|
23
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
24
|
+
"""ruby
|
25
|
+
require "spec_helper"
|
26
|
+
|
27
|
+
describe "routes for Widgets" do
|
28
|
+
it "does not route to widgets/foo/bar" do
|
29
|
+
expect(:get => "/widgets/foo/bar").not_to be_routable
|
30
|
+
end
|
31
|
+
end
|
32
|
+
"""
|
33
|
+
|
34
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
35
|
+
Then the examples should all pass
|
36
|
+
|
37
|
+
Scenario: specify routeable route should be routable (passes)
|
38
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
39
|
+
"""ruby
|
40
|
+
require "spec_helper"
|
41
|
+
|
42
|
+
describe "routes for Widgets" do
|
43
|
+
it "routes to /widgets" do
|
44
|
+
expect(:get => "/widgets").to be_routable
|
45
|
+
end
|
46
|
+
end
|
47
|
+
"""
|
48
|
+
|
49
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
50
|
+
Then the examples should all pass
|
51
|
+
|
52
|
+
Scenario: specify non-routeable route should be routable (fails)
|
53
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
54
|
+
"""ruby
|
55
|
+
require "spec_helper"
|
56
|
+
|
57
|
+
describe "routes for Widgets" do
|
58
|
+
it "routes to widgets/foo/bar" do
|
59
|
+
expect(:get => "/widgets/foo/bar").to be_routable
|
60
|
+
end
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
|
64
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
65
|
+
Then the output should contain "1 example, 1 failure"
|
66
|
+
|
67
|
+
Scenario: be_routable in a controller spec
|
68
|
+
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
69
|
+
"""ruby
|
70
|
+
require "spec_helper"
|
71
|
+
|
72
|
+
describe WidgetsController do
|
73
|
+
it "routes to /widgets" do
|
74
|
+
expect(:get => "/widgets").to be_routable
|
75
|
+
end
|
76
|
+
end
|
77
|
+
"""
|
78
|
+
|
79
|
+
When I run `rspec spec/controllers/widgets_controller_spec.rb`
|
80
|
+
Then the examples should all pass
|
@@ -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
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Feature: named routes
|
2
|
+
|
3
|
+
Routing specs have access to named routes.
|
4
|
+
|
5
|
+
Scenario: access named route
|
6
|
+
Given a file named "spec/routing/widget_routes_spec.rb" with:
|
7
|
+
"""ruby
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
describe "routes to the widgets controller" do
|
11
|
+
it "routes a named route" do
|
12
|
+
expect(:get => new_widget_path).
|
13
|
+
to route_to(:controller => "widgets", :action => "new")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
"""
|
17
|
+
When I run `rspec spec`
|
18
|
+
Then the examples should all pass
|
@@ -0,0 +1,90 @@
|
|
1
|
+
Feature: route_to matcher
|
2
|
+
|
3
|
+
The `route_to` matcher specifies that a request (verb + path) is routable.
|
4
|
+
It is most valuable when specifying routes other than standard RESTful
|
5
|
+
routes.
|
6
|
+
|
7
|
+
expect(get("/")).to route_to("welcome#index") # new in 2.6.0
|
8
|
+
|
9
|
+
or
|
10
|
+
|
11
|
+
expect(:get => "/").to route_to(:controller => "welcome")
|
12
|
+
|
13
|
+
Scenario: passing route spec with shortcut syntax
|
14
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
15
|
+
"""ruby
|
16
|
+
require "spec_helper"
|
17
|
+
|
18
|
+
describe "routes for Widgets" do
|
19
|
+
it "routes /widgets to the widgets controller" do
|
20
|
+
expect(get("/widgets")).
|
21
|
+
to route_to("widgets#index")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
"""
|
25
|
+
|
26
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
27
|
+
Then the examples should all pass
|
28
|
+
|
29
|
+
Scenario: passing route spec with verbose syntax
|
30
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
31
|
+
"""ruby
|
32
|
+
require "spec_helper"
|
33
|
+
|
34
|
+
describe "routes for Widgets" do
|
35
|
+
it "routes /widgets to the widgets controller" do
|
36
|
+
expect(:get => "/widgets").
|
37
|
+
to route_to(:controller => "widgets", :action => "index")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
"""
|
41
|
+
|
42
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
43
|
+
Then the examples should all pass
|
44
|
+
|
45
|
+
Scenario: route spec for a route that doesn't exist (fails)
|
46
|
+
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
47
|
+
"""ruby
|
48
|
+
require "spec_helper"
|
49
|
+
|
50
|
+
describe "routes for Widgets" do
|
51
|
+
it "routes /widgets/foo to the /foo action" do
|
52
|
+
expect(get("/widgets/foo")).to route_to("widgets#foo")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
"""
|
56
|
+
|
57
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
58
|
+
Then the output should contain "1 failure"
|
59
|
+
|
60
|
+
Scenario: route spec for a namespaced route with shortcut specifier
|
61
|
+
Given a file named "spec/routing/admin_routing_spec.rb" with:
|
62
|
+
"""ruby
|
63
|
+
require "spec_helper"
|
64
|
+
|
65
|
+
describe "routes for Widgets" do
|
66
|
+
it "routes /admin/accounts to the admin/accounts controller" do
|
67
|
+
expect(get("/admin/accounts")).
|
68
|
+
to route_to("admin/accounts#index")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
"""
|
72
|
+
|
73
|
+
When I run `rspec spec/routing/admin_routing_spec.rb`
|
74
|
+
Then the examples should all pass
|
75
|
+
|
76
|
+
Scenario: route spec for a namespaced route with verbose specifier
|
77
|
+
Given a file named "spec/routing/admin_routing_spec.rb" with:
|
78
|
+
"""ruby
|
79
|
+
require "spec_helper"
|
80
|
+
|
81
|
+
describe "routes for Widgets" do
|
82
|
+
it "routes /admin/accounts to the admin/accounts controller" do
|
83
|
+
expect(get("/admin/accounts")).
|
84
|
+
to route_to(:controller => "admin/accounts", :action => "index")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
"""
|
88
|
+
|
89
|
+
When I run `rspec spec/routing/admin_routing_spec.rb`
|
90
|
+
Then the examples should all pass
|