g5_authenticatable 0.9.1.pre.2 → 1.0.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.ruby-version +1 -1
  4. data/.travis.yml +23 -9
  5. data/Appraisals +17 -0
  6. data/CHANGELOG.md +14 -0
  7. data/Gemfile +11 -14
  8. data/README.md +40 -13
  9. data/app/controllers/concerns/g5_authenticatable/authorization.rb +4 -1
  10. data/app/controllers/g5_authenticatable/application_controller.rb +3 -0
  11. data/app/controllers/g5_authenticatable/error_controller.rb +3 -2
  12. data/app/controllers/g5_authenticatable/failure_app.rb +35 -0
  13. data/app/controllers/g5_authenticatable/sessions_controller.rb +7 -3
  14. data/app/helpers/g5_authenticatable/application_helper.rb +3 -0
  15. data/app/models/g5_authenticatable/role.rb +5 -2
  16. data/app/models/g5_authenticatable/user.rb +12 -5
  17. data/app/policies/g5_authenticatable/base_policy.rb +75 -58
  18. data/app/policies/g5_updatable/client_policy.rb +5 -5
  19. data/app/policies/g5_updatable/location_policy.rb +6 -5
  20. data/app/policies/g5_updatable/selectable_client_policy.rb +6 -7
  21. data/app/services/g5_authenticatable/impersonate_sessionable.rb +12 -7
  22. data/config/initializers/devise.rb +4 -0
  23. data/config/initializers/impersonate_strategy.rb +5 -2
  24. data/config/initializers/rolify.rb +2 -0
  25. data/config/routes.rb +3 -1
  26. data/g5_authenticatable.gemspec +11 -7
  27. data/gemfiles/rails_4.1.gemfile +28 -0
  28. data/gemfiles/rails_4.2.gemfile +28 -0
  29. data/gemfiles/rails_5.0.gemfile +28 -0
  30. data/gemfiles/rails_5.1.gemfile +28 -0
  31. data/lib/g5_authenticatable.rb +3 -1
  32. data/lib/g5_authenticatable/engine.rb +5 -2
  33. data/lib/g5_authenticatable/rspec.rb +2 -0
  34. data/lib/g5_authenticatable/test/controller_helpers.rb +14 -9
  35. data/lib/g5_authenticatable/test/env_helpers.rb +3 -0
  36. data/lib/g5_authenticatable/test/factories/client_users.rb +45 -0
  37. data/lib/g5_authenticatable/test/factories/global_users.rb +43 -0
  38. data/lib/g5_authenticatable/test/factories/location_users.rb +45 -0
  39. data/lib/g5_authenticatable/test/factories/roles.rb +63 -0
  40. data/lib/g5_authenticatable/test/factory.rb +7 -59
  41. data/lib/g5_authenticatable/test/feature_helpers.rb +31 -17
  42. data/lib/g5_authenticatable/test/request_helpers.rb +5 -1
  43. data/lib/g5_authenticatable/test/token_validation_helpers.rb +15 -10
  44. data/lib/g5_authenticatable/version.rb +3 -1
  45. data/lib/generators/g5_authenticatable/install/install_generator.rb +49 -37
  46. data/lib/generators/g5_authenticatable/install/templates/application_policy.rb +2 -0
  47. data/lib/generators/g5_authenticatable/install/templates/initializer.rb +2 -0
  48. data/lib/generators/g5_authenticatable/install/templates/migrate/add_g5_authenticatable_users_contact_info.rb +3 -1
  49. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_roles.rb +3 -1
  50. data/lib/generators/g5_authenticatable/install/templates/migrate/create_g5_authenticatable_users.rb +3 -1
  51. data/lib/tasks/g5_authenticatable/purge_users.rake +2 -0
  52. data/spec/config/application_spec.rb +7 -4
  53. data/spec/controllers/application_controller_spec.rb +10 -5
  54. data/spec/controllers/concerns/g5_authenticatable/{authorization.rb → authorization_spec.rb} +11 -6
  55. data/spec/dummy/app/controllers/home_controller.rb +5 -5
  56. data/spec/dummy/app/controllers/rails_api/secure_resources_controller.rb +6 -4
  57. data/spec/dummy/app/models/post.rb +1 -1
  58. data/spec/dummy/config/environments/test.rb +25 -4
  59. data/spec/dummy/config/initializers/rails_compatibility.rb +10 -0
  60. data/spec/dummy/db/migrate/20140206070137_create_g5_authenticatable_users.rb +3 -1
  61. data/spec/dummy/db/migrate/20150428182339_add_g5_authenticatable_users_contact_info.rb +3 -1
  62. data/spec/dummy/db/migrate/20150429212919_create_g5_authenticatable_roles.rb +2 -1
  63. data/spec/dummy/db/migrate/20150509061150_create_posts.rb +3 -1
  64. data/spec/dummy/db/migrate/20150603224032_create_g5_updatable_clients_and_locations.g5_updatable.rb +3 -1
  65. data/spec/dummy/db/migrate/20150603224033_create_integration_setting.g5_updatable.rb +3 -1
  66. data/spec/dummy/db/migrate/20150603224034_remove_integration_setting.g5_updatable.rb +3 -1
  67. data/spec/dummy/db/migrate/20150603224035_add_name_to_clients_and_locations.g5_updatable.rb +3 -1
  68. data/spec/dummy/db/migrate/20150603224036_update_names.g5_updatable.rb +3 -1
  69. data/spec/dummy/db/migrate/20170613201430_add_latitude_and_longitude_to_location.g5_updatable.rb +7 -0
  70. data/spec/dummy/db/migrate/20170613201431_copy_lat_long_props_to_lat_long_columns.g5_updatable.rb +20 -0
  71. data/spec/dummy/db/migrate/20170613201432_add_latitude_longitude_indexes_to_location.g5_updatable.rb +7 -0
  72. data/spec/dummy/db/migrate/{20161122070749_add_amenities.rb → 20170613201433_add_amenities.g5_updatable.rb} +2 -1
  73. data/spec/dummy/db/migrate/{20161209070749_add_client_urn_to_locations.rb → 20170613201434_add_client_urn_to_locations.g5_updatable.rb} +2 -1
  74. data/spec/dummy/db/migrate/20170613201435_add_points_of_interest.g5_updatable.rb +21 -0
  75. data/spec/dummy/db/migrate/20170613201436_add_unique_urn_indexes.g5_updatable.rb +11 -0
  76. data/spec/dummy/db/schema.rb +73 -61
  77. data/spec/factories/post.rb +2 -0
  78. data/spec/features/auth_error_path_spec.rb +3 -3
  79. data/spec/features/default_role_authorization_spec.rb +8 -4
  80. data/spec/features/sign_in_spec.rb +23 -13
  81. data/spec/features/token_validation_spec.rb +4 -2
  82. data/spec/g5_authenticatable/version_spec.rb +3 -1
  83. data/spec/lib/generators/g5_authenticatable/install_generator_spec.rb +73 -28
  84. data/spec/models/g5_authenticatable/role_spec.rb +8 -4
  85. data/spec/models/g5_authenticatable/user_spec.rb +119 -84
  86. data/spec/models/post_spec.rb +4 -2
  87. data/spec/policies/application_policy_spec.rb +80 -47
  88. data/spec/policies/client_policy_spec.rb +8 -5
  89. data/spec/policies/location_policy_spec.rb +21 -8
  90. data/spec/policies/selectable_client_policy_spec.rb +26 -15
  91. data/spec/rails_helper.rb +41 -0
  92. data/spec/requests/default_role_authorization_spec.rb +18 -14
  93. data/spec/requests/grape_api_spec.rb +7 -5
  94. data/spec/requests/rails_api_spec.rb +11 -9
  95. data/spec/requests/sign_out_spec.rb +10 -6
  96. data/spec/requests/token_validation_spec.rb +9 -5
  97. data/spec/routing/auth_error_routing_spec.rb +7 -6
  98. data/spec/routing/sign_out_routing_spec.rb +7 -5
  99. data/spec/services/g5_authenticatable/impersonate_sessionable_spec.rb +41 -18
  100. data/spec/spec_helper.rb +78 -45
  101. data/spec/support/devise.rb +3 -1
  102. data/spec/support/safe_request_helpers.rb +36 -0
  103. data/spec/support/shared_contexts/rake.rb +10 -4
  104. data/spec/support/shared_examples/super_admin_authorizer.rb +3 -1
  105. data/spec/tasks/purge_users_spec.rb +3 -1
  106. metadata +75 -39
  107. data/spec/controllers/.gitkeep +0 -0
