rspeckled 2.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/rspeckled/helpers/factories.rb +8 -2
  4. data/lib/rspeckled/helpers/filepaths.rb +30 -22
  5. data/lib/rspeckled/helpers/null_objects.rb +8 -2
  6. data/lib/rspeckled/helpers/patterns.rb +75 -41
  7. data/lib/rspeckled/helpers/responses.rb +8 -2
  8. data/lib/rspeckled/patches.rb +8 -6
  9. data/lib/rspeckled/plugins/configuration/capybara_screenshot.rb +5 -4
  10. data/lib/rspeckled/plugins/configuration/carrier_wave.rb +1 -1
  11. data/lib/rspeckled/plugins/configuration/devise.rb +4 -4
  12. data/lib/rspeckled/plugins/configuration/dox.rb +4 -4
  13. data/lib/rspeckled/plugins/configuration/email_spec.rb +3 -3
  14. data/lib/rspeckled/plugins/configuration/factory_bot.rb +2 -2
  15. data/lib/rspeckled/plugins/configuration/shoulda.rb +2 -2
  16. data/lib/rspeckled/plugins/configuration/vcr.rb +6 -4
  17. data/lib/rspeckled/plugins/configuration/warden.rb +3 -2
  18. data/lib/rspeckled/plugins/extensions/awesome_print.rb +20 -7
  19. data/lib/rspeckled/plugins/extensions/capybara.rb +16 -6
  20. data/lib/rspeckled/plugins/extensions/faraday/middleware/curl_logger.rb +10 -3
  21. data/lib/rspeckled/plugins/extensions/faraday.rb +2 -1
  22. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/ebay.rb +1 -1
  23. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/facebook.rb +1 -1
  24. data/lib/rspeckled/plugins/extensions/omniauth/mock_authentications/twitter.rb +1 -1
  25. data/lib/rspeckled/plugins/extensions/omniauth.rb +6 -3
  26. data/lib/rspeckled/plugins/extensions/ruby/deferred_garbage_collection.rb +3 -1
  27. data/lib/rspeckled/plugins/extensions/selenium/drivers/chrome.rb +6 -6
  28. data/lib/rspeckled/plugins/extensions/selenium/drivers/firefox.rb +14 -3
  29. data/lib/rspeckled/plugins/extensions/strong_parameters.rb +2 -1
  30. data/lib/rspeckled/plugins/extensions/vcr/matchers/uri_without_trailing_id.rb +3 -1
  31. data/lib/rspeckled/plugins/extensions/vcr.rb +8 -4
  32. data/lib/rspeckled/plugins/hooks/action_mailer.rb +2 -2
  33. data/lib/rspeckled/plugins/hooks/authentication.rb +87 -61
  34. data/lib/rspeckled/plugins/hooks/bullet.rb +3 -1
  35. data/lib/rspeckled/plugins/hooks/capybara.rb +2 -2
  36. data/lib/rspeckled/plugins/hooks/carrier_wave.rb +2 -2
  37. data/lib/rspeckled/plugins/hooks/database_cleaner.rb +2 -2
  38. data/lib/rspeckled/plugins/hooks/devise.rb +1 -1
  39. data/lib/rspeckled/plugins/hooks/dox.rb +1 -1
  40. data/lib/rspeckled/plugins/hooks/elasticsearch.rb +13 -9
  41. data/lib/rspeckled/plugins/hooks/factory_bot.rb +1 -1
  42. data/lib/rspeckled/plugins/hooks/foreign_keys.rb +21 -13
  43. data/lib/rspeckled/plugins/hooks/garbage_collection.rb +1 -1
  44. data/lib/rspeckled/plugins/hooks/rails.rb +5 -3
  45. data/lib/rspeckled/plugins/hooks/redis.rb +3 -3
  46. data/lib/rspeckled/plugins/hooks/referehencible.rb +2 -2
  47. data/lib/rspeckled/plugins/hooks/request.rb +1 -1
  48. data/lib/rspeckled/plugins/hooks/rspec_mocks.rb +8 -4
  49. data/lib/rspeckled/plugins/hooks/selenium_webdriver.rb +2 -2
  50. data/lib/rspeckled/plugins/hooks/sidekiq.rb +14 -12
  51. data/lib/rspeckled/plugins/hooks/singletons.rb +2 -2
  52. data/lib/rspeckled/plugins/hooks/stripe.rb +5 -3
  53. data/lib/rspeckled/plugins/hooks/timecop.rb +3 -3
  54. data/lib/rspeckled/plugins/hooks/vcr.rb +2 -2
  55. data/lib/rspeckled/plugins/hooks/warden.rb +3 -3
  56. data/lib/rspeckled/plugins/hooks/webmock.rb +3 -3
  57. data/lib/rspeckled/plugins.rb +22 -19
  58. data/lib/rspeckled/reporting/example.rb +10 -8
  59. data/lib/rspeckled/reporting/outputs/csv.rb +2 -0
  60. data/lib/rspeckled/reporting/outputs/text.rb +17 -15
  61. data/lib/rspeckled/reporting/runner.rb +26 -24
  62. data/lib/rspeckled/spec_helpers/active_record_connection_setup.rb +13 -9
  63. data/lib/rspeckled/spec_helpers/rails_engine.rb +2 -2
  64. data/lib/rspeckled/spec_helpers/rspeckled.rb +17 -1
  65. data/lib/rspeckled/support.rb +26 -24
  66. data/lib/rspeckled/tasks/documentation.rake +28 -8
  67. data/lib/rspeckled/version.rb +3 -1
  68. data.tar.gz.sig +0 -0
  69. metadata +29 -28
  70. metadata.gz.sig +0 -0
