|
5 | 5 | RSpec.describe Rspec::Generators::ControllerGenerator, :type => :generator do
|
6 | 6 | setup_default_destination
|
7 | 7 |
|
8 |
| - describe 'controller specs' do |
9 |
| - subject { file('spec/controllers/posts_controller_spec.rb') } |
| 8 | + describe 'request specs' do |
| 9 | + subject { file('spec/requests/posts_request_spec.rb') } |
| 10 | + |
10 | 11 | describe 'generated by default' do
|
11 | 12 | before do
|
12 |
| - run_generator %w(posts) |
| 13 | + run_generator %w[posts] |
13 | 14 | end
|
14 | 15 |
|
15 | 16 | describe 'the spec' do
|
16 | 17 | it { is_expected.to exist }
|
17 | 18 | it { is_expected.to contain(/require 'rails_helper'/) }
|
18 |
| - it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) } |
| 19 | + it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) } |
19 | 20 | end
|
20 | 21 | end
|
| 22 | + |
21 | 23 | describe 'skipped with a flag' do
|
22 | 24 | before do
|
23 |
| - run_generator %w(posts --no-controller_specs) |
| 25 | + run_generator %w[posts --no-request_specs] |
24 | 26 | end
|
25 | 27 | it { is_expected.not_to exist }
|
26 | 28 | end
|
| 29 | + |
| 30 | + |
| 31 | + describe 'with actions' do |
| 32 | + before do |
| 33 | + run_generator %w[posts index custom_action] |
| 34 | + end |
| 35 | + |
| 36 | + it { is_expected.to exist } |
| 37 | + it { is_expected.to contain('get "/posts/index"') } |
| 38 | + it { is_expected.to contain('get "/posts/custom_action"') } |
| 39 | + end |
| 40 | + |
| 41 | + describe 'with namespace and actions' do |
| 42 | + subject { file('spec/requests/admin/external/users_request_spec.rb') } |
| 43 | + |
| 44 | + before do |
| 45 | + run_generator %w[admin::external::users index custom_action] |
| 46 | + end |
| 47 | + |
| 48 | + it { is_expected.to exist } |
| 49 | + it { is_expected.to contain(/^RSpec.describe "Admin::External::Users", #{type_metatag(:request)}/) } |
| 50 | + it { is_expected.to contain('get "/admin/external/users/index"') } |
| 51 | + it { is_expected.to contain('get "/admin/external/users/custom_action"') } |
| 52 | + end |
27 | 53 | end
|
28 | 54 |
|
29 | 55 | describe 'view specs' do
|
|
127 | 153 | it { is_expected.not_to exist }
|
128 | 154 | end
|
129 | 155 | end
|
| 156 | + |
| 157 | + describe 'controller specs' do |
| 158 | + subject { file('spec/controllers/posts_controller_spec.rb') } |
| 159 | + |
| 160 | + describe 'are not generated' do |
| 161 | + it { is_expected.not_to exist } |
| 162 | + end |
| 163 | + |
| 164 | + describe 'with --controller-specs flag' do |
| 165 | + before do |
| 166 | + run_generator %w[posts --controller-specs] |
| 167 | + end |
| 168 | + |
| 169 | + describe 'the spec' do |
| 170 | + it { is_expected.to exist } |
| 171 | + it { is_expected.to contain(/require 'rails_helper'/) } |
| 172 | + it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) } |
| 173 | + end |
| 174 | + end |
| 175 | + |
| 176 | + describe 'with --no-controller_specs flag' do |
| 177 | + before do |
| 178 | + run_generator %w[posts --no-controller-specs] |
| 179 | + end |
| 180 | + it { is_expected.not_to exist } |
| 181 | + end |
| 182 | + end |
130 | 183 | end
|
0 commit comments