Permalink
Browse files

Started on cucumber specs

  • Loading branch information...
1 parent ab8180f commit 48f6795ef6207caf052e060f1e95da310434c47d @winton committed Dec 11, 2011
View
@@ -1,6 +1,8 @@
.DS_Store
*.gem
.bundle
+features/config.yml
+features/fixtures
Gemfile.lock
pkg
tmp
@@ -12,5 +12,5 @@ elsif gitcycle.respond_to?(command)
elsif ARGV.empty?
gitcycle.create_branch(command)
else
- puts "\nCommand \"#{command}\" not found.\n".red
+ puts "\nCommand '#{command}' not found.\n".red
end
@@ -0,0 +1,8 @@
+gitcycle: # gitcycle api token
+lighthouse:
+ account: # lighthouse subdomain
+ project: # lighthouse project id integer
+ token: # lighthouse api token hash
+owner: # user of parent repo
+repo: # repo name
+user: # user of forked repo
View
@@ -0,0 +1,27 @@
+Feature: gitcycle
+
+Scenario: No command given
+ When I execute gitcycle with ""
+ Then the output should contain "No command specified"
+
+Scenario: Non-existent command
+ When I execute gitcycle with "blah blah"
+ Then the output should contain "Command 'blah' not found"
+
+Scenario: Setup
+ When I execute gitcycle setup
+ Then the output should contain "Configuration saved."
+ And gitcycle.yml should be valid
+
+Scenario: Feature branch
+ Given a fresh set of repositories
+ And a new Lighthouse ticket
+ When I cd to the user repo
+ And I execute gitcycle with the Lighthouse ticket URL
+ And I type "y\n"
+ Then output includes "Retrieving branch information from gitcycle."
+ And output includes "Would you like to name your branch 'ticket.id'?"
+ And output includes "Creating 'ticket.id' from 'master'."
+ And output includes "Checking out branch 'ticket.id'."
+ And output includes "Pushing 'ticket.id'."
+ And output includes "Sending branch information to gitcycle."
@@ -0,0 +1,97 @@
+require 'aruba/cucumber'
+require 'lighthouse'
+require 'rspec/expectations'
+require 'yaml'
+
+BASE = File.expand_path '../../../', __FILE__
+BIN = "#{BASE}/bin/gitc"
+
+ENV['CONFIG'] = GITCYCLE = "#{BASE}/features/fixtures/gitcycle.yml"
+ENV['ENV'] = 'development'
+
+Before do
+ @aruba_timeout_seconds = 10
+end
+
+def config(reload=false)
+ @config = nil if reload
+ @config ||= YAML.load(File.read("#{BASE}/features/config.yml"))
+ Lighthouse.account = @config['lighthouse']['account']
+ Lighthouse.token = @config['lighthouse']['token']
+ @config
+end
+
+def repos(reload=false)
+ if @repos
+ @repos
+ else
+ owner = "#{BASE}/features/fixtures/owner"
+ user = "#{BASE}/features/fixtures/user"
+
+ FileUtils.rm_rf(owner)
+ FileUtils.rm_rf(user)
+
+ system [
+ "cd #{BASE}/features/fixtures",
+ "git clone git@github.com:#{config['owner']}/#{config['repo']}.git owner",
+ "git clone git@github.com:#{config['user']}/#{config['repo']}.git user"
+ ].join(' && ')
+
+ @repos = { :owner => owner, :user => user }
+ end
+end
+
+def run_gitcycle(cmd, interactive=false)
+ cmd = [ BIN, cmd ].join(' ')
+ if interactive
+ run_interactive(unescape(cmd))
+ else
+ run_simple(unescape(cmd), false)
+ end
+end
+
+Given /^a fresh set of repositories$/ do
+ repos(true)
+end
+
+Given /^a new Lighthouse ticket$/ do
+ @ticket = Lighthouse::Ticket.new(
+ :project_id => config['lighthouse']['project'],
+ :state => "open",
+ :title => "Test ticket"
+ )
+ @ticket.save
+end
+
+When /^I execute gitcycle with "([^\"]*)"$/ do |cmd|
+ run_gitcycle(cmd)
+end
+
+When /^I execute gitcycle setup$/ do
+ FileUtils.rm(GITCYCLE) if File.exists?(GITCYCLE)
+ run_gitcycle [
+ "setup",
+ config['user'],
+ config['repo'],
+ config['gitcycle']
+ ].join(' ')
+end
+
+When /^I execute gitcycle with the Lighthouse ticket URL$/ do
+ run_gitcycle @ticket.url, true
+end
+
+When /^I cd to the (.*) repo$/ do |user|
+ dirs.pop
+ cd(@repos[user.to_sym])
+end
+
+Then /^gitcycle\.yml should be valid$/ do
+ gitcycle = YAML.load(File.read(GITCYCLE))
+ gitcycle[config['user']][config['repo']].should == config['gitcycle']
+end
+
+Then /^output includes \"([^\"]*)"$/ do |expected|
+ expected.gsub!('ticket.id', @ticket.attributes['id'])
+ assert_partial_output(expected, all_output)
+end
View
@@ -19,7 +19,10 @@ Gem::Specification.new do |s|
s.require_paths = %w(lib)
s.test_files = `cd #{root} && git ls-files -- {features,test,spec}/*`.split("\n")
- s.add_development_dependency "rspec", "~> 1.0"
+ s.add_development_dependency "aruba"
+ s.add_development_dependency "cucumber"
+ s.add_development_dependency "lighthouse"
+ s.add_development_dependency "rspec"
s.add_dependency "launchy", "= 2.0.5"
s.add_dependency "yajl-ruby", "= 1.1.0"
View
@@ -22,7 +22,11 @@ class Gitcycle
end
def initialize
- @config_path = File.expand_path("~/.gitcycle.yml")
+ if ENV['CONFIG']
+ @config_path = File.expand_path(ENV['CONFIG'])
+ else
+ @config_path = File.expand_path("~/.gitcycle.yml")
+ end
load_config
load_git
end
@@ -53,7 +57,7 @@ def create_branch(url_or_title)
unless branch['exists']
branch['source'] = branches(:current => true)
- unless yes?("Would you like to name your branch #{name}?")
+ unless yes?("Would you like to name your branch '#{name}'?")
name = q("\nWhat would you like to name your branch?")
name = name.gsub(/[\s\W]/, '-')
end
@@ -264,6 +268,7 @@ def setup(login, repo, token)
@config[login] ||= {}
@config[login][repo] = token
save_config
+ puts "\nConfiguration saved.\n".green
end
private
@@ -420,13 +425,15 @@ def require_config
puts "\nGitcycle configuration not found.".red
puts "Are you in the right repository?".yellow
puts "Have you set up this repository at http://gitcycle.com?\n".yellow
+ exit
end
end
def require_git
unless @git_url && @git_repo && @git_login
puts "\norigin entry within '.git/config' not found!".red
puts "Are you sure you are in a git repository?\n".yellow
+ exit
end
end
View
@@ -1,4 +0,0 @@
-require 'spec_helper'
-
-describe Gitcycle do
-end
View
@@ -1,8 +0,0 @@
-require "pp"
-require "bundler"
-
-Bundler.require(:development)
-
-$root = File.expand_path('../../', __FILE__)
-
-require "#{$root}/lib/gitcycle"

0 comments on commit 48f6795

Please sign in to comment.