@@ -1,19 +1,21 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'a secure Grape API' do
4
- subject(:api_call) { get '/api/secure_resource' }
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'a secure Grape API' do
6
+ subject(:api_call) { safe_get '/api/secure_resource' }
5
7
 
6
8
  context 'with an authenticated user', :auth_request do
7
9
  it 'should be successful' do
8
10
  api_call
9
- expect(response).to be_http_ok
11
+ expect(response.status).to eq(200)
10
12
  end
11
13
  end
12
14
 
13
15
  context 'without an authenticated user' do
14
16
  it 'should be unauthorized' do
15
17
  api_call
16
- expect(response).to be_http_unauthorized
18
+ expect(response.status).to eq(401)
17
19
  end
18
20
  end
19
21
  end
@@ -1,44 +1,46 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'a secure Rails API' do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'a secure Rails API' do
4
6
  describe 'POST request to an API-only action' do
5
- subject(:api_call) { post '/rails_api/secure_resource' }
7
+ subject(:api_call) { safe_post '/rails_api/secure_resource' }
6
8
 
7
9
  context 'with an authenticated user', :auth_request do
8
10
  it 'should be successful' do
9
11
  api_call
10
- expect(response).to be_http_ok
12
+ expect(response.status).to eq(200)
11
13
  end
