Skip to content

Commit 5d5baf5

Browse files
committed
Refactor existing generator specs
1 parent 1076191 commit 5d5baf5

4 files changed

Lines changed: 32 additions & 44 deletions

File tree

.rspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
--format documentation
22
--color
3+
--order random

.travis.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,19 @@ jobs:
4747
rvm: 2.7.1
4848
- gemfile: gemfiles/rails6.0_graphql_edge.gemfile
4949
rvm: 2.6.6
50-
env: SKIP_COVERALLS=true
50+
env:
51+
- SKIP_COVERALLS=true
52+
- EAGER_LOAD=true
5153
- gemfile: gemfiles/rails6.0_graphql_edge.gemfile
5254
rvm: 2.7.1
53-
env: SKIP_COVERALLS=true
55+
env:
56+
- SKIP_COVERALLS=true
57+
- EAGER_LOAD=true
5458
- gemfile: gemfiles/rails_edge_graphql_edge.gemfile
5559
rvm: 2.7.1
56-
env: SKIP_COVERALLS=true
60+
env:
61+
- SKIP_COVERALLS=true
62+
- EAGER_LOAD=true
5763
exclude:
5864
- gemfile: gemfiles/rails4.2_graphql1.8.gemfile
5965
rvm: 2.7.1

spec/fixtures/rails

Lines changed: 0 additions & 7 deletions
This file was deleted.

spec/generators/graphql_devise/install_generator_spec.rb

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,44 @@
33
require 'generators/graphql_devise/install_generator'
44

55
RSpec.describe GraphqlDevise::InstallGenerator, type: :generator do
6-
destination File.expand_path('../../../tmp/dummy', __dir__)
6+
destination File.expand_path('../../../../dummy', __dir__)
77

88
before do
99
prepare_destination
10-
copy_rails_bin
10+
create_rails_project
1111
end
1212

1313
let(:routes_path) { "#{destination_root}/config/routes.rb" }
1414
let(:routes_content) { File.read(routes_path) }
15-
let(:dta_route) { "mount_devise_token_auth_for 'User', at: 'auth'" }
16-
17-
context 'when the file exists' do
18-
before do
19-
create_file_with_content(
20-
routes_path,
21-
"Rails.application.routes.draw do\n#{dta_route}\nend"
22-
)
23-
end
24-
25-
context 'when passing no params to the generator' do
26-
before { run_generator }
15+
let(:dta_route) { 'mount_devise_token_auth_for' }
2716

28-
it 'replaces dta route using the default values for class and path' do
29-
generator_added_route = / mount_graphql_devise_for 'User', at: 'auth'/
30-
expect(routes_content).to match(generator_added_route)
31-
expect(routes_content).not_to match(dta_route)
32-
end
33-
end
17+
context 'when passing no params to the generator' do
18+
before { run_generator }
3419

35-
context 'when passing custom params to the generator' do
36-
before { run_generator %w[Admin api] }
20+
it 'creates and updated required files' do
21+
assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'User', at: 'auth'/
22+
expect(routes_content).not_to match(dta_route)
3723

38-
it 'add the routes using the provided values for class and path and keeps dta route' do
39-
generator_added_route = / mount_graphql_devise_for 'Admin', at: 'api'/
40-
expect(routes_content).to match(generator_added_route)
41-
expect(routes_content).to match(dta_route)
42-
end
24+
assert_file 'config/initializers/devise.rb'
25+
assert_file 'config/initializers/devise_token_auth.rb'
4326
end
4427
end
4528

46-
context 'when file does *NOT* exist' do
47-
before { run_generator }
29+
context 'when passing custom params to the generator' do
30+
before { run_generator %w[Admin api] }
31+
32+
it 'creates and updated required files' do
33+
assert_file 'config/routes.rb', /\s{2,}mount_graphql_devise_for 'Admin', at: 'api'/
34+
expect(routes_content).not_to match(dta_route)
4835

49-
it 'does *NOT* create the file and throw no exception' do
50-
expect(File).not_to exist(routes_path)
36+
assert_file 'config/initializers/devise.rb'
37+
assert_file 'config/initializers/devise_token_auth.rb'
5138
end
5239
end
5340

54-
def copy_rails_bin
55-
FileUtils.mkdir_p(File.join(destination_root, 'bin'))
56-
FileUtils.copy_file('spec/fixtures/rails', File.join(destination_root, 'bin/rails'))
41+
def create_rails_project
42+
FileUtils.cd(File.join(destination_root, '..')) do
43+
`rails new dummy -S -C --skip-action-mailbox --skip-action-text -T --skip-spring --skip-bundle --skip-keeps -G --skip-active-storage -J --skip-listen --skip-bootsnap`
44+
end
5745
end
5846
end

0 commit comments

Comments
 (0)