Sha256: 432de5efbf7751965faf50937a86f58bb09a9907cddb77bb5241c821fe66301f

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

require 'json'
require 'flipper/adapters/memory'
require 'rack/test'

module SpecHelpers
  def self.included(base)
    base.let(:flipper) { build_flipper }
    base.let(:app) { build_app(flipper) }
  end

  def build_app(flipper)
    Flipper::UI.app(flipper) do |builder|
      builder.use Rack::Session::Cookie, secret: 'test'
    end
  end

  def build_api(flipper)
    Flipper::Api.app(flipper)
  end

  def build_flipper(adapter = build_memory_adapter)
    Flipper.new(adapter)
  end

  def build_memory_adapter
    Flipper::Adapters::Memory.new
  end

  def json_response
    JSON.parse(last_response.body)
  end

  def api_error_code_reference_url
    'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference'
  end

  def api_not_found_response
    {
      'code' => 1,
      'message' => 'Feature not found.',
      'more_info' => api_error_code_reference_url,
    }
  end

  def api_flipper_id_is_missing_response
    {
      'code' => 4,
      'message' => 'Required parameter flipper_id is missing.',
      'more_info' => api_error_code_reference_url,
    }
  end

  def api_positive_percentage_error_response
    {
      'code' => 3,
      'message' => 'Percentage must be a positive number less than or equal to 100.',
      'more_info' => api_error_code_reference_url,
    }
  end
end

RSpec.configure do |config|
  config.include Rack::Test::Methods
  config.include SpecHelpers
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
flipper-0.11.0.beta4 spec/support/spec_helpers.rb
flipper-0.11.0.beta3 spec/support/spec_helpers.rb
flipper-0.11.0.beta1 spec/support/spec_helpers.rb