Move back to 'gist' gem

This commit is contained in:
Conrad Irwin 2014-04-27 22:23:54 -07:00
parent 2467871169
commit f27e718cfe
3 changed files with 31 additions and 79 deletions

View File

@ -4,7 +4,7 @@ gem 'rake', '~> 10.0'
# For Guard
group :development do
gem 'jist'
gem 'gist'
gem 'yard'
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false

View File

@ -3,7 +3,7 @@ class Pry
match 'gist'
group 'Misc'
description 'Upload code, docs, history to https://gist.github.com/.'
command_options :requires_gem => "jist"
command_options :requires_gem => "gist"
banner <<-'BANNER'
Usage: gist [OPTIONS] [--help]
@ -16,18 +16,18 @@ class Pry
BANNER
def setup
require 'jist'
require 'gist'
end
def options(opt)
CodeCollector.inject_options(opt)
opt.on :login, "Authenticate the jist gem with GitHub"
opt.on :login, "Authenticate the gist gem with GitHub"
opt.on :p, :public, "Create a public gist (default: false)", :default => false
opt.on :clip, "Copy the selected content to clipboard instead, do NOT gist it", :default => false
end
def process
return Jist.login! if opts.present?(:login)
return ::Gist.login! if opts.present?(:login)
cc = CodeCollector.new(args, opts, _pry_)
if cc.content =~ /\A\s*\z/
@ -45,7 +45,7 @@ class Pry
end
def clipboard_content(content)
Jist.copy(content)
::Gist.copy(content)
output.puts "Copied content to clipboard!"
end
@ -81,14 +81,14 @@ class Pry
end
def gist_content(content, filename)
response = Jist.gist(content, :filename => filename || "pry_gist.rb", :public => !!opts[:p])
response = ::Gist.gist(content, :filename => filename || "pry_gist.rb", :public => !!opts[:p])
if response
url = response['html_url']
message = "Gist created at URL #{url}"
begin
Jist.copy(url)
::Gist.copy(url)
message << ", which is now in the clipboard."
rescue Jist::ClipboardError
rescue ::Gist::ClipboardError
end
output.puts message
@ -98,5 +98,4 @@ class Pry
Pry::Commands.add_command(Pry::Command::Gist)
Pry::Commands.alias_command 'clipit', 'gist --clip'
Pry::Commands.alias_command 'jist', 'gist'
end

View File

@ -6,74 +6,27 @@ require_relative '../helper'
describe 'gist' do
it 'has a dependency on the jist gem' do
Pry::Command::Gist.command_options[:requires_gem].should == "jist"
Pry::Command::Gist.command_options[:requires_gem].should == "gist"
end
before do
Pad.gist_calls = {}
end
# In absence of normal mocking, just monkeysmash these with no undoing after.
module ::Gist
class << self
def login!; Pad.gist_calls[:login!] = true end
def gist(*args)
Pad.gist_calls[:gist_args] = args
{'html_url' => 'http://gist.blahblah'}
end
def copy(content); Pad.gist_calls[:copy_args] = content end
end
end
it 'nominally logs in' do
pry_eval 'gist --login'
Pad.gist_calls[:login!].should.not.be.nil
end
end
# before do
# Pad.jist_calls = {}
# end
# # In absence of normal mocking, just monkeysmash these with no undoing after.
# module Jist
# class << self
# def login!; Pad.jist_calls[:login!] = true end
# def gist(*args)
# Pad.jist_calls[:gist_args] = args
# {'html_url' => 'http://gist.blahblah'}
# end
# def copy(content); Pad.jist_calls[:copy_args] = content end
# end
# end
# module Pry::Gist
# # a) The actual require fails for jruby for some odd reason.
# # b) 100% of jist should be stubbed by the above, so this ensures that.
# def self.require_jist; 'nope' end
# end
# it 'nominally logs in' do
# pry_eval 'gist --login'
# Pad.jist_calls[:login!].should.not.be.nil
# end
# EXAMPLE_REPL_METHOD = <<-EOT
# # docdoc
# def my_method
# # line 1
# 'line 2'
# line 3
# Line.four
# end
# EOT
# RANDOM_COUPLE_OF_LINES = %w(a=1 b=2)
# run_case = proc do |sym|
# actual_command = Pry::Gist.example_code(sym)
# pry_eval EXAMPLE_REPL_METHOD, RANDOM_COUPLE_OF_LINES, actual_command
# end
# it 'deduces filenames' do
# Pry::Gist::INVOCATIONS.keys.each do |e|
# run_case.call(e)
# if Pad.jist_calls[:gist_args]
# text, args = Pad.jist_calls[:gist_args]
# args[:filename].should.not == '(pry)'
# end
# Pad.jist_calls[:copy_args].should.not.be.nil
# end
# end
# it 'equates aliae' do
# run_case.call(:clipit).should == run_case.call(:cliponly)
# run_case.call(:jist).should == run_case.call(:class)
# end
# it 'has a reasonable --help' do
# help = pry_eval('gist --help')
# Pry::Gist::INVOCATIONS.keys.each do |e|
# help.should.include? Pry::Gist.example_code(e)
# help.should.include? Pry::Gist.example_description(e)
# end
# end
# end