Skip to content

Commit

Permalink
More work on develop command specs, removing VCR
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Oct 14, 2013
1 parent 0b9a9b4 commit 8b1ccf7
Show file tree
Hide file tree
Showing 14 changed files with 114 additions and 125 deletions.
3 changes: 2 additions & 1 deletion gitcycle.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_development_dependency "bundler"
spec.add_development_dependency "json-schema"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "simplecov"
spec.add_development_dependency "vcr"
spec.add_development_dependency "webmock"

spec.add_dependency "excon"
spec.add_dependency "faraday"
Expand Down
26 changes: 12 additions & 14 deletions lib/gitcycle.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
require "rubygems"

gem "system_timer", :platforms => [ :ruby_18 ]

require "excon"
require "faraday"
require "launchy"
Expand All @@ -8,36 +11,28 @@
require "yajl/json_gem"
require "yaml"

gem "system_timer", :platforms => [ :ruby_18 ]

$:.unshift File.dirname(__FILE__)

require "ext/string"
require "gitcycle/config"

class Gitcycle < Thor
class Config
self.config_path = ENV['CONFIG'] || "~/.gitcycle.yml"
self.config_path = File.expand_path(config_path)
read
end
end

require "gitcycle/api"
require "gitcycle/subcommand"
require "gitcycle/subcommands/assist"
require "gitcycle/subcommands/review"
require "gitcycle/subcommands/setup"

require "gitcycle/api"
require "gitcycle/assist"
require "gitcycle/config"
require "gitcycle/commit"
require "gitcycle/develop"
require "gitcycle/discuss"
require "gitcycle/git"
require "gitcycle/incident"
require "gitcycle/open"
require "gitcycle/pull"
require "gitcycle/qa"
require "gitcycle/ready"
require "gitcycle/subcommands/review"
require "gitcycle/review"
require "gitcycle/subcommands/setup"
require "gitcycle/setup"

class Gitcycle < Thor
Expand All @@ -54,7 +49,9 @@ class Gitcycle < Thor
}

def initialize(args=nil, opts=nil, config=nil)
Config.load
Config.fetches = []

Git.load

unless ENV['ENV'] == 'test'
Expand Down Expand Up @@ -115,6 +112,7 @@ def require_git
end

def yes?(question)
question = question.gsub(/\s+/, ' ').strip
q(question, " (#{"y".green}/#{"n".red})").downcase[0..0] == 'y'
end
end
Expand Down
14 changes: 11 additions & 3 deletions lib/gitcycle/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class <<self

def branch(method, params=nil)
method, params = method_parameters(method, params)
parse http.send(method, "/branch.json", params).body
end

def user
Expand All @@ -14,7 +15,9 @@ def user

def http
options = { :ssl => { :verify => false } }
puts Gitcycle::Config.url
@http ||= Faraday.new Gitcycle::Config.url, options do |conn|
conn.request :url_encoded
conn.adapter :excon
end

Expand All @@ -23,11 +26,16 @@ def http
end

def method_parameters(method, params)
if method
method = :post if method == :create
method = :put if method == :update
end

if params.nil?
[ :get, params ]
else
[ method, params ]
method, params = :get, params
end

[ method, params ]
end

def parse(body)
Expand Down
8 changes: 8 additions & 0 deletions lib/gitcycle/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ class <<self
attr_accessor :git_repo
attr_accessor :git_url

def load
unless self.config_path
self.config_path = ENV['CONFIG'] || "~/.gitcycle.yml"
self.config_path = File.expand_path(config_path)
end
read
end

def method_missing(method, *args, &block)
raise "Call Config.read first" unless config

Expand Down
33 changes: 16 additions & 17 deletions lib/gitcycle/develop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ class Gitcycle < Thor
def branch(url_or_title)
require_git and require_config

puts "Retrieving branch information from gitcycle.".space.green

params = generate_params(url_or_title)
branch = Api.branch(:create, :branch => params)
branch = Api.branch(:create, params)

change_target(branch, params)

begin
checkout_branch(branch)
update_branch(branch)
rescue SystemExit, Interrupt
delete_branch(branch)
Api.branch(:delete, :branch => { :id => branch[:id] })
end
end