@@ -11,11 +11,17 @@ class Firefox
11
11
  end
12
12
 
13
13
  def driver(app)
14
- ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => options)
14
+ ::Capybara::Selenium::Driver.new(app,
15
+ browser: :firefox,
16
+ profile: profile,
17
+ options: options)
15
18
  end
16
19
 
17
20
  def headless(app)
18
- ::Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile, :options => headless_options)
21
+ ::Capybara::Selenium::Driver.new(app,
22
+ browser: :firefox,
23
+ profile: profile,
24
+ options: headless_options)
19
25
  end
20
26
 
21
27
  private
@@ -30,7 +36,12 @@ class Firefox
30
36
  ::Selenium::WebDriver::Firefox::Profile.new.tap do |profile|
31
37
  profile['browser.download.dir'] = downloads_directory
32
38
  profile['browser.download.folderList'] = 2
33
- profile['browser.helperApps.neverAsk.saveToDisk'] = 'images/jpeg, application/pdf, application/octet-stream'
39
+ profile['browser.helperApps.neverAsk.saveToDisk'] = %w{
40
+ images/jpeg
41
+ application/pdf
42
+ application/octet-stream
43
+ }
44
+ .join(', ')
34
45
  profile['pdfjs.disabled'] = true
35
46
  end
36
47
  end
@@ -3,7 +3,8 @@
3
3
  always_permitted_parameters = %w{id}
4
4
 
5
5
  if ::ActionController::Parameters.respond_to?(:always_permitted_parameters)
6
- ::ActionController::Parameters.always_permitted_parameters += always_permitted_parameters
6
+ ::ActionController::Parameters
7
+ .always_permitted_parameters += always_permitted_parameters
7
8
  else
8
9
  always_permitted_parameters.each do |always_permitted_parameter|
9
10
  ::ActionController::Parameters::NEVER_UNPERMITTED_PARAMS << always_permitted_parameter
@@ -16,7 +16,9 @@ class UriWithoutTrailingId
16
16
 
17
17
  if request_uri.match?(trailing_id_matcher)
18
18
  request_uri_without_id = request_uri.sub(trailing_id_matcher, '')
19
- vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub(trailing_id_matcher, '')
19
+ vcr_cassette_request_uri_without_id = vcr_cassette_request_uri.sub(
20
+ trailing_id_matcher, ''
21
+ )
20
22
 
21
23
  request_uri.match(trailing_id_matcher) &&
22
24
  vcr_cassette_request_uri.match(trailing_id_matcher) &&
@@ -3,11 +3,15 @@
3
3
  require 'rspeckled/plugins/extensions/vcr/matchers/uri_without_trailing_id'