12
14
  end
13
15
 
14
16
  context 'without an authenticated user' do
15
17
  it 'should be unauthorized' do
16
18
  api_call
17
- expect(response).to be_http_unauthorized
19
+ expect(response.status).to eq(401)
18
20
  end
19
21
  end
20
22
  end
21
23
 
22
24
  describe 'GET json request to mixed API/website action' do
23
- subject(:api_call) { get '/rails_api/secure_resource.json' }
25
+ subject(:api_call) { safe_get '/rails_api/secure_resource.json' }
24
26
 
25
27
  context 'with an authenticated user', :auth_request do
26
28
  it 'should be successful' do
27
29
  api_call
28
- expect(response).to be_http_ok
30
+ expect(response.status).to eq(200)
29
31
  end
30
32
  end
31
33
 
32
34
  context 'without an authenticated user' do
33
35
  it 'should be unauthorized' do
34
36
  api_call
35
- expect(response).to be_http_unauthorized
37
+ expect(response.status).to eq(401)
36
38
  end
37
39
  end
38
40
  end
39
41
 
40
42
  describe 'GET html request to mixed API/website action' do
41
- subject(:website_call) { get '/rails_api/secure_resource.html' }
43
+ subject(:website_call) { safe_get '/rails_api/secure_resource.html' }
42
44
 
43
45
  it 'should be a redirect' do
44
46
  website_call
@@ -1,16 +1,19 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails_helper'
2
4
 
3
5
  # Normally, we'd do this as a feature spec, but there's
4
6
  # currently no easy way to get capybara to play along nicely
5
7
  # with mocks for external redirects (the capybara-mechanize driver
6
8
  # comes closest, but not quite)
7
- describe 'Signing out' do
9
+ RSpec.describe 'Signing out' do
8
10
  let(:auth_sign_out_url) do
9
- "#{ENV['G5_AUTH_ENDPOINT']}/users/sign_out?redirect_url=http%3A%2F%2Fwww.example.com%2F"
11
+ "#{ENV['G5_AUTH_ENDPOINT']}/users/sign_out" \
12
+ '?redirect_url=http%3A%2F%2Fwww.example.com%2F'
10
13
  end
11
14
 
12
15
  describe 'GET /g5_auth/users/sign_out' do
13
- subject(:sign_out) { get '/g5_auth/users/sign_out' }
16
+ subject(:sign_out) { safe_get '/g5_auth/users/sign_out' }
14
17
 
15
18
  context 'when user is logged in', :auth_request do
16
19
  it 'should redirect to the auth server' do
@@ -19,7 +22,8 @@ describe 'Signing out' do
19
22
 
20
23
  it 'should not allow the user to access protected pages' do
21
24
  sign_out
22
- expect(get '/protected_page').to redirect_to('/g5_auth/users/sign_in')
25
+ expect(safe_get('/protected_page'))
26
+ .to redirect_to('/g5_auth/users/sign_in')
23
27
  end
