Sha256: 8234d61128a8a8f46bbc10de6d1d4b77a0725aa607797ac1b8e5eec992cfaf22

Contents?: true

Size: 960 Bytes

Versions: 5

Compression:

Stored size: 960 Bytes

Contents

module GeoRedirect
  module Support
    def fixture_path(file)
      "spec/fixtures/#{file}"
    end

    def nonexisting_file_path
      '/no_such_file'
    end

    def app
      Rack::Lint.new(@app)
    end

    def mock_app(options = {})
      # Simple HTTP server that always returns 'Hello world!'
      main_app = lambda do |env|
        Rack::Request.new(env)
        headers = { 'Content-Type' => 'text/html' }
        [200, headers, ['Hello world!']]
      end

      @logfile = Tempfile.new('log')
      options = { config: fixture_path('config.yml'),
                  db: fixture_path('GeoIP.dat'),
                  logfile: @logfile.path
                }.merge(options)

      builder = Rack::Builder.new
      builder.use GeoRedirect::Middleware, options
      builder.run main_app
      @app = builder.to_app
    end

    def log_should_include(message)
      @logfile.rewind
      expect(@logfile.read).to include(message)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
geo_redirect-0.8 spec/support/geo_redirect.rb
geo_redirect-0.7 spec/support/geo_redirect.rb
geo_redirect-0.6 spec/support/geo_redirect.rb
geo_redirect-0.5.1 spec/support/geo_redirect.rb
geo_redirect-0.5 spec/support/geo_redirect.rb