4
4
 
5
5
  ::VCR.configure do |config|
6
- config.register_request_matcher :uri_without_trailing_guid do |request, vcr_cassette_request|
7
- ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId.new(%r(/[a-f0-9\-]{32,36}/?\z)).call(request, vcr_cassette_request)
6
+ config.register_request_matcher :uri_without_trailing_guid do |request, vcr_request|
7
+ ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId
8
+ .new(%r(/[a-f0-9\-]{32,36}/?\z))
9
+ .call(request, vcr_request)
8
10
  end
9
11
 
10
- config.register_request_matcher :uri_without_trailing_id do |request, vcr_cassette_request|
11
- ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId.new(%r{/\d+/?\z}).call(request, vcr_cassette_request)
12
+ config.register_request_matcher :uri_without_trailing_id do |request, vcr_request|
13
+ ::Rspeckled::Vcr::Matchers::UriWithoutTrailingId
14
+ .new(%r{/\d+/?\z})
15
+ .call(request, vcr_request)
12
16
  end
13
17
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:each, :email => true) do
3
+ ::RSpec.configure do |config|
4
+ config.before(:each, email: true) do
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  if ::ActionMailer::Base.delivery_method == :cache
@@ -1,29 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :authentication => lambda { |v| !!v }) do |example|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, authentication: ->(v) { !v.nil? }) do |example| # rubocop:disable Metrics/BlockLength
5
6
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
7
 