24
28
  end
25
29
 
@@ -31,7 +35,7 @@ describe 'Signing out' do
31
35
  end
32
36
 
33
37
  describe 'DELETE /g5_auth/users/sign_out', :auth_request do
34
- subject(:sign_out) { delete '/g5_auth/users/sign_out' }
38
+ subject(:sign_out) { safe_delete '/g5_auth/users/sign_out' }
35
39
 
36
40
  it 'should redirect to GET' do
37
41
  expect(sign_out).to redirect_to('/g5_auth/users/sign_out')
@@ -1,9 +1,13 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'API Token validation' do
4
- let(:token_info_url) { URI.join(ENV['G5_AUTH_ENDPOINT'], '/oauth/token/info') }
3
+ require 'rails_helper'
5
4
 
6
- subject(:api_call) { get '/rails_api/secure_resource.json' }
5
+ RSpec.describe 'API Token validation' do
6
+ let(:token_info_url) do
7
+ URI.join(ENV['G5_AUTH_ENDPOINT'], '/oauth/token/info')
8
+ end
9
+
10
+ subject(:api_call) { safe_get '/rails_api/secure_resource.json' }
7
11
 
8
12
  context 'when token validation is enabled' do
9
13
  before { G5Authenticatable.strict_token_validation = true }
@@ -36,7 +40,7 @@ describe 'API Token validation' do
36
40
 
37
41
  it 'should return a 401' do
38
42
  api_call
39
- expect(response).to be_http_unauthorized
43
+ expect(response.status).to eq(401)
40
44
  end
41
45
  end
42
46
 
@@ -1,15 +1,16 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe G5Authenticatable::ErrorController do
4
- routes {G5Authenticatable::Engine.routes}
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe G5Authenticatable::ErrorController do
6
+ routes { G5Authenticatable::Engine.routes }
5
7
 
6
8
  it 'should route GET /g5_auth/auth_error path' do
7
- expect(get: '/auth_error').
8
- to route_to(controller: 'g5_authenticatable/error', action: 'auth_error')
9
+ expect(get: '/auth_error')
10
+ .to route_to(controller: 'g5_authenticatable/error', action: 'auth_error')
9
11
  end
10
12
 
11
13
  it 'should generate a helper' do
12
14
  expect(auth_error_path).to eq('/g5_auth/auth_error')
13
15
  end
14
-
15
16
  end
@@ -1,10 +1,12 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe 'Sign out routes' do
4
- routes {G5Authenticatable::Engine.routes}
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe 'Sign out routes' do
6
+ routes { G5Authenticatable::Engine.routes }
5
7
 
6
8
  it 'should route GET /g5_auth/users/sign_out' do
7
- expect(get('/users/sign_out')).to route_to(controller: 'g5_authenticatable/sessions',
8
- action: 'destroy')
9
+ expect(get('/users/sign_out'))
10
+ .to route_to(controller: 'g5_authenticatable/sessions', action: 'destroy')
9
11
  end
10
12
  end
@@ -1,6 +1,8 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
2
 
3
- describe G5Authenticatable::ImpersonateSessionable do
3
+ require 'rails_helper'
4
+
5
+ RSpec.describe G5Authenticatable::ImpersonateSessionable do
4
6
  let!(:user) { FactoryGirl.create(:g5_authenticatable_user) }
5
7
 
6
8
  class MyImpersponateSessionableTest
@@ -16,31 +18,37 @@ describe G5Authenticatable::ImpersonateSessionable do
16
18
  expect(service_instance).to receive(:impersonation_user).and_return(user)
17
19
  end
18
20
 
19
- it { expect(impersonation_user).to be_truthy }
21
+ it { is_expected.to be_truthy }
20
22
  end
21
23
 
22
24
  describe '#impersonation_user' do
23
25
  subject(:impersonation_user) { service_instance.send(:impersonation_user) }
24
26
 
25
27
  before do
26
- expect(service_instance).to receive(:impersonate_admin_uid).and_return(user.uid)
28
+ expect(service_instance).to receive(:impersonate_admin_uid)
29
+ .and_return(user.uid)
27
30
  end
28
31
 
29
- it { expect(impersonation_user).to eq(user) }
32
+ it { is_expected.to eq(user) }
30
33
  end
31
34
 
