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.
Files changed (134) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +2 -1
  4. data/Capybara.md +1 -3
  5. data/Changelog.md +126 -58
  6. data/README.md +31 -4
  7. data/lib/generators/rspec/controller/templates/controller_spec.rb +1 -1
  8. data/lib/generators/rspec/controller/templates/view_spec.rb +1 -1
  9. data/lib/generators/rspec/feature/templates/feature_spec.rb +1 -1
  10. data/lib/generators/rspec/helper/templates/helper_spec.rb +1 -1
  11. data/lib/generators/rspec/install/templates/spec/spec_helper.rb.tt +21 -1
  12. data/lib/generators/rspec/integration/templates/request_spec.rb +1 -1
  13. data/lib/generators/rspec/mailer/templates/mailer_spec.rb +1 -1
  14. data/lib/generators/rspec/model/templates/model_spec.rb +1 -1
  15. data/lib/generators/rspec/observer/templates/observer_spec.rb +1 -1
  16. data/lib/generators/rspec/scaffold/templates/controller_spec.rb +11 -3
  17. data/lib/generators/rspec/scaffold/templates/edit_spec.rb +4 -3
  18. data/lib/generators/rspec/scaffold/templates/index_spec.rb +2 -2
  19. data/lib/generators/rspec/scaffold/templates/new_spec.rb +5 -4
  20. data/lib/generators/rspec/scaffold/templates/routing_spec.rb +1 -1
  21. data/lib/generators/rspec/scaffold/templates/show_spec.rb +2 -2
  22. data/lib/generators/rspec/view/templates/view_spec.rb +1 -1
  23. data/lib/rspec/rails.rb +1 -8
  24. data/lib/rspec/rails/configuration.rb +72 -0
  25. data/lib/rspec/rails/example.rb +0 -64
  26. data/lib/rspec/rails/example/controller_example_group.rb +16 -12
  27. data/lib/rspec/rails/example/feature_example_group.rb +0 -2
  28. data/lib/rspec/rails/example/helper_example_group.rb +0 -2
  29. data/lib/rspec/rails/example/mailer_example_group.rb +0 -1
  30. data/lib/rspec/rails/example/model_example_group.rb +0 -4
  31. data/lib/rspec/rails/example/request_example_group.rb +0 -2
  32. data/lib/rspec/rails/example/routing_example_group.rb +0 -2
  33. data/lib/rspec/rails/example/view_example_group.rb +1 -2
  34. data/lib/rspec/rails/extensions.rb +0 -1
  35. data/lib/rspec/rails/fixture_support.rb +0 -8
  36. data/lib/rspec/rails/matchers.rb +1 -0
  37. data/lib/rspec/rails/matchers/have_http_status.rb +355 -0
  38. data/lib/rspec/rails/matchers/routing_matchers.rb +1 -1
  39. data/lib/rspec/rails/tasks/rspec.rake +12 -5
  40. data/lib/rspec/rails/version.rb +1 -1
  41. data/lib/rspec/rails/view_rendering.rb +6 -34
  42. metadata +42 -316
  43. metadata.gz.sig +0 -0
  44. data/features/Generators.md +0 -25
  45. data/features/GettingStarted.md +0 -84
  46. data/features/README.md +0 -48
  47. data/features/RailsVersions.md +0 -4
  48. data/features/Transactions.md +0 -84
  49. data/features/Upgrade.md +0 -121
  50. data/features/controller_specs/Cookies.md +0 -57
  51. data/features/controller_specs/README.md +0 -45
  52. data/features/controller_specs/anonymous_controller.feature +0 -436
  53. data/features/controller_specs/bypass_rescue.feature +0 -75
  54. data/features/controller_specs/controller_spec.feature +0 -58
  55. data/features/controller_specs/engine_routes.feature +0 -51
  56. data/features/controller_specs/isolation_from_views.feature +0 -87
  57. data/features/controller_specs/render_views.feature +0 -114
  58. data/features/directory_structure.feature +0 -71
  59. data/features/feature_specs/feature_spec.feature +0 -35
  60. data/features/helper_specs/helper_spec.feature +0 -122
  61. data/features/mailer_specs/url_helpers.feature +0 -38
  62. data/features/matchers/README.md +0 -18
  63. data/features/matchers/new_record_matcher.feature +0 -41
  64. data/features/matchers/redirect_to_matcher.feature +0 -40
  65. data/features/matchers/relation_match_array.feature +0 -27
  66. data/features/matchers/render_template_matcher.feature +0 -49
  67. data/features/mocks/mock_model.feature +0 -147
  68. data/features/mocks/stub_model.feature +0 -58
  69. data/features/model_specs/README.md +0 -21
  70. data/features/model_specs/errors_on.feature +0 -51
  71. data/features/model_specs/records.feature +0 -27
  72. data/features/model_specs/transactional_examples.feature +0 -109
  73. data/features/request_specs/request_spec.feature +0 -49
  74. data/features/routing_specs/README.md +0 -16
  75. data/features/routing_specs/be_routable_matcher.feature +0 -80
  76. data/features/routing_specs/engine_routes.feature +0 -38
  77. data/features/routing_specs/named_routes.feature +0 -18
  78. data/features/routing_specs/route_to_matcher.feature +0 -90
  79. data/features/step_definitions/additional_cli_steps.rb +0 -4
  80. data/features/step_definitions/model_steps.rb +0 -3
  81. data/features/support/capybara.rb +0 -7
  82. data/features/support/env.rb +0 -53
  83. data/features/support/rails_versions.rb +0 -4
  84. data/features/support/rubinius.rb +0 -6
  85. data/features/view_specs/inferred_controller_path.feature +0 -45
  86. data/features/view_specs/stub_template.feature +0 -51
  87. data/features/view_specs/view_spec.feature +0 -206
  88. data/lib/rspec/rails/extensions/active_record/base.rb +0 -58
  89. data/lib/rspec/rails/mocks.rb +0 -272
  90. data/lib/rspec/rails/vendor/webrat.rb +0 -33
  91. data/spec/generators/rspec/controller/controller_generator_spec.rb +0 -97
  92. data/spec/generators/rspec/feature/feature_generator_spec.rb +0 -43
  93. data/spec/generators/rspec/helper/helper_generator_spec.rb +0 -30
  94. data/spec/generators/rspec/install/install_generator_spec.rb +0 -30
  95. data/spec/generators/rspec/integration/integration_generator_spec.rb +0 -32
  96. data/spec/generators/rspec/mailer/mailer_generator_spec.rb +0 -48
  97. data/spec/generators/rspec/model/model_generator_spec.rb +0 -52
  98. data/spec/generators/rspec/observer/observer_generator_spec.rb +0 -21
  99. data/spec/generators/rspec/scaffold/scaffold_generator_spec.rb +0 -138
  100. data/spec/generators/rspec/view/view_generator_spec.rb +0 -41
  101. data/spec/rspec/rails/assertion_adapter_spec.rb +0 -28
  102. data/spec/rspec/rails/assertion_delegator_spec.rb +0 -43
  103. data/spec/rspec/rails/configuration_spec.rb +0 -26
  104. data/spec/rspec/rails/deprecations_spec.rb +0 -18
  105. data/spec/rspec/rails/example/controller_example_group_spec.rb +0 -159
  106. data/spec/rspec/rails/example/feature_example_group_spec.rb +0 -56
  107. data/spec/rspec/rails/example/helper_example_group_spec.rb +0 -66
  108. data/spec/rspec/rails/example/mailer_example_group_spec.rb +0 -21
  109. data/spec/rspec/rails/example/model_example_group_spec.rb +0 -15
  110. data/spec/rspec/rails/example/request_example_group_spec.rb +0 -17
  111. data/spec/rspec/rails/example/routing_example_group_spec.rb +0 -32
  112. data/spec/rspec/rails/example/view_example_group_spec.rb +0 -235
  113. data/spec/rspec/rails/extensions/active_model/errors_on_spec.rb +0 -23
  114. data/spec/rspec/rails/extensions/active_record/base_spec.rb +0 -42
  115. data/spec/rspec/rails/fixture_support_spec.rb +0 -17
  116. data/spec/rspec/rails/matchers/be_a_new_spec.rb +0 -142
  117. data/spec/rspec/rails/matchers/be_new_record_spec.rb +0 -33
  118. data/spec/rspec/rails/matchers/be_routable_spec.rb +0 -41
  119. data/spec/rspec/rails/matchers/be_valid_spec.rb +0 -73
  120. data/spec/rspec/rails/matchers/has_spec.rb +0 -29
  121. data/spec/rspec/rails/matchers/have_rendered_spec.rb +0 -93
  122. data/spec/rspec/rails/matchers/redirect_to_spec.rb +0 -81
  123. data/spec/rspec/rails/matchers/relation_match_array_spec.rb +0 -31
  124. data/spec/rspec/rails/matchers/route_to_spec.rb +0 -151
  125. data/spec/rspec/rails/minitest_lifecycle_adapter_spec.rb +0 -31
  126. data/spec/rspec/rails/mocks/mock_model_spec.rb +0 -400
  127. data/spec/rspec/rails/mocks/stub_model_spec.rb +0 -154
  128. data/spec/rspec/rails/setup_and_teardown_adapter_spec.rb +0 -32
  129. data/spec/rspec/rails/view_rendering_spec.rb +0 -111
  130. data/spec/spec_helper.rb +0 -33
  131. data/spec/support/ar_classes.rb +0 -42
  132. data/spec/support/helpers.rb +0 -34
  133. data/spec/support/matchers.rb +0 -9
  134. data/spec/support/null_object.rb +0 -6