7
- options = if example.metadata[:authentication].is_a?(::Hash)
8
- example.metadata[:authentication]
9
- else
10
- {
11
- :token => {
12
- :roles => example.metadata[:authentication],
13
- },
14
- }
15
- end
16
-
17
- options[:class] ||= described_class
18
- .name[/\A([^:]+)::/, 1]
19
- .concat('::User')
20
- .constantize
21
-
22
- class_name_underscored = options[:class]
23
- .name[/(?:.*::)?(\w+)\z/, 1]
24
- .gsub(/([a-z])([A-Z])/, '\1_\2')
25
- .downcase
26
- defaults = {
8
+ options = if example.metadata[:authentication].is_a?(::Hash)
9
+ example.metadata[:authentication]
10
+ else
11
+ {
12
+ token: {
13
+ roles: example.metadata[:authentication],
14
+ },
15
+ }
16
+ end
17
+
18
+ options[:class] ||= described_class
19
+ .name[/\A([^:]+)::/, 1]
20
+ .concat('::User')
21
+ .constantize
22
+
23
+ class_name_underscored = options[:class]
24
+ .name[/(?:.*::)?(\w+)\z/, 1]
25
+ .gsub(/([a-z])([A-Z])/, '\1_\2')
26
+ .downcase
27
+ defaults = {
27
28
  :type => :json_web_token,
28
29
  :authentication_method => :"authenticate_#{class_name_underscored}!",
29
30
  :class_instance_overrides => {},
@@ -32,56 +33,80 @@ RSpec.configure do |config|
32
33
  :strategy => :factory,
33
34
  :successful? => true,
34
35
  :token => {
35
- :roles => 'standard',
36
+ roles: 'standard',
36
37
  },
37
38
  }
38
39
 
39
- options = defaults.deep_merge(options)
40
- instance = case options[:strategy]
41
- when :factory
42
- ::FactoryBot.create(class_name_underscored.to_sym, *options[:class_instance_traits], options[:class_instance_overrides])
43
- when :instance
44
- options[:class].new(options[:class_instance_overrides])
45
- end
46
- authentication_result = options[:successful?] ? instance : nil
40
+ options = defaults.deep_merge(options)
41
+ instance = case options[:strategy]
42
+ when :factory
43
+ ::FactoryBot.create(
44
+ class_name_underscored.to_sym,
45
+ *options[:class_instance_traits],
46
+ options[:class_instance_overrides],
47
+ )
48
+ when :instance
49
+ options[:class].new(options[:class_instance_overrides])
50
+ end
51
+ authentication_result = options[:successful?] ? instance : nil
47
52
 
48
53
  case options[:type]
49
54
  when :standard
50
- authentication_controller_class = (example.metadata[:type] == :controller) ? described_class : ApplicationController
51
- authentication_controller_instance = authentication_controller_class.new
52
- authentication_method = if authentication_controller_instance.respond_to?(options[:authentication_method], true)
53
- options[:authentication_method]
54
- elsif authentication_controller_instance.respond_to?(:authenticate, true)
55
- :authenticate
56
- end
57
-
58
- authentication_controller_class.__send__(:define_method, authentication_method) { options[:successful?] }
59
- authentication_controller_class.__send__(:define_method, options[:method]) { authentication_result }
55
+ authentication_controller_class = if example.metadata[:type] == :controller
56
+ described_class
57
+ else
58
+ ApplicationController
59
+ end
60
+ authentication_controller_instance = authentication_controller_class.new
61
+ authentication_method = if authentication_controller_instance
62
+ .respond_to?(
63
+ options[:authentication_method],
64
+ true,
65
+ )
66
+
67
+ options[:authentication_method]
68
+ elsif authentication_controller_instance
69
+ .respond_to?(:authenticate, true)
70
+
71
+ :authenticate
72
+ end
73
+
74
+ authentication_controller_class.__send__(:define_method, authentication_method) do
75
+ options[:successful?]
76
+ end
77
+
78
+ authentication_controller_class.__send__(:define_method, options[:method]) do
79
+ authentication_result
80
+ end
81
+
60
82
  authentication_controller_class.__send__(:helper_method, options[:method])
61
- example.example_group_instance.class.let(options[:method]) { authentication_result }
83
+ example.example_group_instance.class.let(options[:method]) { authentication_result }
62
84
 
63
85
  example.run
64
86
 
65
87
  authentication_controller_class.__send__(:remove_method, options[:method])
66
88
  when :json_web_token
67
- @token_data = [
68
- {
69
- 'aid' => options[:token][:audience_id] || instance['account_id'] || instance['id'],
70
- 'aud' => options[:token][:audience] || instance.class.name,
71
- 'exp' => options[:token][:expired_at] || 1.day.from_now.utc.to_i,
72
- 'iat' => options[:token][:issued_at] || ::Time.now.utc.to_i,
73
- 'iss' => options[:token][:issuer] || 'rspeckled',
74
- 'jti' => options[:token][:token_id] || ::SecureRandom.uuid,
75
- 'nbf' => options[:token][:not_before] || 1.day.ago.utc.to_i,
76
- 'rol' => options[:token][:roles] || 'standard',
77
- 'sid' => options[:token][:subject_id],
78
- 'sub' => options[:token][:subject],
79
- },
80
- {
81
- 'typ' => 'JWT',
82
- 'cty' => 'application/json-web-token',
83
- },
84
- ]
89
+ @token_data =
90
+ [
91
+ {
92
+ 'aid' => options[:token][:audience_id] ||
93
+ instance['account_id'] ||
94
+ instance['id'],
95
+ 'aud' => options[:token][:audience] || instance.class.name,
96
+ 'exp' => options[:token][:expired_at] || 1.day.from_now.utc.to_i,
97
+ 'iat' => options[:token][:issued_at] || ::Time.now.utc.to_i,
98
+ 'iss' => options[:token][:issuer] || 'rspeckled',
99
+ 'jti' => options[:token][:token_id] || ::SecureRandom.uuid,
100
+ 'nbf' => options[:token][:not_before] || 1.day.ago.utc.to_i,
101
+ 'rol' => options[:token][:roles] || 'standard',
102
+ 'sid' => options[:token][:subject_id],
103
+ 'sub' => options[:token][:subject],
104
+ },
105
+ {
106
+ 'typ' => 'JWT',
107
+ 'cty' => 'application/json-web-token',
108
+ },
109
+ ]
85
110
 
86
111
  example.example_group_instance.class.let(options[:method]) { authentication_result }
87
112
 
@@ -93,7 +118,7 @@ RSpec.configure do |config|
93
118
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
94
119
  end
95
120
 
96
- config.before(:each, :authentication => lambda { |v| !!v }) do |_example|
121
+ config.before(:each, authentication: ->(v) { !v.nil? }) do |_example|
97
122
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
98
123
 
99
124
  request.env['X_JSON_WEB_TOKEN'] = @token_data
@@ -101,3 +126,4 @@ RSpec.configure do |config|
101
126
  config.rspeckled_logger.debug("Before Each - End - #{__FILE__}")
102
127
  end
103
128
  end
129
+ # rubocop:enable Metrics/BlockNesting
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config|
4
5
  config.before(:each) do
5
6
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
7
 
@@ -20,3 +21,4 @@ RSpec.configure do |config|
20
21
  config.rspeckled_logger.debug("After Each - End - #{__FILE__}")
21
22
  end
22
23
  end
24
+ # rubocop:enable Metrics/BlockNesting
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :js => true) do
4
+ config.before(:each, js: true) do
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  page.driver.reset!
@@ -10,7 +10,7 @@ RSpec.configure do |config|
10
10
  end
