rspec-rails 2.0.0.beta.22 → 2.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +10 -4
- data/.rspec +1 -0
- data/.travis.yml +10 -0
- data/History.md +1 -33
- data/License.txt +23 -0
- data/{README.markdown → README.md} +27 -7
- data/README_DEV.md +43 -0
- data/Rakefile +105 -35
- data/Thorfile +40 -0
- data/Upgrade.md +1 -0
- data/features/.nav +34 -0
- data/features/Autotest.md +24 -0
- data/features/Changelog.md +151 -0
- data/features/Generators.md +8 -0
- data/features/GettingStarted.md +84 -0
- data/features/README.md +58 -0
- data/features/Upgrade.md +117 -0
- data/features/controller_specs/README.md +45 -0
- data/features/controller_specs/anonymous_controller.feature +7 -7
- data/features/controller_specs/controller_spec.feature +18 -0
- data/features/controller_specs/isolation_from_views.feature +55 -8
- data/features/controller_specs/render_views.feature +63 -52
- data/features/helper_specs/helper_spec.feature +40 -6
- data/features/mailer_specs/url_helpers.feature +4 -4
- data/features/matchers/README.md +4 -0
- data/features/matchers/new_record_matcher.feature +6 -48
- data/features/matchers/redirect_to_matcher.feature +5 -6
- data/features/matchers/render_template_matcher.feature +13 -10
- data/features/mocks/mock_model.feature +29 -13
- data/features/mocks/stub_model.feature +4 -4
- data/features/model_specs/README.md +21 -0
- data/features/model_specs/errors_on.feature +2 -2
- data/features/model_specs/transactional_examples.feature +14 -9
- data/features/request_specs/request_spec.feature +49 -0
- data/features/routing_specs/README.md +17 -0
- data/features/{matchers → routing_specs}/be_routable_matcher.feature +25 -25
- data/features/routing_specs/named_routes.feature +18 -0
- data/features/routing_specs/route_to_matcher.feature +58 -0
- data/features/step_definitions/additional_cli_steps.rb +4 -0
- data/features/support/env.rb +14 -6
- data/features/view_specs/inferred_controller_path.feature +6 -6
- data/features/view_specs/stub_template.feature +51 -0
- data/features/view_specs/view_spec.feature +23 -42
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/base.rb +58 -0
- data/gemfiles/rails-3-0-stable +6 -0
- data/gemfiles/rails-3.0.0 +5 -0
- data/gemfiles/rails-3.0.1 +5 -0
- data/gemfiles/rails-3.0.2 +5 -0
- data/gemfiles/rails-3.0.3 +5 -0
- data/gemfiles/rails-3.0.4 +5 -0
- data/gemfiles/rails-3.0.5 +5 -0
- data/gemfiles/rails-3.0.6 +5 -0
- data/gemfiles/rails-3.0.7 +5 -0
- data/gemfiles/rails-3.1.0.beta1 +5 -0
- data/gemfiles/rails-master +7 -0
- data/lib/autotest/rails_rspec2.rb +1 -1
- data/lib/generators/rspec/controller/controller_generator.rb +4 -4
- data/lib/generators/rspec/helper/helper_generator.rb +3 -3
- data/lib/generators/rspec/install/install_generator.rb +0 -8
- data/lib/generators/rspec/integration/integration_generator.rb +15 -1
- data/lib/generators/rspec/integration/templates/request_spec.rb +7 -1
- data/lib/generators/rspec/mailer/mailer_generator.rb +2 -2
- data/lib/generators/rspec/model/model_generator.rb +1 -1
- data/lib/generators/rspec/observer/observer_generator.rb +1 -1
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +40 -11
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +90 -58
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +15 -7
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +7 -2
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +14 -7
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +14 -14
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +7 -2
- data/lib/generators/rspec/view/view_generator.rb +1 -1
- data/lib/rspec/rails/example/controller_example_group.rb +25 -34
- data/lib/rspec/rails/example/helper_example_group.rb +5 -11
- data/lib/rspec/rails/example/mailer_example_group.rb +0 -14
- data/lib/rspec/rails/example/model_example_group.rb +0 -4
- data/lib/rspec/rails/example/rails_example_group.rb +0 -2
- data/lib/rspec/rails/example/request_example_group.rb +5 -30
- data/lib/rspec/rails/example/routing_example_group.rb +3 -5
- data/lib/rspec/rails/example/view_example_group.rb +20 -11
- data/lib/rspec/rails/example.rb +31 -1
- data/lib/rspec/rails/extensions/active_record/base.rb +28 -32
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +5 -0
- data/lib/rspec/rails/matchers/redirect_to.rb +6 -2
- data/lib/rspec/rails/matchers/render_template.rb +5 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +24 -3
- data/lib/rspec/rails/matchers.rb +1 -1
- data/lib/rspec/rails/mocks.rb +118 -79
- data/lib/rspec/rails/module_inclusion.rb +17 -0
- data/lib/rspec/rails/tasks/rspec.rake +1 -1
- data/lib/rspec/rails/vendor/capybara.rb +29 -0
- data/lib/rspec/rails/vendor/webrat.rb +33 -0
- data/lib/rspec/rails/version.rb +1 -1
- data/lib/rspec/rails/view_assigns.rb +23 -4
- data/lib/rspec/rails/view_rendering.rb +50 -13
- data/lib/rspec/rails.rb +7 -10
- data/lib/rspec-rails.rb +4 -2
- data/rspec-rails.gemspec +11 -39
- data/spec/autotest/rails_rspec2_spec.rb +25 -14
- 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 +47 -5
- data/spec/rspec/rails/example/helper_example_group_spec.rb +19 -1
- data/spec/rspec/rails/example/request_example_group_spec.rb +2 -0
- data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +23 -0
- data/spec/rspec/rails/extensions/active_record/records_spec.rb +9 -0
- data/spec/rspec/rails/matchers/be_new_record_spec.rb +17 -0
- data/spec/rspec/rails/matchers/be_routable_spec.rb +41 -0
- data/spec/rspec/rails/matchers/redirect_to_spec.rb +67 -8
- data/spec/rspec/rails/matchers/render_template_spec.rb +67 -10
- data/spec/rspec/rails/matchers/route_to_spec.rb +77 -31
- data/spec/rspec/rails/mocks/ar_classes.rb +17 -25
- data/spec/rspec/rails/mocks/mock_model_spec.rb +50 -13
- data/spec/rspec/rails/mocks/stub_model_spec.rb +121 -67
- data/spec/rspec/rails/view_rendering_spec.rb +105 -0
- data/spec/spec_helper.rb +0 -22
- data/spec/support/matchers.rb +9 -0
- data/templates/generate_stuff.rb +10 -2
- data/templates/run_specs.rb +2 -2
- metadata +141 -79
- data/Gemfile +0 -24
- data/Gotchas.markdown +0 -14
- data/Upgrade.markdown +0 -31
- data/autotest/discover.rb +0 -1
- data/features/README.markdown +0 -12
- data/features/controller_specs/readers.feature +0 -18
- data/features/routing_specs/access_to_named_routes.feature +0 -15
- data/lib/generators/rspec/install/templates/autotest/discover.rb +0 -2
- data/lib/rspec/rails/browser_simulators.rb +0 -30
- data/spec/rspec/rails/example/view_rendering_spec.rb +0 -110
- data/specs.watchr +0 -59
- data/templates/Gemfile +0 -18
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Feature: be_a_new matcher
|
|
2
2
|
|
|
3
|
-
The be_a_new matcher accepts a class and passes if the subject is an
|
|
4
|
-
of that class that returns
|
|
3
|
+
The `be_a_new` matcher accepts a class and passes if the subject is an
|
|
4
|
+
instance of that class that returns false to persisted?
|
|
5
5
|
|
|
6
|
-
You can also
|
|
7
|
-
subject has equal attributes.
|
|
6
|
+
You can also chain `with` on `be_a_new` with a hash of attributes to specify
|
|
7
|
+
the subject has equal attributes.
|
|
8
8
|
|
|
9
9
|
Scenario: example spec with four be_a_new possibilities
|
|
10
10
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -24,47 +24,5 @@ Feature: be_a_new matcher
|
|
|
24
24
|
end
|
|
25
25
|
end
|
|
26
26
|
"""
|
|
27
|
-
When I run
|
|
28
|
-
Then the
|
|
29
|
-
|
|
30
|
-
Scenario: example spec using be_a_new.with
|
|
31
|
-
Given a file named "spec/models/widget_spec.rb" with:
|
|
32
|
-
"""
|
|
33
|
-
require "spec_helper"
|
|
34
|
-
|
|
35
|
-
class Widget < ActiveRecord::Base
|
|
36
|
-
establish_connection :adapter => 'sqlite3',
|
|
37
|
-
:database => ':memory:'
|
|
38
|
-
|
|
39
|
-
connection.execute <<-eosql
|
|
40
|
-
CREATE TABLE widgets (
|
|
41
|
-
foo_id integer,
|
|
42
|
-
number integer
|
|
43
|
-
)
|
|
44
|
-
eosql
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe Widget do
|
|
48
|
-
context "when initialized with attributes" do
|
|
49
|
-
subject { Widget.new(:foo_id => 1, :number => 1) }
|
|
50
|
-
|
|
51
|
-
it "has all of the attributes" do
|
|
52
|
-
should be_a_new(Widget).with(:foo_id => 1, :number => 1)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
it "has one of the attributes" do
|
|
56
|
-
should be_a_new(Widget).with(:foo_id => 1)
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "has none of the attributes" do
|
|
60
|
-
should_not be_a_new(Widget).with(:blah => 'blah')
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
it "has one of the attribute values not the same" do
|
|
64
|
-
should_not be_a_new(Widget).with(:foo_id => 2)
|
|
65
|
-
end
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
"""
|
|
69
|
-
When I run "rspec spec/models/widget_spec.rb"
|
|
70
|
-
Then the output should contain "4 examples, 0 failures"
|
|
27
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
28
|
+
Then the examples should all pass
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
Feature: redirect_to matcher
|
|
2
2
|
|
|
3
|
-
The redirect_to matcher is used to specify that
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
the Rails documentation on this method.
|
|
3
|
+
The `redirect_to` matcher is used to specify that a request redirects to a
|
|
4
|
+
given template or action. It delegates to
|
|
5
|
+
[`assert_redirected_to`](http://api.rubyonrails.org/classes/ActionDispatch/Assertions/ResponseAssertions.html#method-i-assert_redirected_to).
|
|
7
6
|
|
|
8
7
|
It is available in controller specs (spec/controllers) and request
|
|
9
8
|
specs (spec/requests).
|
|
@@ -37,5 +36,5 @@ Feature: redirect_to matcher
|
|
|
37
36
|
end
|
|
38
37
|
end
|
|
39
38
|
"""
|
|
40
|
-
When I run
|
|
41
|
-
Then the
|
|
39
|
+
When I run `rspec spec/controllers/widgets_controller_spec.rb`
|
|
40
|
+
Then the examples should all pass
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
Feature: render_template matcher
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The `render_template` matcher is used to specify that a request renders a
|
|
4
|
+
given template. It delegates to
|
|
5
|
+
[`assert_template`](http://api.rubyonrails.org/classes/ActionController/TemplateAssertions.html#method-i-assert_template)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
It is available in controller specs (spec/controllers) and request
|
|
8
|
+
specs (spec/requests).
|
|
9
|
+
|
|
10
|
+
NOTE: use `redirect_to(:action => 'new')` for redirects, not `render_template`.
|
|
8
11
|
|
|
9
12
|
Scenario: render_template with three possible options
|
|
10
13
|
Given a file named "spec/controllers/gadgets_spec.rb" with:
|
|
@@ -12,14 +15,14 @@ Feature: render_template matcher
|
|
|
12
15
|
require "spec_helper"
|
|
13
16
|
|
|
14
17
|
describe GadgetsController do
|
|
15
|
-
describe "#index" do
|
|
18
|
+
describe "GET #index" do
|
|
16
19
|
subject { get :index }
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
it { should render_template(:index) }
|
|
22
|
+
it { should render_template("index") }
|
|
23
|
+
it { should render_template("gadgets/index") }
|
|
21
24
|
end
|
|
22
25
|
end
|
|
23
26
|
"""
|
|
24
|
-
When I run
|
|
25
|
-
Then the
|
|
27
|
+
When I run `rspec spec/controllers/gadgets_spec.rb`
|
|
28
|
+
Then the examples should all pass
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
Feature: mock_model
|
|
2
2
|
|
|
3
|
-
The mock_model method generates a test double
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
The mock_model method generates a test double that acts like an Active Model
|
|
4
|
+
model. This is different from the stub_model method which generates an
|
|
5
|
+
instance of a real ActiveModel class.
|
|
6
6
|
|
|
7
7
|
The benefit of mock_model over stub_model is that its a true double, so the
|
|
8
8
|
examples are not dependent on the behaviour (or mis-behaviour), or even the
|
|
@@ -36,8 +36,8 @@ Feature: mock_model
|
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
"""
|
|
39
|
-
When I run
|
|
40
|
-
Then the
|
|
39
|
+
When I run `rspec spec/models/car_spec.rb`
|
|
40
|
+
Then the examples should all pass
|
|
41
41
|
|
|
42
42
|
Scenario: passing a string that represents an existing constant
|
|
43
43
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -51,8 +51,8 @@ Feature: mock_model
|
|
|
51
51
|
end
|
|
52
52
|
end
|
|
53
53
|
"""
|
|
54
|
-
When I run
|
|
55
|
-
Then the
|
|
54
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
55
|
+
Then the examples should all pass
|
|
56
56
|
|
|
57
57
|
Scenario: passing a class that does not extend ActiveModel::Naming
|
|
58
58
|
Given a file named "spec/models/string_spec.rb" with:
|
|
@@ -65,8 +65,8 @@ Feature: mock_model
|
|
|
65
65
|
end
|
|
66
66
|
end
|
|
67
67
|
"""
|
|
68
|
-
When I run
|
|
69
|
-
Then the
|
|
68
|
+
When I run `rspec spec/models/string_spec.rb`
|
|
69
|
+
Then the examples should all pass
|
|
70
70
|
|
|
71
71
|
Scenario: passing an Active Record constant
|
|
72
72
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -94,8 +94,8 @@ Feature: mock_model
|
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
96
|
"""
|
|
97
|
-
When I run
|
|
98
|
-
Then the
|
|
97
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
98
|
+
Then the examples should all pass
|
|
99
99
|
|
|
100
100
|
Scenario: passing an Active Record constant with method stubs
|
|
101
101
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -127,5 +127,21 @@ Feature: mock_model
|
|
|
127
127
|
end
|
|
128
128
|
end
|
|
129
129
|
"""
|
|
130
|
-
When I run
|
|
131
|
-
Then the
|
|
130
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
131
|
+
Then the examples should all pass
|
|
132
|
+
|
|
133
|
+
Scenario: mock_model outside rails
|
|
134
|
+
Given a file named "mock_model_outside_rails_spec.rb" with:
|
|
135
|
+
"""
|
|
136
|
+
require 'rspec/rails/mocks'
|
|
137
|
+
|
|
138
|
+
describe "Foo" do
|
|
139
|
+
it "is mockable" do
|
|
140
|
+
foo = mock_model("Foo")
|
|
141
|
+
foo.id.should eq(1001)
|
|
142
|
+
foo.to_param.should eq("1001")
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
"""
|
|
146
|
+
When I run `rspec mock_model_outside_rails_spec.rb`
|
|
147
|
+
Then the examples should all pass
|
|
@@ -34,8 +34,8 @@ Feature: stub_model
|
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
"""
|
|
37
|
-
When I run
|
|
38
|
-
Then the
|
|
37
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
38
|
+
Then the examples should all pass
|
|
39
39
|
|
|
40
40
|
Scenario: passing an Active Record constant with a block of stubs
|
|
41
41
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -54,5 +54,5 @@ Feature: stub_model
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
"""
|
|
57
|
-
When I run
|
|
58
|
-
Then the
|
|
57
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
58
|
+
Then the examples should all pass
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Model specs live in `spec/models` or any example group with
|
|
2
|
+
`:type => :model`.
|
|
3
|
+
|
|
4
|
+
A model spec is a thin wrapper for an ActiveSupport::TestCase, and includes all
|
|
5
|
+
of the behavior and assertions that it provides, in addition to RSpec's own
|
|
6
|
+
behavior and expectations.
|
|
7
|
+
|
|
8
|
+
## Examples
|
|
9
|
+
|
|
10
|
+
require "spec_helper"
|
|
11
|
+
|
|
12
|
+
describe Post do
|
|
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])
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
Feature: transactional examples
|
|
2
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
|
+
|
|
3
8
|
Scenario: run in transactions (default)
|
|
4
9
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
5
10
|
"""
|
|
@@ -20,8 +25,8 @@ Feature: transactional examples
|
|
|
20
25
|
end
|
|
21
26
|
end
|
|
22
27
|
"""
|
|
23
|
-
When I run
|
|
24
|
-
Then the
|
|
28
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
29
|
+
Then the examples should all pass
|
|
25
30
|
|
|
26
31
|
Scenario: run in transactions (explicit)
|
|
27
32
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -47,8 +52,8 @@ Feature: transactional examples
|
|
|
47
52
|
end
|
|
48
53
|
end
|
|
49
54
|
"""
|
|
50
|
-
When I run
|
|
51
|
-
Then the
|
|
55
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
56
|
+
Then the examples should all pass
|
|
52
57
|
|
|
53
58
|
Scenario: disable transactions (explicit)
|
|
54
59
|
Given a file named "spec/models/widget_spec.rb" with:
|
|
@@ -76,15 +81,15 @@ Feature: transactional examples
|
|
|
76
81
|
after(:all) { Widget.destroy_all }
|
|
77
82
|
end
|
|
78
83
|
"""
|
|
79
|
-
When I run
|
|
80
|
-
Then the
|
|
84
|
+
When I run `rspec spec/models/widget_spec.rb`
|
|
85
|
+
Then the examples should all pass
|
|
81
86
|
|
|
82
87
|
Scenario: run in transactions with fixture
|
|
83
88
|
Given a file named "spec/models/thing_spec.rb" with:
|
|
84
89
|
"""
|
|
85
90
|
require "spec_helper"
|
|
86
91
|
|
|
87
|
-
describe Thing do
|
|
92
|
+
describe Thing do
|
|
88
93
|
fixtures :things
|
|
89
94
|
it "fixture method defined" do
|
|
90
95
|
things(:one)
|
|
@@ -96,8 +101,8 @@ Feature: transactional examples
|
|
|
96
101
|
one:
|
|
97
102
|
name: MyString
|
|
98
103
|
"""
|
|
99
|
-
When I run
|
|
100
|
-
Then the
|
|
104
|
+
When I run `rspec spec/models/thing_spec.rb`
|
|
105
|
+
Then the examples should all pass
|
|
101
106
|
|
|
102
107
|
|
|
103
108
|
|
|
@@ -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
|
+
If you would like to use webrat or capybara with your request specs, all you
|
|
23
|
+
have to do is include one of them in your Gemfile and RSpec will
|
|
24
|
+
automatically load them in a request 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
|
+
"""
|
|
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
|
+
response.should render_template(:new)
|
|
36
|
+
|
|
37
|
+
post "/widgets", :widget => {:name => "My Widget"}
|
|
38
|
+
|
|
39
|
+
response.should redirect_to(assigns(:widget))
|
|
40
|
+
follow_redirect!
|
|
41
|
+
|
|
42
|
+
response.should render_template(:show)
|
|
43
|
+
response.body.should 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,17 @@
|
|
|
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
|
+
{ :get => "/articles/2012/11/when-to-use-routing-specs" }.
|
|
9
|
+
should route_to(
|
|
10
|
+
:controller => "articles",
|
|
11
|
+
:month => "2012-11",
|
|
12
|
+
:slug => "when-to-use-routing-specs"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
They are also valuable for routes that should not be available:
|
|
16
|
+
|
|
17
|
+
{ :delete => "/accounts/37" }.should_not be_routable
|
|
@@ -1,67 +1,67 @@
|
|
|
1
1
|
Feature: be_routable matcher
|
|
2
2
|
|
|
3
|
-
The be_routable matcher is
|
|
4
|
-
given route
|
|
5
|
-
spec/routing) and controller specs (in spec/
|
|
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
6
|
|
|
7
|
-
Scenario: specify routeable route should be routable (
|
|
7
|
+
Scenario: specify routeable route should not be routable (fails)
|
|
8
8
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
|
9
9
|
"""
|
|
10
10
|
require "spec_helper"
|
|
11
11
|
|
|
12
|
-
describe
|
|
13
|
-
it "
|
|
14
|
-
{ :get => "/widgets" }.
|
|
12
|
+
describe "routes for Widgets" do
|
|
13
|
+
it "does not route to widgets" do
|
|
14
|
+
{ :get => "/widgets" }.should_not be_routable
|
|
15
15
|
end
|
|
16
16
|
end
|
|
17
17
|
"""
|
|
18
18
|
|
|
19
|
-
When I run
|
|
20
|
-
Then the output should contain "1 example,
|
|
19
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
|
20
|
+
Then the output should contain "1 example, 1 failure"
|
|
21
21
|
|
|
22
|
-
Scenario: specify routeable route should not be routable (
|
|
22
|
+
Scenario: specify non-routeable route should not be routable (passes)
|
|
23
23
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
|
24
24
|
"""
|
|
25
25
|
require "spec_helper"
|
|
26
26
|
|
|
27
|
-
describe
|
|
28
|
-
it "does not route to widgets" do
|
|
29
|
-
{ :get => "/widgets" }.should_not be_routable
|
|
27
|
+
describe "routes for Widgets" do
|
|
28
|
+
it "does not route to widgets/foo/bar" do
|
|
29
|
+
{ :get => "/widgets/foo/bar" }.should_not be_routable
|
|
30
30
|
end
|
|
31
31
|
end
|
|
32
32
|
"""
|
|
33
33
|
|
|
34
|
-
When I run
|
|
35
|
-
Then the
|
|
34
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
|
35
|
+
Then the examples should all pass
|
|
36
36
|
|
|
37
|
-
Scenario: specify
|
|
37
|
+
Scenario: specify routeable route should be routable (passes)
|
|
38
38
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
|
39
39
|
"""
|
|
40
40
|
require "spec_helper"
|
|
41
41
|
|
|
42
|
-
describe
|
|
43
|
-
it "
|
|
44
|
-
{ :get => "/widgets
|
|
42
|
+
describe "routes for Widgets" do
|
|
43
|
+
it "routes to /widgets" do
|
|
44
|
+
{ :get => "/widgets" }.should be_routable
|
|
45
45
|
end
|
|
46
46
|
end
|
|
47
47
|
"""
|
|
48
48
|
|
|
49
|
-
When I run
|
|
50
|
-
Then the
|
|
49
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
|
50
|
+
Then the examples should all pass
|
|
51
51
|
|
|
52
52
|
Scenario: specify non-routeable route should be routable (fails)
|
|
53
53
|
Given a file named "spec/routing/widgets_routing_spec.rb" with:
|
|
54
54
|
"""
|
|
55
55
|
require "spec_helper"
|
|
56
56
|
|
|
57
|
-
describe
|
|
57
|
+
describe "routes for Widgets" do
|
|
58
58
|
it "routes to widgets/foo/bar" do
|
|
59
59
|
{ :get => "/widgets/foo/bar" }.should be_routable
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
"""
|
|
63
63
|
|
|
64
|
-
When I run
|
|
64
|
+
When I run `rspec spec/routing/widgets_routing_spec.rb`
|
|
65
65
|
Then the output should contain "1 example, 1 failure"
|
|
66
66
|
|
|
67
67
|
Scenario: be_routable in a controller spec
|
|
@@ -76,5 +76,5 @@ Feature: be_routable matcher
|
|
|
76
76
|
end
|
|
77
77
|
"""
|
|
78
78
|
|
|
79
|
-
When I run
|
|
80
|
-
Then the
|
|
79
|
+
When I run `rspec spec/controllers/widgets_controller_spec.rb`
|
|
80
|
+
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
|
+
"""
|
|
8
|
+
require "spec_helper"
|
|
9
|
+
|
|
10
|
+
describe "routes to the widgets controller" do
|
|
11
|
+
it "routes a named route" do
|
|
12
|
+
{:get => new_widget_path}.
|
|
13
|
+
should 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,58 @@
|
|
|
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
|
+
get("/").should route_to("welcome#index") # new in 2.6.0
|
|
8
|
+
|
|
9
|
+
or
|
|
10
|
+
|
|
11
|
+
{ :get => "/" }.should 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
|
+
"""
|
|
16
|
+
require "spec_helper"
|
|
17
|
+
|
|
18
|
+
describe "routes for Widgets" do
|
|
19
|
+
it "routes /widgets to the widgets controller" do
|
|
20
|
+
get("/widgets").
|
|
21
|
+
should 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
|
+
"""
|
|
32
|
+
require "spec_helper"
|
|
33
|
+
|
|
34
|
+
describe "routes for Widgets" do
|
|
35
|
+
it "routes /widgets to the widgets controller" do
|
|
36
|
+
{ :get => "/widgets" }.
|
|
37
|
+
should 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
|
+
"""
|
|
48
|
+
require "spec_helper"
|
|
49
|
+
|
|
50
|
+
describe "routes for Widgets" do
|
|
51
|
+
it "routes /widgets/foo to the /foo action" do
|
|
52
|
+
get("/widgets/foo").should 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"
|
data/features/support/env.rb
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
require 'aruba'
|
|
2
|
-
|
|
1
|
+
require 'aruba/cucumber'
|
|
2
|
+
|
|
3
|
+
module ArubaExt
|
|
4
|
+
def run(cmd)
|
|
5
|
+
super(cmd =~ /^rspec/ ? "bundle exec #{cmd}" : cmd)
|
|
6
|
+
end
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
World(ArubaExt)
|
|
10
|
+
|
|
11
|
+
Before do
|
|
12
|
+
@aruba_timeout_seconds = 10
|
|
13
|
+
end
|
|
3
14
|
|
|
4
15
|
unless File.directory?('./tmp/example_app')
|
|
5
16
|
system "rake generate:app generate:stuff"
|
|
@@ -31,9 +42,7 @@ Before do
|
|
|
31
42
|
}
|
|
32
43
|
|
|
33
44
|
Dir['tmp/example_app/*'].each do |file_or_dir|
|
|
34
|
-
if file_or_dir =~ /
|
|
35
|
-
copy(file_or_dir)
|
|
36
|
-
elsif !(file_or_dir =~ /spec$/)
|
|
45
|
+
if !(file_or_dir =~ /spec$/)
|
|
37
46
|
write_symlink(file_or_dir)
|
|
38
47
|
end
|
|
39
48
|
end
|
|
@@ -41,5 +50,4 @@ Before do
|
|
|
41
50
|
["spec/spec_helper.rb"].each do |file_or_dir|
|
|
42
51
|
write_symlink("tmp/example_app/#{file_or_dir}")
|
|
43
52
|
end
|
|
44
|
-
|
|
45
53
|
end
|
|
@@ -11,8 +11,8 @@ Feature: view spec infers controller path and action
|
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
"""
|
|
14
|
-
When I run
|
|
15
|
-
Then the
|
|
14
|
+
When I run `rspec spec/views`
|
|
15
|
+
Then the examples should all pass
|
|
16
16
|
|
|
17
17
|
Scenario: infer action
|
|
18
18
|
Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
|
|
@@ -25,8 +25,8 @@ Feature: view spec infers controller path and action
|
|
|
25
25
|
end
|
|
26
26
|
end
|
|
27
27
|
"""
|
|
28
|
-
When I run
|
|
29
|
-
Then the
|
|
28
|
+
When I run `rspec spec/views`
|
|
29
|
+
Then the examples should all pass
|
|
30
30
|
|
|
31
31
|
Scenario: do not infer action in a partial
|
|
32
32
|
Given a file named "spec/views/widgets/_form.html.erb_spec.rb" with:
|
|
@@ -39,6 +39,6 @@ Feature: view spec infers controller path and action
|
|
|
39
39
|
end
|
|
40
40
|
end
|
|
41
41
|
"""
|
|
42
|
-
When I run
|
|
43
|
-
Then the
|
|
42
|
+
When I run `rspec spec/views`
|
|
43
|
+
Then the examples should all pass
|
|
44
44
|
|