32
35
  describe '#user_to_impersonate' do
33
- subject(:user_to_impersonate) { service_instance.send(:user_to_impersonate) }
36
+ subject(:user_to_impersonate) do
37
+ service_instance.send(:user_to_impersonate)
38
+ end
34
39
 
35
40
  before do
36
- expect(service_instance).to receive(:impersonating_user_uid).and_return(user.uid)
41
+ expect(service_instance).to receive(:impersonating_user_uid)
42
+ .and_return(user.uid)
37
43
  end
38
44
 
39
- it { expect(user_to_impersonate).to eq(user) }
45
+ it { is_expected.to eq(user) }
40
46
  end
41
47
 
42
48
  describe '#able_to_impersonate?' do
43
- subject(:able_to_impersonate) { service_instance.send(:able_to_impersonate?, user, user2) }
49
+ subject(:able_to_impersonate) do
50
+ service_instance.send(:able_to_impersonate?, user, user2)
51
+ end
44
52
 
45
53
  context 'having a super admin and any other user' do
46
54
  let!(:user) do
@@ -50,7 +58,7 @@ describe G5Authenticatable::ImpersonateSessionable do
50
58
  end
51
59
  let!(:user2) { FactoryGirl.create(:g5_authenticatable_user) }
52
60
 
53
- it { expect(able_to_impersonate).to eq(true) }
61
+ it { is_expected.to eq(true) }
54
62
  end
55
63
 
56
64
  context 'having an admin' do
@@ -67,7 +75,7 @@ describe G5Authenticatable::ImpersonateSessionable do
67
75
  user
68
76
  end
69
77
 
70
- it { expect(able_to_impersonate).to eq(false) }
78
+ it { is_expected.to eq(false) }
71
79
  end
72
80
 
73
81
  context 'assuming another admin' do
@@ -77,22 +85,37 @@ describe G5Authenticatable::ImpersonateSessionable do
77
85
  user
78
86
  end
79
87
 
80
- it { expect(able_to_impersonate).to eq(true) }
88
+ it { is_expected.to eq(true) }
81
89
  end
82
90
 
83
91
  context 'assuming a regular user' do
84
92
  let!(:user2) { FactoryGirl.create(:g5_authenticatable_user) }
85
93
 
86
- it { expect(able_to_impersonate).to eq(true) }
94
+ it { is_expected.to eq(true) }
87
95
  end
88
96
  end
89
97
 
90
98
  context 'providing no user' do
91
- it { expect(service_instance.send(:able_to_impersonate?, user, nil)).to eq(false) }
99
+ context 'when user to impersonate is nil' do
100
+ let(:user) { FactoryGirl.create(:g5_authenticatable_super_admin) }
101
+ let(:user2) {}
102
+
103
+ it { is_expected.to eq(false) }
104
+ end
92
105
 
93
- it { expect(service_instance.send(:able_to_impersonate?, nil, user)).to eq(false) }
106
+ context 'when signed-in user is nil' do
107
+ let(:user) {}
108
+ let(:user2) { FactoryGirl.create(:g5_authenticatable_user) }
94
109
 
95
- it { expect(service_instance.send(:able_to_impersonate?, nil, nil)).to eq(false) }
110
+ it { is_expected.to eq(false) }
111
+ end
112
+
113
+ context 'when both users are nil' do
114
+ let(:user) {}
115
+ let(:user2) {}
116
+
117
+ it { is_expected.to eq(false) }
118
+ end
96
119
  end
97
120
  end
98
121
 
@@ -101,12 +124,12 @@ describe G5Authenticatable::ImpersonateSessionable do
101
124
 
102
125
  context 'having an existing uid' do
103
126
  let(:uid) { user.uid }
104
- it { expect(user_by_uid).to eq(user) }
127
+ it { is_expected.to eq(user) }
105
128
  end
106
129
 
107
130
  context 'having a no existing uid' do
108
131
  let(:uid) { 'some-random-text' }
109
- it { expect(user_by_uid).to be_nil }
132
+ it { is_expected.to be_nil }
110
133
  end
111
134
  end
112
135
  end
data/spec/spec_helper.rb CHANGED
@@ -1,60 +1,93 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # MUST happen before any other code is loaded
2
4
  require 'simplecov'