11
11
 
12
12
  # Focus The Browser on Activation
13
- config.around(:each, :js => true, :autofocus => true) do |example|
13
+ config.around(:each, js: true, autofocus: true) do |example|
14
14
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
15
15
 
16
16
  browser_name = example.metadata[:driver].to_s.capitalize
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :file_attachment => true) do |example|
3
+ ::RSpec.configure do |config|
4
+ config.around(:each, file_attachment: true) do |example|
5
5
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
6
 
7
7
  previous_carrierwave_processing_mode = subject.class.enable_processing
@@ -4,7 +4,7 @@ RSpec.configure do |config|
4
4
  config.before(:suite) do
5
5
  config.rspeckled_logger.debug("Before Suite - Start - #{__FILE__}")
6
6
 
7
- ::DatabaseCleaner.clean_with(:truncation, :except => %w{ar_internal_metadata})
7
+ ::DatabaseCleaner.clean_with(:truncation, except: %w{ar_internal_metadata})
8
8
 
9
9
  config.rspeckled_logger.debug("Before Suite - End - #{__FILE__}")
10
10
  end
@@ -13,7 +13,7 @@ RSpec.configure do |config|
13
13
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
14
14
 
15
15
  ::DatabaseCleaner.strategy = if example.metadata[:js]
16
- [:truncation, :except => %w{ar_internal_metadata}]
16
+ [:truncation, { except: %w{ar_internal_metadata} }]
17
17
  else
18
18
  :transaction
19
19
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :type => :controller) do |_example|
4
+ config.before(:each, type: :controller) do |_example|
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  @request.env['devise.mapping'] = ::Devise.mappings[:user]
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ ::RSpec.configure do |config|
4
4
  config.after(:each, :dox) do |example|
5
5
  example.metadata[:request] = request
6
6
  example.metadata[:response] = response
@@ -1,15 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:all, :elasticsearch => lambda { |v| !!v }) do
3
+ ::RSpec.configure do |config|
4
+ config.before(:all, elasticsearch: ->(v) { !v.nil? }) do
5
5
  config.rspeckled_logger.debug("Before All - Start - #{__FILE__}")
6
6
 
7
- ::Elasticsearch::Extensions::Test::Cluster.start(:port => 9200) unless ::Elasticsearch::Extensions::Test::Cluster.running?
7
+ unless ::Elasticsearch::Extensions::Test::Cluster.running?
8
+ ::Elasticsearch::Extensions::Test::Cluster.start(port: 9200)
9
+ end
8
10
 
9
11
  config.rspeckled_logger.debug("Before All - End - #{__FILE__}")
10
12
  end
11
13
 
12
- config.around(:each, :elasticsearch => lambda { |v| !!v }) do |example|
14
+ config.around(:each, elasticsearch: ->(v) { !v.nil? }) do |example|
13
15
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
14
16
 
15
17
  model = case example.metadata[:elasticsearch]
@@ -17,20 +19,22 @@ RSpec.configure do |config|
17
19
  example.metadata[:elasticsearch].constantize
18
20
  end
19
21
 
20
- model.__elasticsearch__.client.indices.delete :index => '_all'
21
- model.__elasticsearch__.create_index! :index => model.index_name
22
+ model.__elasticsearch__.client.indices.delete index: '_all'
23
+ model.__elasticsearch__.create_index! index: model.index_name
22
24
 
