rspec-rails 2.13.1 → 2.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +12 -1
- data/README.md +1 -1
- data/lib/generators/rspec.rb +1 -2
- data/lib/generators/rspec/install/install_generator.rb +0 -2
- data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +1 -1
- data/lib/generators/rspec/scaffold/templates/controller_spec.rb +1 -1
- data/lib/rspec/rails.rb +1 -1
- data/lib/rspec/rails/example/controller_example_group.rb +4 -2
- data/lib/rspec/rails/example/rails_example_group.rb +1 -2
- data/lib/rspec/rails/example/view_example_group.rb +1 -1
- data/lib/rspec/rails/fixture_support.rb +1 -1
- data/lib/rspec/rails/version.rb +1 -1
- metadata +5 -182
- data/features/Autotest.md +0 -24
- data/features/Generators.md +0 -8
- data/features/GettingStarted.md +0 -84
- data/features/README.md +0 -56
- 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 -378
- data/features/controller_specs/bypass_rescue.feature +0 -75
- data/features/controller_specs/controller_spec.feature +0 -35
- 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/feature_specs/feature_spec.feature +0 -34
- 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 -22
- 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/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/env.rb +0 -53
- data/features/support/rails_versions.rb +0 -4
- 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/rails_version.rb +0 -17
- data/spec/autotest/rails_rspec2_spec.rb +0 -36
- data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
- 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 -44
- 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 -100
- data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
- data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -64
- 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 -220
- 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/extensions/active_record/records_spec.rb +0 -9
- 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 -44
- data/spec/rspec/rails/matchers/errors_on_spec.rb +0 -38
- 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 -80
- 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 -22
- data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -379
- data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
- data/spec/rspec/rails/rails_version_spec.rb +0 -29
- 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 -31
- data/spec/support/ar_classes.rb +0 -42
- data/spec/support/helpers.rb +0 -20
- data/spec/support/matchers.rb +0 -9
- data/spec/support/null_object.rb +0 -6
@@ -1,75 +0,0 @@
|
|
1
|
-
Feature: bypass rescue
|
2
|
-
|
3
|
-
Use `bypass_rescue` to bypass both Rails' default handling of errors in
|
4
|
-
controller actions, and any custom handling declared with a `rescue_from`
|
5
|
-
statement.
|
6
|
-
|
7
|
-
This lets you specify details of the exception being raised, regardless of
|
8
|
-
how it might be handled upstream.
|
9
|
-
|
10
|
-
Background:
|
11
|
-
Given a file named "spec/controllers/gadgets_controller_spec_context.rb" with:
|
12
|
-
"""ruby
|
13
|
-
class AccessDenied < StandardError; end
|
14
|
-
|
15
|
-
class ApplicationController < ActionController::Base
|
16
|
-
rescue_from AccessDenied, :with => :access_denied
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
def access_denied
|
21
|
-
redirect_to "/401.html"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
"""
|
25
|
-
|
26
|
-
Scenario: standard exception handling using `rescue_from`
|
27
|
-
Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
|
28
|
-
"""ruby
|
29
|
-
require "spec_helper"
|
30
|
-
|
31
|
-
require 'controllers/gadgets_controller_spec_context'
|
32
|
-
|
33
|
-
describe GadgetsController do
|
34
|
-
before do
|
35
|
-
def controller.index
|
36
|
-
raise AccessDenied
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
describe "index" do
|
41
|
-
it "redirects to the /401.html page" do
|
42
|
-
get :index
|
43
|
-
expect(response).to redirect_to("/401.html")
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
"""
|
48
|
-
When I run `rspec spec/controllers/gadgets_controller_spec.rb`
|
49
|
-
Then the examples should all pass
|
50
|
-
|
51
|
-
Scenario: bypass `rescue_from` handling with `bypass_rescue`
|
52
|
-
Given a file named "spec/controllers/gadgets_controller_spec.rb" with:
|
53
|
-
"""ruby
|
54
|
-
require "spec_helper"
|
55
|
-
|
56
|
-
require 'controllers/gadgets_controller_spec_context'
|
57
|
-
|
58
|
-
describe GadgetsController do
|
59
|
-
before do
|
60
|
-
def controller.index
|
61
|
-
raise AccessDenied
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe "index" do
|
66
|
-
it "raises AccessDenied" do
|
67
|
-
bypass_rescue
|
68
|
-
expect { get :index }.to raise_error(AccessDenied)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
"""
|
73
|
-
When I run `rspec spec/controllers/gadgets_controller_spec.rb`
|
74
|
-
Then the examples should all pass
|
75
|
-
|
@@ -1,35 +0,0 @@
|
|
1
|
-
Feature: controller spec
|
2
|
-
|
3
|
-
Scenario: simple passing example
|
4
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
5
|
-
"""ruby
|
6
|
-
require "spec_helper"
|
7
|
-
|
8
|
-
describe WidgetsController do
|
9
|
-
describe "GET index" do
|
10
|
-
it "has a 200 status code" do
|
11
|
-
get :index
|
12
|
-
expect(response.status).to eq(200)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
"""
|
17
|
-
When I run `rspec spec`
|
18
|
-
Then the example should pass
|
19
|
-
|
20
|
-
Scenario: controller is exposed to global before hooks
|
21
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
22
|
-
"""ruby
|
23
|
-
require "spec_helper"
|
24
|
-
|
25
|
-
RSpec.configure {|c| c.before { expect(controller).not_to be_nil }}
|
26
|
-
|
27
|
-
describe WidgetsController do
|
28
|
-
describe "GET index" do
|
29
|
-
it "doesn't matter" do
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
"""
|
34
|
-
When I run `rspec spec`
|
35
|
-
Then the example should pass
|
@@ -1,51 +0,0 @@
|
|
1
|
-
Feature: engine routes for controllers
|
2
|
-
|
3
|
-
Controller specs can specify the routeset that will be used for the example
|
4
|
-
group. This is most useful when testing Rails engines.
|
5
|
-
|
6
|
-
@unsupported-on-rails-3-0
|
7
|
-
Scenario: specify engine route
|
8
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
9
|
-
"""ruby
|
10
|
-
require "spec_helper"
|
11
|
-
|
12
|
-
# A very simple Rails engine
|
13
|
-
module MyEngine
|
14
|
-
class Engine < ::Rails::Engine
|
15
|
-
isolate_namespace MyEngine
|
16
|
-
end
|
17
|
-
|
18
|
-
Engine.routes.draw do
|
19
|
-
resources :widgets, :only => [:show] do
|
20
|
-
get :random, :on => :collection
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
class WidgetsController < ::ActionController::Base
|
25
|
-
def random
|
26
|
-
@random_widget = Widget.all.shuffle.first
|
27
|
-
redirect_to widget_path(@random_widget)
|
28
|
-
end
|
29
|
-
|
30
|
-
def show
|
31
|
-
@widget = Widget.find(params[:id])
|
32
|
-
render :text => @widget.name
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe MyEngine::WidgetsController do
|
38
|
-
routes { MyEngine::Engine.routes }
|
39
|
-
|
40
|
-
it "redirects to a random widget" do
|
41
|
-
widget1 = Widget.create!(:name => "Widget 1")
|
42
|
-
widget2 = Widget.create!(:name => "Widget 2")
|
43
|
-
|
44
|
-
get :random
|
45
|
-
expect(response).to be_redirect
|
46
|
-
expect(response).to redirect_to(assigns(:random_widget))
|
47
|
-
end
|
48
|
-
end
|
49
|
-
"""
|
50
|
-
When I run `rspec spec`
|
51
|
-
Then the examples should all pass
|
@@ -1,87 +0,0 @@
|
|
1
|
-
Feature: views are stubbed by default
|
2
|
-
|
3
|
-
By default, controller specs stub views with a template that renders an empty
|
4
|
-
string instead of the views in the app. This allows you specify which view
|
5
|
-
template an action should try to render regardless of whether the template
|
6
|
-
compiles cleanly.
|
7
|
-
|
8
|
-
NOTE: unlike rspec-rails-1.x, the real template must exist.
|
9
|
-
|
10
|
-
Scenario: expect template that is rendered by controller action (passes)
|
11
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
12
|
-
"""ruby
|
13
|
-
require "spec_helper"
|
14
|
-
|
15
|
-
describe WidgetsController do
|
16
|
-
describe "index" do
|
17
|
-
it "renders the index template" do
|
18
|
-
get :index
|
19
|
-
expect(response).to render_template("index")
|
20
|
-
expect(response.body).to eq ""
|
21
|
-
end
|
22
|
-
it "renders the widgets/index template" do
|
23
|
-
get :index
|
24
|
-
expect(response).to render_template("widgets/index")
|
25
|
-
expect(response.body).to eq ""
|
26
|
-
end
|
27
|
-
end
|
28
|
-
end
|
29
|
-
"""
|
30
|
-
When I run `rspec spec`
|
31
|
-
Then the examples should all pass
|
32
|
-
|
33
|
-
Scenario: expect template that is not rendered by controller action (fails)
|
34
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
35
|
-
"""ruby
|
36
|
-
require "spec_helper"
|
37
|
-
|
38
|
-
describe WidgetsController do
|
39
|
-
describe "index" do
|
40
|
-
it "renders the 'new' template" do
|
41
|
-
get :index
|
42
|
-
expect(response).to render_template("new")
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
"""
|
47
|
-
When I run `rspec spec`
|
48
|
-
Then the output should contain "1 example, 1 failure"
|
49
|
-
|
50
|
-
Scenario: expect empty templates to render when view path is changed at runtime (passes)
|
51
|
-
Given a file named "spec/controllers/things_controller_spec.rb" with:
|
52
|
-
"""ruby
|
53
|
-
require "spec_helper"
|
54
|
-
|
55
|
-
describe ThingsController do
|
56
|
-
describe "custom_action" do
|
57
|
-
it "renders an empty custom_action template" do
|
58
|
-
controller.prepend_view_path 'app/views'
|
59
|
-
controller.append_view_path 'app/views'
|
60
|
-
get :custom_action
|
61
|
-
expect(response).to render_template("custom_action")
|
62
|
-
expect(response.body).to eq ""
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
"""
|
67
|
-
When I run `rspec spec`
|
68
|
-
Then the examples should all pass
|
69
|
-
|
70
|
-
Scenario: expect template to render the real template with render_views when view path is changed at runtime
|
71
|
-
Given a file named "spec/controllers/things_controller_spec.rb" with:
|
72
|
-
"""ruby
|
73
|
-
require "spec_helper"
|
74
|
-
|
75
|
-
describe ThingsController do
|
76
|
-
render_views
|
77
|
-
|
78
|
-
it "renders the real custom_action template" do
|
79
|
-
controller.prepend_view_path 'app/views'
|
80
|
-
get :custom_action
|
81
|
-
expect(response).to render_template("custom_action")
|
82
|
-
expect(response.body).to match(/template for a custom action/)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
"""
|
86
|
-
When I run `rspec spec`
|
87
|
-
Then the examples should all pass
|
@@ -1,114 +0,0 @@
|
|
1
|
-
Feature: render_views
|
2
|
-
|
3
|
-
You can tell a controller example group to render views with the
|
4
|
-
`render_views` declaration in any individual group, or globally.
|
5
|
-
|
6
|
-
Scenario: render_views directly in a single group
|
7
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
8
|
-
"""ruby
|
9
|
-
require "spec_helper"
|
10
|
-
|
11
|
-
describe WidgetsController do
|
12
|
-
render_views
|
13
|
-
|
14
|
-
describe "GET index" do
|
15
|
-
it "says 'Listing widgets'" do
|
16
|
-
get :index
|
17
|
-
expect(response.body).to match /Listing widgets/m
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
"""
|
22
|
-
When I run `rspec spec`
|
23
|
-
Then the examples should all pass
|
24
|
-
|
25
|
-
Scenario: render_views on and off in nested groups
|
26
|
-
Given a file named "spec/controllers/widgets_controller_spec.rb" with:
|
27
|
-
"""ruby
|
28
|
-
require "spec_helper"
|
29
|
-
|
30
|
-
describe WidgetsController do
|
31
|
-
context "with render_views" do
|
32
|
-
render_views
|
33
|
-
|
34
|
-
describe "GET index" do
|
35
|
-
it "renders the actual template" do
|
36
|
-
get :index
|
37
|
-
expect(response.body).to match /Listing widgets/m
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
context "with render_views(false) nested in a group with render_views" do
|
42
|
-
render_views false
|
43
|
-
|
44
|
-
describe "GET index" do
|
45
|
-
it "renders the RSpec generated template" do
|
46
|
-
get :index
|
47
|
-
expect(response.body).to eq("")
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
context "without render_views" do
|
54
|
-
describe "GET index" do
|
55
|
-
it "renders the RSpec generated template" do
|
56
|
-
get :index
|
57
|
-
expect(response.body).to eq("")
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
context "with render_views again" do
|
63
|
-
render_views
|
64
|
-
|
65
|
-
describe "GET index" do
|
66
|
-
it "renders the actual template" do
|
67
|
-
get :index
|
68
|
-
expect(response.body).to match /Listing widgets/m
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
"""
|
74
|
-
When I run `rspec spec --order default --format documentation`
|
75
|
-
Then the output should contain:
|
76
|
-
"""ruby
|
77
|
-
WidgetsController
|
78
|
-
with render_views
|
79
|
-
GET index
|
80
|
-
renders the actual template
|
81
|
-
with render_views(false) nested in a group with render_views
|
82
|
-
GET index
|
83
|
-
renders the RSpec generated template
|
84
|
-
without render_views
|
85
|
-
GET index
|
86
|
-
renders the RSpec generated template
|
87
|
-
with render_views again
|
88
|
-
GET index
|
89
|
-
renders the actual template
|
90
|
-
"""
|
91
|
-
|
92
|
-
Scenario: render_views globally
|
93
|
-
Given a file named "spec/support/render_views.rb" with:
|
94
|
-
"""ruby
|
95
|
-
RSpec.configure do |config|
|
96
|
-
config.render_views
|
97
|
-
end
|
98
|
-
"""
|
99
|
-
And a file named "spec/controllers/widgets_controller_spec.rb" with:
|
100
|
-
"""ruby
|
101
|
-
require "spec_helper"
|
102
|
-
|
103
|
-
describe WidgetsController do
|
104
|
-
describe "GET index" do
|
105
|
-
it "renders the index template" do
|
106
|
-
get :index
|
107
|
-
expect(response.body).to match /Listing widgets/m
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|
111
|
-
"""
|
112
|
-
When I run `rspec spec`
|
113
|
-
Then the examples should all pass
|
114
|
-
|
@@ -1,34 +0,0 @@
|
|
1
|
-
Feature: feature spec
|
2
|
-
|
3
|
-
Feature specs are high-level tests meant to exercise slices of functionality
|
4
|
-
through an application. They should drive the application only via its
|
5
|
-
external interface, usually web pages.
|
6
|
-
|
7
|
-
Feature specs require the [capybara](http://github.com/jnicklas/capybara)
|
8
|
-
gem, version 2.0.0 or later. Refer to the [capybara API
|
9
|
-
documentation](http://rubydoc.info/github/jnicklas/capybara/master) for more
|
10
|
-
information on the methods and matchers that can be used in feature specs.
|
11
|
-
|
12
|
-
The `feature` and `scenario` DSL correspond to `describe` and `it`,
|
13
|
-
respectively. These methods are simply aliases that allow feature specs to
|
14
|
-
read more as [customer tests](http://c2.com/cgi/wiki?CustomerTest) and
|
15
|
-
[acceptance tests](http://c2.com/cgi/wiki?AcceptanceTest).
|
16
|
-
|
17
|
-
Scenario: specify creating a Widget by driving the application with capybara
|
18
|
-
Given a file named "spec/features/widget_management_spec.rb" with:
|
19
|
-
"""ruby
|
20
|
-
require "spec_helper"
|
21
|
-
|
22
|
-
feature "Widget management" do
|
23
|
-
scenario "User creates a new widget" do
|
24
|
-
visit "/widgets/new"
|
25
|
-
|
26
|
-
fill_in "Name", :with => "My Widget"
|
27
|
-
click_button "Create Widget"
|
28
|
-
|
29
|
-
expect(page).to have_text("Widget was successfully created.")
|
30
|
-
end
|
31
|
-
end
|
32
|
-
"""
|
33
|
-
When I run `rspec spec/features/widget_management_spec.rb`
|
34
|
-
Then the example should pass
|
@@ -1,122 +0,0 @@
|
|
1
|
-
Feature: helper spec
|
2
|
-
|
3
|
-
Helper specs live in `spec/helpers`, or any example group with `:type =>
|
4
|
-
:helper`.
|
5
|
-
|
6
|
-
Helper specs expose a `helper` object, which includes the helper module being
|
7
|
-
specified, the `ApplicationHelper` module (if there is one) and all of the
|
8
|
-
helpers built into Rails. It does not include the other helper modules in
|
9
|
-
your app.
|
10
|
-
|
11
|
-
To access the helper methods you're specifying, simply call them directly
|
12
|
-
on the `helper` object.
|
13
|
-
|
14
|
-
NOTE: helper methods defined in controllers are not included.
|
15
|
-
|
16
|
-
Scenario: helper method that returns a value
|
17
|
-
Given a file named "spec/helpers/application_helper_spec.rb" with:
|
18
|
-
"""ruby
|
19
|
-
require "spec_helper"
|
20
|
-
|
21
|
-
describe ApplicationHelper do
|
22
|
-
describe "#page_title" do
|
23
|
-
it "returns the default title" do
|
24
|
-
expect(helper.page_title).to eq("RSpec is your friend")
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
"""
|
29
|
-
And a file named "app/helpers/application_helper.rb" with:
|
30
|
-
"""ruby
|
31
|
-
module ApplicationHelper
|
32
|
-
def page_title
|
33
|
-
"RSpec is your friend"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
"""
|
37
|
-
When I run `rspec spec/helpers/application_helper_spec.rb`
|
38
|
-
Then the examples should all pass
|
39
|
-
|
40
|
-
Scenario: helper method that accesses an instance variable
|
41
|
-
Given a file named "spec/helpers/application_helper_spec.rb" with:
|
42
|
-
"""ruby
|
43
|
-
require "spec_helper"
|
44
|
-
|
45
|
-
describe ApplicationHelper do
|
46
|
-
describe "#page_title" do
|
47
|
-
it "returns the instance variable" do
|
48
|
-
assign(:title, "My Title")
|
49
|
-
expect(helper.page_title).to eql("My Title")
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
"""
|
54
|
-
And a file named "app/helpers/application_helper.rb" with:
|
55
|
-
"""ruby
|
56
|
-
module ApplicationHelper
|
57
|
-
def page_title
|
58
|
-
@title || nil
|
59
|
-
end
|
60
|
-
end
|
61
|
-
"""
|
62
|
-
When I run `rspec spec/helpers/application_helper_spec.rb`
|
63
|
-
Then the examples should all pass
|
64
|
-
|
65
|
-
Scenario: application helper is included in helper object
|
66
|
-
Given a file named "spec/helpers/widgets_helper_spec.rb" with:
|
67
|
-
"""ruby
|
68
|
-
require "spec_helper"
|
69
|
-
|
70
|
-
describe WidgetsHelper do
|
71
|
-
describe "#widget_title" do
|
72
|
-
it "includes the app name" do
|
73
|
-
assign(:title, "This Widget")
|
74
|
-
expect(helper.widget_title).to eq("The App: This Widget")
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
"""
|
79
|
-
And a file named "app/helpers/application_helper.rb" with:
|
80
|
-
"""ruby
|
81
|
-
module ApplicationHelper
|
82
|
-
def app_name
|
83
|
-
"The App"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
"""
|
87
|
-
And a file named "app/helpers/widgets_helper.rb" with:
|
88
|
-
"""ruby
|
89
|
-
module WidgetsHelper
|
90
|
-
def widget_title
|
91
|
-
"#{app_name}: #{@title}"
|
92
|
-
end
|
93
|
-
end
|
94
|
-
"""
|
95
|
-
When I run `rspec spec/helpers/widgets_helper_spec.rb`
|
96
|
-
Then the examples should all pass
|
97
|
-
|
98
|
-
Scenario: url helpers are defined
|
99
|
-
Given a file named "spec/helpers/widgets_helper_spec.rb" with:
|
100
|
-
"""ruby
|
101
|
-
require "spec_helper"
|
102
|
-
|
103
|
-
describe WidgetsHelper do
|
104
|
-
describe "#link_to_widget" do
|
105
|
-
it "links to a widget using its name" do
|
106
|
-
widget = Widget.create!(:name => "This Widget")
|
107
|
-
expect(helper.link_to_widget(widget)).to include("This Widget")
|
108
|
-
expect(helper.link_to_widget(widget)).to include(widget_path(widget))
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
"""
|
113
|
-
And a file named "app/helpers/widgets_helper.rb" with:
|
114
|
-
"""ruby
|
115
|
-
module WidgetsHelper
|
116
|
-
def link_to_widget(widget)
|
117
|
-
link_to(widget.name, widget_path(widget))
|
118
|
-
end
|
119
|
-
end
|
120
|
-
"""
|
121
|
-
When I run `rspec spec/helpers/widgets_helper_spec.rb`
|
122
|
-
Then the examples should all pass
|