|
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') } |
10 |
| - describe 'generated by default' do |
11 |
| - before do |
12 |
| - run_generator %w(posts) |
13 |
| - end |
| 8 | + describe 'request specs' do |
| 9 | + subject { file('spec/requests/posts_request_spec.rb') } |
14 | 10 |
|
15 |
| - describe 'the spec' do |
16 |
| - it { is_expected.to exist } |
17 |
| - it { is_expected.to contain(/require 'rails_helper'/) } |
18 |
| - it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) } |
| 11 | + if Rails.version.to_f >= 5.0 |
| 12 | + describe 'generated by default' do |
| 13 | + before do |
| 14 | + run_generator %w[posts] |
| 15 | + end |
| 16 | + |
| 17 | + describe 'the spec' do |
| 18 | + it { is_expected.to exist } |
| 19 | + it { is_expected.to contain(/require 'rails_helper'/) } |
| 20 | + it { is_expected.to contain(/^RSpec.describe "Posts", #{type_metatag(:request)}/) } |
| 21 | + end |
19 | 22 | end
|
20 |
| - end |
21 |
| - describe 'skipped with a flag' do |
22 |
| - before do |
23 |
| - run_generator %w(posts --no-controller_specs) |
| 23 | + |
| 24 | + describe 'skipped with a flag' do |
| 25 | + before do |
| 26 | + run_generator %w[posts --no-request_specs] |
| 27 | + end |
| 28 | + it { is_expected.not_to exist } |
24 | 29 | end
|
| 30 | + else |
25 | 31 | it { is_expected.not_to exist }
|
26 | 32 | end
|
27 | 33 | end
|
|
127 | 133 | it { is_expected.not_to exist }
|
128 | 134 | end
|
129 | 135 | end
|
| 136 | + |
| 137 | + describe 'controller specs' do |
| 138 | + subject { file('spec/controllers/posts_controller_spec.rb') } |
| 139 | + |
| 140 | + if Rails.version.to_f < 5.0 |
| 141 | + describe 'generated by default' do |
| 142 | + before do |
| 143 | + run_generator %w[posts] |
| 144 | + end |
| 145 | + |
| 146 | + describe 'the spec' do |
| 147 | + it { is_expected.to exist } |
| 148 | + it { is_expected.to contain(/require 'rails_helper'/) } |
| 149 | + it { is_expected.to contain(/^RSpec.describe PostsController, #{type_metatag(:controller)}/) } |
| 150 | + end |
| 151 | + end |
| 152 | + |
| 153 | + describe 'skipped with a flag' do |
| 154 | + before do |
| 155 | + run_generator %w[posts --no-controller-specs] |
| 156 | + end |
| 157 | + it { is_expected.not_to exist } |
| 158 | + end |
| 159 | + else |
| 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 |
| 183 | + end |
130 | 184 | end
|
0 commit comments