23
25
  example.run
24
26
 
25
- model.__elasticsearch__.client.indices.delete :index => '_all'
27
+ model.__elasticsearch__.client.indices.delete index: '_all'
26
28
 
27
29
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
28
30
  end
29
31
 
30
- config.after(:all, :elasticsearch => lambda { |v| !!v }) do
32
+ config.after(:all, elasticsearch: ->(v) { !v.nil? }) do
31
33
  config.rspeckled_logger.debug("After All - Start - #{__FILE__}")
32
34
 
33
- ::Elasticsearch::Extensions::Test::Cluster.stop(:port => 9200) if ::Elasticsearch::Extensions::Test::Cluster.running?
35
+ if ::Elasticsearch::Extensions::Test::Cluster.running?
36
+ ::Elasticsearch::Extensions::Test::Cluster.stop(port: 9200)
37
+ end
34
38
 
35
39
  config.rspeckled_logger.debug("After All - End - #{__FILE__}")
36
40
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
3
+ ::RSpec.configure do |config|
4
4
  config.before(:suite) do
5
5
  config.rspeckled_logger.debug("Before Suite - Start - #{__FILE__}")
6
6
 
@@ -1,22 +1,23 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :disable_foreign_keys => lambda { |v| !!v }) do |example|
3
+ # rubocop:disable Metrics/BlockNesting
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, disable_foreign_keys: ->(v) { !v.nil? }) do |example| # rubocop:disable Metrics/BlockLength
5
6
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
7
 
7
8
  options = example.metadata[:disable_foreign_keys]
8
9
  options = case options
9
10
  when ::Array
10
- { :tables => options.map(&:to_s) }
11
+ { tables: options.map(&:to_s) }
11
12
  when ::String, ::Symbol
12
- { :tables => [options.to_s] }
13
+ { tables: [options.to_s] }
13
14
  when ::FalseClass
14
- { :tables => [] }
15
+ { tables: [] }
15
16
  when ::TrueClass
16
- { :tables => :all }
17
+ { tables: :all }
17
18
  end
18
19
 
19
- foreign_key_trigger_disable_statements_sql = <<~HEREDOC
20
+ foreign_key_disable_sql = <<~HEREDOC
20
21
  SELECT
21
22
  'ALTER TABLE "' || "pg_namespace"."nspname" || '"."' || "pg_class"."relname" || '" DISABLE TRIGGER "' || "pg_trigger"."tgname" || '";' AS "statement"
22
23
  FROM
@@ -38,22 +39,28 @@ RSpec.configure do |config|
38
39
  HEREDOC
39
40
 
40
41
  unless options[:tables] == :all
41
- foreign_key_trigger_disable_statements_sql += " AND\n "
42
+ foreign_key_disable_sql += " AND\n "
42
43
 
43
44
  table_constraint_sql = options[:tables]
44
45
  .map { |table_name| "'#{table_name}'" }
45
46
  .join(', ')
46
47
 