Expand All @@ -26,6 +26,17 @@ def change_name(name)
end
end

def change_target(branch, params)
question = <<-STR
Your work will eventually merge into "#{params['branch[source]']}".
Is this correct?
STR

unless yes?(question)
params[:source] = q("What branch would you like to eventually merge into?")
end
end

def checkout_branch(branch)
owner = branch[:repo][:owner].login
repo = branch[:repo].name
Expand All @@ -36,26 +47,16 @@ def checkout_branch(branch)
Git.checkout_remote_branch(owner, repo, branch[:source], :branch => name)
end

def delete_branch(branch)
puts "Deleting branch from gitcycle.".space(true).green

Api.branch(:delete, :branch => { :id => branch[:id] })
end

def generate_params(url_or_title)
url, title = parse_url_or_title(url_or_title)
params = { :source => branches(:current => true) }
params = { :source => Git.branches(:current => true) }

if url
params.merge!(ticket_provider_params(url))
elsif title
params.merge!(:title => title)
end

unless yes?("Your work will eventually merge into '#{params['branch[source]']}'. Is this correct?")
params[:source] = q("What branch would you like to eventually merge into?")
end

params
end

Expand All @@ -79,8 +80,6 @@ def ticket_provider_params(url)
end

def update_branch(branch)
puts "Sending branch information to gitcycle.".green

Api.branch(:update,
:branch => {
:id => branch[:id],
Expand Down

This file was deleted.

36 changes: 18 additions & 18 deletions spec/gitcycle/api_spec.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
require File.expand_path("../../spec_helper", __FILE__)
# require File.expand_path("../../spec_helper", __FILE__)

describe Gitcycle::Api do
# describe Gitcycle::Api do

let(:api) do
Gitcycle::Config.config = config
Gitcycle::Api
end
# let(:api) do
# Gitcycle::Config.config = config
# Gitcycle::Api
# end

describe "#user" do
# describe "#user" do

let(:user) { api.user }
# let(:user) { api.user }

it "should retrieve user information", :vcr do
%w(gravatar login name).each do |key|
user[key.to_sym].should be_a String
end
%w(created_at updated_at).each do |key|
user[key.to_sym].should be_a Time
end
end
end
end
# it "should retrieve user information", :vcr do
# %w(gravatar login name).each do |key|
# user[key.to_sym].should be_a String
# end
# %w(created_at updated_at).each do |key|
# user[key.to_sym].should be_a Time
# end
# end
# end
# end
3 changes: 2 additions & 1 deletion spec/gitcycle/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
describe Gitcycle::Config do

before :all do
gitcycle_instance
Gitcycle::Config.config_path = config_fixture_path
Gitcycle::Config.load
end

it "should save" do
Expand Down
30 changes: 30 additions & 0 deletions spec/gitcycle/develop_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
require File.expand_path("../../spec_helper", __FILE__)

describe Gitcycle do

describe "#develop" do

let(:gitcycle) do
Gitcycle::Config.config_path = config_path
Gitcycle.new
end

it "should" do
body = {
:lighthouse_url => "https://test.lighthouseapp.com/projects/0000/tickets/0000-ticket",
:source => "gitcycle_api2"
}
headers = {
'Authorization' => 'Token token="8546f464"',
'Content-Type' => 'application/x-www-form-urlencoded',
'Host' => '127.0.0.1:3000',
'User-Agent' => 'Faraday v0.8.8'
}
stub_request(:post, "http://127.0.0.1:3000/branch.json").
with(:body => body, :headers => headers).
to_return(:status => 200, :body => "{}", :headers => {})
$stdin.stub!(:gets).and_return("y")
gitcycle.branch("https://test.lighthouseapp.com/projects/0000/tickets/0000-ticket")
end
end
end
5 changes: 4 additions & 1 deletion spec/gitcycle/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

describe Gitcycle do

let(:setup) { Gitcycle::Subcommands::Setup.new }
let(:setup) do
Gitcycle::Config.config_path = config_fixture_path
Gitcycle::Subcommands::Setup.new
end

%w(lighthouse token url).each do |property|
describe "setup #{property} #{property.upcase}" do
Expand Down
Loading

0 comments on commit 8b1ccf7

Please sign in to comment.