rspec-rails 2.99.0 → 3.0.0.beta1
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 +8 -8
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +40 -68
- data/License.txt +1 -0
- data/README.md +6 -4
- 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/directory_structure.feature +71 -0
- data/features/feature_specs/feature_spec.feature +35 -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/capybara.rb +7 -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/generators/rspec/controller/templates/controller_spec.rb +1 -1
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +2 -21
- data/lib/generators/rspec/integration/integration_generator.rb +2 -3
- data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
- data/lib/generators/rspec/mailer/templates/mailer_spec.rb +4 -4
- data/lib/generators/rspec/scaffold/scaffold_generator.rb +2 -3
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +16 -16
- data/lib/generators/rspec/scaffold/templates/edit_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/index_spec.rb +1 -1
- data/lib/generators/rspec/scaffold/templates/new_spec.rb +2 -2
- data/lib/generators/rspec/scaffold/templates/routing_spec.rb +7 -7
- data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
- data/lib/rspec/rails.rb +0 -5
- data/lib/rspec/rails/adapters.rb +5 -12
- data/lib/rspec/rails/example.rb +55 -24
- data/lib/rspec/rails/example/controller_example_group.rb +7 -31
- data/lib/rspec/rails/example/view_example_group.rb +0 -3
- data/lib/rspec/rails/matchers.rb +1 -2
- data/lib/rspec/rails/matchers/be_a_new.rb +1 -1
- data/lib/rspec/rails/matchers/be_new_record.rb +1 -1
- data/lib/rspec/rails/matchers/be_valid.rb +1 -1
- data/lib/rspec/rails/matchers/have_rendered.rb +1 -1
- data/lib/rspec/rails/matchers/redirect_to.rb +1 -1
- data/lib/rspec/rails/matchers/relation_match_array.rb +1 -1
- data/lib/rspec/rails/matchers/routing_matchers.rb +6 -10
- data/lib/rspec/rails/mocks.rb +5 -41
- data/lib/rspec/rails/tasks/rspec.rake +5 -12
- data/lib/rspec/rails/vendor/capybara.rb +4 -35
- data/lib/rspec/rails/version.rb +1 -1
- 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/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 +35 -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 +229 -42
- metadata.gz.sig +0 -0
- data/lib/autotest/rails_rspec2.rb +0 -91
- data/lib/rspec/rails/infer_type_configuration.rb +0 -26
- data/lib/rspec/rails/matchers/have_extension.rb +0 -36
- data/lib/rspec/rails/module_inclusion.rb +0 -19
@@ -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
|
@@ -0,0 +1,7 @@
|
|
1
|
+
Around "@capybara" do |scenario, block|
|
2
|
+
# We are caught in a weird situation here. rspec-rails supports 1.8.7 and
|
3
|
+
# above, but capybara beyond a certain version only supports 1.9.3 and above.
|
4
|
+
# On 1.8.7 and 1.9.2, we run most of the rspec-rails test suite but leave out
|
5
|
+
# parts that require capybara.
|
6
|
+
block.call if defined?(::Capybara)
|
7
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'aruba/cucumber'
|
2
|
+
|
3
|
+
module ArubaExt
|
4
|
+
def run(cmd)
|
5
|
+
super(cmd =~ /^rspec/ ? "bin/#{cmd}" : cmd)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
World(ArubaExt)
|
10
|
+
|
11
|
+
Before do
|
12
|
+
@aruba_timeout_seconds = 30
|
13
|
+
end
|
14
|
+
|
15
|
+
unless File.directory?('./tmp/example_app')
|
16
|
+
system "rake generate:app generate:stuff"
|
17
|
+
end
|
18
|
+
|
19
|
+
def aruba_path(file_or_dir)
|
20
|
+
File.expand_path("../../../#{file_or_dir.sub('example_app','aruba')}", __FILE__)
|
21
|
+
end
|
22
|
+
|
23
|
+
def example_app_path(file_or_dir)
|
24
|
+
File.expand_path("../../../#{file_or_dir}", __FILE__)
|
25
|
+
end
|
26
|
+
|
27
|
+
def write_symlink(file_or_dir)
|
28
|
+
source = example_app_path(file_or_dir)
|
29
|
+
target = aruba_path(file_or_dir)
|
30
|
+
system "ln -s #{source} #{target}"
|
31
|
+
end
|
32
|
+
|
33
|
+
def copy(file_or_dir)
|
34
|
+
source = example_app_path(file_or_dir)
|
35
|
+
target = aruba_path(file_or_dir)
|
36
|
+
system "cp -r #{source} #{target}"
|
37
|
+
end
|
38
|
+
|
39
|
+
Before do
|
40
|
+
steps %Q{
|
41
|
+
Given a directory named "spec"
|
42
|
+
}
|
43
|
+
|
44
|
+
Dir['tmp/example_app/*'].each do |file_or_dir|
|
45
|
+
if !(file_or_dir =~ /spec$/)
|
46
|
+
write_symlink(file_or_dir)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
["spec/spec_helper.rb"].each do |file_or_dir|
|
51
|
+
write_symlink("tmp/example_app/#{file_or_dir}")
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
Feature: view spec infers controller path and action
|
2
|
+
|
3
|
+
Scenario: infer controller path
|
4
|
+
Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
|
5
|
+
"""ruby
|
6
|
+
require "spec_helper"
|
7
|
+
|
8
|
+
describe "widgets/new" do
|
9
|
+
it "infers the controller path" do
|
10
|
+
expect(controller.request.path_parameters[:controller]).to eq("widgets")
|
11
|
+
expect(controller.controller_path).to eq("widgets")
|
12
|
+
end
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
When I run `rspec spec/views`
|
16
|
+
Then the examples should all pass
|
17
|
+
|
18
|
+
Scenario: infer action
|
19
|
+
Given a file named "spec/views/widgets/new.html.erb_spec.rb" with:
|
20
|
+
"""ruby
|
21
|
+
require "spec_helper"
|
22
|
+
|
23
|
+
describe "widgets/new" do
|
24
|
+
it "infers the controller path" do
|
25
|
+
expect(controller.request.path_parameters[:action]).to eq("new")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
"""
|
29
|
+
When I run `rspec spec/views`
|
30
|
+
Then the examples should all pass
|
31
|
+
|
32
|
+
Scenario: do not infer action in a partial
|
33
|
+
Given a file named "spec/views/widgets/_form.html.erb_spec.rb" with:
|
34
|
+
"""ruby
|
35
|
+
require "spec_helper"
|
36
|
+
|
37
|
+
describe "widgets/_form" do
|
38
|
+
it "includes a link to new" do
|
39
|
+
expect(controller.request.path_parameters[:action]).to be_nil
|
40
|
+
end
|
41
|
+
end
|
42
|
+
"""
|
43
|
+
When I run `rspec spec/views`
|
44
|
+
Then the examples should all pass
|
45
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
Feature: stub template
|
2
|
+
|
3
|
+
In order to isolate view specs from the partials rendered by the primary
|
4
|
+
view, rspec-rails (since 2.2) provides the stub_template method.
|
5
|
+
|
6
|
+
Scenario: stub template that does not exist
|
7
|
+
Given a file named "spec/views/gadgets/list.html.erb_spec.rb" with:
|
8
|
+
"""ruby
|
9
|
+
require "spec_helper"
|
10
|
+
|
11
|
+
describe "gadgets/list" do
|
12
|
+
it "renders the gadget partial for each gadget" do
|
13
|
+
assign(:gadgets, [
|
14
|
+
mock_model(Gadget, :id => 1, :name => "First"),
|
15
|
+
mock_model(Gadget, :id => 2, :name => "Second")
|
16
|
+
])
|
17
|
+
stub_template "gadgets/_gadget.html.erb" => "<%= gadget.name %><br/>"
|
18
|
+
render
|
19
|
+
expect(rendered).to match /First/
|
20
|
+
expect(rendered).to match /Second/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
"""
|
24
|
+
|
25
|
+
And a file named "app/views/gadgets/list.html.erb" with:
|
26
|
+
"""
|
27
|
+
<%= render :partial => "gadget", :collection => @gadgets %>
|
28
|
+
"""
|
29
|
+
When I run `rspec spec/views/gadgets/list.html.erb_spec.rb`
|
30
|
+
Then the examples should all pass
|
31
|
+
|
32
|
+
Scenario: stub template that exists
|
33
|
+
Given a file named "spec/views/gadgets/edit.html.erb_spec.rb" with:
|
34
|
+
"""ruby
|
35
|
+
require "spec_helper"
|
36
|
+
|
37
|
+
describe "gadgets/edit" do
|
38
|
+
before(:each) do
|
39
|
+
@gadget = assign(:gadget, stub_model(Gadget))
|
40
|
+
end
|
41
|
+
|
42
|
+
it "renders the form partial" do
|
43
|
+
stub_template "gadgets/_form.html.erb" => "This content"
|
44
|
+
render
|
45
|
+
expect(rendered).to match /This content/
|
46
|
+
end
|
47
|
+
end
|
48
|
+
"""
|
49
|
+
When I run `rspec spec/views/gadgets/edit.html.erb_spec.rb`
|
50
|
+
Then the examples should all pass
|
51
|
+
|
@@ -0,0 +1,206 @@
|
|
1
|
+
Feature: view spec
|
2
|
+
|
3
|
+
View specs live in spec/views and render view templates in isolation.
|
4
|
+
|
5
|
+
Scenario: passing spec that renders the described view file
|
6
|
+
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
7
|
+
"""ruby
|
8
|
+
require "spec_helper"
|
9
|
+
|
10
|
+
describe "widgets/index" do
|
11
|
+
it "displays all the widgets" do
|
12
|
+
assign(:widgets, [
|
13
|
+
stub_model(Widget, :name => "slicer"),
|
14
|
+
stub_model(Widget, :name => "dicer")
|
15
|
+
])
|
16
|
+
|
17
|
+
render
|
18
|
+
|
19
|
+
expect(rendered).to match /slicer/
|
20
|
+
expect(rendered).to match /dicer/
|
21
|
+
end
|
22
|
+
end
|
23
|
+
"""
|
24
|
+
When I run `rspec spec/views`
|
25
|
+
Then the examples should all pass
|
26
|
+
|
27
|
+
Scenario: passing spec with before and nesting
|
28
|
+
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
29
|
+
"""ruby
|
30
|
+
require "spec_helper"
|
31
|
+
|
32
|
+
describe "widgets/index" do
|
33
|
+
|
34
|
+
context "with 2 widgets" do
|
35
|
+
before(:each) do
|
36
|
+
assign(:widgets, [
|
37
|
+
stub_model(Widget, :name => "slicer"),
|
38
|
+
stub_model(Widget, :name => "dicer")
|
39
|
+
])
|
40
|
+
end
|
41
|
+
|
42
|
+
it "displays both widgets" do
|
43
|
+
render
|
44
|
+
|
45
|
+
expect(rendered).to match /slicer/
|
46
|
+
expect(rendered).to match /dicer/
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
"""
|
51
|
+
When I run `rspec spec/views`
|
52
|
+
Then the examples should all pass
|
53
|
+
|
54
|
+
Scenario: passing spec with explicit template rendering
|
55
|
+
Given a file named "spec/views/widgets/widget.html.erb_spec.rb" with:
|
56
|
+
"""ruby
|
57
|
+
require "spec_helper"
|
58
|
+
|
59
|
+
describe "rendering the widget template" do
|
60
|
+
it "displays the widget" do
|
61
|
+
assign(:widget, stub_model(Widget, :name => "slicer"))
|
62
|
+
|
63
|
+
render :template => "widgets/widget.html.erb"
|
64
|
+
|
65
|
+
expect(rendered).to match /slicer/
|
66
|
+
end
|
67
|
+
end
|
68
|
+
"""
|
69
|
+
And a file named "app/views/widgets/widget.html.erb" with:
|
70
|
+
"""
|
71
|
+
<h2><%= @widget.name %></h2>
|
72
|
+
"""
|
73
|
+
When I run `rspec spec/views`
|
74
|
+
Then the examples should all pass
|
75
|
+
|
76
|
+
Scenario: passing spec with a description that includes the format and handler
|
77
|
+
Given a file named "spec/views/widgets/widget.xml.erb_spec.rb" with:
|
78
|
+
"""ruby
|
79
|
+
require "spec_helper"
|
80
|
+
|
81
|
+
describe "widgets/widget.html.erb" do
|
82
|
+
it "renders the HTML template" do
|
83
|
+
render
|
84
|
+
|
85
|
+
expect(rendered).to match /HTML/
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "widgets/widget.xml.erb" do
|
90
|
+
it "renders the XML template" do
|
91
|
+
render
|
92
|
+
|
93
|
+
expect(rendered).to match /XML/
|
94
|
+
end
|
95
|
+
end
|
96
|
+
"""
|
97
|
+
And a file named "app/views/widgets/widget.html.erb" with:
|
98
|
+
"""
|
99
|
+
HTML
|
100
|
+
"""
|
101
|
+
And a file named "app/views/widgets/widget.xml.erb" with:
|
102
|
+
"""
|
103
|
+
XML
|
104
|
+
"""
|
105
|
+
When I run `rspec spec/views`
|
106
|
+
Then the examples should all pass
|
107
|
+
|
108
|
+
Scenario: passing spec with rendering of locals in a partial
|
109
|
+
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
110
|
+
"""ruby
|
111
|
+
require "spec_helper"
|
112
|
+
|
113
|
+
describe "rendering locals in a partial" do
|
114
|
+
it "displays the widget" do
|
115
|
+
widget = stub_model(Widget, :name => "slicer")
|
116
|
+
|
117
|
+
render :partial => "widgets/widget.html.erb", :locals => {:widget => widget}
|
118
|
+
|
119
|
+
expect(rendered).to match /slicer/
|
120
|
+
end
|
121
|
+
end
|
122
|
+
"""
|
123
|
+
And a file named "app/views/widgets/_widget.html.erb" with:
|
124
|
+
"""
|
125
|
+
<h3><%= widget.name %></h3>
|
126
|
+
"""
|
127
|
+
When I run `rspec spec/views`
|
128
|
+
Then the examples should all pass
|
129
|
+
|
130
|
+
Scenario: passing spec with rendering of locals in an implicit partial
|
131
|
+
Given a file named "spec/views/widgets/_widget.html.erb_spec.rb" with:
|
132
|
+
"""ruby
|
133
|
+
require "spec_helper"
|
134
|
+
|
135
|
+
describe "rendering locals in a partial" do
|
136
|
+
it "displays the widget" do
|
137
|
+
widget = stub_model(Widget, :name => "slicer")
|
138
|
+
|
139
|
+
render "widgets/widget", :widget => widget
|
140
|
+
|
141
|
+
expect(rendered).to match /slicer/
|
142
|
+
end
|
143
|
+
end
|
144
|
+
"""
|
145
|
+
And a file named "app/views/widgets/_widget.html.erb" with:
|
146
|
+
"""
|
147
|
+
<h3><%= widget.name %></h3>
|
148
|
+
"""
|
149
|
+
When I run `rspec spec/views`
|
150
|
+
Then the examples should all pass
|
151
|
+
|
152
|
+
Scenario: passing spec with rendering of text
|
153
|
+
Given a file named "spec/views/widgets/direct.html.erb_spec.rb" with:
|
154
|
+
"""ruby
|
155
|
+
require "spec_helper"
|
156
|
+
|
157
|
+
describe "rendering text directly" do
|
158
|
+
it "displays the given text" do
|
159
|
+
|
160
|
+
render :text => "This is directly rendered"
|
161
|
+
|
162
|
+
expect(rendered).to match /directly rendered/
|
163
|
+
end
|
164
|
+
end
|
165
|
+
"""
|
166
|
+
When I run `rspec spec/views`
|
167
|
+
Then the examples should all pass
|
168
|
+
|
169
|
+
Scenario: passing view spec that stubs a helper method
|
170
|
+
Given a file named "app/views/secrets/index.html.erb" with:
|
171
|
+
"""
|
172
|
+
<%- if admin? %>
|
173
|
+
<h1>Secret admin area</h1>
|
174
|
+
<%- end %>
|
175
|
+
"""
|
176
|
+
And a file named "spec/views/secrets/index.html.erb_spec.rb" with:
|
177
|
+
"""ruby
|
178
|
+
require 'spec_helper'
|
179
|
+
|
180
|
+
describe 'secrets/index' do
|
181
|
+
before do
|
182
|
+
view.stub(:admin?).and_return(true)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'checks for admin access' do
|
186
|
+
render
|
187
|
+
expect(rendered).to match /Secret admin area/
|
188
|
+
end
|
189
|
+
end
|
190
|
+
"""
|
191
|
+
When I run `rspec spec/views/secrets`
|
192
|
+
Then the examples should all pass
|
193
|
+
|
194
|
+
Scenario: request.path_parameters should match Rails by using symbols for keys
|
195
|
+
Given a file named "spec/views/widgets/index.html.erb_spec.rb" with:
|
196
|
+
"""ruby
|
197
|
+
require "spec_helper"
|
198
|
+
|
199
|
+
describe "controller.request.path_parameters" do
|
200
|
+
it "matches the Rails environment by using symbols for keys" do
|
201
|
+
[:controller, :action].each { |k| expect(controller.request.path_parameters.keys).to include(k) }
|
202
|
+
end
|
203
|
+
end
|
204
|
+
"""
|
205
|
+
When I run `rspec spec/views`
|
206
|
+
Then the examples should all pass
|