File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed
lib/generators/rspec/scaffold/templates
spec/generators/rspec/scaffold Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -112,3 +112,43 @@ Feature: request spec
112
112
"""
113
113
When I run `rspec spec/requests/widget_management_spec.rb`
114
114
Then the example should pass
115
+
116
+ Scenario : using engine route helpers
117
+ Given a file named "spec/requests/widgets_spec.rb" with:
118
+ """ruby
119
+ require "rails_helper"
120
+
121
+ # A very simple Rails engine
122
+ module MyEngine
123
+ class Engine < ::Rails::Engine
124
+ isolate_namespace MyEngine
125
+ end
126
+
127
+ class LinksController < ::ActionController::Base
128
+ def index
129
+ render plain: 'hit_engine_route'
130
+ end
131
+ end
132
+ end
133
+
134
+ MyEngine::Engine.routes.draw do
135
+ resources :links, :only => [:index]
136
+ end
137
+
138
+ Rails.application.routes.draw do
139
+ mount MyEngine::Engine => "/my_engine"
140
+ end
141
+
142
+ module MyEngine
143
+ RSpec.describe "Links", :type => :request do
144
+ include Engine.routes.url_helpers
145
+
146
+ it "redirects to a random widget" do
147
+ get links_url
148
+ expect(response.body).to eq('hit_engine_route')
149
+ end
150
+ end
151
+ end
152
+ """
153
+ When I run `rspec spec`
154
+ Then the example should pass
Original file line number Diff line number Diff line change 14
14
15
15
<% module_namespacing do -%>
16
16
RSpec.describe "/<%= name.underscore.pluralize %>", <%= type_metatag(:request) %> do
17
+ <% if mountable_engine? -%>
18
+ include Engine.routes.url_helpers
19
+ <% end -%>
20
+
17
21
# <%= class_name %>. As you add validations to <%= class_name %>, be sure to
18
22
# adjust the attributes here as well.
19
23
let(:valid_attributes) {
Original file line number Diff line number Diff line change 39
39
it { is_expected . to contain ( 'renders a JSON response with the post' ) }
40
40
it { is_expected . to contain ( 'renders a JSON response with errors for the post' ) }
41
41
end
42
+
43
+ describe 'in an engine' do
44
+ before do
45
+ allow_any_instance_of ( ::Rails ::Generators ::NamedBase ) . to receive ( :mountable_engine? ) . and_return ( true )
46
+ run_generator %w[ posts --request_specs ]
47
+ end
48
+
49
+ it { is_expected . to contain ( 'Engine.routes.url_helpers' ) }
50
+ end
42
51
end
43
52
44
53
describe 'standard controller spec' do
You can’t perform that action at this time.
0 commit comments