diff --git a/.rubocop.yml b/.rubocop.yml index 1bb990a9f..7a89ddfdc 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,11 +11,14 @@ AllCops: - 'tmp/**/*' - 'bin/**/*' - 'vendor/bundle/**/*' - TargetRubyVersion: 2.0 + TargetRubyVersion: 2.6 # DefaultFormatter: fuubar Style/Alias: Enabled: false +Style/SymbolArray: + EnforcedStyle: brackets + Style/Documentation: Enabled: false @@ -42,14 +45,20 @@ Metrics/LineLength: Style/RegexpLiteral: EnforcedStyle: mixed -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: consistent_comma + +Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: consistent_comma RSpec/InstanceVariable: Enabled: false -Style/AccessorMethodName: - Enabled: false +RSpec/MultipleExpectations: + Max: 20 + +RSpec/NestedGroups: + Max: 5 Lint/HandleExceptions: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2b53afe35..1f42a6adc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,17 +1,14 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2016-11-20 15:49:33 +0000 using RuboCop version 0.45.0. +# on 2019-09-13 08:15:02 -0400 using RuboCop version 0.74.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -require: rubocop-rspec - -# Offense count: 2 +# Offense count: 1 Lint/AmbiguousRegexpLiteral: Exclude: - - 'lib/flipper/instrumentation/metriks.rb' - 'lib/flipper/instrumentation/statsd.rb' # Offense count: 6 @@ -23,24 +20,21 @@ Lint/AssignmentInCondition: - 'lib/flipper/feature.rb' - 'lib/flipper/gate_values.rb' -# Offense count: 1 -Lint/Eval: +# Offense count: 2 +Lint/DuplicateMethods: Exclude: - - 'flipper.gemspec' + - 'lib/flipper/ui.rb' + - 'lib/flipper/ui/configuration.rb' -# Offense count: 3 -Lint/HandleExceptions: +# Offense count: 1 +# Configuration parameters: MaximumRangeSize. +Lint/MissingCopEnableDirective: Exclude: - - 'spec/flipper/adapters/mongo_spec.rb' - - 'test/adapters/mongo_test.rb' - - 'test/helper.rb' + - 'lib/flipper/test/shared_adapter_test.rb' -# Offense count: 24 +# Offense count: 21 Lint/ShadowingOuterLocalVariable: Exclude: - - 'lib/flipper/adapters/active_record.rb' - - 'lib/flipper/adapters/instrumented.rb' - - 'lib/flipper/adapters/sequel.rb' - 'spec/flipper/api/v1/actions/actors_gate_spec.rb' - 'spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb' - 'spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb' @@ -48,70 +42,179 @@ Lint/ShadowingOuterLocalVariable: - 'spec/flipper/feature_spec.rb' - 'spec/flipper/types/group_spec.rb' -# Offense count: 26 +# Offense count: 27 Lint/UselessAssignment: Exclude: - 'lib/flipper/instrumentation/log_subscriber.rb' - 'lib/flipper/instrumentation/subscriber.rb' - - 'lib/flipper/ui/actions/groups_gate.rb' - 'spec/flipper/api/action_spec.rb' - 'spec/flipper/dsl_spec.rb' - 'spec/flipper/feature_spec.rb' - 'spec/flipper/gates/group_spec.rb' - - 'spec/flipper/instrumentation/metriks_subscriber_spec.rb' - 'spec/flipper/instrumentation/statsd_subscriber_spec.rb' - - 'spec/flipper_spec.rb' - 'spec/flipper/middleware/memoizer_spec.rb' - - 'test/helper.rb' + - 'spec/flipper_spec.rb' -# Offense count: 27 +# Offense count: 35 Metrics/AbcSize: - Max: 30 + Max: 29 -# Offense count: 1 -# Configuration parameters: CountComments. +# Offense count: 137 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: - Max: 195 + Max: 683 -# Offense count: 4 +# Offense count: 11 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 178 + Max: 150 -# Offense count: 39 -# Configuration parameters: CountComments. +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Metrics/LineLength: + Max: 111 + +# Offense count: 59 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 23 -# Offense count: 65 +# Offense count: 18 +Naming/AccessorMethodName: + Enabled: false + +# Offense count: 25 +Naming/ConstantName: + Exclude: + - 'lib/flipper.rb' + - 'lib/flipper/adapters/active_support_cache_store.rb' + - 'lib/flipper/adapters/dalli.rb' + - 'lib/flipper/adapters/instrumented.rb' + - 'lib/flipper/adapters/memoizable.rb' + - 'lib/flipper/adapters/memory.rb' + - 'lib/flipper/adapters/mongo.rb' + - 'lib/flipper/adapters/operation_logger.rb' + - 'lib/flipper/adapters/pstore.rb' + - 'lib/flipper/adapters/redis.rb' + - 'lib/flipper/adapters/redis_cache.rb' + - 'lib/flipper/feature.rb' + - 'lib/flipper/gate_values.rb' + - 'lib/flipper/typecast.rb' + - 'lib/flipper/ui/decorators/feature.rb' + +# Offense count: 9 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/flipper-active_record.rb' + - 'lib/flipper-active_support_cache_store.rb' + - 'lib/flipper-api.rb' + - 'lib/flipper-cloud.rb' + - 'lib/flipper-dalli.rb' + - 'lib/flipper-mongo.rb' + - 'lib/flipper-redis.rb' + - 'lib/flipper-sequel.rb' + - 'lib/flipper-ui.rb' + +# Offense count: 3 +RSpec/BeforeAfterAll: + Exclude: + - 'spec/spec_helper.rb' + - 'spec/rails_helper.rb' + - 'spec/support/**/*.rb' + - 'spec/flipper/adapters/active_record_spec.rb' + - 'spec/flipper/adapters/http_spec.rb' + +# Offense count: 45 +# Configuration parameters: Prefixes. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/flipper/adapters/http_spec.rb' + - 'spec/flipper/api/v1/actions/feature_spec.rb' + - 'spec/flipper/api/v1/actions/features_spec.rb' + - 'spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb' + - 'spec/flipper/cloud_spec.rb' + - 'spec/flipper/feature_spec.rb' + - 'spec/flipper/gates/group_spec.rb' + - 'spec/flipper/instrumentation/log_subscriber_spec.rb' + - 'spec/flipper/middleware/memoizer_spec.rb' + - 'spec/flipper/registry_spec.rb' + - 'spec/flipper/ui/actions/actors_gate_spec.rb' + - 'spec/flipper/ui/actions/features_spec.rb' + - 'spec/flipper/ui/actions/groups_gate_spec.rb' + +# Offense count: 1 +# Configuration parameters: CustomIncludeMethods. +RSpec/EmptyExampleGroup: + Exclude: + - 'spec/flipper/gates/actor_spec.rb' + +# Offense count: 137 # Configuration parameters: Max. RSpec/ExampleLength: Enabled: false -# Offense count: 2 -# Configuration parameters: CustomTransform. +# Offense count: 1 +# Configuration parameters: CustomTransform, IgnoreMethods. RSpec/FilePath: Exclude: - 'spec/flipper/adapters/pstore_spec.rb' - - 'spec/integration_spec.rb' -# Offense count: 91 -RSpec/InstanceVariable: +# Offense count: 4 +RSpec/IteratedExpectation: Exclude: - - 'spec/flipper/adapters/operation_logger_spec.rb' - 'spec/flipper/dsl_spec.rb' - 'spec/flipper/feature_spec.rb' + - 'spec/flipper/gates/percentage_of_actors_spec.rb' + - 'spec/flipper/registry_spec.rb' + +# Offense count: 16 +# Configuration parameters: . +# SupportedStyles: have_received, receive +RSpec/MessageSpies: + EnforcedStyle: receive + +# Offense count: 34 +# Configuration parameters: AggregateFailuresByDefault. +RSpec/MultipleExpectations: + Max: 20 + +# Offense count: 449 +# Configuration parameters: IgnoreSharedExamples. +RSpec/NamedSubject: + Enabled: false + +# Offense count: 7 +RSpec/NestedGroups: + Max: 5 + +# Offense count: 2 +RSpec/RepeatedDescription: + Exclude: + - 'spec/flipper/gates/boolean_spec.rb' + +# Offense count: 2 +RSpec/RepeatedExample: + Exclude: + - 'spec/flipper/cloud_spec.rb' + +# Offense count: 1 +RSpec/ScatteredLet: + Exclude: - 'spec/flipper/instrumentation/log_subscriber_spec.rb' - - 'spec/flipper/ui/actions/add_feature_spec.rb' - - 'spec/flipper/ui/actions/features_spec.rb' - - 'spec/flipper/ui/decorators/feature_spec.rb' - - 'spec/flipper/ui/decorators/gate_spec.rb' - - 'spec/flipper/ui_spec.rb' - - 'spec/flipper_spec.rb' - - 'spec/integration_spec.rb' -# Offense count: 15 -# Configuration parameters: IgnoreSymbolicNames. +# Offense count: 4 +RSpec/SubjectStub: + Exclude: + - 'spec/flipper/adapters/sync_spec.rb' + +# Offense count: 17 +# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/flipper/api/v1/actions/features_spec.rb' @@ -121,22 +224,24 @@ RSpec/VerifiedDoubles: - 'spec/flipper_spec.rb' - 'spec/integration_spec.rb' -# Offense count: 2 -Style/AccessorMethodName: +# Offense count: 1 +Security/Eval: Exclude: - - 'lib/flipper/adapters/memory.rb' - - 'lib/flipper/adapters/pstore.rb' + - 'flipper.gemspec' -# Offense count: 7 -Style/ConstantName: +# Offense count: 5 +Security/MarshalLoad: Exclude: - - 'lib/flipper.rb' - - 'lib/flipper/adapters/dalli.rb' - - 'lib/flipper/adapters/memoizable.rb' - - 'lib/flipper/adapters/memory.rb' - - 'lib/flipper/adapters/mongo.rb' - - 'lib/flipper/adapters/pstore.rb' - - 'lib/flipper/adapters/redis.rb' + - 'lib/flipper/adapters/redis_cache.rb' + - 'spec/flipper/adapters/redis_cache_spec.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyle. +# SupportedStyles: inline, group +Style/AccessModifierDeclarations: + Exclude: + - 'lib/flipper/api/action.rb' + - 'lib/flipper/ui/action.rb' # Offense count: 3 Style/DoubleNegation: @@ -145,55 +250,45 @@ Style/DoubleNegation: - 'lib/flipper/gates/boolean.rb' - 'lib/flipper/typecast.rb' -# Offense count: 7 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts. -Style/FileName: - Exclude: - - 'lib/flipper-active_record.rb' - - 'lib/flipper-api.rb' - - 'lib/flipper-active_support_cache_store.rb' - - 'lib/flipper-cloud.rb' - - 'lib/flipper-dalli.rb' - - 'lib/flipper-mongo.rb' - - 'lib/flipper-redis.rb' - - 'lib/flipper-sequel.rb' - - 'lib/flipper-ui.rb' - # Offense count: 2 -# Configuration parameters: EnforcedStyle, SupportedStyles. +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle. # SupportedStyles: format, sprintf, percent Style/FormatString: Exclude: - 'lib/flipper/instrumentation/log_subscriber.rb' -# Offense count: 10 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Exclude: - - 'lib/flipper/api/v1/actions/percentage_of_actors_gate.rb' - - 'lib/flipper/api/v1/actions/percentage_of_time_gate.rb' - - 'lib/flipper/gate_values.rb' - - 'lib/flipper/instrumentation/statsd_subscriber.rb' - - 'lib/flipper/instrumentation/subscriber.rb' - - 'lib/flipper/registry.rb' - - 'lib/flipper/typecast.rb' +# Offense count: 2 +# Configuration parameters: . +# SupportedStyles: annotated, template, unannotated +Style/FormatStringToken: + EnforcedStyle: unannotated # Offense count: 1 +# Configuration parameters: AllowIfModifier. Style/IfInsideElse: Exclude: - 'lib/flipper/gates/actor.rb' # Offense count: 1 -Style/MethodMissing: +Style/MethodMissingSuper: Exclude: - 'lib/flipper/types/actor.rb' -Style/AccessorMethodName: +# Offense count: 1 +Style/MissingRespondToMissing: Exclude: - - 'lib/flipper/adapter.rb' - - 'lib/flipper/adapters/http.rb' - - 'lib/flipper/adapters/instrumented.rb' - - 'lib/flipper/adapters/memoizable.rb' - - 'lib/flipper/adapters/operation_logger.rb' - - 'lib/flipper/adapters/memory.rb' - - 'lib/flipper/adapters/pstore.rb' + - 'lib/flipper/types/actor.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/flipper/api/v1/actions/percentage_of_actors_gate.rb' + - 'lib/flipper/api/v1/actions/percentage_of_time_gate.rb' + - 'lib/flipper/gates/percentage_of_actors.rb' + - 'lib/flipper/gates/percentage_of_time.rb' + - 'lib/flipper/types/percentage.rb' diff --git a/Gemfile b/Gemfile index 1dd7cc17b..6de5ff79d 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec name: 'flipper' @@ -6,25 +8,25 @@ Dir['flipper-*.gemspec'].each do |gemspec| gemspec(name: "flipper-#{plugin}", development_group: plugin) end +gem 'minitest', '~> 5.8' gem 'pry' -gem 'rake', '~> 12.3.3' -gem 'shotgun', '~> 0.9' -gem 'statsd-ruby', '~> 1.2.1' -gem 'rspec', '~> 3.0' gem 'rack-test', '~> 0.6.3' -gem 'sqlite3', "~> #{ENV['SQLITE3_VERSION'] || '1.3.11'}" gem 'rails', "~> #{ENV['RAILS_VERSION'] || '6.0.0'}" -gem 'minitest', '~> 5.8' -gem 'rubocop', '~> 0.45.0' +gem 'rake', '~> 12.3.3' +gem 'rspec', '~> 3.0' +gem 'rubocop' gem 'rubocop-rspec' +gem 'shotgun', '~> 0.9' +gem 'sqlite3', "~> #{ENV['SQLITE3_VERSION'] || '1.3.11'}" +gem 'statsd-ruby', '~> 1.2.1' gem 'webmock', '~> 3.0' group(:guard) do gem 'guard', '~> 2.15' - gem 'guard-rubocop', '~> 1.3' - gem 'guard-rspec', '~> 4.5' gem 'guard-bundler', '~> 2.2' gem 'guard-coffeescript', '~> 2.0' + gem 'guard-rspec', '~> 4.5' + gem 'guard-rubocop', '~> 1.3' gem 'guard-sass', '~> 1.6' gem 'rb-fsevent', '~> 0.9' end diff --git a/Guardfile b/Guardfile index b33cd0568..f6c92c071 100644 --- a/Guardfile +++ b/Guardfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # A sample Guardfile # More info at https://github.com/guard/guard#readme diff --git a/Rakefile b/Rakefile old mode 100644 new mode 100755 index 89b55e785..d97a183d5 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,7 @@ #!/usr/bin/env rake -$LOAD_PATH.push File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +$LOAD_PATH.push File.expand_path('lib', __dir__) require 'rake/testtask' require 'flipper/version' @@ -25,19 +27,19 @@ end require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |t| - t.rspec_opts = %w(--color) + t.rspec_opts = %w[--color] end namespace :spec do desc 'Run specs for UI queue' RSpec::Core::RakeTask.new(:ui) do |t| - t.rspec_opts = %w(--color) + t.rspec_opts = %w[--color] t.pattern = ['spec/flipper/ui/**/*_spec.rb', 'spec/flipper/ui_spec.rb'] end end Rake::TestTask.new do |t| - t.libs = %w(lib test) + t.libs = %w[lib test] t.pattern = 'test/**/*_test.rb' end diff --git a/flipper-active_record.gemspec b/flipper-active_record.gemspec index 2b0de34f4..0e0f5cfbc 100644 --- a/flipper-active_record.gemspec +++ b/flipper-active_record.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_active_record_files = lambda do |file| file =~ /active_record/ @@ -25,6 +27,6 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" gem.add_dependency 'activerecord', '>= 4.2', '< 7' + gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" end diff --git a/flipper-active_support_cache_store.gemspec b/flipper-active_support_cache_store.gemspec index 8efa1bb98..db39372d8 100644 --- a/flipper-active_support_cache_store.gemspec +++ b/flipper-active_support_cache_store.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_active_support_cache_store_files = lambda do |file| file =~ /active_support_cache_store/ @@ -21,6 +23,6 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" gem.add_dependency 'activesupport', '>= 4.2', '< 7' + gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" end diff --git a/flipper-api.gemspec b/flipper-api.gemspec index c7a9c48c5..1380aa2f6 100644 --- a/flipper-api.gemspec +++ b/flipper-api.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_api_files = lambda do |file| file =~ %r{(flipper)[\/-]api} @@ -20,6 +22,6 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'rack', '>= 1.4', '< 3' gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" + gem.add_dependency 'rack', '>= 1.4', '< 3' end diff --git a/flipper-cloud.gemspec b/flipper-cloud.gemspec index 505f8b973..098dff177 100644 --- a/flipper-cloud.gemspec +++ b/flipper-cloud.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_cloud_files = lambda do |file| file =~ /cloud/ diff --git a/flipper-dalli.gemspec b/flipper-dalli.gemspec index c5c804923..4024237a9 100644 --- a/flipper-dalli.gemspec +++ b/flipper-dalli.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_dalli_files = lambda do |file| file =~ /dalli/ @@ -21,6 +23,6 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA - gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" gem.add_dependency 'dalli', '>= 2.0', '< 3' + gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" end diff --git a/flipper-moneta.gemspec b/flipper-moneta.gemspec index f1af9b0c9..f5007ff4b 100644 --- a/flipper-moneta.gemspec +++ b/flipper-moneta.gemspec @@ -1,5 +1,7 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) flipper_moneta_files = lambda do |file| file =~ /moneta/ diff --git a/flipper-mongo.gemspec b/flipper-mongo.gemspec index 01aeab6b3..2b7c4ca6f 100644 --- a/flipper-mongo.gemspec +++ b/flipper-mongo.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_mongo_files = lambda do |file| file =~ /mongo/ diff --git a/flipper-redis.gemspec b/flipper-redis.gemspec index a8eeee805..0876fd918 100644 --- a/flipper-redis.gemspec +++ b/flipper-redis.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_redis_files = lambda do |file| file =~ /redis/ diff --git a/flipper-rollout.gemspec b/flipper-rollout.gemspec index 9d9e58379..afb1247cf 100644 --- a/flipper-rollout.gemspec +++ b/flipper-rollout.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_rollout_files = lambda do |file| file =~ /rollout/ diff --git a/flipper-sequel.gemspec b/flipper-sequel.gemspec index fa167650d..10511cb4d 100644 --- a/flipper-sequel.gemspec +++ b/flipper-sequel.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_sequel_files = ->(file) { file =~ /sequel/ } diff --git a/flipper-ui.gemspec b/flipper-ui.gemspec index 7f99c027a..c8737db4d 100644 --- a/flipper-ui.gemspec +++ b/flipper-ui.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) flipper_ui_files = lambda do |file| file =~ %r{(docs|examples|flipper)[\/-]ui} @@ -21,8 +23,8 @@ Gem::Specification.new do |gem| gem.version = Flipper::VERSION gem.metadata = Flipper::METADATA + gem.add_dependency 'erubi', '>= 1.0.0', '< 2.0.0' + gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" gem.add_dependency 'rack', '>= 1.4', '< 3' gem.add_dependency 'rack-protection', '>= 1.5.3', '< 2.1.0' - gem.add_dependency 'flipper', "~> #{Flipper::VERSION}" - gem.add_dependency 'erubi', '>= 1.0.0', '< 2.0.0' end diff --git a/flipper.gemspec b/flipper.gemspec index 05eedfaf3..28b71cf62 100644 --- a/flipper.gemspec +++ b/flipper.gemspec @@ -1,6 +1,8 @@ # -*- encoding: utf-8 -*- -require File.expand_path('../lib/flipper/version', __FILE__) -require File.expand_path('../lib/flipper/metadata', __FILE__) +# frozen_string_literal: true + +require File.expand_path('lib/flipper/version', __dir__) +require File.expand_path('lib/flipper/metadata', __dir__) plugin_files = [] plugin_test_files = [] diff --git a/lib/flipper-active_record.rb b/lib/flipper-active_record.rb index e90cb0d63..7ee57cf83 100644 --- a/lib/flipper-active_record.rb +++ b/lib/flipper-active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'activesupport/lazy_load_hooks' ActiveSupport.on_load(:active_record) do diff --git a/lib/flipper-active_support_cache_store.rb b/lib/flipper-active_support_cache_store.rb index 7d6c343d2..081e0fd58 100644 --- a/lib/flipper-active_support_cache_store.rb +++ b/lib/flipper-active_support_cache_store.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/adapters/active_support_cache_store' diff --git a/lib/flipper-api.rb b/lib/flipper-api.rb index a3a228d64..155cc553f 100644 --- a/lib/flipper-api.rb +++ b/lib/flipper-api.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/api' diff --git a/lib/flipper-cloud.rb b/lib/flipper-cloud.rb index dccb59d34..509873268 100644 --- a/lib/flipper-cloud.rb +++ b/lib/flipper-cloud.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require "flipper/cloud" diff --git a/lib/flipper-dalli.rb b/lib/flipper-dalli.rb index ec5341cd9..1c5ef33d5 100644 --- a/lib/flipper-dalli.rb +++ b/lib/flipper-dalli.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/adapters/dalli' diff --git a/lib/flipper-mongo.rb b/lib/flipper-mongo.rb index 8116aacad..9bf0f8599 100644 --- a/lib/flipper-mongo.rb +++ b/lib/flipper-mongo.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/adapters/mongo' diff --git a/lib/flipper-redis.rb b/lib/flipper-redis.rb index 3c16cc609..780458ecf 100644 --- a/lib/flipper-redis.rb +++ b/lib/flipper-redis.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/adapters/redis' diff --git a/lib/flipper-sequel.rb b/lib/flipper-sequel.rb index dee0621c9..3a0050d3e 100644 --- a/lib/flipper-sequel.rb +++ b/lib/flipper-sequel.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/adapters/sequel' diff --git a/lib/flipper-ui.rb b/lib/flipper-ui.rb index b04f9d634..1036ffdab 100644 --- a/lib/flipper-ui.rb +++ b/lib/flipper-ui.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'flipper/ui' diff --git a/lib/flipper.rb b/lib/flipper.rb index 654a7d65a..6b2e93064 100644 --- a/lib/flipper.rb +++ b/lib/flipper.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true + require "forwardable" module Flipper - extend self # rubocop:disable Style/ModuleFunction + # rubocop:disable Style/ModuleFunction + extend self + # rubocop:enable Style/ModuleFunction extend Forwardable # Private: The namespace for all instrumented events. diff --git a/lib/flipper/actor.rb b/lib/flipper/actor.rb index e434ecbed..90a77d505 100644 --- a/lib/flipper/actor.rb +++ b/lib/flipper/actor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Simple class for turning a flipper_id into an actor that can be based # to Flipper::Feature#enabled?. module Flipper diff --git a/lib/flipper/adapter.rb b/lib/flipper/adapter.rb index 3d4737b63..b0a06e0ae 100644 --- a/lib/flipper/adapter.rb +++ b/lib/flipper/adapter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "set" require "flipper/feature" require "flipper/adapters/sync/synchronizer" diff --git a/lib/flipper/adapters/active_record.rb b/lib/flipper/adapters/active_record.rb index 1abb5718d..393d20217 100644 --- a/lib/flipper/adapters/active_record.rb +++ b/lib/flipper/adapters/active_record.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require 'flipper' require 'active_record' @@ -188,8 +190,8 @@ def enable_multi(feature, gate, thing) g.value = thing.value.to_s end rescue ::ActiveRecord::RecordNotUnique - rescue ::ActiveRecord::StatementInvalid => error - raise unless error.message =~ /unique/i + rescue ::ActiveRecord::StatementInvalid => e + raise unless e.message =~ /unique/i end def result_for_feature(feature, db_gates) diff --git a/lib/flipper/adapters/active_support_cache_store.rb b/lib/flipper/adapters/active_support_cache_store.rb index a3b43a54b..4fb7d6ac3 100644 --- a/lib/flipper/adapters/active_support_cache_store.rb +++ b/lib/flipper/adapters/active_support_cache_store.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper' module Flipper @@ -8,10 +10,10 @@ module Adapters class ActiveSupportCacheStore include ::Flipper::Adapter - Version = 'v1'.freeze - Namespace = "flipper/#{Version}".freeze - FeaturesKey = "#{Namespace}/features".freeze - GetAllKey = "#{Namespace}/get_all".freeze + Version = 'v1' + Namespace = "flipper/#{Version}" + FeaturesKey = "#{Namespace}/features" + GetAllKey = "#{Namespace}/get_all" # Private def self.key_for(key) diff --git a/lib/flipper/adapters/dalli.rb b/lib/flipper/adapters/dalli.rb index d98f2e685..35435a6e0 100644 --- a/lib/flipper/adapters/dalli.rb +++ b/lib/flipper/adapters/dalli.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'dalli' require 'flipper' @@ -8,10 +10,10 @@ module Adapters class Dalli include ::Flipper::Adapter - Version = 'v1'.freeze - Namespace = "flipper/#{Version}".freeze - FeaturesKey = "#{Namespace}/features".freeze - GetAllKey = "#{Namespace}/get_all".freeze + Version = 'v1' + Namespace = "flipper/#{Version}" + FeaturesKey = "#{Namespace}/features" + GetAllKey = "#{Namespace}/get_all" # Private def self.key_for(key) diff --git a/lib/flipper/adapters/http.rb b/lib/flipper/adapters/http.rb index 4b41e66a8..1699f5be2 100644 --- a/lib/flipper/adapters/http.rb +++ b/lib/flipper/adapters/http.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'net/http' require 'json' require 'set' diff --git a/lib/flipper/adapters/http/client.rb b/lib/flipper/adapters/http/client.rb index 1e693f876..9de93af01 100644 --- a/lib/flipper/adapters/http/client.rb +++ b/lib/flipper/adapters/http/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'uri' require 'openssl' require 'flipper/version' @@ -12,7 +14,7 @@ class Client 'User-Agent' => "Flipper HTTP Adapter v#{VERSION}", }.freeze - HTTPS_SCHEME = "https".freeze + HTTPS_SCHEME = "https" def initialize(options = {}) @uri = URI(options.fetch(:url)) diff --git a/lib/flipper/adapters/http/error.rb b/lib/flipper/adapters/http/error.rb index 6eff84bf6..d816a4e08 100644 --- a/lib/flipper/adapters/http/error.rb +++ b/lib/flipper/adapters/http/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Adapters class Http diff --git a/lib/flipper/adapters/instrumented.rb b/lib/flipper/adapters/instrumented.rb index f102769c9..1c98194f4 100644 --- a/lib/flipper/adapters/instrumented.rb +++ b/lib/flipper/adapters/instrumented.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' module Flipper @@ -8,7 +10,7 @@ class Instrumented < SimpleDelegator include ::Flipper::Adapter # Private: The name of instrumentation events. - InstrumentationName = "adapter_operation.#{InstrumentationNamespace}".freeze + InstrumentationName = "adapter_operation.#{InstrumentationNamespace}" # Private: What is used to instrument all the things. attr_reader :instrumenter diff --git a/lib/flipper/adapters/memoizable.rb b/lib/flipper/adapters/memoizable.rb index 8f3112c39..869cb0c0d 100644 --- a/lib/flipper/adapters/memoizable.rb +++ b/lib/flipper/adapters/memoizable.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' module Flipper diff --git a/lib/flipper/adapters/memory.rb b/lib/flipper/adapters/memory.rb index 71f334024..215eda204 100644 --- a/lib/flipper/adapters/memory.rb +++ b/lib/flipper/adapters/memory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' module Flipper diff --git a/lib/flipper/adapters/moneta.rb b/lib/flipper/adapters/moneta.rb index 34f61f86d..f2d0f69f5 100644 --- a/lib/flipper/adapters/moneta.rb +++ b/lib/flipper/adapters/moneta.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'moneta' module Flipper diff --git a/lib/flipper/adapters/mongo.rb b/lib/flipper/adapters/mongo.rb index af8aebb8f..361b2de2c 100644 --- a/lib/flipper/adapters/mongo.rb +++ b/lib/flipper/adapters/mongo.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require 'flipper' require 'mongo' diff --git a/lib/flipper/adapters/operation_logger.rb b/lib/flipper/adapters/operation_logger.rb index 54ba544d1..517e512b3 100644 --- a/lib/flipper/adapters/operation_logger.rb +++ b/lib/flipper/adapters/operation_logger.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' module Flipper diff --git a/lib/flipper/adapters/pstore.rb b/lib/flipper/adapters/pstore.rb index 37156df22..e58ac5f72 100644 --- a/lib/flipper/adapters/pstore.rb +++ b/lib/flipper/adapters/pstore.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pstore' require 'set' require 'flipper' diff --git a/lib/flipper/adapters/read_only.rb b/lib/flipper/adapters/read_only.rb index 9e6ecaa52..b26abe593 100644 --- a/lib/flipper/adapters/read_only.rb +++ b/lib/flipper/adapters/read_only.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper' module Flipper diff --git a/lib/flipper/adapters/redis.rb b/lib/flipper/adapters/redis.rb index 52fb6cf90..664fbacbf 100644 --- a/lib/flipper/adapters/redis.rb +++ b/lib/flipper/adapters/redis.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require 'redis' require 'flipper' diff --git a/lib/flipper/adapters/redis_cache.rb b/lib/flipper/adapters/redis_cache.rb index 1742377ce..890e0cec3 100644 --- a/lib/flipper/adapters/redis_cache.rb +++ b/lib/flipper/adapters/redis_cache.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'redis' require 'flipper' @@ -8,10 +10,10 @@ module Adapters class RedisCache include ::Flipper::Adapter - Version = 'v1'.freeze - Namespace = "flipper/#{Version}".freeze - FeaturesKey = "#{Namespace}/features".freeze - GetAllKey = "#{Namespace}/get_all".freeze + Version = 'v1' + Namespace = "flipper/#{Version}" + FeaturesKey = "#{Namespace}/features" + GetAllKey = "#{Namespace}/get_all" # Private def self.key_for(key) diff --git a/lib/flipper/adapters/rollout.rb b/lib/flipper/adapters/rollout.rb index 4e268f4b6..71a911450 100644 --- a/lib/flipper/adapters/rollout.rb +++ b/lib/flipper/adapters/rollout.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper' module Flipper diff --git a/lib/flipper/adapters/sequel.rb b/lib/flipper/adapters/sequel.rb index 14ac235a1..2af6a65e0 100644 --- a/lib/flipper/adapters/sequel.rb +++ b/lib/flipper/adapters/sequel.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require 'flipper' require 'sequel' diff --git a/lib/flipper/adapters/sync.rb b/lib/flipper/adapters/sync.rb index f7f72d658..600947257 100644 --- a/lib/flipper/adapters/sync.rb +++ b/lib/flipper/adapters/sync.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "flipper/adapters/sync/synchronizer" require "flipper/adapters/sync/interval_synchronizer" diff --git a/lib/flipper/adapters/sync/feature_synchronizer.rb b/lib/flipper/adapters/sync/feature_synchronizer.rb index f778755eb..ef8ec7ecf 100644 --- a/lib/flipper/adapters/sync/feature_synchronizer.rb +++ b/lib/flipper/adapters/sync/feature_synchronizer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "flipper/actor" require "flipper/gate_values" @@ -34,9 +36,11 @@ def initialize(feature, local_gate_values, remote_gate_values) def call if remote_disabled? return if local_disabled? + @feature.disable elsif remote_boolean_enabled? return if local_boolean_enabled? + @feature.enable else @feature.disable if local_boolean_enabled? diff --git a/lib/flipper/adapters/sync/interval_synchronizer.rb b/lib/flipper/adapters/sync/interval_synchronizer.rb index 7d777f4a0..89f2d39b2 100644 --- a/lib/flipper/adapters/sync/interval_synchronizer.rb +++ b/lib/flipper/adapters/sync/interval_synchronizer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Adapters class Sync diff --git a/lib/flipper/adapters/sync/synchronizer.rb b/lib/flipper/adapters/sync/synchronizer.rb index 847f7e3d7..adcd09d44 100644 --- a/lib/flipper/adapters/sync/synchronizer.rb +++ b/lib/flipper/adapters/sync/synchronizer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "flipper/feature" require "flipper/gate_values" require "flipper/adapters/sync/feature_synchronizer" @@ -51,8 +53,8 @@ def sync features_to_remove.each { |key| Feature.new(key, @local).remove } nil - rescue => exception - @instrumenter.instrument("synchronizer_exception.flipper", exception: exception) + rescue StandardError => e + @instrumenter.instrument("synchronizer_exception.flipper", exception: e) raise if @raise end end diff --git a/lib/flipper/api.rb b/lib/flipper/api.rb index 06bd796b8..e77954d35 100644 --- a/lib/flipper/api.rb +++ b/lib/flipper/api.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack' require 'flipper' require 'flipper/api/middleware' @@ -5,11 +7,11 @@ module Flipper module Api - CONTENT_TYPE = 'application/json'.freeze + CONTENT_TYPE = 'application/json' def self.app(flipper = nil, options = {}) env_key = options.fetch(:env_key, 'flipper') - app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] } + app = ->(_) { [404, { 'Content-Type' => CONTENT_TYPE }, ['{}']] } builder = Rack::Builder.new yield builder if block_given? builder.use Flipper::Api::JsonParams diff --git a/lib/flipper/api/action.rb b/lib/flipper/api/action.rb index bfd684c76..062c40b53 100644 --- a/lib/flipper/api/action.rb +++ b/lib/flipper/api/action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'forwardable' require 'flipper/api/error' require 'flipper/api/error_response' @@ -18,11 +20,11 @@ def feature_name extend Forwardable - VALID_REQUEST_METHOD_NAMES = Set.new([ - 'get'.freeze, - 'post'.freeze, - 'put'.freeze, - 'delete'.freeze, + VALID_REQUEST_METHOD_NAMES = Set.new(%w[ + get + post + put + delete ]).freeze # Public: Call this in subclasses so the action knows its route. diff --git a/lib/flipper/api/action_collection.rb b/lib/flipper/api/action_collection.rb index 7fdaa366b..fc2e072b9 100644 --- a/lib/flipper/api/action_collection.rb +++ b/lib/flipper/api/action_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Api # Internal: Used to detect the action that should be used in the middleware. diff --git a/lib/flipper/api/error.rb b/lib/flipper/api/error.rb index e1db2fbb1..d4d780230 100644 --- a/lib/flipper/api/error.rb +++ b/lib/flipper/api/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Api # All flipper api errors inherit from this. diff --git a/lib/flipper/api/error_response.rb b/lib/flipper/api/error_response.rb index b2d10bba7..8633ca360 100644 --- a/lib/flipper/api/error_response.rb +++ b/lib/flipper/api/error_response.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Api module ErrorResponse diff --git a/lib/flipper/api/json_params.rb b/lib/flipper/api/json_params.rb index 14d79a172..0124bd326 100644 --- a/lib/flipper/api/json_params.rb +++ b/lib/flipper/api/json_params.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack/utils' module Flipper @@ -9,9 +11,9 @@ def initialize(app) @app = app end - CONTENT_TYPE = 'CONTENT_TYPE'.freeze - QUERY_STRING = 'QUERY_STRING'.freeze - REQUEST_BODY = 'rack.input'.freeze + CONTENT_TYPE = 'CONTENT_TYPE' + QUERY_STRING = 'QUERY_STRING' + REQUEST_BODY = 'rack.input' # Public: Merge request body params with query string params # This way can access all params with Rack::Request#params @@ -34,6 +36,7 @@ def call(env) # This method accomplishes similar functionality def update_params(env, data) return if data.empty? + parsed_request_body = JSON.parse(data) parsed_query_string = parse_query(env[QUERY_STRING]) parsed_query_string.merge!(parsed_request_body) diff --git a/lib/flipper/api/middleware.rb b/lib/flipper/api/middleware.rb index 74423e395..d6e8e53e3 100644 --- a/lib/flipper/api/middleware.rb +++ b/lib/flipper/api/middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack' require 'flipper/api/action_collection' diff --git a/lib/flipper/api/v1/actions/actors.rb b/lib/flipper/api/v1/actions/actors.rb index 6aa179b11..298cb4f2f 100644 --- a/lib/flipper/api/v1/actions/actors.rb +++ b/lib/flipper/api/v1/actions/actors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/actor' diff --git a/lib/flipper/api/v1/actions/actors_gate.rb b/lib/flipper/api/v1/actions/actors_gate.rb index 0c319a757..082b362dc 100644 --- a/lib/flipper/api/v1/actions/actors_gate.rb +++ b/lib/flipper/api/v1/actions/actors_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' diff --git a/lib/flipper/api/v1/actions/boolean_gate.rb b/lib/flipper/api/v1/actions/boolean_gate.rb index 80114ca3f..8e761ace5 100644 --- a/lib/flipper/api/v1/actions/boolean_gate.rb +++ b/lib/flipper/api/v1/actions/boolean_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' diff --git a/lib/flipper/api/v1/actions/clear_feature.rb b/lib/flipper/api/v1/actions/clear_feature.rb index 60a1b9499..10077fdaf 100644 --- a/lib/flipper/api/v1/actions/clear_feature.rb +++ b/lib/flipper/api/v1/actions/clear_feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' diff --git a/lib/flipper/api/v1/actions/feature.rb b/lib/flipper/api/v1/actions/feature.rb index 46e301032..8aa5fde56 100644 --- a/lib/flipper/api/v1/actions/feature.rb +++ b/lib/flipper/api/v1/actions/feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' @@ -12,6 +14,7 @@ class Feature < Api::Action def get return json_error_response(:feature_not_found) unless feature_exists?(feature_name) + feature = Decorators::Feature.new(flipper[feature_name]) json_response(feature.as_json) end diff --git a/lib/flipper/api/v1/actions/features.rb b/lib/flipper/api/v1/actions/features.rb index b14560fbe..7706ba109 100644 --- a/lib/flipper/api/v1/actions/features.rb +++ b/lib/flipper/api/v1/actions/features.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' diff --git a/lib/flipper/api/v1/actions/groups_gate.rb b/lib/flipper/api/v1/actions/groups_gate.rb index ea53a86d4..a81b4aba6 100644 --- a/lib/flipper/api/v1/actions/groups_gate.rb +++ b/lib/flipper/api/v1/actions/groups_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' diff --git a/lib/flipper/api/v1/actions/percentage_of_actors_gate.rb b/lib/flipper/api/v1/actions/percentage_of_actors_gate.rb index 66a030f8e..cb0e2e539 100644 --- a/lib/flipper/api/v1/actions/percentage_of_actors_gate.rb +++ b/lib/flipper/api/v1/actions/percentage_of_actors_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' @@ -33,8 +35,8 @@ def delete def percentage @percentage ||= begin Integer(params['percentage']) - rescue ArgumentError, TypeError - -1 + rescue ArgumentError, TypeError + -1 end end end diff --git a/lib/flipper/api/v1/actions/percentage_of_time_gate.rb b/lib/flipper/api/v1/actions/percentage_of_time_gate.rb index 4feec4b10..2eae5920c 100644 --- a/lib/flipper/api/v1/actions/percentage_of_time_gate.rb +++ b/lib/flipper/api/v1/actions/percentage_of_time_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/api/action' require 'flipper/api/v1/decorators/feature' @@ -34,8 +36,8 @@ def delete def percentage @percentage ||= begin Integer(params['percentage']) - rescue ArgumentError, TypeError - -1 + rescue ArgumentError, TypeError + -1 end end end diff --git a/lib/flipper/api/v1/decorators/actor.rb b/lib/flipper/api/v1/decorators/actor.rb index 42bb6e93c..84b124465 100644 --- a/lib/flipper/api/v1/decorators/actor.rb +++ b/lib/flipper/api/v1/decorators/actor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Api module V1 diff --git a/lib/flipper/api/v1/decorators/feature.rb b/lib/flipper/api/v1/decorators/feature.rb index a1d33031a..8b8137522 100644 --- a/lib/flipper/api/v1/decorators/feature.rb +++ b/lib/flipper/api/v1/decorators/feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' require 'flipper/api/v1/decorators/gate' diff --git a/lib/flipper/api/v1/decorators/gate.rb b/lib/flipper/api/v1/decorators/gate.rb index f971e28fa..f0f40a4e1 100644 --- a/lib/flipper/api/v1/decorators/gate.rb +++ b/lib/flipper/api/v1/decorators/gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Api module V1 diff --git a/lib/flipper/cloud.rb b/lib/flipper/cloud.rb index 235dbf9fb..85ed02b7e 100644 --- a/lib/flipper/cloud.rb +++ b/lib/flipper/cloud.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "flipper" require "flipper/cloud/configuration" diff --git a/lib/flipper/cloud/configuration.rb b/lib/flipper/cloud/configuration.rb index 6861682d0..3e70350f6 100644 --- a/lib/flipper/cloud/configuration.rb +++ b/lib/flipper/cloud/configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "flipper/adapters/http" require "flipper/adapters/memory" require "flipper/adapters/sync" @@ -6,7 +8,7 @@ module Flipper module Cloud class Configuration # The default url should be the one, the only, the website. - DEFAULT_URL = "https://www.flippercloud.io/adapter".freeze + DEFAULT_URL = "https://www.flippercloud.io/adapter" # Public: The token corresponding to an environment on flippercloud.io. attr_accessor :token diff --git a/lib/flipper/configuration.rb b/lib/flipper/configuration.rb index 0bf97d480..c4bed96aa 100644 --- a/lib/flipper/configuration.rb +++ b/lib/flipper/configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper class Configuration def initialize diff --git a/lib/flipper/dsl.rb b/lib/flipper/dsl.rb index bc3114b08..10ff26896 100644 --- a/lib/flipper/dsl.rb +++ b/lib/flipper/dsl.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'forwardable' module Flipper diff --git a/lib/flipper/errors.rb b/lib/flipper/errors.rb index 939ed3e36..ad4875c9d 100644 --- a/lib/flipper/errors.rb +++ b/lib/flipper/errors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper # Top level error that all other errors inherit from. class Error < StandardError; end diff --git a/lib/flipper/feature.rb b/lib/flipper/feature.rb index b11ca149d..3d41848dd 100644 --- a/lib/flipper/feature.rb +++ b/lib/flipper/feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/errors' require 'flipper/type' require 'flipper/gate' @@ -8,7 +10,7 @@ module Flipper # rubocop:disable Metrics/ClassLength class Feature # Private: The name of feature instrumentation events. - InstrumentationName = "feature_operation.#{InstrumentationNamespace}".freeze + InstrumentationName = "feature_operation.#{InstrumentationNamespace}" # Public: The name of the feature. attr_reader :name @@ -377,4 +379,5 @@ def instrument(operation) end end end + # rubocop:enable Metrics/ClassLength end diff --git a/lib/flipper/feature_check_context.rb b/lib/flipper/feature_check_context.rb index ed2f660a1..e816f97d6 100644 --- a/lib/flipper/feature_check_context.rb +++ b/lib/flipper/feature_check_context.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper class FeatureCheckContext # Public: The name of the feature. diff --git a/lib/flipper/gate.rb b/lib/flipper/gate.rb index da7af2e55..374d13440 100644 --- a/lib/flipper/gate.rb +++ b/lib/flipper/gate.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + module Flipper class Gate # Public - def initialize(options = {}) - end + def initialize(options = {}); end # Public: The name of the gate. Implemented in subclass. def name diff --git a/lib/flipper/gate_values.rb b/lib/flipper/gate_values.rb index 71967244c..f912d1da4 100644 --- a/lib/flipper/gate_values.rb +++ b/lib/flipper/gate_values.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'set' require 'flipper/typecast' diff --git a/lib/flipper/gates/actor.rb b/lib/flipper/gates/actor.rb index a85985ee8..46d62d346 100644 --- a/lib/flipper/gates/actor.rb +++ b/lib/flipper/gates/actor.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Gates class Actor < Gate diff --git a/lib/flipper/gates/boolean.rb b/lib/flipper/gates/boolean.rb index 7aa2a1dc0..4e6c98ae4 100644 --- a/lib/flipper/gates/boolean.rb +++ b/lib/flipper/gates/boolean.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Gates class Boolean < Gate diff --git a/lib/flipper/gates/group.rb b/lib/flipper/gates/group.rb index 1ea9d0b5b..e6a430b10 100644 --- a/lib/flipper/gates/group.rb +++ b/lib/flipper/gates/group.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Gates class Group < Gate diff --git a/lib/flipper/gates/percentage_of_actors.rb b/lib/flipper/gates/percentage_of_actors.rb index 76420a0d6..273839b2a 100644 --- a/lib/flipper/gates/percentage_of_actors.rb +++ b/lib/flipper/gates/percentage_of_actors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'zlib' module Flipper diff --git a/lib/flipper/gates/percentage_of_time.rb b/lib/flipper/gates/percentage_of_time.rb index 47de10aba..b1b6b491a 100644 --- a/lib/flipper/gates/percentage_of_time.rb +++ b/lib/flipper/gates/percentage_of_time.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Gates class PercentageOfTime < Gate diff --git a/lib/flipper/instrumentation/log_subscriber.rb b/lib/flipper/instrumentation/log_subscriber.rb index df06252a9..3bff2076b 100644 --- a/lib/flipper/instrumentation/log_subscriber.rb +++ b/lib/flipper/instrumentation/log_subscriber.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'securerandom' require 'active_support/notifications' require 'active_support/log_subscriber' diff --git a/lib/flipper/instrumentation/statsd.rb b/lib/flipper/instrumentation/statsd.rb index d88cc8137..b82d32a8d 100644 --- a/lib/flipper/instrumentation/statsd.rb +++ b/lib/flipper/instrumentation/statsd.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'securerandom' require 'active_support/notifications' require 'flipper/instrumentation/statsd_subscriber' diff --git a/lib/flipper/instrumentation/statsd_subscriber.rb b/lib/flipper/instrumentation/statsd_subscriber.rb index b7f73f3fb..0e49d45d9 100644 --- a/lib/flipper/instrumentation/statsd_subscriber.rb +++ b/lib/flipper/instrumentation/statsd_subscriber.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # Note: You should never need to require this file directly if you are using # ActiveSupport::Notifications. Instead, you should require the statsd file # that lives in the same directory as this file. The benefit is that it @@ -12,13 +14,11 @@ class << self end def update_timer(metric) - if self.class.client - self.class.client.timing metric, (@duration * 1_000).round - end + self.class.client&.timing metric, (@duration * 1_000).round end def update_counter(metric) - self.class.client.increment metric if self.class.client + self.class.client&.increment metric end end end diff --git a/lib/flipper/instrumentation/subscriber.rb b/lib/flipper/instrumentation/subscriber.rb index 3721a500c..b3844d92f 100644 --- a/lib/flipper/instrumentation/subscriber.rb +++ b/lib/flipper/instrumentation/subscriber.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Instrumentation class Subscriber @@ -72,7 +74,7 @@ def update_adapter_operation_metrics update_timer "flipper.adapter.#{adapter_name}.#{operation}" end - QUESTION_MARK = '?'.freeze + QUESTION_MARK = '?' # Private def strip_trailing_question_mark(operation) diff --git a/lib/flipper/instrumenters/memory.rb b/lib/flipper/instrumenters/memory.rb index f9c2882c6..46e27153a 100644 --- a/lib/flipper/instrumenters/memory.rb +++ b/lib/flipper/instrumenters/memory.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Instrumenters # Instrumentor that is useful for tests as it stores each of the events that diff --git a/lib/flipper/instrumenters/noop.rb b/lib/flipper/instrumenters/noop.rb index cd252431a..c5a0d0557 100644 --- a/lib/flipper/instrumenters/noop.rb +++ b/lib/flipper/instrumenters/noop.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Instrumenters class Noop diff --git a/lib/flipper/metadata.rb b/lib/flipper/metadata.rb index 88df56e82..12c6f8463 100644 --- a/lib/flipper/metadata.rb +++ b/lib/flipper/metadata.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper METADATA = { 'changelog_uri' => 'https://github.com/jnunemaker/flipper/blob/master/Changelog.md', diff --git a/lib/flipper/middleware/memoizer.rb b/lib/flipper/middleware/memoizer.rb index af5395138..6134419ce 100644 --- a/lib/flipper/middleware/memoizer.rb +++ b/lib/flipper/middleware/memoizer.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Middleware class Memoizer @@ -44,7 +46,7 @@ def call(env) private def skip_memoize?(request) - @opts[:unless] && @opts[:unless].call(request) + @opts[:unless]&.call(request) end def memoized_call(env) diff --git a/lib/flipper/middleware/setup_env.rb b/lib/flipper/middleware/setup_env.rb index f776b35ee..bcfd7e79d 100644 --- a/lib/flipper/middleware/setup_env.rb +++ b/lib/flipper/middleware/setup_env.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Middleware class SetupEnv diff --git a/lib/flipper/registry.rb b/lib/flipper/registry.rb index 4eb0c3165..91620d303 100644 --- a/lib/flipper/registry.rb +++ b/lib/flipper/registry.rb @@ -1,4 +1,4 @@ -require 'thread' +# frozen_string_literal: true module Flipper # Internal: Used to store registry of groups by name. diff --git a/lib/flipper/spec/shared_adapter_specs.rb b/lib/flipper/spec/shared_adapter_specs.rb index 2f3c7732a..88e58af1f 100644 --- a/lib/flipper/spec/shared_adapter_specs.rb +++ b/lib/flipper/spec/shared_adapter_specs.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + # Requires the following methods: # * subject - The instance of the adapter -# rubocop:disable Metrics/BlockLength RSpec.shared_examples_for 'a flipper adapter' do let(:flipper) { Flipper.new(subject) } let(:feature) { flipper[:stats] } @@ -265,7 +266,7 @@ flipper.disable(:search) result = subject.get_all - expect(result.keys.sort).to eq(%w(search stats)) + expect(result.keys.sort).to eq(%w[search stats]) end it 'can double enable an actor without error' do diff --git a/lib/flipper/test/shared_adapter_test.rb b/lib/flipper/test/shared_adapter_test.rb index 4d7327b3c..92432070d 100644 --- a/lib/flipper/test/shared_adapter_test.rb +++ b/lib/flipper/test/shared_adapter_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + # rubocop:disable Metrics/ModuleLength module Flipper module Test @@ -260,7 +262,7 @@ def test_includes_explicitly_disabled_features_when_getting_all_features @flipper.disable(:search) result = @adapter.get_all - assert_equal %w(search stats), result.keys.sort + assert_equal %w[search stats], result.keys.sort end def test_can_double_enable_an_actor_without_error diff --git a/lib/flipper/type.rb b/lib/flipper/type.rb index 3cd736801..501566cf1 100644 --- a/lib/flipper/type.rb +++ b/lib/flipper/type.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + module Flipper # Internal: Root class for all flipper types. You should never need to use this. class Type def self.wrap(value_or_instance) return value_or_instance if value_or_instance.is_a?(self) + new(value_or_instance) end diff --git a/lib/flipper/typecast.rb b/lib/flipper/typecast.rb index ec1689857..05bdc12af 100644 --- a/lib/flipper/typecast.rb +++ b/lib/flipper/typecast.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'set' module Flipper module Typecast TruthMap = { - true => true, - 1 => true, - 'true' => true, - '1' => true, + true => true, + 1 => true, + 'true' => true, + '1' => true, }.freeze # Internal: Convert value to a boolean. @@ -45,7 +47,7 @@ def self.to_float(value) # Returns a Integer or Float representation of the value. # Raises ArgumentError if conversion is not possible. def self.to_percentage(value) - if value.to_s.include?('.'.freeze) + if value.to_s.include?('.') to_float(value) else to_integer(value) diff --git a/lib/flipper/types/actor.rb b/lib/flipper/types/actor.rb index e1f10e033..ac1fa853d 100644 --- a/lib/flipper/types/actor.rb +++ b/lib/flipper/types/actor.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + module Flipper module Types class Actor < Type def self.wrappable?(thing) return false if thing.nil? + thing.respond_to?(:flipper_id) end diff --git a/lib/flipper/types/boolean.rb b/lib/flipper/types/boolean.rb index 925559ad2..a8b0e1347 100644 --- a/lib/flipper/types/boolean.rb +++ b/lib/flipper/types/boolean.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/typecast' module Flipper diff --git a/lib/flipper/types/group.rb b/lib/flipper/types/group.rb index 121f4696b..37824128b 100644 --- a/lib/flipper/types/group.rb +++ b/lib/flipper/types/group.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + module Flipper module Types class Group < Type def self.wrap(group_or_name) return group_or_name if group_or_name.is_a?(self) + Flipper.group(group_or_name) end diff --git a/lib/flipper/types/percentage.rb b/lib/flipper/types/percentage.rb index faaaba997..da28e57a8 100644 --- a/lib/flipper/types/percentage.rb +++ b/lib/flipper/types/percentage.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/typecast' module Flipper diff --git a/lib/flipper/types/percentage_of_actors.rb b/lib/flipper/types/percentage_of_actors.rb index ccf3c22bc..f134cecd1 100644 --- a/lib/flipper/types/percentage_of_actors.rb +++ b/lib/flipper/types/percentage_of_actors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Types class PercentageOfActors < Percentage diff --git a/lib/flipper/types/percentage_of_time.rb b/lib/flipper/types/percentage_of_time.rb index 3a4cb1933..0cd466396 100644 --- a/lib/flipper/types/percentage_of_time.rb +++ b/lib/flipper/types/percentage_of_time.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module Types class PercentageOfTime < Percentage diff --git a/lib/flipper/ui.rb b/lib/flipper/ui.rb index bf77dd2de..fc900883d 100644 --- a/lib/flipper/ui.rb +++ b/lib/flipper/ui.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'pathname' require 'rack' begin @@ -16,9 +18,9 @@ module Flipper module UI class << self # These three configuration options have been moved to Flipper::UI::Configuration - deprecated_configuration_options = %w(application_breadcrumb_href + deprecated_configuration_options = %w[application_breadcrumb_href feature_creation_enabled - feature_removal_enabled) + feature_removal_enabled] deprecated_configuration_options.each do |attribute_name| send(:define_method, "#{attribute_name}=".to_sym) do raise ConfigurationDeprecated, "The UI configuration for #{attribute_name} has " \ @@ -42,7 +44,7 @@ def self.root def self.app(flipper = nil, options = {}) env_key = options.fetch(:env_key, 'flipper') rack_protection_options = options.fetch(:rack_protection, use: :authenticity_token) - app = ->() { [200, { 'Content-Type' => 'text/html' }, ['']] } + app = -> { [200, { 'Content-Type' => 'text/html' }, ['']] } builder = Rack::Builder.new yield builder if block_given? builder.use Rack::Protection, rack_protection_options diff --git a/lib/flipper/ui/action.rb b/lib/flipper/ui/action.rb index 2ac0f3970..e8b1f9c96 100644 --- a/lib/flipper/ui/action.rb +++ b/lib/flipper/ui/action.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'forwardable' require 'flipper/ui/error' require 'erubi' @@ -18,11 +20,11 @@ def feature_name extend Forwardable - VALID_REQUEST_METHOD_NAMES = Set.new([ - 'get'.freeze, - 'post'.freeze, - 'put'.freeze, - 'delete'.freeze, + VALID_REQUEST_METHOD_NAMES = Set.new(%w[ + get + post + put + delete ]).freeze # Public: Call this in subclasses so the action knows its route. @@ -208,9 +210,9 @@ def view(name) raise "Template does not exist: #{path}" unless path.exist? - # rubocop:disable Lint/Eval + # rubocop:disable Security/Eval eval(Erubi::Engine.new(path.read, escape: true).src) - # rubocop:enable Lint/Eval + # rubocop:enable Security/Eval end # Internal: The path the app is mounted at. diff --git a/lib/flipper/ui/action_collection.rb b/lib/flipper/ui/action_collection.rb index f4f86d679..5f94981f4 100644 --- a/lib/flipper/ui/action_collection.rb +++ b/lib/flipper/ui/action_collection.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module UI # Internal: Used to detect the action that should be used in the middleware. diff --git a/lib/flipper/ui/actions/actors_gate.rb b/lib/flipper/ui/actions/actors_gate.rb index 2344a8fa8..55db83ae1 100644 --- a/lib/flipper/ui/actions/actors_gate.rb +++ b/lib/flipper/ui/actions/actors_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' require 'flipper/ui/util' diff --git a/lib/flipper/ui/actions/add_feature.rb b/lib/flipper/ui/actions/add_feature.rb index bd22f1a00..7f81ed9fc 100644 --- a/lib/flipper/ui/actions/add_feature.rb +++ b/lib/flipper/ui/actions/add_feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' diff --git a/lib/flipper/ui/actions/boolean_gate.rb b/lib/flipper/ui/actions/boolean_gate.rb index a5e22ac0e..732c1b056 100644 --- a/lib/flipper/ui/actions/boolean_gate.rb +++ b/lib/flipper/ui/actions/boolean_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' diff --git a/lib/flipper/ui/actions/feature.rb b/lib/flipper/ui/actions/feature.rb index ea2b0876c..654d0856d 100644 --- a/lib/flipper/ui/actions/feature.rb +++ b/lib/flipper/ui/actions/feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' diff --git a/lib/flipper/ui/actions/features.rb b/lib/flipper/ui/actions/features.rb index be5aa38ca..9c2953cbd 100644 --- a/lib/flipper/ui/actions/features.rb +++ b/lib/flipper/ui/actions/features.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' require 'flipper/ui/util' diff --git a/lib/flipper/ui/actions/file.rb b/lib/flipper/ui/actions/file.rb index 173b5b424..904f004af 100644 --- a/lib/flipper/ui/actions/file.rb +++ b/lib/flipper/ui/actions/file.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack/file' require 'flipper/ui/action' diff --git a/lib/flipper/ui/actions/groups_gate.rb b/lib/flipper/ui/actions/groups_gate.rb index 2de569cc7..10c4aed1a 100644 --- a/lib/flipper/ui/actions/groups_gate.rb +++ b/lib/flipper/ui/actions/groups_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' diff --git a/lib/flipper/ui/actions/home.rb b/lib/flipper/ui/actions/home.rb index ea2b7a769..abc2c7670 100644 --- a/lib/flipper/ui/actions/home.rb +++ b/lib/flipper/ui/actions/home.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' diff --git a/lib/flipper/ui/actions/percentage_of_actors_gate.rb b/lib/flipper/ui/actions/percentage_of_actors_gate.rb index 89f166bdd..44f396914 100644 --- a/lib/flipper/ui/actions/percentage_of_actors_gate.rb +++ b/lib/flipper/ui/actions/percentage_of_actors_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' @@ -15,8 +17,8 @@ def post begin feature.enable_percentage_of_actors params['value'] - rescue ArgumentError => exception - error = Rack::Utils.escape("Invalid percentage of actors value: #{exception.message}") + rescue ArgumentError => e + error = Rack::Utils.escape("Invalid percentage of actors value: #{e.message}") redirect_to("/features/#{@feature.key}?error=#{error}") end diff --git a/lib/flipper/ui/actions/percentage_of_time_gate.rb b/lib/flipper/ui/actions/percentage_of_time_gate.rb index bf4ff6e1d..cf2296935 100644 --- a/lib/flipper/ui/actions/percentage_of_time_gate.rb +++ b/lib/flipper/ui/actions/percentage_of_time_gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/action' require 'flipper/ui/decorators/feature' @@ -15,8 +17,8 @@ def post begin feature.enable_percentage_of_time params['value'] - rescue ArgumentError => exception - error = Rack::Utils.escape("Invalid percentage of time value: #{exception.message}") + rescue ArgumentError => e + error = Rack::Utils.escape("Invalid percentage of time value: #{e.message}") redirect_to("/features/#{@feature.key}?error=#{error}") end diff --git a/lib/flipper/ui/configuration.rb b/lib/flipper/ui/configuration.rb index d40cee828..624836bea 100644 --- a/lib/flipper/ui/configuration.rb +++ b/lib/flipper/ui/configuration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper/ui/configuration/option' module Flipper @@ -30,7 +32,7 @@ class Configuration # won't see a videoclip of Taylor Swift when there aren't any features attr_accessor :fun - VALID_BANNER_CLASS_VALUES = %w( + VALID_BANNER_CLASS_VALUES = %w[ danger dark info @@ -39,7 +41,7 @@ class Configuration secondary success warning - ).freeze + ].freeze def initialize @actors = Option.new("Actors", "Enable actors using the form above.") diff --git a/lib/flipper/ui/configuration/option.rb b/lib/flipper/ui/configuration/option.rb index 723a2dc4c..016976ac5 100644 --- a/lib/flipper/ui/configuration/option.rb +++ b/lib/flipper/ui/configuration/option.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module UI class Option diff --git a/lib/flipper/ui/decorators/feature.rb b/lib/flipper/ui/decorators/feature.rb index b65da181e..151bacf99 100644 --- a/lib/flipper/ui/decorators/feature.rb +++ b/lib/flipper/ui/decorators/feature.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' require 'flipper/ui/decorators/gate' require 'flipper/ui/util' diff --git a/lib/flipper/ui/decorators/gate.rb b/lib/flipper/ui/decorators/gate.rb index 9f02aea0e..784e37821 100644 --- a/lib/flipper/ui/decorators/gate.rb +++ b/lib/flipper/ui/decorators/gate.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'delegate' module Flipper diff --git a/lib/flipper/ui/error.rb b/lib/flipper/ui/error.rb index ae1e3aab9..5ad2e5950 100644 --- a/lib/flipper/ui/error.rb +++ b/lib/flipper/ui/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper module UI # All flipper ui errors inherit from this. diff --git a/lib/flipper/ui/middleware.rb b/lib/flipper/ui/middleware.rb index 431855d76..c6a6436d4 100644 --- a/lib/flipper/ui/middleware.rb +++ b/lib/flipper/ui/middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rack' require 'flipper/ui/action_collection' diff --git a/lib/flipper/ui/util.rb b/lib/flipper/ui/util.rb index 1f940aceb..288c49442 100644 --- a/lib/flipper/ui/util.rb +++ b/lib/flipper/ui/util.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module Flipper module UI module Util # Private: 0x3000: fullwidth whitespace - NON_WHITESPACE_REGEXP = /[^\s#{[0x3000].pack("U")}]/ + NON_WHITESPACE_REGEXP = /[^\s#{[0x3000].pack("U")}]/.freeze def self.blank?(str) str.to_s !~ NON_WHITESPACE_REGEXP diff --git a/lib/flipper/version.rb b/lib/flipper/version.rb index 47f8f6f6c..1e3d461f7 100644 --- a/lib/flipper/version.rb +++ b/lib/flipper/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Flipper - VERSION = '0.16.2'.freeze + VERSION = '0.16.2' end diff --git a/lib/generators/flipper/active_record_generator.rb b/lib/generators/flipper/active_record_generator.rb index 13751e0f2..282af3cf7 100644 --- a/lib/generators/flipper/active_record_generator.rb +++ b/lib/generators/flipper/active_record_generator.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rails/generators/active_record' module Flipper diff --git a/lib/generators/flipper/templates/sequel_migration.rb b/lib/generators/flipper/templates/sequel_migration.rb index 0a782a358..2f4ba7586 100644 --- a/lib/generators/flipper/templates/sequel_migration.rb +++ b/lib/generators/flipper/templates/sequel_migration.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class CreateFlipperTablesSequel < Sequel::Migration def up create_table :flipper_features do |_t| diff --git a/script/console b/script/console index f54a604fb..5945a191b 100755 --- a/script/console +++ b/script/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require "bundler/setup" require "flipper" diff --git a/spec/flipper/actor_spec.rb b/spec/flipper/actor_spec.rb index 230340e75..4a6629a91 100644 --- a/spec/flipper/actor_spec.rb +++ b/spec/flipper/actor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Actor do diff --git a/spec/flipper/adapter_spec.rb b/spec/flipper/adapter_spec.rb index 1eec522bb..e0a500bf5 100644 --- a/spec/flipper/adapter_spec.rb +++ b/spec/flipper/adapter_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Adapter do @@ -16,7 +18,7 @@ describe '.default_config' do it 'returns default config' do adapter_class = Class.new do - include Flipper::Adapter # rubocop:disable RSpec/DescribedClass + include Flipper::Adapter end expect(adapter_class.default_config).to eq(default_config) end @@ -25,7 +27,7 @@ describe '#default_config' do it 'returns default config' do adapter_class = Class.new do - include Flipper::Adapter # rubocop:disable RSpec/DescribedClass + include Flipper::Adapter end expect(adapter_class.new.default_config).to eq(default_config) end @@ -41,7 +43,7 @@ source_flipper.enable(:search) destination_flipper.import(source_flipper) expect(destination_flipper[:search].boolean_value).to eq(true) - expect(destination_flipper.features.map(&:key).sort).to eq(%w(search)) + expect(destination_flipper.features.map(&:key).sort).to eq(%w[search]) end it 'can import features that have been added but their state is off' do diff --git a/spec/flipper/adapters/active_record_spec.rb b/spec/flipper/adapters/active_record_spec.rb index 0742168dc..f11b2609f 100644 --- a/spec/flipper/adapters/active_record_spec.rb +++ b/spec/flipper/adapters/active_record_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/active_record' require 'flipper/spec/shared_adapter_specs' @@ -13,7 +15,7 @@ database: ':memory:') end - before(:each) do + before do ActiveRecord::Base.connection.execute <<-SQL CREATE TABLE flipper_features ( id integer PRIMARY KEY, @@ -39,10 +41,10 @@ SQL end - after(:each) do + after do ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_features`") ActiveRecord::Base.connection.execute("DROP table IF EXISTS `flipper_gates`") end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/active_support_cache_store_spec.rb b/spec/flipper/adapters/active_support_cache_store_spec.rb index 37a765dd9..eab87c852 100644 --- a/spec/flipper/adapters/active_support_cache_store_spec.rb +++ b/spec/flipper/adapters/active_support_cache_store_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'active_support/cache' require 'active_support/cache/dalli_store' @@ -6,6 +8,8 @@ require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::ActiveSupportCacheStore do + subject { adapter } + let(:memory_adapter) do Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new) end @@ -13,13 +17,11 @@ let(:adapter) { described_class.new(memory_adapter, cache, expires_in: 10.seconds) } let(:flipper) { Flipper.new(adapter) } - subject { adapter } - before do cache.clear end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' describe '#remove' do it 'expires feature' do diff --git a/spec/flipper/adapters/dalli_spec.rb b/spec/flipper/adapters/dalli_spec.rb index d4439c96e..0d8c80012 100644 --- a/spec/flipper/adapters/dalli_spec.rb +++ b/spec/flipper/adapters/dalli_spec.rb @@ -1,9 +1,13 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/operation_logger' require 'flipper/adapters/dalli' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Dalli do + subject { adapter } + let(:memory_adapter) do Flipper::Adapters::OperationLogger.new(Flipper::Adapters::Memory.new) end @@ -11,13 +15,11 @@ let(:adapter) { described_class.new(memory_adapter, cache) } let(:flipper) { Flipper.new(adapter) } - subject { adapter } - before do cache.flush end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' describe '#remove' do it 'expires feature' do diff --git a/spec/flipper/adapters/http_spec.rb b/spec/flipper/adapters/http_spec.rb index 2be4387ca..c71976a96 100644 --- a/spec/flipper/adapters/http_spec.rb +++ b/spec/flipper/adapters/http_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/http' require 'flipper/adapters/pstore' @@ -37,14 +39,14 @@ end after :all do - @server.shutdown if @server + @server&.shutdown end - before(:each) do + before do @pstore_file.unlink if @pstore_file.exist? end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' it "can enable and disable unregistered group" do flipper = Flipper.new(subject) @@ -119,6 +121,8 @@ end describe 'configuration' do + subject { described_class.new(options) } + let(:debug_output) { object_double($stderr) } let(:options) do { @@ -132,7 +136,7 @@ debug_output: debug_output, } end - subject { described_class.new(options) } + let(:feature) { flipper[:feature_panel] } before do @@ -151,7 +155,7 @@ subject.get(feature) expect( a_request(:get, 'http://app.com/mount-point/features/feature_panel') - .with(basic_auth: %w(username password)) + .with(basic_auth: %w[username password]) ).to have_been_made.once end @@ -165,7 +169,7 @@ end def fixture_file(name) - fixtures_path = File.expand_path('../../../fixtures', __FILE__) + fixtures_path = File.expand_path('../../fixtures', __dir__) File.new(fixtures_path + '/' + name) end end diff --git a/spec/flipper/adapters/instrumented_spec.rb b/spec/flipper/adapters/instrumented_spec.rb index 2b9a8fdcc..cecc334f1 100644 --- a/spec/flipper/adapters/instrumented_spec.rb +++ b/spec/flipper/adapters/instrumented_spec.rb @@ -1,9 +1,15 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/instrumented' require 'flipper/instrumenters/memory' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Instrumented do + subject do + described_class.new(adapter, instrumenter: instrumenter) + end + let(:instrumenter) { Flipper::Instrumenters::Memory.new } let(:adapter) { Flipper::Adapters::Memory.new } let(:flipper) { Flipper.new(adapter) } @@ -12,11 +18,7 @@ let(:gate) { feature.gate(:percentage_of_actors) } let(:thing) { flipper.actors(22) } - subject do - described_class.new(adapter, instrumenter: instrumenter) - end - - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' it 'forwards missing methods to underlying adapter' do adapter = Class.new do diff --git a/spec/flipper/adapters/memoizable_spec.rb b/spec/flipper/adapters/memoizable_spec.rb index 121f83b3a..0ce9632bc 100644 --- a/spec/flipper/adapters/memoizable_spec.rb +++ b/spec/flipper/adapters/memoizable_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/memoizable' require 'flipper/adapters/operation_logger' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Memoizable do + subject { described_class.new(adapter, cache) } + let(:features_key) { described_class::FeaturesKey } let(:adapter) { Flipper::Adapters::Memory.new } let(:flipper) { Flipper.new(adapter) } let(:cache) { {} } - subject { described_class.new(adapter, cache) } - - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' it 'forwards missing methods to underlying adapter' do adapter = Class.new do @@ -91,7 +93,7 @@ def foo end it 'memoizes features' do - names = %i(stats shiny) + names = [:stats, :shiny] features = names.map { |name| flipper[name] } results = subject.get_multi(features) features.each do |feature| @@ -107,7 +109,7 @@ def foo end it 'returns result' do - names = %i(stats shiny) + names = [:stats, :shiny] features = names.map { |name| flipper[name] } result = subject.get_multi(features) adapter_result = adapter.get_multi(features) @@ -123,7 +125,7 @@ def foo end it 'memoizes features' do - names = %i(stats shiny) + names = [:stats, :shiny] features = names.map { |name| flipper[name].tap(&:enable) } results = subject.get_all features.each do |feature| @@ -161,7 +163,7 @@ def foo end it 'returns result' do - names = %i(stats shiny) + names = [:stats, :shiny] names.map { |name| flipper[name].tap(&:enable) } result = subject.get_all adapter_result = adapter.get_all diff --git a/spec/flipper/adapters/memory_spec.rb b/spec/flipper/adapters/memory_spec.rb index 62a3a594a..847b3ab05 100644 --- a/spec/flipper/adapters/memory_spec.rb +++ b/spec/flipper/adapters/memory_spec.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Memory do subject { described_class.new } - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/moneta_spec.rb b/spec/flipper/adapters/moneta_spec.rb index 368254812..fca7bee76 100644 --- a/spec/flipper/adapters/moneta_spec.rb +++ b/spec/flipper/adapters/moneta_spec.rb @@ -1,10 +1,13 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/moneta' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Moneta do - let(:moneta) { Moneta.new(:Memory) } subject { described_class.new(moneta) } - it_should_behave_like 'a flipper adapter' + let(:moneta) { Moneta.new(:Memory) } + + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/mongo_spec.rb b/spec/flipper/adapters/mongo_spec.rb index bb6934b9a..58d9bf89e 100644 --- a/spec/flipper/adapters/mongo_spec.rb +++ b/spec/flipper/adapters/mongo_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/mongo' require 'flipper/spec/shared_adapter_specs' @@ -23,5 +25,5 @@ collection.create end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/operation_logger_spec.rb b/spec/flipper/adapters/operation_logger_spec.rb index 5eec8f1a6..e468a1de8 100644 --- a/spec/flipper/adapters/operation_logger_spec.rb +++ b/spec/flipper/adapters/operation_logger_spec.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/operation_logger' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::OperationLogger do + subject { described_class.new(adapter, operations) } + let(:operations) { [] } let(:adapter) { Flipper::Adapters::Memory.new } let(:flipper) { Flipper.new(adapter) } - subject { described_class.new(adapter, operations) } - - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' it 'forwards missing methods to underlying adapter' do adapter = Class.new do diff --git a/spec/flipper/adapters/pstore_spec.rb b/spec/flipper/adapters/pstore_spec.rb index 2ccf9993e..bdeae19c5 100644 --- a/spec/flipper/adapters/pstore_spec.rb +++ b/spec/flipper/adapters/pstore_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/pstore' require 'flipper/spec/shared_adapter_specs' @@ -10,7 +12,7 @@ described_class.new(pstore_file) end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' it 'defaults path to flipper.pstore' do expect(described_class.new.path).to eq('flipper.pstore') diff --git a/spec/flipper/adapters/read_only_spec.rb b/spec/flipper/adapters/read_only_spec.rb index 12caa81bb..f384c3239 100644 --- a/spec/flipper/adapters/read_only_spec.rb +++ b/spec/flipper/adapters/read_only_spec.rb @@ -1,7 +1,11 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/read_only' RSpec.describe Flipper::Adapters::ReadOnly do + subject { described_class.new(adapter) } + let(:adapter) { Flipper::Adapters::Memory.new } let(:flipper) { Flipper.new(subject) } let(:feature) { flipper[:stats] } @@ -12,8 +16,6 @@ let(:actors_gate) { feature.gate(:percentage_of_actors) } let(:time_gate) { feature.gate(:percentage_of_time) } - subject { described_class.new(adapter) } - before do Flipper.register(:admins) do |actor| actor.respond_to?(:admin?) && actor.admin? diff --git a/spec/flipper/adapters/redis_cache_spec.rb b/spec/flipper/adapters/redis_cache_spec.rb index f1618a981..586a098c0 100644 --- a/spec/flipper/adapters/redis_cache_spec.rb +++ b/spec/flipper/adapters/redis_cache_spec.rb @@ -1,9 +1,13 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/operation_logger' require 'flipper/adapters/redis_cache' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::RedisCache do + subject { adapter } + let(:client) do options = {} options[:url] = ENV['REDIS_URL'] if ENV['REDIS_URL'] @@ -16,13 +20,11 @@ let(:adapter) { described_class.new(memory_adapter, client) } let(:flipper) { Flipper.new(adapter) } - subject { adapter } - before do client.flushdb end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' describe '#remove' do it 'expires feature' do diff --git a/spec/flipper/adapters/redis_spec.rb b/spec/flipper/adapters/redis_spec.rb index 9ed6d5c83..8cca0e344 100644 --- a/spec/flipper/adapters/redis_spec.rb +++ b/spec/flipper/adapters/redis_spec.rb @@ -1,8 +1,12 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/redis' require 'flipper/spec/shared_adapter_specs' RSpec.describe Flipper::Adapters::Redis do + subject { described_class.new(client) } + let(:client) do options = {} @@ -11,11 +15,9 @@ Redis.new(options) end - subject { described_class.new(client) } - before do client.flushdb end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/rollout_spec.rb b/spec/flipper/adapters/rollout_spec.rb index 003e850b5..07bf04c4e 100644 --- a/spec/flipper/adapters/rollout_spec.rb +++ b/spec/flipper/adapters/rollout_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'redis' require 'rollout' diff --git a/spec/flipper/adapters/sequel_spec.rb b/spec/flipper/adapters/sequel_spec.rb index 7463450eb..634049cce 100644 --- a/spec/flipper/adapters/sequel_spec.rb +++ b/spec/flipper/adapters/sequel_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'sequel' @@ -17,15 +19,15 @@ let(:feature_class) { Flipper::Adapters::Sequel::Feature } let(:gate_class) { Flipper::Adapters::Sequel::Gate } - before(:each) do + before do CreateFlipperTablesSequel.new(Sequel::Model.db).up feature_class.dataset = feature_class.dataset gate_class.dataset = gate_class.dataset end - after(:each) do + after do CreateFlipperTablesSequel.new(Sequel::Model.db).down end - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' end diff --git a/spec/flipper/adapters/sync/feature_synchronizer_spec.rb b/spec/flipper/adapters/sync/feature_synchronizer_spec.rb index c474acbdf..1d651aac7 100644 --- a/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +++ b/spec/flipper/adapters/sync/feature_synchronizer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require "helper" require "flipper/adapters/memory" require "flipper/adapters/operation_logger" diff --git a/spec/flipper/adapters/sync/interval_synchronizer_spec.rb b/spec/flipper/adapters/sync/interval_synchronizer_spec.rb index 5c8c3324a..a2ab053f5 100644 --- a/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +++ b/spec/flipper/adapters/sync/interval_synchronizer_spec.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require "helper" require "flipper/adapters/sync/interval_synchronizer" RSpec.describe Flipper::Adapters::Sync::IntervalSynchronizer do + subject { described_class.new(synchronizer, interval: interval) } + let(:events) { [] } let(:synchronizer) { -> { events << described_class.now } } let(:interval) { 10 } - subject { described_class.new(synchronizer, interval: interval) } - it 'synchronizes on first call' do expect(events.size).to be(0) subject.call diff --git a/spec/flipper/adapters/sync/synchronizer_spec.rb b/spec/flipper/adapters/sync/synchronizer_spec.rb index ba51a0ad1..2fa89efd3 100644 --- a/spec/flipper/adapters/sync/synchronizer_spec.rb +++ b/spec/flipper/adapters/sync/synchronizer_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require "helper" require "flipper/adapters/memory" require "flipper/instrumenters/memory" require "flipper/adapters/sync/synchronizer" RSpec.describe Flipper::Adapters::Sync::Synchronizer do + subject { described_class.new(local, remote, instrumenter: instrumenter) } + let(:local) { Flipper::Adapters::Memory.new } let(:remote) { Flipper::Adapters::Memory.new } let(:local_flipper) { Flipper.new(local) } let(:remote_flipper) { Flipper.new(remote) } let(:instrumenter) { Flipper::Instrumenters::Memory.new } - subject { described_class.new(local, remote, instrumenter: instrumenter) } - it "instruments call" do subject.call expect(instrumenter.events_by_name("synchronizer_exception.flipper").size).to be(0) @@ -65,7 +67,7 @@ expect(local_flipper[:search].boolean_value).to eq(true) expect(local_flipper[:logging].percentage_of_time_value).to eq(10) - expect(local_flipper.features.map(&:key).sort).to eq(%w(logging search)) + expect(local_flipper.features.map(&:key).sort).to eq(%w[logging search]) end it 'adds features in remote that are not in local' do diff --git a/spec/flipper/adapters/sync_spec.rb b/spec/flipper/adapters/sync_spec.rb index dd7eed702..ea0803f63 100644 --- a/spec/flipper/adapters/sync_spec.rb +++ b/spec/flipper/adapters/sync_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/sync' require 'flipper/adapters/operation_logger' @@ -5,6 +7,10 @@ require 'active_support/notifications' RSpec.describe Flipper::Adapters::Sync do + subject do + described_class.new(local_adapter, remote_adapter, interval: 1) + end + let(:local_adapter) do Flipper::Adapters::OperationLogger.new Flipper::Adapters::Memory.new end @@ -15,42 +21,38 @@ let(:remote) { Flipper.new(remote_adapter) } let(:sync) { Flipper.new(subject) } - subject do - described_class.new(local_adapter, remote_adapter, interval: 1) - end - - it_should_behave_like 'a flipper adapter' + it_behaves_like 'a flipper adapter' context 'when local has never been synced' do it 'syncs boolean' do remote.enable(:search) expect(sync[:search].boolean_value).to be(true) - expect(subject.features.sort).to eq(%w(search)) + expect(subject.features.sort).to eq(%w[search]) end it 'syncs actor' do actor = Flipper::Actor.new("User;1000") remote.enable_actor(:search, actor) expect(sync[:search].actors_value).to eq(Set[actor.flipper_id]) - expect(subject.features.sort).to eq(%w(search)) + expect(subject.features.sort).to eq(%w[search]) end it 'syncs group' do remote.enable_group(:search, :staff) expect(sync[:search].groups_value).to eq(Set["staff"]) - expect(subject.features.sort).to eq(%w(search)) + expect(subject.features.sort).to eq(%w[search]) end it 'syncs percentage of actors' do remote.enable_percentage_of_actors(:search, 25) expect(sync[:search].percentage_of_actors_value).to eq(25) - expect(subject.features.sort).to eq(%w(search)) + expect(subject.features.sort).to eq(%w[search]) end it 'syncs percentage of time' do remote.enable_percentage_of_time(:search, 15) expect(sync[:search].percentage_of_time_value).to eq(15) - expect(subject.features.sort).to eq(%w(search)) + expect(subject.features.sort).to eq(%w[search]) end end diff --git a/spec/flipper/api/action_spec.rb b/spec/flipper/api/action_spec.rb index 4ee974f04..0a87106db 100644 --- a/spec/flipper/api/action_spec.rb +++ b/spec/flipper/api/action_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::Action do diff --git a/spec/flipper/api/json_params_spec.rb b/spec/flipper/api/json_params_spec.rb index 186fdd15d..946e976c8 100644 --- a/spec/flipper/api/json_params_spec.rb +++ b/spec/flipper/api/json_params_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::JsonParams do diff --git a/spec/flipper/api/v1/actions/actors_gate_spec.rb b/spec/flipper/api/v1/actions/actors_gate_spec.rb index dfa35948e..7490a47d8 100644 --- a/spec/flipper/api/v1/actions/actors_gate_spec.rb +++ b/spec/flipper/api/v1/actions/actors_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::ActorsGate do @@ -12,7 +14,7 @@ it 'enables feature for actor' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(actor)).to be_truthy + expect(flipper[:my_feature]).to be_enabled(actor) expect(flipper[:my_feature].enabled_gate_names).to eq([:actor]) end @@ -32,7 +34,7 @@ it 'disables feature' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(actor)).to be_falsy + expect(flipper[:my_feature]).not_to be_enabled(actor) expect(flipper[:my_feature].enabled_gate_names).to be_empty end @@ -50,7 +52,7 @@ it 'enables feature for actor' do expect(last_response.status).to eq(200) - expect(flipper["my/feature"].enabled?(actor)).to be_truthy + expect(flipper["my/feature"]).to be_enabled(actor) expect(flipper["my/feature"].enabled_gate_names).to eq([:actor]) end @@ -115,7 +117,7 @@ it 'enables feature for actor' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(actor)).to be_truthy + expect(flipper[:my_feature]).to be_enabled(actor) expect(flipper[:my_feature].enabled_gate_names).to eq([:actor]) end @@ -132,7 +134,7 @@ it 'disables feature' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(actor)).to be_falsy + expect(flipper[:my_feature]).not_to be_enabled(actor) expect(flipper[:my_feature].enabled_gate_names).to be_empty end diff --git a/spec/flipper/api/v1/actions/actors_spec.rb b/spec/flipper/api/v1/actions/actors_spec.rb index 78346a399..c8b80af1c 100644 --- a/spec/flipper/api/v1/actions/actors_spec.rb +++ b/spec/flipper/api/v1/actions/actors_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::Actors do diff --git a/spec/flipper/api/v1/actions/boolean_gate_spec.rb b/spec/flipper/api/v1/actions/boolean_gate_spec.rb index 71978a87b..467af0cf3 100644 --- a/spec/flipper/api/v1/actions/boolean_gate_spec.rb +++ b/spec/flipper/api/v1/actions/boolean_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::BooleanGate do @@ -11,7 +13,7 @@ it 'enables feature' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].on?).to be_truthy + expect(flipper[:my_feature]).to be_on end it 'returns decorated feature with boolean gate enabled' do @@ -28,7 +30,7 @@ it 'enables feature' do expect(last_response.status).to eq(200) - expect(flipper["my/feature"].on?).to be_truthy + expect(flipper["my/feature"]).to be_on end it 'returns decorated feature with boolean gate enabled' do @@ -45,7 +47,7 @@ it 'disables feature' do expect(last_response.status).to eq(200) - expect(flipper[:my_feature].off?).to be_truthy + expect(flipper[:my_feature]).to be_off end it 'returns decorated feature with boolean gate disabled' do diff --git a/spec/flipper/api/v1/actions/clear_feature_spec.rb b/spec/flipper/api/v1/actions/clear_feature_spec.rb index bda8f14c4..3d9f686c4 100644 --- a/spec/flipper/api/v1/actions/clear_feature_spec.rb +++ b/spec/flipper/api/v1/actions/clear_feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::ClearFeature do @@ -20,7 +22,7 @@ it 'clears feature' do expect(last_response.status).to eq(204) - expect(flipper[:my_feature].off?).to be_truthy + expect(flipper[:my_feature]).to be_off end end @@ -41,7 +43,7 @@ it 'clears feature' do expect(last_response.status).to eq(204) - expect(flipper["my/feature"].off?).to be_truthy + expect(flipper["my/feature"]).to be_off end end end diff --git a/spec/flipper/api/v1/actions/feature_spec.rb b/spec/flipper/api/v1/actions/feature_spec.rb index f738ba667..d35467e52 100644 --- a/spec/flipper/api/v1/actions/feature_spec.rb +++ b/spec/flipper/api/v1/actions/feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::Feature do diff --git a/spec/flipper/api/v1/actions/features_spec.rb b/spec/flipper/api/v1/actions/features_spec.rb index 8915cac6a..086db46f2 100644 --- a/spec/flipper/api/v1/actions/features_spec.rb +++ b/spec/flipper/api/v1/actions/features_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::Features do @@ -66,7 +68,7 @@ it 'responds with correct attributes' do expect(last_response.status).to eq(200) keys = json_response.fetch('features').map { |feature| feature.fetch('key') }.sort - expect(keys).to eq(%w(search stats)) + expect(keys).to eq(%w[search stats]) end end @@ -80,7 +82,7 @@ it 'only returns features that exist' do expect(last_response.status).to eq(200) keys = json_response.fetch('features').map { |feature| feature.fetch('key') }.sort - expect(keys).to eq(%w(search stats)) + expect(keys).to eq(%w[search stats]) end end @@ -150,7 +152,7 @@ end it 'does not enable feature' do - expect(flipper['my_feature'].enabled?).to be_falsy + expect(flipper['my_feature']).not_to be_enabled end end diff --git a/spec/flipper/api/v1/actions/groups_gate_spec.rb b/spec/flipper/api/v1/actions/groups_gate_spec.rb index a330633c7..e7cc8d7e1 100644 --- a/spec/flipper/api/v1/actions/groups_gate_spec.rb +++ b/spec/flipper/api/v1/actions/groups_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::GroupsGate do @@ -17,7 +19,7 @@ allow(person).to receive(:flipper_id).and_return(1) allow(person).to receive(:admin?).and_return(true) expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(person)).to be_truthy + expect(flipper[:my_feature]).to be_enabled(person) end it 'returns decorated feature with group enabled' do @@ -40,7 +42,7 @@ allow(person).to receive(:flipper_id).and_return(1) allow(person).to receive(:admin?).and_return(true) expect(last_response.status).to eq(200) - expect(flipper["my/feature"].enabled?(person)).to be_truthy + expect(flipper["my/feature"]).to be_enabled(person) end it 'returns decorated feature with group enabled' do @@ -87,7 +89,7 @@ allow(person).to receive(:flipper_id).and_return(1) allow(person).to receive(:admin?).and_return(true) expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(person)).to be_falsey + expect(flipper[:my_feature]).not_to be_enabled(person) end it 'returns decorated feature with group disabled' do @@ -109,7 +111,7 @@ allow(person).to receive(:flipper_id).and_return(1) allow(person).to receive(:admin?).and_return(true) expect(last_response.status).to eq(200) - expect(flipper[:my_feature].enabled?(person)).to be_falsey + expect(flipper[:my_feature]).not_to be_enabled(person) end it 'returns decorated feature with group disabled' do diff --git a/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb b/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb index f568cce0a..a9e5d827c 100644 --- a/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb +++ b/spec/flipper/api/v1/actions/percentage_of_actors_gate_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::PercentageOfActorsGate do let(:app) { build_api(flipper) } describe 'enable' do - context 'for feature with slash in name' do + context 'with feature with slash in name' do before do flipper["my/feature"].disable post '/features/my/feature/percentage_of_actors', percentage: '10' diff --git a/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb b/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb index 72bb35d5a..9b7377d67 100644 --- a/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb +++ b/spec/flipper/api/v1/actions/percentage_of_time_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api::V1::Actions::PercentageOfTimeGate do diff --git a/spec/flipper/api_spec.rb b/spec/flipper/api_spec.rb index e22ffb6ac..2e1165ecf 100644 --- a/spec/flipper/api_spec.rb +++ b/spec/flipper/api_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Api do @@ -20,7 +22,7 @@ expect(last_response.status).to eq(200) feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') } - expect(feature_names).to eq(%w(env_a env_b)) + expect(feature_names).to eq(%w[env_a env_b]) end end @@ -39,7 +41,7 @@ expect(last_response.status).to eq(200) feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') } - expect(feature_names).to eq(%w(a b)) + expect(feature_names).to eq(%w[a b]) end end @@ -63,7 +65,7 @@ expect(last_response.status).to eq(200) feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') } - expect(feature_names).to eq(%w(a b)) + expect(feature_names).to eq(%w[a b]) end end diff --git a/spec/flipper/cloud/configuration_spec.rb b/spec/flipper/cloud/configuration_spec.rb index adc347268..57430c306 100644 --- a/spec/flipper/cloud/configuration_spec.rb +++ b/spec/flipper/cloud/configuration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/cloud/configuration' require 'flipper/adapters/instrumented' diff --git a/spec/flipper/cloud_spec.rb b/spec/flipper/cloud_spec.rb index 2af5e6d4d..c760ad370 100644 --- a/spec/flipper/cloud_spec.rb +++ b/spec/flipper/cloud_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/cloud' require 'flipper/adapters/instrumented' diff --git a/spec/flipper/configuration_spec.rb b/spec/flipper/configuration_spec.rb index ffc06023f..32293fcb2 100644 --- a/spec/flipper/configuration_spec.rb +++ b/spec/flipper/configuration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/configuration' diff --git a/spec/flipper/dsl_spec.rb b/spec/flipper/dsl_spec.rb index 4d98d7e70..98beb3ce3 100644 --- a/spec/flipper/dsl_spec.rb +++ b/spec/flipper/dsl_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/dsl' @@ -28,7 +30,7 @@ end describe '#feature' do - it_should_behave_like 'a DSL feature' do + it_behaves_like 'a DSL feature' do let(:method_name) { :feature } let(:instrumenter) { double('Instrumentor', instrument: nil) } let(:feature) { dsl.send(method_name, :stats) } @@ -39,7 +41,7 @@ describe '#preload' do let(:instrumenter) { double('Instrumentor', instrument: nil) } let(:dsl) { described_class.new(adapter, instrumenter: instrumenter) } - let(:names) { %i(stats shiny) } + let(:names) { [:stats, :shiny] } let(:features) { dsl.preload(names) } it 'returns array of features' do @@ -75,7 +77,7 @@ names.each { |name| adapter.add subject[name] } described_class.new(adapter, instrumenter: instrumenter) end - let(:names) { %i(stats shiny) } + let(:names) { [:stats, :shiny] } let(:features) { dsl.preload_all } it 'returns array of features' do @@ -106,7 +108,7 @@ end describe '#[]' do - it_should_behave_like 'a DSL feature' do + it_behaves_like 'a DSL feature' do let(:method_name) { :[] } let(:instrumenter) { double('Instrumentor', instrument: nil) } let(:feature) { dsl.send(method_name, :stats) } @@ -115,19 +117,19 @@ end describe '#boolean' do - it_should_behave_like 'a DSL boolean method' do + it_behaves_like 'a DSL boolean method' do let(:method_name) { :boolean } end end describe '#bool' do - it_should_behave_like 'a DSL boolean method' do + it_behaves_like 'a DSL boolean method' do let(:method_name) { :bool } end end describe '#group' do - context 'for registered group' do + context 'with registered group' do before do @group = Flipper.register(:admins) {} end @@ -140,7 +142,7 @@ end describe '#actor' do - context 'for a thing' do + context 'with a thing' do it 'returns actor instance' do thing = Flipper::Actor.new(33) actor = subject.actor(thing) @@ -149,7 +151,7 @@ end end - context 'for nil' do + context 'with nil' do it 'raises argument error' do expect do subject.actor(nil) @@ -157,7 +159,7 @@ end end - context 'for something that is not actor wrappable' do + context 'with something that is not actor wrappable' do it 'raises argument error' do expect do subject.actor(Object.new) @@ -221,7 +223,7 @@ subject.features.each do |feature| expect(feature).to be_instance_of(Flipper::Feature) end - expect(subject.features.map(&:name).map(&:to_s).sort).to eq(%w(cache search stats)) + expect(subject.features.map(&:name).map(&:to_s).sort).to eq(%w[cache search stats]) end end end diff --git a/spec/flipper/feature_check_context_spec.rb b/spec/flipper/feature_check_context_spec.rb index 52dc7f306..18522359f 100644 --- a/spec/flipper/feature_check_context_spec.rb +++ b/spec/flipper/feature_check_context_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::FeatureCheckContext do diff --git a/spec/flipper/feature_spec.rb b/spec/flipper/feature_spec.rb index 77551af56..d3f99bb0b 100644 --- a/spec/flipper/feature_spec.rb +++ b/spec/flipper/feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/feature' require 'flipper/instrumenters/memory' @@ -142,12 +144,12 @@ end describe 'instrumentation' do - let(:instrumenter) { Flipper::Instrumenters::Memory.new } - subject do described_class.new(:search, adapter, instrumenter: instrumenter) end + let(:instrumenter) { Flipper::Instrumenters::Memory.new } + it 'is recorded for enable' do thing = Flipper::Types::Actor.new(Flipper::Actor.new('1')) gate = subject.gate_for(thing) diff --git a/spec/flipper/gate_spec.rb b/spec/flipper/gate_spec.rb index 364d8e148..38383519a 100644 --- a/spec/flipper/gate_spec.rb +++ b/spec/flipper/gate_spec.rb @@ -1,14 +1,20 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gate do - let(:feature_name) { :stats } - subject do described_class.new end + let(:feature_name) { :stats } + describe '#inspect' do - context 'for subclass' do + context 'with subclass' do + subject do + subclass.new + end + let(:subclass) do Class.new(described_class) do def name @@ -25,10 +31,6 @@ def data_type end end - subject do - subclass.new - end - it 'includes attributes' do string = subject.inspect expect(string).to include(subject.object_id.to_s) diff --git a/spec/flipper/gate_values_spec.rb b/spec/flipper/gate_values_spec.rb index 5aab8c70e..23fc43274 100644 --- a/spec/flipper/gate_values_spec.rb +++ b/spec/flipper/gate_values_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/gate_values' diff --git a/spec/flipper/gates/actor_spec.rb b/spec/flipper/gates/actor_spec.rb index ea6669572..3836a0bed 100644 --- a/spec/flipper/gates/actor_spec.rb +++ b/spec/flipper/gates/actor_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gates::Actor do - let(:feature_name) { :search } - subject do described_class.new end + + let(:feature_name) { :search } end diff --git a/spec/flipper/gates/boolean_spec.rb b/spec/flipper/gates/boolean_spec.rb index cf9545e6a..9ac6121cf 100644 --- a/spec/flipper/gates/boolean_spec.rb +++ b/spec/flipper/gates/boolean_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gates::Boolean do - let(:feature_name) { :search } - subject do described_class.new end + let(:feature_name) { :search } + def context(bool) Flipper::FeatureCheckContext.new( feature_name: feature_name, @@ -16,13 +18,13 @@ def context(bool) end describe '#enabled?' do - context 'for true value' do + context 'with true value' do it 'returns true' do expect(subject.enabled?(true)).to eq(true) end end - context 'for false value' do + context 'with false value' do it 'returns false' do expect(subject.enabled?(false)).to eq(false) end @@ -30,13 +32,13 @@ def context(bool) end describe '#open?' do - context 'for true value' do + context 'with true value' do it 'returns true' do expect(subject.open?(context(true))).to be(true) end end - context 'for false value' do + context 'with false value' do it 'returns false' do expect(subject.open?(context(false))).to be(false) end diff --git a/spec/flipper/gates/group_spec.rb b/spec/flipper/gates/group_spec.rb index fcb719492..7b8e170cf 100644 --- a/spec/flipper/gates/group_spec.rb +++ b/spec/flipper/gates/group_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gates::Group do - let(:feature_name) { :search } - subject do described_class.new end + let(:feature_name) { :search } + def context(set) Flipper::FeatureCheckContext.new( feature_name: feature_name, diff --git a/spec/flipper/gates/percentage_of_actors_spec.rb b/spec/flipper/gates/percentage_of_actors_spec.rb index 95d6fc04d..44b482ec5 100644 --- a/spec/flipper/gates/percentage_of_actors_spec.rb +++ b/spec/flipper/gates/percentage_of_actors_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gates::PercentageOfActors do - let(:feature_name) { :search } - subject do described_class.new end + let(:feature_name) { :search } + def context(percentage_of_actors_value, feature = feature_name, thing = nil) Flipper::FeatureCheckContext.new( feature_name: feature, @@ -50,7 +52,9 @@ def context(percentage_of_actors_value, feature = feature_name, thing = nil) end end - context 'for fractional percentage' do + context 'with fractional percentage' do + subject { described_class.new } + let(:decimal) { 0.001 } let(:percentage) { decimal * 100 } let(:number_of_actors) { 10_000 } @@ -59,8 +63,6 @@ def context(percentage_of_actors_value, feature = feature_name, thing = nil) (1..number_of_actors).map { |n| Flipper::Actor.new(n) } end - subject { described_class.new } - it 'enables feature for accurate number of actors' do margin_of_error = 0.02 * number_of_actors expected_open_count = number_of_actors * decimal diff --git a/spec/flipper/gates/percentage_of_time_spec.rb b/spec/flipper/gates/percentage_of_time_spec.rb index 1ce386c78..2e7c8f2fb 100644 --- a/spec/flipper/gates/percentage_of_time_spec.rb +++ b/spec/flipper/gates/percentage_of_time_spec.rb @@ -1,12 +1,14 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Gates::PercentageOfTime do - let(:feature_name) { :search } - subject do described_class.new end + let(:feature_name) { :search } + def context(percentage_of_time_value, feature = feature_name, thing = nil) Flipper::FeatureCheckContext.new( feature_name: feature, @@ -16,13 +18,13 @@ def context(percentage_of_time_value, feature = feature_name, thing = nil) end describe '#open?' do - context 'for fractional percentage' do + context 'with fractional percentage' do + subject { described_class.new } + let(:decimal) { 0.001 } let(:percentage) { decimal * 100 } let(:number_of_invocations) { 10_000 } - subject { described_class.new } - it 'enables feature for accurate percentage of time' do margin_of_error = 0.02 * number_of_invocations expected_open_count = number_of_invocations * decimal diff --git a/spec/flipper/instrumentation/log_subscriber_spec.rb b/spec/flipper/instrumentation/log_subscriber_spec.rb index 1ec8d400a..ddea85ccb 100644 --- a/spec/flipper/instrumentation/log_subscriber_spec.rb +++ b/spec/flipper/instrumentation/log_subscriber_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'logger' require 'helper' require 'flipper/adapters/instrumented' diff --git a/spec/flipper/instrumentation/statsd_subscriber_spec.rb b/spec/flipper/instrumentation/statsd_subscriber_spec.rb index 1e596815d..fddc0a0ec 100644 --- a/spec/flipper/instrumentation/statsd_subscriber_spec.rb +++ b/spec/flipper/instrumentation/statsd_subscriber_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/adapters/instrumented' require 'flipper/instrumentation/statsd' @@ -37,7 +39,7 @@ def assert_counter(metric) expect(result).not_to be_nil end - context 'for enabled feature' do + context 'with enabled feature' do it 'updates feature metrics when calls happen' do flipper[:stats].enable(user) assert_timer 'flipper.feature_operation.enable' @@ -48,7 +50,7 @@ def assert_counter(metric) end end - context 'for disabled feature' do + context 'with disabled feature' do it 'updates feature metrics when calls happen' do flipper[:stats].disable(user) assert_timer 'flipper.feature_operation.disable' diff --git a/spec/flipper/instrumenters/memory_spec.rb b/spec/flipper/instrumenters/memory_spec.rb index 26f769308..ae6977ba7 100644 --- a/spec/flipper/instrumenters/memory_spec.rb +++ b/spec/flipper/instrumenters/memory_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/instrumenters/memory' diff --git a/spec/flipper/instrumenters/noop_spec.rb b/spec/flipper/instrumenters/noop_spec.rb index d7b075446..4d0dd6d41 100644 --- a/spec/flipper/instrumenters/noop_spec.rb +++ b/spec/flipper/instrumenters/noop_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Instrumenters::Noop do diff --git a/spec/flipper/middleware/memoizer_spec.rb b/spec/flipper/middleware/memoizer_spec.rb index e6df6ecab..087d48e16 100644 --- a/spec/flipper/middleware/memoizer_spec.rb +++ b/spec/flipper/middleware/memoizer_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'rack/test' require 'active_support/cache' @@ -74,7 +76,7 @@ flipper.adapter.cache['hello'] = 'world' begin get '/fail', {}, 'flipper' => flipper - rescue + rescue StandardError nil end expect(flipper.adapter.cache).to be_empty @@ -171,7 +173,7 @@ middleware = described_class Rack::Builder.new do - use middleware, preload: %i(stats) + use middleware, preload: [:stats] map '/' do run ->(_env) { [200, {}, []] } @@ -197,7 +199,7 @@ [200, {}, []] end - middleware = described_class.new app, preload: %i(stats) + middleware = described_class.new app, preload: [:stats] middleware.call(env) expect(adapter.count(:get_multi)).to be(1) @@ -214,7 +216,7 @@ [200, {}, []] end - middleware = described_class.new app, preload: %i(stats) + middleware = described_class.new app, preload: [:stats] middleware.call(env) expect(adapter.count(:get)).to be(1) @@ -224,13 +226,11 @@ context 'when an app raises an exception' do it 'resets memoize' do - begin - app = ->(_env) { raise } - middleware = described_class.new(app) - middleware.call(env) - rescue RuntimeError - expect(flipper.memoizing?).to be(false) - end + app = ->(_env) { raise } + middleware = described_class.new(app) + middleware.call(env) + rescue RuntimeError + expect(flipper.memoizing?).to be(false) end end @@ -328,7 +328,7 @@ end it 'does NOT preload_all if request matches unless block' do - expect(flipper).to receive(:preload_all).never + expect(flipper).not_to receive(:preload_all) get '/assets/foo.png', {}, 'flipper' => flipper end diff --git a/spec/flipper/middleware/setup_env_spec.rb b/spec/flipper/middleware/setup_env_spec.rb index 2a3c8981a..7325e41b9 100644 --- a/spec/flipper/middleware/setup_env_spec.rb +++ b/spec/flipper/middleware/setup_env_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::Middleware::SetupEnv do diff --git a/spec/flipper/registry_spec.rb b/spec/flipper/registry_spec.rb index d661a7580..a40f0e7a0 100644 --- a/spec/flipper/registry_spec.rb +++ b/spec/flipper/registry_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/registry' @@ -87,7 +89,7 @@ end it 'returns the keys' do - expect(subject.keys.map(&:to_s).sort).to eq(%w(admins devs)) + expect(subject.keys.map(&:to_s).sort).to eq(%w[admins devs]) end it 'returns the keys as symbols' do @@ -104,7 +106,7 @@ end it 'returns the values' do - expect(subject.values.map(&:to_s).sort).to eq(%w(admins devs)) + expect(subject.values.map(&:to_s).sort).to eq(%w[admins devs]) end end @@ -123,8 +125,8 @@ values << value end - expect(keys.map(&:to_s).sort).to eq(%w(admins devs)) - expect(values.sort).to eq(%w(admins devs)) + expect(keys.map(&:to_s).sort).to eq(%w[admins devs]) + expect(values.sort).to eq(%w[admins devs]) end end diff --git a/spec/flipper/typecast_spec.rb b/spec/flipper/typecast_spec.rb index 99072a3a7..d9b19cc63 100644 --- a/spec/flipper/typecast_spec.rb +++ b/spec/flipper/typecast_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/typecast' diff --git a/spec/flipper/types/actor_spec.rb b/spec/flipper/types/actor_spec.rb index 6abec0b9f..c61b353d3 100644 --- a/spec/flipper/types/actor_spec.rb +++ b/spec/flipper/types/actor_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/actor' @@ -39,7 +41,7 @@ def admin? end describe '.wrap' do - context 'for actor' do + context 'with actor' do it 'returns actor' do actor = described_class.wrap(subject) expect(actor).to be_instance_of(described_class) @@ -47,7 +49,7 @@ def admin? end end - context 'for other thing' do + context 'with other thing' do it 'returns actor' do thing = thing_class.new('1') actor = described_class.wrap(thing) diff --git a/spec/flipper/types/boolean_spec.rb b/spec/flipper/types/boolean_spec.rb index d82f433f0..69f5444a4 100644 --- a/spec/flipper/types/boolean_spec.rb +++ b/spec/flipper/types/boolean_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/boolean' diff --git a/spec/flipper/types/group_spec.rb b/spec/flipper/types/group_spec.rb index 2d500187c..6a66b09e7 100644 --- a/spec/flipper/types/group_spec.rb +++ b/spec/flipper/types/group_spec.rb @@ -1,13 +1,15 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/group' RSpec.describe Flipper::Types::Group do - let(:fake_context) { double('FeatureCheckContext') } - subject do Flipper.register(:admins, &:admin?) end + let(:fake_context) { double('FeatureCheckContext') } + describe '.wrap' do context 'with group instance' do it 'returns group instance' do @@ -55,14 +57,14 @@ group = described_class.new(:examples) do |actor| actor.email =~ /@example\.com/ end - expect(group.match?(double('Actor', email: 'foo@example.com'), fake_context)).to be_truthy + expect(group).to be_match(double('Actor', email: 'foo@example.com'), fake_context) end it 'returns false for falsey block results' do group = described_class.new(:examples) do |_actor| nil end - expect(group.match?(double('Actor'), fake_context)).to be_falsey + expect(group).not_to be_match(double('Actor'), fake_context) end it 'returns true for truthy shortand block results' do @@ -73,7 +75,7 @@ def admin? end.new group = described_class.new(:admin, &:admin?) - expect(group.match?(actor, fake_context)).to be_truthy + expect(group).to be_match(actor, fake_context) end it 'returns false for falsy shortand block results' do @@ -84,7 +86,7 @@ def admin? end.new group = described_class.new(:admin, &:admin?) - expect(group.match?(actor, fake_context)).to be_falsey + expect(group).not_to be_match(actor, fake_context) end it 'can yield without context as block argument' do diff --git a/spec/flipper/types/percentage_of_actors_spec.rb b/spec/flipper/types/percentage_of_actors_spec.rb index d34785097..697b05915 100644 --- a/spec/flipper/types/percentage_of_actors_spec.rb +++ b/spec/flipper/types/percentage_of_actors_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/percentage_of_actors' RSpec.describe Flipper::Types::PercentageOfActors do - it_should_behave_like 'a percentage' + it_behaves_like 'a percentage' end diff --git a/spec/flipper/types/percentage_of_time_spec.rb b/spec/flipper/types/percentage_of_time_spec.rb index 07e12ea9d..024b52052 100644 --- a/spec/flipper/types/percentage_of_time_spec.rb +++ b/spec/flipper/types/percentage_of_time_spec.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/percentage_of_time' RSpec.describe Flipper::Types::PercentageOfTime do - it_should_behave_like 'a percentage' + it_behaves_like 'a percentage' end diff --git a/spec/flipper/types/percentage_spec.rb b/spec/flipper/types/percentage_spec.rb index 6d6a826a3..1a60378e0 100644 --- a/spec/flipper/types/percentage_spec.rb +++ b/spec/flipper/types/percentage_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/types/percentage_of_actors' @@ -5,7 +7,8 @@ subject do described_class.new(5) end - it_should_behave_like 'a percentage' + + it_behaves_like 'a percentage' describe '.wrap' do context 'with percentage instance' do diff --git a/spec/flipper/ui/action_spec.rb b/spec/flipper/ui/action_spec.rb index dafab01c1..fe1861d81 100644 --- a/spec/flipper/ui/action_spec.rb +++ b/spec/flipper/ui/action_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Action do diff --git a/spec/flipper/ui/actions/actors_gate_spec.rb b/spec/flipper/ui/actions/actors_gate_spec.rb index eb3ace17c..ea694a7e5 100644 --- a/spec/flipper/ui/actions/actors_gate_spec.rb +++ b/spec/flipper/ui/actions/actors_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::ActorsGate do @@ -69,7 +71,7 @@ end end - context 'for an invalid actor value' do + context 'with an invalid actor value' do context 'empty value' do let(:value) { '' } diff --git a/spec/flipper/ui/actions/add_feature_spec.rb b/spec/flipper/ui/actions/add_feature_spec.rb index 2b85b31fd..03cb92837 100644 --- a/spec/flipper/ui/actions/add_feature_spec.rb +++ b/spec/flipper/ui/actions/add_feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::AddFeature do diff --git a/spec/flipper/ui/actions/boolean_gate_spec.rb b/spec/flipper/ui/actions/boolean_gate_spec.rb index f9448a2c4..c44e07ab7 100644 --- a/spec/flipper/ui/actions/boolean_gate_spec.rb +++ b/spec/flipper/ui/actions/boolean_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::BooleanGate do diff --git a/spec/flipper/ui/actions/feature_spec.rb b/spec/flipper/ui/actions/feature_spec.rb index f7c92b630..8b8288cc7 100644 --- a/spec/flipper/ui/actions/feature_spec.rb +++ b/spec/flipper/ui/actions/feature_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::Feature do @@ -31,13 +33,11 @@ context 'when feature_removal_enabled is set to false' do around do |example| - begin - @original_feature_removal_enabled = Flipper::UI.configuration.feature_removal_enabled - Flipper::UI.configuration.feature_removal_enabled = false - example.run - ensure - Flipper::UI.configuration.feature_removal_enabled = @original_feature_removal_enabled - end + @original_feature_removal_enabled = Flipper::UI.configuration.feature_removal_enabled + Flipper::UI.configuration.feature_removal_enabled = false + example.run + ensure + Flipper::UI.configuration.feature_removal_enabled = @original_feature_removal_enabled end it 'returns with 403 status' do diff --git a/spec/flipper/ui/actions/features_spec.rb b/spec/flipper/ui/actions/features_spec.rb index 158c22f98..ec536c952 100644 --- a/spec/flipper/ui/actions/features_spec.rb +++ b/spec/flipper/ui/actions/features_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::Features do @@ -42,6 +44,7 @@ context "when fun mode is enabled" do let(:fun_mode) { true } + before { get '/features' } it 'responds with success' do @@ -55,6 +58,7 @@ context "when fun mode is disabled" do let(:fun_mode) { false } + before { get '/features' } it 'responds with success' do @@ -103,7 +107,7 @@ end end - context 'for an invalid feature name' do + context 'with an invalid feature name' do context 'empty feature name' do let(:feature_name) { '' } diff --git a/spec/flipper/ui/actions/file_spec.rb b/spec/flipper/ui/actions/file_spec.rb index c5f0923ff..248d17552 100644 --- a/spec/flipper/ui/actions/file_spec.rb +++ b/spec/flipper/ui/actions/file_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::File do diff --git a/spec/flipper/ui/actions/groups_gate_spec.rb b/spec/flipper/ui/actions/groups_gate_spec.rb index a74a2f63e..540e31999 100644 --- a/spec/flipper/ui/actions/groups_gate_spec.rb +++ b/spec/flipper/ui/actions/groups_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::GroupsGate do @@ -68,7 +70,7 @@ end end - context 'for an unregistered group' do + context 'with an unregistered group' do context 'unknown group name' do let(:group_name) { 'not_here' } diff --git a/spec/flipper/ui/actions/home_spec.rb b/spec/flipper/ui/actions/home_spec.rb index 639613622..4b6cbeb46 100644 --- a/spec/flipper/ui/actions/home_spec.rb +++ b/spec/flipper/ui/actions/home_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::Home do diff --git a/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb b/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb index 78bbe2c3b..2178975ce 100644 --- a/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb +++ b/spec/flipper/ui/actions/percentage_of_actors_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::PercentageOfActorsGate do diff --git a/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb b/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb index 2e71f7fad..8aa767ea5 100644 --- a/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb +++ b/spec/flipper/ui/actions/percentage_of_time_gate_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Actions::PercentageOfTimeGate do diff --git a/spec/flipper/ui/configuration_spec.rb b/spec/flipper/ui/configuration_spec.rb index d0f52207f..608287581 100644 --- a/spec/flipper/ui/configuration_spec.rb +++ b/spec/flipper/ui/configuration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Configuration do diff --git a/spec/flipper/ui/decorators/feature_spec.rb b/spec/flipper/ui/decorators/feature_spec.rb index 8f5cba743..8420f217d 100644 --- a/spec/flipper/ui/decorators/feature_spec.rb +++ b/spec/flipper/ui/decorators/feature_spec.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI::Decorators::Feature do + subject do + described_class.new(feature) + end + let(:source) { {} } let(:adapter) { Flipper::Adapters::Memory.new(source) } let(:flipper) { build_flipper } let(:feature) { flipper[:some_awesome_feature] } - subject do - described_class.new(feature) - end - describe '#initialize' do it 'sets the feature' do expect(subject.feature).to be(feature) diff --git a/spec/flipper/ui/decorators/gate_spec.rb b/spec/flipper/ui/decorators/gate_spec.rb index 11a51b0dc..bcc81cbbb 100644 --- a/spec/flipper/ui/decorators/gate_spec.rb +++ b/spec/flipper/ui/decorators/gate_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/ui/decorators/gate' RSpec.describe Flipper::UI::Decorators::Gate do + subject do + described_class.new(gate, false) + end + let(:source) { {} } let(:adapter) { Flipper::Adapters::Memory.new(source) } let(:flipper) { build_flipper } let(:feature) { flipper[:some_awesome_feature] } let(:gate) { feature.gate(:boolean) } - subject do - described_class.new(gate, false) - end - describe '#initialize' do it 'sets gate' do expect(subject.gate).to be(gate) diff --git a/spec/flipper/ui/util_spec.rb b/spec/flipper/ui/util_spec.rb index 6f3fb7340..697422c73 100644 --- a/spec/flipper/ui/util_spec.rb +++ b/spec/flipper/ui/util_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/ui/util' diff --git a/spec/flipper/ui_spec.rb b/spec/flipper/ui_spec.rb index 7698eb238..0263b71d3 100644 --- a/spec/flipper/ui_spec.rb +++ b/spec/flipper/ui_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper::UI do @@ -96,13 +98,11 @@ describe 'when set' do around do |example| - begin - @original_banner_text = described_class.configuration.banner_text - described_class.configuration.banner_text = 'Production Environment' - example.run - ensure - described_class.configuration.banner_text = @original_banner_text - end + @original_banner_text = described_class.configuration.banner_text + described_class.configuration.banner_text = 'Production Environment' + example.run + ensure + described_class.configuration.banner_text = @original_banner_text end it 'includes banner' do @@ -177,14 +177,14 @@ configuration.feature_creation_enabled = true end + after do + configuration.feature_creation_enabled = @original_feature_creation_enabled + end + it 'has the add_feature button' do get '/features' expect(last_response.body).to include('Add Feature') end - - after do - configuration.feature_creation_enabled = @original_feature_creation_enabled - end end context 'with feature_creation_enabled set to false' do @@ -193,14 +193,14 @@ configuration.feature_creation_enabled = false end + after do + configuration.feature_creation_enabled = @original_feature_creation_enabled + end + it 'does not have the add_feature button' do get '/features' expect(last_response.body).not_to include('Add Feature') end - - after do - configuration.feature_creation_enabled = @original_feature_creation_enabled - end end end @@ -215,14 +215,14 @@ configuration.feature_removal_enabled = true end + after do + configuration.feature_removal_enabled = @original_feature_removal_enabled + end + it 'has the add_feature button' do get '/features/test' expect(last_response.body).to include('Delete') end - - after do - configuration.feature_removal_enabled = @original_feature_removal_enabled - end end context 'with feature_removal_enabled set to false' do @@ -231,14 +231,14 @@ configuration.feature_removal_enabled = false end + after do + configuration.feature_removal_enabled = @original_feature_removal_enabled + end + it 'does not have the add_feature button' do get '/features/test' expect(last_response.body).not_to include('Delete') end - - after do - configuration.feature_removal_enabled = @original_feature_removal_enabled - end end end end diff --git a/spec/flipper_spec.rb b/spec/flipper_spec.rb index b02814f60..2395c3829 100644 --- a/spec/flipper_spec.rb +++ b/spec/flipper_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' RSpec.describe Flipper do @@ -265,7 +267,7 @@ describe '.unregister_groups' do it 'clear group registry' do - expect(described_class.groups_registry).to receive(:clear) + expect(described_class.groups_registry).to have_receive(:clear) described_class.unregister_groups end end @@ -282,7 +284,7 @@ end describe '.group' do - context 'for registered group' do + context 'with registered group' do before do @group = described_class.register(:admins) {} end @@ -296,7 +298,7 @@ end end - context 'for unregistered group' do + context 'with unregistered group' do before do @group = described_class.group(:cats) end diff --git a/spec/helper.rb b/spec/helper.rb index af43d907c..f73c8e1d8 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,4 +1,6 @@ -$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__)) +# frozen_string_literal: true + +$LOAD_PATH.unshift(File.expand_path('../lib', __dir__)) require 'pp' require 'pathname' @@ -20,7 +22,7 @@ Dir[FlipperRoot.join('spec/support/**/*.rb')].each { |f| require f } RSpec.configure do |config| - config.before(:example) do + config.before do Flipper.unregister_groups Flipper.configuration = nil end diff --git a/spec/integration_spec.rb b/spec/integration_spec.rb index 45939e012..34bff6886 100644 --- a/spec/integration_spec.rb +++ b/spec/integration_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'flipper/feature' @@ -211,7 +213,7 @@ expect(feature.enabled?).to eq(false) end - it 'disables for individual actor' do + it 'disables for individual actor and percentage of time' do expect(feature.enabled?(pitt)).to eq(false) end @@ -228,10 +230,6 @@ expect(enabled).to be(0) end - it 'disables percentage of time' do - expect(feature.enabled?(pitt)).to eq(false) - end - it 'adds feature to set of features' do expect(flipper.features.map(&:name)).to include(:search) end @@ -368,7 +366,7 @@ end end - context 'for actor in enabled group' do + context 'with actor in enabled group' do before do feature.enable admin_group end @@ -383,7 +381,7 @@ end end - context 'for actor in disabled group' do + context 'with actor in disabled group' do it 'returns false' do expect(feature.enabled?(flipper.actor(dev_thing))).to eq(false) expect(feature.enabled?(dev_thing)).to eq(false) @@ -394,7 +392,7 @@ end end - context 'for enabled actor' do + context 'with enabled actor' do before do feature.enable pitt end @@ -404,7 +402,7 @@ end end - context 'for not enabled actor' do + context 'with not enabled actor' do it 'returns false' do expect(feature.enabled?(clooney)).to eq(false) end @@ -415,7 +413,7 @@ end end - context 'for enabled percentage of time' do + context 'with enabled percentage of time' do before do # ensure percentage of time returns percentage that makes five percent # of time true @@ -433,7 +431,7 @@ end end - context 'for enabled float percentage of time' do + context 'with enabled float percentage of time' do before do # ensure percentage of time returns percentage that makes 4.1 percent # of time true @@ -451,7 +449,7 @@ end end - context 'for NOT enabled integer percentage of time' do + context 'with NOT enabled integer percentage of time' do before do # ensure percentage of time returns percentage that makes enabled? false @gate = feature.gate(:percentage_of_time) @@ -476,7 +474,7 @@ end end - context 'for NOT enabled float percentage of time' do + context 'with NOT enabled float percentage of time' do before do # ensure percentage of time returns percentage that makes enabled? false @gate = feature.gate(:percentage_of_time) @@ -501,7 +499,7 @@ end end - context 'for a non flipper thing' do + context 'with a non flipper thing' do before do feature.enable admin_group end @@ -522,7 +520,7 @@ end end - context 'enabling multiple groups, disabling everything, then enabling one group' do + context 'with enabling multiple groups, disabling everything, then enabling one group' do before do feature.enable(admin_group) feature.enable(dev_group) diff --git a/spec/support/fake_udp_socket.rb b/spec/support/fake_udp_socket.rb index 40367d23c..9d66005b5 100644 --- a/spec/support/fake_udp_socket.rb +++ b/spec/support/fake_udp_socket.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + class FakeUDPSocket attr_reader :buffer diff --git a/spec/support/spec_helpers.rb b/spec/support/spec_helpers.rb index d26e3dbd2..7e28f4559 100644 --- a/spec/support/spec_helpers.rb +++ b/spec/support/spec_helpers.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'json' require 'rack/test' diff --git a/test/adapters/active_record_test.rb b/test/adapters/active_record_test.rb index 6ee3aadb3..ad3e3974a 100644 --- a/test/adapters/active_record_test.rb +++ b/test/adapters/active_record_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/active_record' @@ -53,7 +55,6 @@ def test_models_honor_table_name_prefixes_and_suffixes assert_equal "foo_flipper_features_bar", Flipper::Adapters::ActiveRecord::Feature.table_name assert_equal "foo_flipper_gates_bar", Flipper::Adapters::ActiveRecord::Gate.table_name - ensure ActiveRecord::Base.table_name_prefix = "" ActiveRecord::Base.table_name_suffix = "" diff --git a/test/adapters/dalli_test.rb b/test/adapters/dalli_test.rb index 9cdce24af..31f8b1bd5 100644 --- a/test/adapters/dalli_test.rb +++ b/test/adapters/dalli_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/dalli' diff --git a/test/adapters/memory_test.rb b/test/adapters/memory_test.rb index 3acb4e757..bd2072008 100644 --- a/test/adapters/memory_test.rb +++ b/test/adapters/memory_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' class MemoryTest < MiniTest::Test diff --git a/test/adapters/mongo_test.rb b/test/adapters/mongo_test.rb index 91b2a2e55..a0ced6e37 100644 --- a/test/adapters/mongo_test.rb +++ b/test/adapters/mongo_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/mongo' diff --git a/test/adapters/pstore_test.rb b/test/adapters/pstore_test.rb index 71ab76fa6..a8c8051ea 100644 --- a/test/adapters/pstore_test.rb +++ b/test/adapters/pstore_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/pstore' diff --git a/test/adapters/redis_cache_test.rb b/test/adapters/redis_cache_test.rb index ad4b65d19..e8dd2fa02 100644 --- a/test/adapters/redis_cache_test.rb +++ b/test/adapters/redis_cache_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/redis_cache' diff --git a/test/adapters/redis_test.rb b/test/adapters/redis_test.rb index 2d9ce5c49..ed48eafcc 100644 --- a/test/adapters/redis_test.rb +++ b/test/adapters/redis_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'flipper/adapters/redis' diff --git a/test/adapters/sequel_test.rb b/test/adapters/sequel_test.rb index 93e83e4b4..af930c9c7 100644 --- a/test/adapters/sequel_test.rb +++ b/test/adapters/sequel_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'sequel' diff --git a/test/generators/flipper/active_record_generator_test.rb b/test/generators/flipper/active_record_generator_test.rb index 5ac688e39..5ace4cb43 100644 --- a/test/generators/flipper/active_record_generator_test.rb +++ b/test/generators/flipper/active_record_generator_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'active_record' require 'rails/generators/test_case' @@ -5,7 +7,7 @@ class FlipperActiveRecordGeneratorTest < Rails::Generators::TestCase tests Flipper::Generators::ActiveRecordGenerator - destination File.expand_path('../../../../tmp', __FILE__) + destination File.expand_path('../../../tmp', __dir__) setup :prepare_destination def test_generates_migration @@ -15,29 +17,29 @@ def test_generates_migration else "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end - assert_migration 'db/migrate/create_flipper_tables.rb', <<-EOM -class CreateFlipperTables < ActiveRecord::Migration#{migration_version} - def self.up - create_table :flipper_features do |t| - t.string :key, null: false - t.timestamps null: false - end - add_index :flipper_features, :key, unique: true + assert_migration 'db/migrate/create_flipper_tables.rb', <<~MIGRATION + class CreateFlipperTables < ActiveRecord::Migration#{migration_version} + def self.up + create_table :flipper_features do |t| + t.string :key, null: false + t.timestamps null: false + end + add_index :flipper_features, :key, unique: true - create_table :flipper_gates do |t| - t.string :feature_key, null: false - t.string :key, null: false - t.string :value - t.timestamps null: false - end - add_index :flipper_gates, [:feature_key, :key, :value], unique: true - end + create_table :flipper_gates do |t| + t.string :feature_key, null: false + t.string :key, null: false + t.string :value + t.timestamps null: false + end + add_index :flipper_gates, [:feature_key, :key, :value], unique: true + end - def self.down - drop_table :flipper_gates - drop_table :flipper_features - end -end -EOM + def self.down + drop_table :flipper_gates + drop_table :flipper_features + end + end + MIGRATION end end diff --git a/test/helper.rb b/test/helper.rb index 4589bdce2..ccb0d36c4 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'rubygems' require 'bundler' Bundler.setup(:default) diff --git a/test/test_helper.rb b/test/test_helper.rb index d80df34c1..4759d5884 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'flipper' require 'minitest/autorun' require 'minitest/unit'