Module: Subflag::Rails::TestHelpers

Defined in:
lib/subflag/rails/test_helpers.rb,
lib/subflag/rails/test_helpers.rb

Overview

Update TestHelpers to use thread-local storage

Instance Method Summary collapse

Instance Method Details

#clear_stubbed_subflagsObject

Clear all stubbed flags



72
73
74
# File 'lib/subflag/rails/test_helpers.rb', line 72

def clear_stubbed_subflags
  stubbed_flags.clear
end

#stub_subflag(flag_name, value) ⇒ Object

Stub a flag to return a specific value

Examples:

Boolean

stub_subflag(:new_checkout, true)

String

stub_subflag(:headline, "Welcome!")

Integer

stub_subflag(:max_projects, 100)

Hash

stub_subflag(:limits, { max_items: 50 })

Parameters:

  • flag_name (Symbol, String)

    The flag name (underscores or dashes)

  • value (Object)

    The value to return



51
52
53
54
# File 'lib/subflag/rails/test_helpers.rb', line 51

def stub_subflag(flag_name, value)
  flag_key = normalize_flag_key(flag_name)
  stubbed_flags[flag_key] = value
end

#stub_subflags(flags) ⇒ Object

Stub multiple flags at once

Examples:

stub_subflags(
  new_checkout: true,
  max_projects: 100,
  headline: "Welcome!"
)

Parameters:

  • flags (Hash)

    Flag names to values



67
68
69
# File 'lib/subflag/rails/test_helpers.rb', line 67

def stub_subflags(flags)
  flags.each { |name, value| stub_subflag(name, value) }
end