@@ -34,32 +34,65 @@ def self.included(klass)
34
34
35
35
describe 'generated with no flags' do
36
36
before do
37
- run_generator %w( posts )
37
+ run_generator name
38
38
end
39
39
40
- subject ( :request_spec ) { file ( 'spec/requests/posts_spec.rb' ) }
40
+ subject ( :request_spec ) { file ( spec_file_name ) }
41
41
42
- it "creates the request spec" do
43
- expect ( request_spec ) . to exist
44
- end
42
+ context 'When NAME=posts' do
43
+ let ( :name ) { %w( posts ) }
44
+ let ( :spec_file_name ) { 'spec/requests/posts_spec.rb' }
45
45
46
- it "the generator requires 'rails_helper' " do
47
- expect ( request_spec ) . to contain ( /require 'rails_helper'/ )
48
- end
46
+ it "creates the request spec " do
47
+ expect ( request_spec ) . to exist
48
+ end
49
49
50
- it "the generator describes the provided NAME without monkey " \
51
- "patching setting the type to `:request`" do
52
- expect ( request_spec ) . to contain (
53
- /^RSpec.describe \" Posts\" , #{ type_metatag ( :request ) } /
54
- )
55
- end
50
+ it "the generator requires 'rails_helper'" do
51
+ expect ( request_spec ) . to contain ( /require 'rails_helper'/ )
52
+ end
53
+
54
+ it "the generator describes the provided NAME without monkey " \
55
+ "patching setting the type to `:request`" do
56
+ expect ( request_spec ) . to contain (
57
+ /^RSpec.describe \" Posts\" , #{ type_metatag ( :request ) } /
58
+ )
59
+ end
60
+
61
+ it "the generator includes a sample GET request" do
62
+ expect ( request_spec ) . to contain ( /describe "GET \/ posts"/ )
63
+ end
56
64
57
- it "the generator includes a sample GET request" do
58
- expect ( request_spec ) . to contain ( /describe "GET \/ posts"/ )
65
+ it "the generator sends the GET request to the index path" do
66
+ expect ( request_spec ) . to contain ( /get posts_index_path/ )
67
+ end
59
68
end
60
69
61
- it "the generator sends the GET request to the index path" do
62
- expect ( request_spec ) . to contain ( /get posts_index_path/ )
70
+ context 'When NAME=api/posts' do
71
+ let ( :name ) { %w( api/posts ) }
72
+ let ( :spec_file_name ) { 'spec/requests/api/posts_spec.rb' }
73
+
74
+ it "creates the request spec" do
75
+ expect ( request_spec ) . to exist
76
+ end
77
+
78
+ it "the generator requires 'rails_helper'" do
79
+ expect ( request_spec ) . to contain ( /require 'rails_helper'/ )
80
+ end
81
+
82
+ it "the generator describes the provided NAME without monkey " \
83
+ "patching setting the type to `:request`" do
84
+ expect ( request_spec ) . to contain (
85
+ /^RSpec.describe \" Api::Posts\" , #{ type_metatag ( :request ) } /
86
+ )
87
+ end
88
+
89
+ it "the generator includes a sample GET request" do
90
+ expect ( request_spec ) . to contain ( /describe "GET \/ api\/ posts\" / )
91
+ end
92
+
93
+ it "the generator sends the GET request to the index path" do
94
+ expect ( request_spec ) . to contain ( /get api_posts_index_path\n / )
95
+ end
63
96
end
64
97
end
65
98
end
0 commit comments