@@ -1,58 +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
36
-
37
- Scenario: controller is extended with a helper module
38
- Given a file named "spec/controllers/widgets_controller_spec.rb" with:
39
- """ruby
40
- require "spec_helper"
41
-
42
- module MyHelper
43
- def my_variable
44
- end
45
- end
46
-
47
- RSpec.configure {|c| c.include MyHelper }
48
-
49
- describe WidgetsController do
50
- let(:my_variable) { 'is a value' }
51
-
52
- describe 'something' do
53
- specify { expect(my_variable).to eq 'is a value' }
54
- end
55
- end
56
- """
57
- When I run `rspec spec`
58
- 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,71 +0,0 @@
1
- Feature: Directory Structure
2
-
3
- Specs are usually placed in a canonical directory structure that describes
4
- their purpose.
5
-
6
- * Model specs reside in the `spec/models` directory
7
- * Controller specs reside in the `spec/controllers` directory
8
- * Request specs reside in the `spec/requests` directory
9
- * Feature specs reside in the `spec/features` directory
10
- * View specs reside in the `spec/views` directory
11
- * Helper specs reside in the `spec/helpers` directory
12
- * Mailer specs reside in the `spec/mailers` directory
13
- * Routing specs reside in the `spec/routing` directory
14
-
15
- If you follow this directory structure, RSpec will automatically include the
16
- correct test support functions for each type of test.
17
-
18
- Application developers are free to use a different directory structure, but
19
- will need to specify the types manually by adding a `:type` metadata key (for
20
- example, `describe WidgetsController, :type => :controller`)
21
-
22
- Scenario: Specs in the `spec/controllers` directory automatically tagged as controller specs
23
- Given a file named "spec/controllers/widgets_controller_spec.rb" with:
24
- """ruby
25
- require "spec_helper"
26
-
27
- describe WidgetsController do
28
- it "responds successfully" do
29
- get :index
30
- expect(response.status).to eq(200)
31
- end
32
- end
33
- """
34
- When I run `rspec spec`
35
- Then the example should pass
36
-
37
- Scenario: Specs in other directories must have their types specified manually
38
- Given a file named "spec/functional/widgets_controller_spec.rb" with:
39
- """ruby
40
- require "spec_helper"
41
-
42
- describe WidgetsController, :type => :controller do
43
- it "responds successfully" do
44
- get :index
45
- expect(response.status).to eq(200)
46
- end
47
- end
48
- """
49
- When I run `rspec spec`
50
- Then the example should pass
51
-
52
- Scenario: Specs in canonical directories can override their types
53
- Given a file named "spec/routing/duckduck_routing_spec.rb" with:
54
- """ruby
55
- require "spec_helper"
56
-
57
- Rails.application.routes.draw do
58
- get "/example" => redirect("http://example.com")
59
- end
60
-
61
- # Due to limitations in the Rails routing test framework, routes that
62
- # perform redirects must actually be tested via request specs
63
- describe "/example", :type => :request do
64
- it "redirects to example.com" do
65
- get "/example"
66
- expect(response).to redirect_to("http://example.com")
67
- end
68
- end
69
- """
70
- When I run `rspec spec`
71
- Then the example should pass
@@ -1,35 +0,0 @@
1
- @capybara
2
- Feature: feature spec
3
-
4
- Feature specs are high-level tests meant to exercise slices of functionality
5
- through an application. They should drive the application only via its
6
- external interface, usually web pages.
7
-
8
- Feature specs require the [capybara](http://github.com/jnicklas/capybara)
9
- gem, version 2.0.0 or later. Refer to the [capybara API
10
- documentation](http://rubydoc.info/github/jnicklas/capybara/master) for more
11
- information on the methods and matchers that can be used in feature specs.
12
-
13
- The `feature` and `scenario` DSL correspond to `describe` and `it`,
14
- respectively. These methods are simply aliases that allow feature specs to
15
- read more as [customer tests](http://c2.com/cgi/wiki?CustomerTest) and
16
- [acceptance tests](http://c2.com/cgi/wiki?AcceptanceTest).
17
-
18
- Scenario: specify creating a Widget by driving the application with capybara
19
- Given a file named "spec/features/widget_management_spec.rb" with:
20
- """ruby
21
- require "spec_helper"
22
-
23
- feature "Widget management" do
24
- scenario "User creates a new widget" do
25
- visit "/widgets/new"
26
-
27
- fill_in "Name", :with => "My Widget"
28
- click_button "Create Widget"
29
-
30
- expect(page).to have_text("Widget was successfully created.")
31
- end
32
- end
33
- """
34
- When I run `rspec spec/features/widget_management_spec.rb`
35
- 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