Skip to content

Commit

Permalink
Upgrade the project to the conventions of the latest Ruby, Bundler, R…
Browse files Browse the repository at this point in the history
…Spec, and Guard-RSpec

But in order to preserve as much compatibility as possible with Ruby
v1.8.7, don't touch:

* The RubyGem's 'required_ruby_version' property
* The RubyGem's mime-types dependency
* Old-style hashrocket hash literals
  • Loading branch information
njonsson committed Oct 7, 2015
1 parent 87a4cbe commit 725c238
Show file tree
Hide file tree
Showing 107 changed files with 1,901 additions and 1,875 deletions.
21 changes: 12 additions & 9 deletions .gitignore
@@ -1,9 +1,12 @@
.bundle/
.rbx
.ruby-gemset
.ruby-version
.yardoc/
*.gem
Gemfile.lock
doc/
pkg/*
/.bundle/
/.rbx
/.ruby-*
/.yardoc/
/Gemfile.lock
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/examples.txt
/spec/reports/
/tmp/
3 changes: 2 additions & 1 deletion .rspec
@@ -1,2 +1,3 @@
--color
--format progress
--format documentation
--require spec_helper
1 change: 1 addition & 0 deletions .travis.yml
@@ -1,4 +1,5 @@
language: ruby
before_install: gem install bundler -v 1.10.6
bundler_args: --without debug doc tooling
rvm:
- 2.0
Expand Down
22 changes: 12 additions & 10 deletions Gemfile
@@ -1,26 +1,28 @@
source 'http://rubygems.org'
source 'https://rubygems.org'

gemspec

gem 'jruby-openssl', '~> 0', :platforms => :jruby

group :debug do
gem 'ruby-debug', '~> 0', :platforms => :mri_18
gem 'ruby-debug19', '~> 0', :platforms => :mri_19, :require => 'ruby-debug'
gem 'pry-byebug', '~> 3'
end

group :development do
gem 'codeclimate-test-reporter', '~> 0', :platforms => :mri_20, :require => false
if RUBY_VERSION.start_with?('1.8')
gem 'codeclimate-test-reporter', '> 0', '< 0.4.2',
:require => false
else
gem 'codeclimate-test-reporter', '~> 0', :require => false
end
end

group :doc do
gem 'yard', '~> 0', :platforms => [:ruby, :mswin, :mingw]
gem 'rdiscount', :platforms => [:ruby, :mswin, :mingw]
gem 'yard', '~> 0', :require => false
gem 'rdiscount', '~> 2', :require => false
end

group :tooling do
gem 'guard-rspec', '~> 3'
gem 'guard-rspec', '~> 4', :require => false
if RUBY_PLATFORM =~ /darwin/i
gem 'rb-fsevent', '~> 0', :require => false
gem 'rb-fsevent', '~> 0', :require => false
end
end
42 changes: 29 additions & 13 deletions Guardfile
@@ -1,19 +1,35 @@
interactor :off
require 'guard/rspec/dsl'

guard :rspec, :cli => '--debug' do
# Run the corresponding spec(s) (or all specs) when code changes.
watch(%r{^lib/(.+)\.rb$}) do |match|
corresponding_specs = Dir["spec/{integration,unit}/#{match[1]}_spec.rb"]
corresponding_specs.empty? ? 'spec' : corresponding_specs
end
debug_option = begin
require 'pry-byebug'
' --require pry-byebug'
rescue LoadError
nil
end
guard :rspec, :all_on_start => true,
:all_after_pass => true,
:cmd => "bundle exec rspec --format progress#{debug_option}" do
dsl = Guard::RSpec::Dsl.new(self)
rspec, ruby = dsl.rspec, dsl.ruby

# Run a spec when it changes.
watch %r{^spec/.+_spec\.rb$}
# RSpec files
watch('.rspec') { rspec.spec_dir }
watch rspec.spec_helper { rspec.spec_dir }
watch rspec.spec_support { rspec.spec_dir }
watch rspec.spec_files

# Run all specs when the RSpec configuration changes.
watch('.rspec' ) { 'spec' }
watch('spec/spec_helper.rb') { 'spec' }
# Run all specs when a shared spec changes.
watch(%r{^spec/.+_sharedspec\.rb$}) { rspec.spec_dir }

# Run all specs when the bundle changes.
watch('Gemfile.lock') { 'spec' }
watch('Gemfile.lock') { rspec.spec_dir }

# Ruby files
dsl.watch_spec_files_for ruby.lib_files

# Run the corresponding spec(s) (or all specs) when code changes.
watch(%r{^lib/(.+)\.rb$}) do |match|
corresponding_specs = Dir["spec/{integration,unit}/#{match[1]}_spec.rb"]
corresponding_specs.empty? ? rspec.spec_dir : corresponding_specs
end
end
7 changes: 7 additions & 0 deletions README.markdown
Expand Up @@ -191,6 +191,13 @@ Report defects and feature requests on [GitHub Issues](http://github.com/htty/ht

Your patches are welcome, and you will receive attribution here for good stuff. Fork [the official _htty_ repository](http://github.com/htty/htty "htty’s ‘htty’ repository at GitHub") and send a pull request.

Development
-----------

After cloning the repository, `bin/setup` to install dependencies. Then `rake` to run the tests. You can also `bin/console` to get an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, `bundle exec rake install`. To release a new version, update the version number in _lib/htty/version.rb_, and then `bundle exec rake release`, which will create a Git tag for the version, push Git commits and tags, and push the _.gem_ file to [RubyGems.org](http://rubygems.org).

News and information
====================

Expand Down
9 changes: 5 additions & 4 deletions Rakefile
Expand Up @@ -35,12 +35,13 @@ end
def define_spec_task(name, options={})
RSpec::Core::RakeTask.new name do |t|
t.rspec_opts ||= []
t.rspec_opts << "--format #{options[:format]}" if options[:format]
unless options[:debug] == false
begin
require 'ruby-debug'
require 'pry-byebug'
rescue LoadError
else
t.rspec_opts << '--debug'
t.rspec_opts << '--require pry-byebug'
end
end

Expand All @@ -60,9 +61,9 @@ desc 'Run all specs'
define_spec_task :spec

desc 'Run all specs'
task '' => :spec
task '' => :spec
task :default => :spec

# Support the 'gem test' command.
desc ''
define_spec_task :test, :debug => false
define_spec_task :test, :debug => false, :format => :progress
14 changes: 14 additions & 0 deletions bin/console
@@ -0,0 +1,14 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "htty"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require "irb"
IRB.start
8 changes: 8 additions & 0 deletions bin/setup
@@ -0,0 +1,8 @@
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'

which bundle || gem install bundler
bundle

# Do any other automated setup that you need to do here
File renamed without changes.
56 changes: 27 additions & 29 deletions htty.gemspec
@@ -1,36 +1,34 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path('../lib', __FILE__)
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'htty/version'

Gem::Specification.new do |s|
s.name = 'htty'
s.version = HTTY::VERSION
s.platform = Gem::Platform::RUBY
s.authors = ['Nils Jonsson']
s.email = ['htty@nilsjonsson.com']
s.homepage = 'http://htty.github.io'
s.summary = 'The HTTP TTY'
s.description = <<-end_description.gsub(/^\s+/, '').chomp
htty is a console application for interacting with web servers.
It's a fun way to explore web APIs and to learn the ins and
outs of HTTP.
end_description
s.license = 'MIT'
Gem::Specification.new do |spec|
spec.name = 'htty'
spec.version = HTTY::VERSION
spec.authors = ['Nils Jonsson']
spec.email = ['nils@alumni.rice.edu']

s.required_ruby_version = '>= 1.8.7'
spec.summary = 'The HTTP TTY'
spec.description = <<-end_description.gsub(/^\s+/, '').chomp
htty is a console application for interacting with web
servers. It's a fun way to explore web APIs and to learn
the ins and outs of HTTP.
end_description
spec.homepage = 'http://htty.github.io'
spec.license = 'MIT'

s.add_dependency 'mime-types', '~> 1'
spec.required_ruby_version = '>= 1.8.7'

s.add_development_dependency 'rake'
s.add_development_dependency 'rspec', '~> 2'
spec.add_dependency 'mime-types', '~> 1'
spec.add_development_dependency 'bundler', '~> 1'
spec.add_development_dependency 'rake', '~> 10'
spec.add_development_dependency 'rspec', '~> 3'

s.rubyforge_project = 'htty'
s.has_rdoc = true

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map do |f|
File.basename f
end
s.require_paths = %w(lib)
spec.files = `git ls-files -z`.split("\x0").reject do |f|
f.match(%r{^(test|spec|features)/})
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename f }
spec.require_paths = %w(lib)
end
22 changes: 9 additions & 13 deletions lib/htty/cli/command.rb
Expand Up @@ -29,9 +29,7 @@ def self.build_for(command_line, attributes={})
if (match = (command_line_regexp.match(command_line)))
begin
if (arguments = match.captures[0])
attributes = attributes.merge(
:arguments => sanitize_arguments(arguments.strip.shellsplit)
)
attributes = attributes.merge(:arguments => sanitize_arguments(arguments.strip.shellsplit))
end
rescue ArgumentError
:unclosed_quote
Expand Down Expand Up @@ -61,17 +59,15 @@ def self.command_line
end
end
all_command_lines = [my_command_line] + other_command_lines
all_abbrevs = Abbrev.abbrev(all_command_lines).group_by do |abbrev,
command_line|
all_abbrevs = Abbrev.abbrev(all_command_lines).group_by { |abbrev,
command_line|
command_line
end.collect do |command_line, abbrevs|
abbrevs.sort_by do |command_line, abbrev|
command_line
end.first
}.collect do |command_line, abbrevs|
abbrevs.sort_by { |command_line, abbrev| command_line }.first
end
my_abbrev = all_abbrevs.detect do |abbrev, command_line|
my_abbrev = all_abbrevs.detect { |abbrev, command_line|
command_line == my_command_line
end.first
}.first
my_abbrev_regexp = Regexp.new("^(#{Regexp.escape my_abbrev})(.*)$")
my_command_line.gsub my_abbrev_regexp do
$2.empty? ? $1 : "#{$1}[#{$2}]"
Expand Down Expand Up @@ -165,10 +161,10 @@ def self.namespaces

def self.namespace_siblings
namespace = namespaces.last
other_commands = namespace.constants.collect do |constant|
namespace.constants.collect { |constant|
type = namespace.module_eval(constant.to_s, __FILE__, __LINE__)
(type == self) ? nil : type
end.compact
}.compact
end

public
Expand Down
5 changes: 2 additions & 3 deletions lib/htty/cli/commands.rb
Expand Up @@ -22,9 +22,8 @@ def self.build_for(command_line, attributes={})
# Yields each HTTY::CLI::Command descendant in turn.
def self.each
Dir.glob "#{File.dirname __FILE__}/commands/*.rb" do |f|
class_name = File.basename(f, '.rb').gsub(/^(.)/) do |initial|
initial.upcase
end.gsub(/_(\S)/) do |initial|
class_name = File.basename(f, '.rb').gsub(/^(.)/, &:upcase).
gsub(/_(\S)/) do |initial|
initial.gsub(/_/, '').upcase
end
klass = const_get(class_name) rescue nil
Expand Down
6 changes: 3 additions & 3 deletions lib/htty/cli/commands/help.rb
Expand Up @@ -54,15 +54,15 @@ def display_help
'Inspecting Responses',
'Preferences',
nil]
HTTY::CLI::Commands.select do |c|
HTTY::CLI::Commands.select { |c|
# Filter out commands not yet implemented.
c.instance_methods.collect(&:to_sym).include?(:perform) ||
(c.alias_for &&
c.alias_for.instance_methods.collect(&:to_sym).include?(:perform))
end.group_by(&:category).sort_by do |category, commands|
}.group_by(&:category).sort_by { |category, commands|
# Group commands by category and give the categories a custom order.
categories_in_order.index(category) || 0
end.each do |category, commands|
}.each do |category, commands|
category ||= 'Miscellaneous'
puts
puts((' ' * ((80 - category.length) / 2)) +
Expand Down
6 changes: 3 additions & 3 deletions lib/htty/cli/display.rb
Expand Up @@ -174,13 +174,13 @@ def word_wrap(text, column=nil)
# http://api.rubyonrails.org/classes/ActionView/Helpers/TextHelper.html#M002281
def word_wrap_indented(text, columns=2..80)
indent_by, wrap_at = columns.min, columns.max - columns.min
text.split("\n").collect do |line|
text.split("\n").collect { |line|
(wrap_at < line.length) ?
line.gsub(/(.{1,#{wrap_at}})(\s+|$)/, "\\1\n").strip :
line
end.join("\n").split("\n").collect do |line|
}.join("\n").split("\n").collect { |line|
indent line, indent_by
end.join "\n"
}.join "\n"
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/htty/cookies_util.rb
Expand Up @@ -21,9 +21,9 @@ def self.cookies_to_string(cookies)
cookies = Array(cookies)
return nil if cookies.empty?

cookies.collect do |name, value|
cookies.collect { |name, value|
[name, value].compact.join COOKIE_NAME_VALUE_DELIMITER
end.join COOKIES_DELIMITER
}.join COOKIES_DELIMITER
end

protected
Expand Down
2 changes: 1 addition & 1 deletion lib/htty/headers.rb
Expand Up @@ -74,7 +74,7 @@ def self.basic_authentication_for(username, password = nil)
def self.credentials_from(basic_authentication)
if match = /^Basic (.+)$/.match(basic_authentication)
credentials = Base64.decode64(match[1]).split(':')
return yield *credentials if block_given?
return yield(*credentials) if block_given?
return credentials
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/htty/request.rb
Expand Up @@ -206,13 +206,13 @@ def cookie_remove(name)

# Remove just one matching cookie from the end.
rejected = false
new_cookies = cookies.reverse.reject do |cookie_name, cookie_value|
new_cookies = cookies.reverse.reject { |cookie_name, cookie_value|
if !rejected && (cookie_name == name)
rejected = true
else
false
end
end.reverse
}.reverse

cookies_string = HTTY::CookiesUtil.cookies_to_string(new_cookies)
if cookies_string
Expand Down

0 comments on commit 725c238

Please sign in to comment.