3
- SimpleCov.start 'test_frameworks'
5
+ SimpleCov.start 'rails'
6
+
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
4
16
 
5
- require 'codeclimate-test-reporter'
6
- CodeClimate::TestReporter.start
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
7
31
 
8
- ENV["RAILS_ENV"] ||= 'test'
9
- require File.expand_path("../dummy/config/environment", __FILE__)
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
10
40
 
11
- require 'rspec/rails'
12
- require 'capybara/rspec'
13
- require 'webmock/rspec'
14
- require 'g5_authenticatable/rspec'
15
- require 'g5_updatable/rspec'
16
- require 'g5_updatable/factories'
41
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
42
+ # have no way to turn it off -- the option exists only for backwards
43
+ # compatibility in RSpec 3). It causes shared context metadata to be
44
+ # inherited by the metadata hash of host groups and examples, rather than
45
+ # triggering implicit auto-inclusion in groups with matching metadata.
46
+ config.shared_context_metadata_behavior = :apply_to_host_groups
17
47
 
18
- Rails.backtrace_cleaner.remove_silencers!
48
+ # This allows you to limit a spec run to individual examples or groups
49
+ # you care about by tagging them with `:focus` metadata. When nothing
50
+ # is tagged with `:focus`, all examples get run. RSpec also provides
51
+ # aliases for `it`, `describe`, and `context` that include `:focus`
52
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
53
+ config.filter_run_when_matching :focus
19
54
 
20
- # Requires supporting ruby files with custom matchers and macros, etc,
21
- # in spec/support/ and its subdirectories.
22
- Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |f| require f }
55
+ # Allows RSpec to persist some state between runs in order to support
56
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
57
+ # you configure your source control system to ignore this file.
58
+ # config.example_status_persistence_file_path = "spec/examples.txt"
23
59
 
24
- RSpec.configure do |config|
25
- # ## Mock Framework
26
- #
27
- # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
28
- #
29
- # config.mock_with :mocha
30
- # config.mock_with :flexmock
31
- # config.mock_with :rr
32
- config.mock_with :rspec
33
-
34
- # If you're not using ActiveRecord, or you'd prefer not to run each of your
35
- # examples within a transaction, remove the following line or assign false
36
- # instead of true.
37
- config.use_transactional_fixtures = true
38
-
39
- # If true, the base class of anonymous controllers will be inferred
40
- # automatically. This will be the default behavior in future versions of
41
- # rspec-rails.
42
- config.infer_base_class_for_anonymous_controllers = false
60
+ # Limits the available syntax to the non-monkey patched syntax that is
61
+ # recommended. For more details, see:
62
+ # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
63
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
64
+ # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
65
+ config.disable_monkey_patching!
66
+
67
+ # Many RSpec users commonly either run the entire suite or an individual
68
+ # file, and it's useful to allow more verbose output when running an
69
+ # individual spec file.
70
+ if config.files_to_run.one?
71
+ # Use the documentation formatter for detailed output,
72
+ # unless a formatter has already been configured
73
+ # (e.g. via a command-line flag).
74
+ config.default_formatter = 'doc'
75
+ end
76
+
77
+ # Print the 10 slowest examples and example groups at the
78
+ # end of the spec run, to help surface which specs are running
79
+ # particularly slow.
80
+ # config.profile_examples = 10
43
81
 
44
82
  # Run specs in random order to surface order dependencies. If you find an
45
83
  # order dependency and want to debug it, you can fix the order by providing
46
84
  # the seed, which is printed after each run.
47
85
  # --seed 1234
48
- config.order = 'random'
49
-
50
- # These two settings work together to allow you to limit a spec run
51
- # to individual examples or groups you care about by tagging them with
52
- # `:focus` metadata. When nothing is tagged with `:focus`, all examples
53
- # get run.
54
- config.filter_run :focus
55
- config.run_all_when_everything_filtered = true
56
-
57
- config.infer_spec_type_from_file_location!
86
+ config.order = :random
58
87
 
59
- config.after(:suite) { WebMock.disable! }
88
+ # Seed global randomization in this process using the `--seed` CLI option.
89
+ # Setting this allows you to use `--seed` to deterministically reproduce
90
+ # test failures related to randomization by passing the same `--seed` value
91
+ # as the one that triggered the failure.
92
+ Kernel.srand config.seed
60
93
  end