rspec-rails 3.0.0.beta2 → 3.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +2 -1
- data/Capybara.md +1 -3
- data/Changelog.md +126 -58
- data/README.md +31 -4
- data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
- data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
- data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
- data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
- data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
- data/lib/rspec/rails.rb +1 -8
- data/lib/rspec/rails/configuration.rb +72 -0
- data/lib/rspec/rails/example.rb +0 -64
- data/lib/rspec/rails/example/controller_example_group.rb +16 -12
- data/lib/rspec/rails/example/feature_example_group.rb +0 -2
- data/lib/rspec/rails/example/helper_example_group.rb +0 -2
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/request_example_group.rb +0 -2
- data/lib/rspec/rails/example/routing_example_group.rb +0 -2
- data/lib/rspec/rails/example/view_example_group.rb +1 -2
- data/lib/rspec/rails/extensions.rb +0 -1
- data/lib/rspec/rails/fixture_support.rb +0 -8
- data/lib/rspec/rails/matchers.rb +1 -0
- data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
- data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
- data/lib/rspec/rails/tasks/rspec.rake +12 -5
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_rendering.rb +6 -34
- metadata +42 -316
- metadata.gz.sig +0 -0
- data/features/Generators.md +0 -25
- data/features/GettingStarted.md +0 -84
- data/features/README.md +0 -48
- data/features/RailsVersions.md +0 -4
- data/features/Transactions.md +0 -84
- data/features/Upgrade.md +0 -121
- data/features/controller_specs/Cookies.md +0 -57
- data/features/controller_specs/README.md +0 -45
- data/features/controller_specs/anonymous_controller.feature +0 -436
- data/features/controller_specs/bypass_rescue.feature +0 -75
- data/features/controller_specs/controller_spec.feature +0 -58
- data/features/controller_specs/engine_routes.feature +0 -51
- data/features/controller_specs/isolation_from_views.feature +0 -87
- data/features/controller_specs/render_views.feature +0 -114
- data/features/directory_structure.feature +0 -71
- data/features/feature_specs/feature_spec.feature +0 -35
- data/features/helper_specs/helper_spec.feature +0 -122
- data/features/mailer_specs/url_helpers.feature +0 -38
- data/features/matchers/README.md +0 -18
- data/features/matchers/new_record_matcher.feature +0 -41
- data/features/matchers/redirect_to_matcher.feature +0 -40
- data/features/matchers/relation_match_array.feature +0 -27
- data/features/matchers/render_template_matcher.feature +0 -49
- data/features/mocks/mock_model.feature +0 -147
- data/features/mocks/stub_model.feature +0 -58
- data/features/model_specs/README.md +0 -21
- data/features/model_specs/errors_on.feature +0 -51
- data/features/model_specs/records.feature +0 -27
- data/features/model_specs/transactional_examples.feature +0 -109
- data/features/request_specs/request_spec.feature +0 -49
- data/features/routing_specs/README.md +0 -16
- data/features/routing_specs/be_routable_matcher.feature +0 -80
- data/features/routing_specs/engine_routes.feature +0 -38
- data/features/routing_specs/named_routes.feature +0 -18
- data/features/routing_specs/route_to_matcher.feature +0 -90
- data/features/step_definitions/additional_cli_steps.rb +0 -4
- data/features/step_definitions/model_steps.rb +0 -3
- data/features/support/capybara.rb +0 -7
- data/features/support/env.rb +0 -53
- data/features/support/rails_versions.rb +0 -4
- data/features/support/rubinius.rb +0 -6
- data/features/view_specs/inferred_controller_path.feature +0 -45
- data/features/view_specs/stub_template.feature +0 -51
- data/features/view_specs/view_spec.feature +0 -206
- data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
- data/lib/rspec/rails/mocks.rb +0 -272
- data/lib/rspec/rails/vendor/webrat.rb +0 -33
- data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
- data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
- data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
- data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
- data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
- data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
- data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
- data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
- data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
- data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
- data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
- data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
- data/spec/rspec/rails/configuration_spec.rb +0 -26
- data/spec/rspec/rails/deprecations_spec.rb +0 -18
- data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
- data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
- data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
- data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
- data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
- data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
- data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
- data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
- data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
- data/spec/rspec/rails/fixture_support_spec.rb +0 -17
- data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
- data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
- data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
- data/spec/rspec/rails/matchers/has_spec.rb +0 -29
- data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
- data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
- data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
- data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
- data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
- data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
- data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
- data/spec/rspec/rails/view_rendering_spec.rb +0 -111
- data/spec/spec_helper.rb +0 -33
- data/spec/support/ar_classes.rb +0 -42
- data/spec/support/helpers.rb +0 -34
- data/spec/support/matchers.rb +0 -9
- data/spec/support/null_object.rb +0 -6
@@ -1,51 +0,0 @@
|
|
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
|
@@ -1,27 +0,0 @@
|
|
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
|
@@ -1,109 +0,0 @@
|
|
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 = "defined"
|
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
|
-
|
@@ -1,49 +0,0 @@
|
|
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
|
@@ -1,16 +0,0 @@
|
|
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
|
@@ -1,80 +0,0 @@
|
|
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
|
@@ -1,38 +0,0 @@
|
|
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
|
@@ -1,18 +0,0 @@
|
|
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
|
@@ -1,90 +0,0 @@
|
|
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
|