Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Eliminating Aruba, adding simplecov

  • Loading branch information...
commit 55acb57bbd3382130f4e4a5a71a1b7911697ef1d 1 parent c3bb722
@winton authored
View
1  .gitignore
@@ -1,6 +1,7 @@
.DS_Store
*.gem
.bundle
+coverage
features/config.yml
features/fixtures
Gemfile.lock
View
13 bin/gitc
@@ -2,15 +2,4 @@
require File.expand_path("../../lib/gitcycle", __FILE__)
-gitcycle = Gitcycle.new
-command = ARGV.shift
-
-if command.nil?
- puts "\nNo command specified\n".red
-elsif gitcycle.respond_to?(command)
- gitcycle.send(command, *ARGV)
-elsif ARGV.empty?
- gitcycle.create_branch(command)
-else
- puts "\nCommand '#{command}' not found.\n".red
-end
+Gitcycle.new(ARGV)
View
51 features/gitcycle.feature
@@ -1,16 +1,19 @@
Feature: gitcycle
Scenario: No command given
- When I execute gitcycle with ""
- Then output includes "No command specified"
+ When I execute gitcycle with nothing
+ Then gitcycle runs
+ And output includes "No command specified"
Scenario: Non-existent command
When I execute gitcycle with "blah blah"
- Then output includes "Command 'blah' not found"
+ Then gitcycle runs
+ And output includes "Command 'blah' not found"
Scenario: Setup
When I execute gitcycle setup
- Then output includes "Configuration saved."
+ Then gitcycle runs
+ And output includes "Configuration saved."
And gitcycle.yml should be valid
Scenario: Feature branch w/ custom branch name
@@ -20,7 +23,8 @@ Scenario: Feature branch w/ custom branch name
And I execute gitcycle with the Lighthouse ticket URL
And I enter "n"
And I enter "ticket.id-rename"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output includes "Would you like to name your branch 'ticket.id'?"
And output includes "What would you like to name your branch?"
And output includes "Creating 'ticket.id-rename' from 'master'."
@@ -35,7 +39,8 @@ Scenario: Feature branch
When I cd to the user repo
And I execute gitcycle with the Lighthouse ticket URL
And I enter "y"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output includes "Would you like to name your branch 'ticket.id'?"
And output does not include "What would you like to name your branch?"
And output includes "Creating 'ticket.id' from 'master'."
@@ -47,7 +52,8 @@ Scenario: Feature branch
Scenario: Checkout via ticket w/ existing branch
When I cd to the user repo
And I execute gitcycle with the Lighthouse ticket URL
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output does not include "Would you like to name your branch 'ticket.id'?"
And output does not include "What would you like to name your branch?"
And output does not include "Creating 'ticket.id' from 'master'."
@@ -60,7 +66,8 @@ Scenario: Checkout via ticket w/ fresh repo
Given a fresh set of repositories
When I cd to the user repo
And I execute gitcycle with the Lighthouse ticket URL
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output does not include "Would you like to name your branch 'ticket.id'?"
And output does not include "What would you like to name your branch?"
And output does not include "Creating 'ticket.id' from 'master'."
@@ -75,7 +82,8 @@ Scenario: Pull changes from upstream
And I commit something
And I cd to the user repo
And I execute gitcycle with "pull"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output includes "Adding remote repo 'config.owner/config.repo'."
And output includes "Fetching remote branch 'master'."
And output includes "Merging remote branch 'master' from 'config.owner/config.repo'."
@@ -85,7 +93,8 @@ Scenario: Discuss commits w/ no parameters and nothing committed
When I cd to the user repo
And I checkout ticket.id
And I execute gitcycle with "discuss"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output includes "Creating GitHub pull request."
And output does not include "Branch not found."
And output does not include "Opening issue"
@@ -97,7 +106,8 @@ Scenario: Discuss commits w/ no parameters and something committed
And I checkout ticket.id
And I commit something
And I execute gitcycle with "discuss"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output includes "Creating GitHub pull request."
And output does not include "Branch not found."
And output includes "Opening issue" with URL
@@ -109,7 +119,8 @@ Scenario: Discuss commits w/ parameters
When I cd to the user repo
And I checkout ticket.id
And I execute gitcycle with "discuss issue.id"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output does not include "Creating GitHub pull request."
And output does not include "Branch not found."
And output does not include "You must push code before opening a pull request."
@@ -120,32 +131,36 @@ Scenario: Ready issue w/ no parameters
When I cd to the user repo
And I checkout ticket.id
And I execute gitcycle with "ready"
- Then output includes "Labeling issue as 'Pending Review'."
+ Then gitcycle runs
+ And output includes "Labeling issue as 'Pending Review'."
Scenario: Ready issue w/ parameters
When I cd to the user repo
And I execute gitcycle with "ready issue.id"
- Then output includes "Labeling issues as 'Pending Review'."
+ Then gitcycle runs
+ And output includes "Labeling issues as 'Pending Review'."
Scenario: Reviewed issue w/ no parameters
When I cd to the user repo
And I checkout ticket.id
And I execute gitcycle with "reviewed"
- Then output includes "Labeling issue as 'Pending QA'."
+ Then gitcycle runs
+ And output includes "Labeling issue as 'Pending QA'."
Scenario: Reviewed issue w/ parameters
When I cd to the user repo
And I execute gitcycle with "reviewed issue.id"
- Then output includes "Labeling issues as 'Pending QA'."
+ Then gitcycle runs
+ And output includes "Labeling issues as 'Pending QA'."
Scenario: QA issue
When I cd to the owner repo
And I checkout master
And I execute gitcycle with "qa issue.id"
- Then output includes "Retrieving branch information from gitcycle."
+ Then gitcycle runs
+ And output includes "Retrieving branch information from gitcycle."
And output does not include "Checking out source branch 'master'."
And output does not include "Tracking source branch 'master'."
- And output does not include "Deleting old QA branch 'qa_master'."
And output includes "Creating QA branch 'qa_master'."
And output includes "Adding remote repo 'config.user/config.repo'."
And output includes "Fetching remote branch 'ticket.id'."
View
90 features/steps/gitcycle_steps.rb
@@ -1,4 +1,4 @@
-require 'aruba/cucumber'
+require 'cucumber/rspec/doubles'
require 'lighthouse'
require 'redis'
require 'rspec/expectations'
@@ -11,23 +11,25 @@
ENV['CONFIG'] = GITCYCLE = "#{BASE}/features/fixtures/gitcycle.yml"
ENV['ENV'] = 'development'
+$:.unshift File.expand_path(__FILE__, "../../../lib")
+require "gitcycle"
+
$redis = Redis.new
Before do |scenario|
- @aruba_timeout_seconds = 10
@scenario_title = scenario.title
+ $execute = []
+ $input = []
end
def branches(options={})
- in_current_dir do
- b = `git branch#{" -a" if options[:all]}`
- if options[:current]
- b.match(/\*\s+(.+)/)[1]
- elsif options[:match]
- b.match(/([\s]+|origin\/)(#{options[:match]})/)[2] rescue nil
- else
- b
- end
+ b = `git branch#{" -a" if options[:all]}`
+ if options[:current]
+ b.match(/\*\s+(.+)/)[1]
+ elsif options[:match]
+ b.match(/([\s]+|origin\/)(#{options[:match]})/)[2] rescue nil
+ else
+ b
end
end
@@ -54,11 +56,8 @@ def gsub_variables(str)
end
def log(match)
- in_current_dir do
- log = `git log --pretty=format:%s`
- match = !(match =~ /^#{match}$/).nil?
- end
- match
+ log = `git log --pretty=format:%s`
+ !(match =~ /^#{match}$/).nil?
end
def repos(reload=false)
@@ -81,15 +80,21 @@ def repos(reload=false)
end
end
-def run_gitcycle(cmd, interactive=false)
- cmd = [ BIN, cmd ].join(' ')
- if interactive
- run_interactive(unescape(cmd))
+def run_gitcycle(cmd)
+ @output = ''
+ @gitcycle = Gitcycle.new
+ @gitcycle.stub(:puts) { |str| @output << str.gsub(/\e\[\d{1,2}m/, '') }
+ if cmd
+ @gitcycle.start(Shellwords.split(cmd))
else
- run_simple(unescape(cmd), false)
+ @gitcycle.start
end
end
+def type(text)
+ $input << text
+end
+
Given /^a fresh set of repositories$/ do
repos(true)
end
@@ -104,20 +109,23 @@ def run_gitcycle(cmd, interactive=false)
$ticket.save
end
+When /^I execute gitcycle with nothing$/ do
+ $execute << nil
+end
+
When /^I execute gitcycle with "([^\"]*)"$/ do |cmd|
- cmd = gsub_variables(cmd)
- run_gitcycle(cmd)
+ $execute << gsub_variables(cmd)
end
When /^I execute gitcycle setup$/ do
FileUtils.rm(GITCYCLE) if File.exists?(GITCYCLE)
- run_gitcycle [
+ $execute << [
"setup",
config['user'],
config['repo'],
config['token_dev']
].join(' ')
- run_gitcycle [
+ $execute << [
"setup",
config['user'],
"#{config['owner']}/#{config['repo']}",
@@ -126,12 +134,11 @@ def run_gitcycle(cmd, interactive=false)
end
When /^I execute gitcycle with the Lighthouse ticket URL$/ do
- run_gitcycle $ticket.url, true
+ $execute << $ticket.url
end
When /^I cd to the (.*) repo$/ do |user|
- dirs.pop
- cd($repos[user.to_sym])
+ Dir.chdir($repos[user.to_sym])
end
When /^I enter "([^\"]*)"$/ do |input|
@@ -141,18 +148,20 @@ def run_gitcycle(cmd, interactive=false)
When /^I commit something$/ do
branch = branches(:current => true)
- in_current_dir do
- $commit_msg = "#{@scenario_title} - #{rand}"
- File.open('README', 'w') {|f| f.write($commit_msg) }
- `git add . && git add . -u && git commit -a -m '#{$commit_msg}'`
- `git push origin #{branch}`
- end
+ $commit_msg = "#{@scenario_title} - #{rand}"
+ File.open('README', 'w') {|f| f.write($commit_msg) }
+ `git add . && git add . -u && git commit -a -m '#{$commit_msg}'`
+ `git push origin #{branch}`
end
When /^I checkout (.+)$/ do |branch|
branch = gsub_variables(branch)
- in_current_dir do
- `git checkout #{branch}`
+ `git checkout #{branch}`
+end
+
+Then /^gitcycle runs$/ do
+ $execute.each do |cmd|
+ run_gitcycle(cmd)
end
end
@@ -168,19 +177,18 @@ def run_gitcycle(cmd, interactive=false)
Then /^output includes \"([^\"]*)"$/ do |expected|
expected = gsub_variables(expected)
- assert_partial_output(expected, all_output)
+ @output.include?(expected).should == true
end
Then /^output includes \"([^\"]*)" with URL$/ do |expected|
- puts all_output.inspect
expected = gsub_variables(expected)
- assert_partial_output(expected, all_output)
- $url = all_output.match(/^#{expected}.*(https?:\/\/[^\s]+)/)[1]
+ @output.include?(expected).should == true
+ $url = @output.match(/#{expected}.*(https?:\/\/[^\s]+)/)[1]
end
Then /^output does not include \"([^\"]*)"$/ do |expected|
expected = gsub_variables(expected)
- assert_no_partial_output(expected, all_output)
+ @output.include?(expected).should == false
end
Then /^redis entries valid$/ do
View
2  features/support/env.rb
@@ -0,0 +1,2 @@
+require 'simplecov'
+SimpleCov.start
View
1  gitcycle.gemspec
@@ -24,6 +24,7 @@ Gem::Specification.new do |s|
s.add_development_dependency "lighthouse"
s.add_development_dependency "redis"
s.add_development_dependency "rspec"
+ s.add_development_dependency "simplecov"
s.add_development_dependency "yajl-ruby"
s.add_dependency "launchy", "= 2.0.5"
View
22 lib/gitcycle.rb
@@ -21,14 +21,17 @@ class Gitcycle
"http://gitcycle.bleacherreport.com/api"
end
- def initialize
+ def initialize(args=nil)
if ENV['CONFIG']
@config_path = File.expand_path(ENV['CONFIG'])
else
@config_path = File.expand_path("~/.gitcycle.yml")
end
+
load_config
load_git
+
+ start(args) if args
end
def create_branch(url_or_title)
@@ -294,6 +297,19 @@ def setup(login, repo, token)
puts "\nConfiguration saved.\n".green
end
+ def start(args=[])
+ command = args.shift
+ if command.nil?
+ puts "\nNo command specified\n".red
+ elsif self.respond_to?(command)
+ send(command, *args)
+ elsif args.empty?
+ create_branch(command)
+ else
+ puts "\nCommand '#{command}' not found.\n".red
+ end
+ end
+
private
def branches(options={})
@@ -334,7 +350,7 @@ def create_qa_branch(options)
run("git fetch && git checkout -b #{source} origin/#{source}")
end
- if branches(:match => name)
+ if branches(:match => name, :all => true)
puts "Deleting old QA branch '#{name}'.\n".green
run("git branch -D #{name}")
run("git push origin :#{name}")
@@ -481,7 +497,7 @@ def save_config
def q(question, extra='')
puts "#{question.yellow}#{extra}"
- $stdin.gets.strip
+ $input ? $input.shift : $stdin.gets.strip
end
def run(cmd)
Please sign in to comment.
Something went wrong with that request. Please try again.