47
- foreign_key_trigger_disable_statements_sql += %Q{ "pg_class"."relname" IN (#{table_constraint_sql})}
48
+ foreign_key_disable_sql += %Q{ "pg_class"."relname" IN (#{table_constraint_sql})}
48
49
  end
49
50
 
50
- foreign_key_trigger_disable_statements = ::ActiveRecord::Base.connection.select_values(foreign_key_trigger_disable_statements_sql).join(' ')
51
+ foreign_key_disable = ::ActiveRecord::Base
52
+ .connection
53
+ .select_values(foreign_key_disable_sql)
54
+ .join(' ')
51
55
 
52
56
  ::ActiveRecord::Base.transaction do
53
- if foreign_key_trigger_disable_statements.blank?
54
- puts 'You asked to disable foreign keys but there were no foreign keys found to disable'
57
+ if foreign_key_disable.blank?
58
+ puts(<<~HEREDOC).tr("\n", ' ')
59
+ You asked to disable foreign keys but there were no foreign keys found
60
+ to disable
61
+ HEREDOC
55
62
  else
56
- ::ActiveRecord::Base.connection.execute(foreign_key_trigger_disable_statements)
63
+ ::ActiveRecord::Base.connection.execute(foreign_key_disable)
57
64
  end
58
65
 
59
66
  example.run
@@ -62,3 +69,4 @@ RSpec.configure do |config|
62
69
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}")
63
70
  end
64
71
  end
72
+ # rubocop:enable Metrics/BlockNesting
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'rspeckled/plugins/extensions/ruby/deferred_garbage_collection'
4
4
 
5
- RSpec.configure do |config|
5
+ ::RSpec.configure do |config|
6
6
  config.before(:all) do
7
7
  config.rspeckled_logger.debug("Before All - Start - #{__FILE__}")
8
8
 
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :debug => true) do |example|
3
+ # rubocop:disable Layout/LineLength
4
+ ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength
5
+ config.around(:each, debug: true) do |example| # rubocop:disable Metrics/BlockLength
5
6
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
7
 
7
- debug_rails_logger = ::ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new($stdout))
8
+ debug_rails_logger = ::ActiveSupport::TaggedLogging.new(::ActiveSupport::Logger.new($stdout))
8
9
  debug_rails_logger.level = :debug
9
10
 
10
11
  current_rails_configuration_logger = ::Rails.configuration.logger
@@ -48,3 +49,4 @@ RSpec.configure do |config|
48
49
  config.rspeckled_logger.debug("Around Each - End - #{__FILE__}") if defined?(config)
49
50
  end
50
51
  end
52
+ # rubocop:enable Layout/LineLength
@@ -1,17 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :cache => lambda { |v| !!v }) do |example|
4
+ config.before(:each, cache: ->(v) { !v.nil? }) do |example|
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  cache_metadata = example.metadata[:cache]
8
8
 
9
9
  # rubocop:disable Metrics/BlockNesting
10
10
  if cache_metadata[:reset]
11
- client = ::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 2) # rubocop:disable Style/IpAddresses
11
+ client = ::Redis.new(host: '127.0.0.1', port: 6379, db: 2)
12
12
  reset_patterns = Array(cache_metadata[:reset])
13
13
 
14
- client.keys.each do |key|
14
+ client.each_key do |key|
15
15
  next unless reset_patterns.any? { |regex| key.match?(regex) }
16
16
 
17
17
  client.del(key)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.before(:each, :mock_refs => lambda { |v| !!v }) do |example|
3
+ ::RSpec.configure do |config|
4
+ config.before(:each, mock_refs: ->(v) { !v.nil? }) do |example|
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  reference = if example.metadata[:mock_refs].is_a? ::TrueClass
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  RSpec.configure do |config|
4
- config.before(:each, :type => :controller) do
4
+ config.before(:each, type: :controller) do
5
5
  config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}")
6
6
 
7
7
  request.headers['accept'] = 'application/json'
@@ -1,11 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :verify => false) do |example|
3
+ ::RSpec.configure do |config|
4
+ config.around(:each, verify: false) do |example|
5
5
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
6
 
7
- verify_partial = ::RSpec::Mocks.configuration.instance_variable_get(:@verify_partial_doubles)
8
- verify_constant = ::RSpec::Mocks.configuration.instance_variable_get(:@verify_doubled_constant_names)
7
+ verify_partial = ::RSpec::Mocks
8
+ .configuration
9
+ .instance_variable_get(:@verify_partial_doubles)
10
+ verify_constant = ::RSpec::Mocks
11
+ .configuration
12
+ .instance_variable_get(:@verify_doubled_constant_names)
9
13
 
10
14
  ::RSpec::Mocks.configuration.verify_partial_doubles = example.metadata[:verify]
11
15
  ::RSpec::Mocks.configuration.verify_doubled_constant_names = example.metadata[:verify]
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- RSpec.configure do |config|
4
- config.around(:each, :js => true, :debug => true) do |example|
3
+ ::RSpec.configure do |config|
4
+ config.around(:each, js: true, debug: true) do |example|
5
5
  config.rspeckled_logger.debug("Around Each - Start - #{__FILE__}")
6
6
 
7
7
  ::Selenium::WebDriver.logger.level = :debug