source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | awilliams/RTanque | https://github.com/awilliams/RTanque | spec/rtanque/heading_spec.rb | Ruby | mit | 300 | master | 7,591 | require "spec_helper"
describe RTanque::Heading do
NINETY = Math::PI / 2.0
describe '#delta' do
before do
@instance = described_class.new(0)
end
it 'receives floats' do
other = 0.0
expect(@instance.delta(other)).to eql 0.0
end
it 'receives headings' do
other = describ... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | spec/rtanque/radar_spec.rb | Ruby | mit | 300 | master | 2,932 | require "spec_helper"
describe RTanque::Bot::Radar do
def reflection(heading, distance, name)
described_class::Reflection.new(RTanque::Heading.new(heading), distance, name)
end
let(:radar) { described_class.new(mockbot(10, 10), RTanque::Heading.new(0)) }
context '#scan' do
it 'should return an array'... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | spec/rtanque/match_spec.rb | Ruby | mit | 300 | master | 1,131 | require "spec_helper"
describe RTanque::Match do
before do
@instance = described_class.new(@arena)
end
it 'should start with 0 ticks' do
expect(@instance.ticks).to eql 0
end
it 'should allow adding bots' do
bot = double('bot')
@instance.add_bots(bot)
expect(@instance.bots.include?(bot))... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque.rb | Ruby | mit | 300 | master | 886 | # RTanque
#
# #Interesting classes for the spelunker:
#
# * {RTanque::Bot::Brain} All brains should inherit from this class
# * {RTanque::Bot::Sensors} Instance provided to {RTanque::Bot::Brain#sensors}
# * {RTanque::Bot::Command} Instance provided to {RTanque::Bot::Brain#command}
# * {RTanque::Heading} Handles angles
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/heading.rb | Ruby | mit | 300 | master | 4,475 | # -*- encoding: utf-8 -*-
module RTanque
# A Heading represents an angle. Basically a wrapper around `Float` bound to `(0..Math::PI * 2)`
#
# 0.0 == `RTanque::Heading::NORTH` is 'up'
#
# ##Basic Usage
# RTanque::Heading.new(Math::PI)
# # => <RTanque::Heading: 1.0rad 180.0deg>
#
# RTanque::... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/match.rb | Ruby | mit | 300 | master | 1,811 | module RTanque
class Match
attr_reader :arena, :bots, :shells, :explosions, :ticks, :max_ticks, :teams
def initialize(arena, max_ticks = nil, teams = false)
@arena = arena
@max_ticks = max_ticks
@teams = teams
@ticks = 0
@shells = TickGroup.new
@bots = TickGroup.new
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot.rb | Ruby | mit | 300 | master | 3,640 | module RTanque
class Bot
include Movable
extend NormalizedAttr
HEALTH_REDUCTION_ON_EXCEPTION = Configuration.bot.health_reduction_on_exception
RADIUS = Configuration.bot.radius
MAX_GUN_ENERGY = Configuration.bot.gun_energy_max
GUN_ENERGY_FACTOR = Configuration.bot.gun_energy_factor
attr_re... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/explosion.rb | Ruby | mit | 300 | master | 375 | module RTanque
class Explosion
include Movable
attr_reader :position
LIFE_SPAN = Configuration.explosion.life_span # ticks
def initialize(position)
@position = position
@ticks = 0
end
def percent_dead
@ticks / LIFE_SPAN.to_f
end
def tick
@ticks += 1
end
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/configuration.rb | Ruby | mit | 300 | master | 1,111 | require 'configuration'
module RTanque
one_degree = (Math::PI / 180.0)
# @!visibility private
Configuration = ::Configuration.for('default') do
raise_brain_tick_errors true
quit_when_finished true
bot do
radius 19
health_reduction_on_exception 2
health 0..100
speed -3..3
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui.rb | Ruby | mit | 300 | master | 533 | module RTanque
module Gui
RESOURCE_DIR = File.expand_path('../../../resources', __FILE__)
def self.resource_path(*components)
File.join(RESOURCE_DIR, *components)
end
module ZOrder
BACKGROUND = -1
BOT_HEALTH = 5
BOT_NAME = 6
BOT_BODY = 7
BOT_TURRET = 8
BOT_RA... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/normalized_attr.rb | Ruby | mit | 300 | master | 2,102 | module RTanque
module NormalizedAttr
MAX_DELTA = 1.0 / 0.0 # INFINITY
def attr_normalized(attr_name, range, max_delta = MAX_DELTA)
@_normalized_attrs ||= {}
@_normalized_attrs[attr_name] = AttrContainer.new(range, max_delta)
const_set("MAX_#{attr_name.to_s.upcase}", @_normalized_attrs[attr_n... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/runner.rb | Ruby | mit | 300 | master | 2,791 | # Add the working directory so that loading of bots works as expected
$LOAD_PATH << Dir.pwd
# Add the gem root dir so that sample_bots can be loaded
$LOAD_PATH << File.expand_path('../../../', __FILE__)
module RTanque
# Runner manages running an {RTanque::Match}
class Runner
LoadError = Class.new(::LoadError)
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/shell.rb | Ruby | mit | 300 | master | 989 | module RTanque
class Shell
include Movable
RATIO = Configuration.shell.ratio
SHELL_SPEED_FACTOR = Configuration.shell.speed_factor
attr_reader :bot, :arena, :fire_power
def self.speed fire_power
fire_power * SHELL_SPEED_FACTOR
end
def initialize(bot, position, heading, fire_power)
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/point.rb | Ruby | mit | 300 | master | 3,511 | module RTanque
# A `Point` represents an [x, y] coordinate pair in the {RTanque::Arena}
#
# ##Usage
# @arena = RTanque::Arena.new(100, 100)
# # => #<struct RTanque::Arena width=100, height=100>
#
# @point_one = RTanque::Point.new(0, 1, @arena)
# # => #<struct RTanque::Point x=0, y=1, are... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/movable.rb | Ruby | mit | 300 | master | 677 | module RTanque
module Movable
def tick
update_position
end
def dead?
false # should overwrite
end
def arena
@arena
end
def arena=(val)
@arena = val
end
def position
@position
end
def position=(val)
@position = val
end
def bo... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/draw_group.rb | Ruby | mit | 300 | master | 718 | module RTanque
module Gui
class DrawGroup
include Enumerable
def initialize(tick_group, &create_drawable)
@tick_group = tick_group
@mapped_drawables = Hash.new do |h, tickable|
h[tickable] = create_drawable.call(tickable)
end
end
def each(&block)
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/explosion.rb | Ruby | mit | 300 | master | 682 | require 'gosu'
module RTanque
module Gui
class Explosion
FRAMES = (1..71)
def initialize(window, explosion)
@window = window
@explosion = explosion
@position = [explosion.position.x, window.height - explosion.position.y]
@explosion_images = FRAMES.map { |i| Gosu::Imag... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/bot.rb | Ruby | mit | 300 | master | 2,351 | require 'gosu'
require 'rtanque/gui/bot/health_color_calculator'
module RTanque
module Gui
class Bot
attr_reader :bot
HEALTH_BAR_HEIGHT = 3
HEALTH_BAR_WIDTH = 100
def initialize(window, bot)
@window = window
@bot = bot
@body_image = Gosu::Image.new(@window, Gui.... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/window.rb | Ruby | mit | 300 | master | 1,789 | require 'gosu'
module RTanque
module Gui
class Window < Gosu::Window
UPDATE_INTERVAL = Configuration.gui.update_interval
FONT_NAME = Gosu::default_font_name
SMALL_FONT_SIZE = Configuration.gui.fonts.small
attr_reader :gui_bots, :gui_shells, :gui_explosions
def initialize(match)
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/shell.rb | Ruby | mit | 300 | master | 820 | require 'gosu'
module RTanque
module Gui
class Shell
attr_reader :shell
DEBUG = ENV["DEBUG_SHELLS"]
def initialize(window, shell)
@window = window
@shell = shell
@x0 = shell.position.x
@y0 = @window.height - shell.position.y
@shell_image = Gosu::Image.n... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/gui/bot/health_color_calculator.rb | Ruby | mit | 300 | master | 1,110 | module RTanque
module Gui
class Bot
class HealthColorCalculator
# Different health-colors as RGB values
# Blue, Green,Red, Alpha
FULL_HEALTH_COLOR = [0x4A, 0xBE, 0x4A, 0xFF].freeze
MEDIUM_HEALTH_COLOR = [0x00, 0xBE, 0xFF, 0xFF].freeze
LOW_HEAL... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/brain_helper.rb | Ruby | mit | 300 | master | 804 | module RTanque
class Bot
# Some helpful constants and methods for use as mixin in {RTanque::Bot::Brain}
module BrainHelper
BOT_RADIUS = Bot::RADIUS
MAX_FIRE_POWER = Bot::MAX_FIRE_POWER
MIN_FIRE_POWER = Bot::MIN_FIRE_POWER
MAX_HEALTH = Bot::MAX_HEALTH
M... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/brain.rb | Ruby | mit | 300 | master | 1,338 | module RTanque
class Bot
# Commands the associated {RTanque::Bot}. This class should be inherited from and {NAME} and {#tick!} overridden.
#
# See {RTanque::Bot::BrainHelper} for a useful mixin
#
# Sample bots:
#
# * {file:sample_bots/seek_and_destroy.rb SeekAndDestroy}
# * {file:sam... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/turret.rb | Ruby | mit | 300 | master | 307 | module RTanque
class Bot
class Turret
include Movable
extend NormalizedAttr
LENGTH = Configuration.turret.length
attr_normalized(:heading, Heading::FULL_RANGE, Configuration.turret.turn_step)
def initialize(heading)
@heading = heading
end
end
end
end |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/sensors.rb | Ruby | mit | 300 | master | 1,422 | module RTanque
class Bot
# Sensors provide input to the {RTanque::Bot::Brain} about the current state of the {RTanque::Match}
#
# They are made available to {RTanque::Bot::Brain} via {RTanque::Bot::Brain#sensors}
#
# @attr_reader [Integer] ticks number of ticks, starts at 0
# @attr_reader [Flo... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/radar.rb | Ruby | mit | 300 | master | 1,497 | module RTanque
class Bot
class Radar
include Enumerable
include Movable
extend NormalizedAttr
VISION_RANGE = Configuration.radar.vision
attr_normalized(:heading, Heading::FULL_RANGE, Configuration.radar.turn_step)
# A Reflection is the information obtained for a bot detected b... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/bot/command.rb | Ruby | mit | 300 | master | 932 | module RTanque
class Bot
# Command provide output from the {RTanque::Bot::Brain} about the current state of the {RTanque::Match}
#
# They are made available to {RTanque::Bot::Brain} via {RTanque::Bot::Brain#command}
#
# All values are bound. Setting an out-of-bounds value will result in it being s... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | lib/rtanque/match/tick_group.rb | Ruby | mit | 300 | master | 892 | module RTanque
class Match
class TickGroup
include Enumerable
def initialize
@members = []
@pre_tick = nil
@post_tick = nil
end
def each(&block)
@members.each(&block)
end
def all_but(*to_exclude)
self.to_a - to_exclude
end
... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | sample_bots/seek_and_destroy.rb | Ruby | mit | 300 | master | 1,464 | # Seek&Destroy: Sample Bot
#
# Enjoys following and target and firing many shots
class SeekAndDestroy < RTanque::Bot::Brain
NAME = 'Seek&Destroy'
include RTanque::Bot::BrainHelper
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0
def tick!
@desired_heading ||= nil
if (lock = self.get_radar_lock)... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | sample_bots/keyboard.rb | Ruby | mit | 300 | master | 1,344 | # -*- encoding: utf-8 -*-
# Keyboard: Sample Bot
#
# Special bot controlled with the keyboard
#
# Controls:
# w drive forward
# s drive backwards
# a rotate left
# d rotate right
#
# ↑ fire powerful shot
# ↓ fire week shot
# ← rotate turret left
# → rotate turret right
class Keyboard < R... |
github | awilliams/RTanque | https://github.com/awilliams/RTanque | sample_bots/camper.rb | Ruby | mit | 300 | master | 1,962 | # Camper: Sample Bot
#
# Enjoys sitting in the corners and firing powerful shots
class Camper < RTanque::Bot::Brain
NAME = 'Camper'
include RTanque::Bot::BrainHelper
CORNERS = [:NW, :NE, :SE, :SW]
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.0
SWITCH_CORNER_TICK_RANGE = (600..1000)
def tick!
s... |
github | savonrb/httpi | https://github.com/savonrb/httpi | Rakefile | Ruby | mit | 300 | main | 443 | require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new do |t|
t.pattern = "spec/httpi/**/*_spec.rb"
end
desc "Run RSpec integration examples"
RSpec::Core::RakeTask.new "spec_integration" do |t|
t.pattern = "spec/integration/*_spec.rb"
end
desc "Run RSpec code and integration example... |
github | savonrb/httpi | https://github.com/savonrb/httpi | httpi.gemspec | Ruby | mit | 300 | main | 1,474 | lib = File.expand_path('../lib/', __FILE__)
$:.unshift lib unless $:.include?(lib)
require 'httpi/version'
Gem::Specification.new do |s|
s.name = 'httpi'
s.version = HTTPI::VERSION
s.authors = ['Daniel Harrington', 'Martin Tepper']
s.email = 'me@rubiii.com'
s.homepage = "https://gith... |
github | savonrb/httpi | https://github.com/savonrb/httpi | Gemfile | Ruby | mit | 300 | main | 798 | source 'https://rubygems.org'
gemspec
gem 'jruby-openssl', :platforms => :jruby
gem 'public_suffix', '~> 4.0'
# http clients
gem 'httpclient', '~> 2.3', :require => false
gem 'curb', '~> 0.8', :require => false, :platforms => [:ruby]
gem 'em-http-re... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/spec_helper.rb | Ruby | mit | 300 | main | 355 | require 'bundler'
Bundler.setup(:default, :development)
unless RUBY_PLATFORM =~ /java/
require 'simplecov'
SimpleCov.start do
add_filter 'spec'
end
end
require 'httpi'
require 'rspec'
RSpec.configure do |config|
config.mock_with :mocha
config.order = 'random'
end
HTTPI.log = false
require 'support/f... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/response_spec.rb | Ruby | mit | 300 | main | 3,748 | require "spec_helper"
require "httpi/response"
describe HTTPI::Response do
context "normal" do
let(:response) { HTTPI::Response.new 200, {}, Fixture.xml }
describe "#error?" do
it "returns false" do
expect(response).not_to be_an_error
end
end
describe "#headers" do
it "re... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter_spec.rb | Ruby | mit | 300 | main | 1,724 | require "spec_helper"
require "httpi/adapter"
describe HTTPI::Adapter do
let(:adapter) { HTTPI::Adapter }
describe ".register" do
it "registers a new adapter" do
name = :custom
klass = Class.new
deps = %w(some_dependency)
adapter.register(name, klass, deps)
expect(HTTPI::Adap... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/cookie_store_spec.rb | Ruby | mit | 300 | main | 783 | require "spec_helper"
require "httpi"
describe HTTPI::CookieStore do
let(:user_cookie) { some_cookie(:user, "chucknorris") }
let(:token_cookie) { some_cookie(:token, "strawberry") }
it "stores a set of cookies" do
cookie_store = HTTPI::CookieStore.new
cookie_store.add(user_cookie, token_cookie)
ex... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/cookie_spec.rb | Ruby | mit | 300 | main | 1,018 | require "spec_helper"
require "httpi"
describe HTTPI::Cookie do
let(:cookie) { HTTPI::Cookie.new("token=choc-choc-chip; Path=/; HttpOnly") }
describe ".list_from_headers" do
it "returns a list of cookies from a Hash of headers" do
headers = { "Set-Cookie" => "token=strawberry; Path=/; HttpOnly" }
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/error_spec.rb | Ruby | mit | 300 | main | 1,344 | require "spec_helper"
require "support/error_helper"
describe HTTPI do
include ErrorHelper
context "with :httpclient" do
it "tags Errno::ECONNREFUSED with HTTPI::ConnectionError" do
expect_error(Errno::ECONNREFUSED, "Connection refused - connect(2)").to be_tagged_with(HTTPI::ConnectionError)
end
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/httpi_spec.rb | Ruby | mit | 300 | main | 11,936 | require "spec_helper"
require "integration/support/server"
# find out why httpi doesn't load these automatically. [dh, 2012-12-15]
require "excon"
require "net/http/persistent"
require "http"
unless RUBY_PLATFORM =~ /java/
require "em-synchrony"
require "em-http-request"
require "curb"
end
describe HTTPI do
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/request_spec.rb | Ruby | mit | 300 | main | 9,213 | require "spec_helper"
require "httpi/request"
describe HTTPI::Request do
let(:request) { HTTPI::Request.new }
describe ".new" do
it "accepts a url" do
request = HTTPI::Request.new "http://example.com"
expect(request.url).to eq(URI("http://example.com"))
end
it "accepts a Hash of accessors... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/auth/ssl_spec.rb | Ruby | mit | 300 | main | 6,213 | require "spec_helper"
require "httpi/auth/ssl"
describe HTTPI::Auth::SSL do
before(:all) do
@ssl_versions = HTTPI::Auth::SSL::SSL_VERSIONS
@min_max_versions = HTTPI::Auth::SSL::MIN_MAX_VERSIONS
end
describe "VERIFY_MODES" do
it "contains the supported SSL verify modes" do
expect(HTTPI::Auth::S... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/auth/config_spec.rb | Ruby | mit | 300 | main | 4,038 | require "spec_helper"
require "httpi/auth/config"
describe HTTPI::Auth::Config do
let(:auth) { HTTPI::Auth::Config.new }
describe "#basic" do
it "lets you specify the basic auth credentials" do
auth.basic "username", "password"
expect(auth.basic).to eq(["username", "password"])
end
it "al... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/net_http_spec.rb | Ruby | mit | 300 | main | 1,489 | require "spec_helper"
require "httpi/adapter/net_http"
require "httpi/request"
begin
HTTPI::Adapter.load_adapter(:net_http)
describe HTTPI::Adapter::NetHTTP do
let(:adapter) { HTTPI::Adapter::NetHTTP.new(request) }
let(:request) { HTTPI::Request.new("http://example.com") }
let(:response) {
Obje... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/rack_spec.rb | Ruby | mit | 300 | main | 3,171 | require "spec_helper"
require "integration/support/application"
describe HTTPI::Adapter::NetHTTP do
subject(:adapter) { :rack }
context "http requests" do
before :all do
@app = 'app'
@url = "http://#{@app}/"
HTTPI::Adapter::Rack.mount @app, IntegrationServer::Application
end
it "s... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/em_http_spec.rb | Ruby | mit | 300 | main | 5,418 | require "spec_helper"
require "httpi/adapter/em_http"
require "httpi/request"
unless RUBY_PLATFORM =~ /java/
HTTPI::Adapter.load_adapter(:em_http)
describe HTTPI::Adapter::EmHttpRequest do
around(:each) do |example|
EM.synchrony do
example.run
EM.stop
end
end
let(:adapter... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/base_spec.rb | Ruby | mit | 300 | main | 624 | require "spec_helper"
require "httpi/adapter/base"
describe HTTPI::Adapter::Base do
subject(:base) { HTTPI::Adapter::Base.new(request) }
let(:request) { HTTPI::Request.new }
describe "#client" do
it "returns the adapter's client instance" do
expect { base.client }.
to raise_error(HTTPI::NotI... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/http_spec.rb | Ruby | mit | 300 | main | 738 | require "spec_helper"
require "httpi/adapter/http"
require "httpi/request"
begin
HTTPI::Adapter.load_adapter(:http)
describe HTTPI::Adapter::HTTP do
let(:adapter) { HTTPI::Adapter::HTTP.new(request) }
let(:request) { HTTPI::Request.new("http://example.com") }
describe "settings" do
describe "co... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/net_http_persistent_spec.rb | Ruby | mit | 300 | main | 1,249 | require "spec_helper"
require "httpi/adapter/net_http_persistent"
require "httpi/request"
begin
HTTPI::Adapter.load_adapter(:net_http_persistent)
describe HTTPI::Adapter::NetHTTPPersistent do
let(:adapter) { HTTPI::Adapter::NetHTTPPersistent.new(request) }
let(:request) { HTTPI::Request.new("http://exampl... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/httpclient_spec.rb | Ruby | mit | 300 | main | 6,908 | require "spec_helper"
require "httpi/adapter/httpclient"
require "httpi/request"
require "integration/support/server"
HTTPI::Adapter.load_adapter(:httpclient)
describe HTTPI::Adapter::HTTPClient do
let(:adapter) { HTTPI::Adapter::HTTPClient.new(request) }
let(:httpclient) { HTTPClient.any_instance }
let(:ssl... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/excon_spec.rb | Ruby | mit | 300 | main | 954 | require "spec_helper"
require "httpi/adapter/excon"
require "httpi/request"
begin
HTTPI::Adapter.load_adapter(:excon)
describe HTTPI::Adapter::Excon do
let(:adapter) { HTTPI::Adapter::Excon.new(request) }
let(:request) { HTTPI::Request.new("http://example.com") }
describe "settings" do
describe... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/httpi/adapter/curb_spec.rb | Ruby | mit | 300 | main | 10,854 | require "spec_helper"
require "httpi/adapter/curb"
require "httpi/request"
require "integration/support/server"
# curb does not run on jruby
unless RUBY_PLATFORM =~ /java/
HTTPI::Adapter.load_adapter(:curb)
describe "NTLM authentication" do
before :all do
@server = IntegrationServer.run
end
af... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/httpclient_spec.rb | Ruby | mit | 300 | main | 4,048 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::HTTPClient do
subject(:adapter) { :httpclient }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
@server.stop
end
it "sends and receives HTTP headers" d... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/http_spec.rb | Ruby | mit | 300 | main | 4,737 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::HTTP do
subject(:adapter) { :http }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
@server.stop
end
it "sends and receives HTTP headers" do
requ... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/net_http_spec.rb | Ruby | mit | 300 | main | 9,540 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::NetHTTP do
subject(:adapter) { :net_http }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
@server.stop
end
context "when socks is specified" do
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/net_http_persistent_spec.rb | Ruby | mit | 300 | main | 5,527 | require "spec_helper"
require "integration/support/server"
require "net/http/persistent"
describe HTTPI::Adapter::NetHTTPPersistent do
subject(:adapter) { :net_http_persistent }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
@server.stop
e... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/excon_spec.rb | Ruby | mit | 300 | main | 5,591 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::Excon do
subject(:adapter) { :excon }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
@server.stop
end
it "sends and receives HTTP headers" do
re... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/em_http_spec.rb | Ruby | mit | 300 | main | 3,314 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::EmHttpRequest do
# em_http is not supported on java
unless RUBY_PLATFORM =~ /java/
require "em-synchrony"
subject(:adapter) { :em_http }
around :each do |example|
EM.synchrony do
example.run
EM.... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/curb_spec.rb | Ruby | mit | 300 | main | 4,148 | require "spec_helper"
require "integration/support/server"
describe HTTPI::Adapter::Curb do
# curb is not supported on jruby
unless RUBY_PLATFORM =~ /java/
subject(:adapter) { :curb }
context "http requests" do
before :all do
@server = IntegrationServer.run
end
after :all do
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/support/application.rb | Ruby | mit | 300 | main | 2,720 | require 'rack'
require "rack/builder"
class IntegrationServer
def self.respond_with(body)
[200, { "Content-Type" => "text/plain", "Content-Length" => body.size.to_s }, [body]]
end
Application = Rack::Builder.new do
map "/" do
run lambda { |env|
IntegrationServer.respond_with env["REQUEST... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/integration/support/server.rb | Ruby | mit | 300 | main | 1,675 | require "puma"
require "puma/minissl"
require "integration/support/application"
class IntegrationServer
def self.run(options = {})
server = new(options)
server.run
server
end
def self.ssl_ca_file; integration_fixture("ca_all.pem") end
def self.ssl_key_file; integration_fixture("server.key") ... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/support/error_helper.rb | Ruby | mit | 300 | main | 411 | module ErrorHelper
class Expectation
def initialize(error, spec)
@error = error
@spec = spec
end
def to(tag_error)
@spec.expect(@error).to @spec.be_a(tag_error)
end
end
def expect_error(error_to_raise, message)
fake_error(error_to_raise, message)
rescue => error
Ex... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/support/fixture.rb | Ruby | mit | 300 | main | 398 | class Fixture
class << self
def xml
@xml ||= load :xml
end
def xml_dime
@xml_dime ||= load :xml_dime
end
def gzip
@gzip ||= load :xml, :gz
end
def dime
@dime ||= load :xml_dime, :dime
end
private
def load(fixture, type = :xml)
File.read File.... |
github | savonrb/httpi | https://github.com/savonrb/httpi | spec/support/matchers.rb | Ruby | mit | 300 | main | 554 | RSpec::Matchers.define :match_response do |options|
defaults = { :code => 200, :headers => { "Accept-encoding" => "utf-8" }, :body => "" }
response = defaults.merge options
match do |actual|
expect(actual).to be_an(HTTPI::Response)
expect(actual.code).to eq(response[:code])
expect(downcase(actual.hea... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi.rb | Ruby | mit | 300 | main | 5,236 | require "uri"
require "httpi/version"
require "httpi/logger"
require "httpi/request"
require "httpi/query_builder"
require "httpi/utils"
require "httpi/adapter/httpclient"
require "httpi/adapter/curb"
require "httpi/adapter/excon"
require "httpi/adapter/net_http"
require "httpi/adapter/net_http_persistent"
require "ht... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter.rb | Ruby | mit | 300 | main | 1,541 | module HTTPI
# = HTTPI::Adapter
#
# Manages the adapter classes. Currently supports:
#
# * httpclient
# * curb
# * em_http
# * net/http
module Adapter
ADAPTERS = {}
ADAPTER_CLASS_MAP = {}
LOAD_ORDER = [:httpclient, :curb, :em_http, :excon, :http, :net_http, :net_http_persistent]
cl... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/query_builder.rb | Ruby | mit | 300 | main | 1,128 | module HTTPI
module QueryBuilder
class Flat
# Returns a +query+ string given a +Hash+.
# Example:
#
# build({names => ['Bruno', 'Samantha', 'Alexandre']})
# # => "names=Bruno&names=Samantha&names=Alexandre"
def self.build(query)
Rack::Utils.build_query(query)
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/request.rb | Ruby | mit | 300 | main | 4,368 | require "uri"
require "httpi/cookie_store"
require "httpi/auth/config"
require "rack/utils"
module HTTPI
# = HTTPI::Request
#
# Represents an HTTP request and contains various methods for customizing that request.
class Request
# Available attribute writers.
ATTRIBUTES = [:url, :proxy, :headers, :bod... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/utils.rb | Ruby | mit | 300 | main | 2,099 | # mostly verbatim from: https://github.com/rack/rack/blob/main/lib/rack/headers.rb
# Because this is part of httpi's public API, its better not to load an external
# library for it.
module HTTPI
module Utils
# A case-insensitive Hash that preserves the original case of a
# header when set.
#
class H... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/cookie.rb | Ruby | mit | 300 | main | 734 | module HTTPI
# = HTTPI::Cookie
#
# Represents a single delicious cookie.
#
# == Examples
#
# cookie = HTTPI::Cookie.new("token=choc-choc-chip; Path=/; HttpOnly")
#
# cookie.name # "token"
# cookie.name_and_value # "token=choc-choc-chip"
class Cookie
# Returns a list of cook... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/dime.rb | Ruby | mit | 300 | main | 2,600 | module HTTPI
DimeRecord = Struct.new(
'DimeRecord', :version, :first, :last, :chunked,
:type_format, :options, :id, :type, :data
)
class Dime < Array
BINARY = 1
XML = 2
def initialize(body)
bytes = body.unpack('C*')
while bytes.length > 0
record = DimeRec... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/response.rb | Ruby | mit | 300 | main | 2,433 | require "zlib"
require "stringio"
require "rack/utils"
require "httpi/dime"
require "httpi/cookie"
module HTTPI
# = HTTPI::Response
#
# Represents an HTTP response and contains various response details.
class Response
# Range of HTTP response codes considered to be successful.
SuccessfulResponseCode... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/logger.rb | Ruby | mit | 300 | main | 1,178 | require "logger"
module HTTPI
class << self
# Sets whether to log HTTP requests.
attr_writer :log
# Returns whether to log HTTP requests. Defaults to +true+.
def log?
@log != false
end
# Sets the logger to use.
attr_writer :logger
# Returns the logger. Defaults to an instan... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/cookie_store.rb | Ruby | mit | 300 | main | 801 | module HTTPI
# = HTTPI::CookieStore
#
# Stores a unique list of cookies for future requests.
#
# == Examples
#
# # Add one or more cookies to the store
# cookie_store = HTTPI::CookieStore.new
# cookie_store.add HTTPI::Cookie.new("token=choc-choc-chip; Path=/; HttpOnly")
#
# # Fetch the na... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/curb.rb | Ruby | mit | 300 | main | 5,415 | require "httpi/adapter/base"
require "httpi/response"
module HTTPI
module Adapter
# = HTTPI::Adapter::Curb
#
# Adapter for the Curb client.
# http://rubygems.org/gems/curb
class Curb < Base
register :curb, :deps => %w(curb)
def initialize(request)
@request = request
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/net_http.rb | Ruby | mit | 300 | main | 7,588 | require "uri"
require "httpi/adapter/base"
require "httpi/response"
require 'kconv'
require 'socket'
module HTTPI
module Adapter
# = HTTPI::Adapter::NetHTTP
#
# Adapter for the Net::HTTP client.
# http://ruby-doc.org/stdlib/libdoc/net/http/rdoc/
class NetHTTP < Base
register :net_http, :... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/excon.rb | Ruby | mit | 300 | main | 2,787 | require "httpi/adapter/base"
require "httpi/response"
module HTTPI
module Adapter
# = HTTPI::Adapter::Excon
#
# Adapter for the Excon client.
# https://github.com/geemus/excon
class Excon < Base
register :excon, :deps => %w(excon)
def initialize(request)
@request = request
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/base.rb | Ruby | mit | 300 | main | 825 | require "httpi/adapter"
module HTTPI
module Adapter
# HTTPI::Adapter::Base
#
# Allows you to build your own adapter by implementing all public instance methods.
# Register your adapter by calling the base class' .register method.
class Base
# Registers an adapter.
def self.register(... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/http.rb | Ruby | mit | 300 | main | 2,967 | require "httpi/adapter/base"
require "httpi/response"
module HTTPI
module Adapter
# = HTTPI::Adapter::HTTP
#
# Adapter for the http.rb client.
# https://github.com/httprb/http.rb
class HTTP < Base
register :http, :deps => %w(http)
def initialize(request)
if request.auth.dig... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/httpclient.rb | Ruby | mit | 300 | main | 2,946 | require "httpi/adapter/base"
require "httpi/response"
module HTTPI
module Adapter
# = HTTPI::Adapter::HTTPClient
#
# Adapter for the HTTPClient client.
# http://rubygems.org/gems/httpclient
class HTTPClient < Base
register :httpclient, :deps => %w(httpclient)
def initialize(request... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/em_http.rb | Ruby | mit | 300 | main | 3,977 | require "httpi/adapter/base"
require "httpi/response"
module HTTPI
module Adapter
# An HTTPI adapter for `EventMachine::HttpRequest`. Due to limitations of
# the em-httprequest library, not all features are supported. In particular,
#
# * CA files,
# * certificate verification modes other than "... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/net_http_persistent.rb | Ruby | mit | 300 | main | 1,417 | module HTTPI
module Adapter
# = HTTPI::Adapter::NetHTTPPersistent
#
# Adapter for the Net::HTTP::Persistent client.
# http://docs.seattlerb.org/net-http-persistent/Net/HTTP/Persistent.html
class NetHTTPPersistent < NetHTTP
register :net_http_persistent, :deps => %w(net/http/persistent)
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/adapter/rack.rb | Ruby | mit | 300 | main | 2,865 | require 'base64'
require 'httpi/adapter/base'
require 'httpi/response'
module HTTPI
module Adapter
# = HTTPI::Adapter::Rack
#
# Adapter for Rack::MockRequest.
# Due to limitations, not all features are supported.
# https://github.com/rack/rack/blob/master/lib/rack/mock.rb
#
# Usage:
... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/auth/ssl.rb | Ruby | mit | 300 | main | 6,178 | require "openssl"
module HTTPI
module Auth
# = HTTPI::Auth::SSL
#
# Provides SSL client authentication.
class SSL
VERIFY_MODES = [:none, :peer, :fail_if_no_peer_cert, :client_once]
CERT_TYPES = [:pem, :der]
# Fix for
# httpi/auth/ssl.rb:13: warning: constant OpenSSL::SSL::S... |
github | savonrb/httpi | https://github.com/savonrb/httpi | lib/httpi/auth/config.rb | Ruby | mit | 300 | main | 2,028 | require "httpi/auth/ssl"
module HTTPI
module Auth
# = HTTPI::Auth::Config
#
# Manages HTTP and SSL auth configuration. Currently supports HTTP basic/digest,
# Negotiate/SPNEGO, and SSL client authentication.
class Config
# Supported authentication types.
TYPES = [:basic, :digest, :g... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | Gemfile | Ruby | mit | 300 | master | 756 | source 'https://rubygems.org'
# Specify your gem's dependencies in specinfra.gemspec
gemspec
ruby_version = Gem::Version.new(RUBY_VERSION.dup)
if ruby_version < Gem::Version.new('2.0.0')
# net-ssh 3.x dropped Ruby 1.8 and 1.9 support.
gem 'net-ssh', '~> 2.7'
end
if ruby_version < Gem::Version.new('1.9.3')
# pry... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | specinfra.gemspec | Ruby | mit | 300 | master | 1,433 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'specinfra/version'
Gem::Specification.new do |spec|
spec.name = "specinfra"
spec.version = Specinfra::VERSION
spec.authors = ["Gosuke Miyashita"]
spec.email =... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | Rakefile | Ruby | mit | 300 | master | 1,180 | require "bundler/gem_tasks"
begin
require "rspec/core/rake_task"
require "octorelease"
rescue LoadError
end
if defined?(RSpec)
task :spec => 'spec:all'
task :default => 'spec:all'
namespace :spec do
task :all => [ :helper, :backend, :configuration, :processor, :command, :host_inventory ]
RSpec::Cor... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/configuration_spec.rb | Ruby | mit | 300 | master | 558 | require 'spec_helper'
describe 'RSpec.configuration.path' do
before do
RSpec.configure do |c|
c.path = 'foo'
end
end
after do
RSpec.configure do |c|
c.path = nil
end
end
subject { RSpec.configuration.path }
it { should eq Specinfra.configuration.path }
end
Specinfra.configur... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/processor_spec.rb | Ruby | mit | 300 | master | 5,151 | require 'spec_helper'
describe Specinfra::Processor do
describe 'check_file_is_mounted' do
let(:path) { '/proc' }
let(:cmd) { Specinfra.command.get(:check_file_is_mounted, path) }
def mock_output(stdout)
Specinfra::CommandResult.new :stdout => stdout
end
context 'freebsd' do
before ... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/spec_helper.rb | Ruby | mit | 300 | master | 494 | require 'specinfra'
require 'rspec/mocks/standalone'
require 'rspec/its'
require 'specinfra/helper/set'
require 'specinfra/helper/host_inventory'
include Specinfra::Helper::Set
set :backend, :exec
module Specinfra
module Backend
class Ssh
def run_command(cmd, opts={})
CommandResult.new :stdout => ... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/ssh/build_command_spec.rb | Ruby | mit | 300 | master | 5,202 | require 'spec_helper'
describe Specinfra::Backend::Ssh do
before(:all) do
set :backend, :ssh
end
after(:all) do
if Specinfra.configuration.instance_variable_defined?(:@ssh_options)
Specinfra.configuration.instance_variable_set(:@ssh_options, nil)
end
end
describe '#build_command' do
c... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/lxd/build_command_spec.rb | Ruby | mit | 300 | master | 6,422 | # frozen_string_literal: true
require 'spec_helper'
describe Specinfra::Backend::Lxd do
let(:lxd_instance) { 'instance' }
let(:lxd_remote) { 'remote' }
let(:lxc_exec) { "lxc exec #{lxd_remote}:#{lxd_instance}" }
before(:each) do
set :backend, :lxd
RSpec.configure do |c|
c.lxd_instance = lxd_ins... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/read_noblock_spec.rb | Ruby | mit | 300 | master | 1,340 | require 'spec_helper'
def command(cmd)
Specinfra::Runner.run_command(cmd)
end
shared_examples "IO checks" do
let (:generator) { "seq 1 #{max}" }
let (:expected) { (1..max).map { |x| x.to_s }.join("\n") << "\n" }
it "stdout only" do
out = command(generator).stdout
expect(out).to eq expec... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/consume_exited_process_spec.rb | Ruby | mit | 300 | master | 1,449 | require 'spec_helper'
RSpec.describe 'exec backend' do
before :all do
set :backend, :exec
end
context 'when executed process had exited before read stdout and stderr,' do
let(:backend) { Specinfra::Backend::Exec.new }
it 'can consume stdout and stderr from buffer' do
allow(IO).to receive(:sel... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/build_command_spec.rb | Ruby | mit | 300 | master | 6,709 | require 'spec_helper'
describe Specinfra::Backend::Exec do
before :all do
set :backend, :exec
end
describe '#build_command' do
context 'with simple command' do
it 'should escape spaces' do
expect(Specinfra.backend.build_command('test -f /etc/passwd')).to eq '/bin/sh -c test\ -f\ /etc/passw... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/stdxxx_handler_spec.rb | Ruby | mit | 300 | master | 509 | require 'spec_helper'
backend = Specinfra::Backend::Exec.new
context 'Output of stdout_handler' do
subject(:stdout) do
out = ''
backend.stdout_handler = Proc.new {|o| out += o }
backend.run_command('echo foo')
out
end
it { expect(stdout).to eq "foo\n" }
end
context 'Output of stderr_handler' d... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/child_process_spec.rb | Ruby | mit | 300 | master | 702 | # Ref: https://github.com/sorah/infra_operator/blob/6259aada3fdd9d4bed5759115d39bd1df25a81f2/spec/backends/exec_spec.rb#L36
require 'spec_helper'
context "when executed process launches child process like a daemon, and the daemon doesn't close stdout,err" do
before :all do
set :backend, :exec
end
subject(:... |
github | mizzy/specinfra | https://github.com/mizzy/specinfra | spec/backend/exec/env_spec.rb | Ruby | mit | 300 | master | 659 | require 'spec_helper'
set :backend, :exec
describe Specinfra.backend.run_command('echo $LANG').stdout.strip do
it { should eq 'C' }
end
describe "override ENV with config(:env)" do
before do
set :backend, :exec
ENV['LANG'] = 'C'
set :env, :LANG => 'ja_JP.UTF-8'
end
let(:lang) { Specinfra.backend... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.