Permalink
Browse files

More cucumber specs, allowing 'qa pass' and 'qa fail' commands to tak…

…e list of issues
  • Loading branch information...
1 parent 48f6795 commit aca2a9bfb1626481750873dd8356f88b749a6910 @winton committed Dec 28, 2011
Showing with 318 additions and 51 deletions.
  1. +117 −5 features/gitcycle.feature
  2. +125 −9 features/steps/gitcycle_steps.rb
  3. +2 −0 gitcycle.gemspec
  4. +74 −37 lib/gitcycle.rb
@@ -2,26 +2,138 @@ Feature: gitcycle
Scenario: No command given
When I execute gitcycle with ""
- Then the output should contain "No command specified"
+ Then output includes "No command specified"
Scenario: Non-existent command
When I execute gitcycle with "blah blah"
- Then the output should contain "Command 'blah' not found"
+ Then output includes "Command 'blah' not found"
Scenario: Setup
When I execute gitcycle setup
- Then the output should contain "Configuration saved."
+ Then output includes "Configuration saved."
And gitcycle.yml should be valid
+Scenario: Feature branch w/ custom branch name
+ 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 enter "n"
+ And I enter "ticket.id-rename"
+ Then 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'."
+ And output includes "Checking out branch 'ticket.id-rename'."
+ And output includes "Pushing 'ticket.id-rename'."
+ And output includes "Sending branch information to gitcycle."
+ And redis entries 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"
+ And I enter "y"
Then 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'."
And output includes "Checking out branch 'ticket.id'."
And output includes "Pushing 'ticket.id'."
- And output includes "Sending branch information to gitcycle."
+ And output includes "Sending branch information to gitcycle."
+ And redis entries valid
+
+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."
+ 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'."
+ And output includes "Checking out branch 'ticket.id'."
+ And output does not include "Pushing 'ticket.id'."
+ And output does not include "Sending branch information to gitcycle."
+ And current branch is "ticket.id"
+
+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."
+ 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'."
+ And output includes "Tracking branch 'ticket.id'."
+ And output does not include "Pushing 'ticket.id'."
+ And output does not include "Sending branch information to gitcycle."
+ And current branch is "ticket.id"
+
+Scenario: Pull changes from upstream
+ When I cd to the owner repo
+ And I checkout master
+ 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."
+ 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'."
+ And git log should contain the last commit
+
+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."
+ And output includes "Creating GitHub pull request."
+ And output does not include "Branch not found."
+ And output does not include "Opening issue"
+ And output includes "You must push code before opening a pull request."
+ And redis entries valid
+
+Scenario: Discuss commits w/ no parameters and something committed
+ When I cd to the user repo
+ And I checkout ticket.id
+ And I commit something
+ And I execute gitcycle with "discuss"
+ Then 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
+ And output does not include "You must push code before opening a pull request."
+ And URL is a valid issue
+ And redis entries valid
+
+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."
+ 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."
+ And output includes "Opening issue" with URL
+ And URL is a valid issue
+
+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'."
+
+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'."
+
+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'."
+
+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'."
@@ -1,16 +1,34 @@
require 'aruba/cucumber'
require 'lighthouse'
+require 'redis'
require 'rspec/expectations'
require 'yaml'
+require 'yajl'
BASE = File.expand_path '../../../', __FILE__
BIN = "#{BASE}/bin/gitc"
ENV['CONFIG'] = GITCYCLE = "#{BASE}/features/fixtures/gitcycle.yml"
ENV['ENV'] = 'development'
-Before do
+$redis = Redis.new
+
+Before do |scenario|
@aruba_timeout_seconds = 10
+ @scenario_title = scenario.title
+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
+ end
end
def config(reload=false)
@@ -21,9 +39,30 @@ def config(reload=false)
@config
end
+def gsub_variables(str)
+ if $ticket
+ str = str.gsub('ticket.id', $ticket.attributes['id'])
+ end
+ if $url
+ issue_id = $url.match(/https:\/\/github.com\/.+\/issues\/(\d+)/)[1]
+ str = str.gsub('issue.id', issue_id)
+ end
+ str = str.gsub('config.owner', config['owner'])
+ str = str.gsub('config.repo', config['repo'])
+ str
+end
+
+def log(match)
+ in_current_dir do
+ log = `git log --pretty=format:%s`
+ match = !(match =~ /^#{match}$/).nil?
+ end
+ match
+end
+
def repos(reload=false)
- if @repos
- @repos
+ if $repos && !reload
+ $repos
else
owner = "#{BASE}/features/fixtures/owner"
user = "#{BASE}/features/fixtures/user"
@@ -37,7 +76,7 @@ def repos(reload=false)
"git clone git@github.com:#{config['user']}/#{config['repo']}.git user"
].join(' && ')
- @repos = { :owner => owner, :user => user }
+ $repos = { :owner => owner, :user => user }
end
end
@@ -55,15 +94,17 @@ def run_gitcycle(cmd, interactive=false)
end
Given /^a new Lighthouse ticket$/ do
- @ticket = Lighthouse::Ticket.new(
+ $ticket = Lighthouse::Ticket.new(
+ :body => "test",
:project_id => config['lighthouse']['project'],
:state => "open",
:title => "Test ticket"
)
- @ticket.save
+ $ticket.save
end
When /^I execute gitcycle with "([^\"]*)"$/ do |cmd|
+ cmd = gsub_variables(cmd)
run_gitcycle(cmd)
end
@@ -78,12 +119,34 @@ def run_gitcycle(cmd, interactive=false)
end
When /^I execute gitcycle with the Lighthouse ticket URL$/ do
- run_gitcycle @ticket.url, true
+ run_gitcycle $ticket.url, true
end
When /^I cd to the (.*) repo$/ do |user|
dirs.pop
- cd(@repos[user.to_sym])
+ cd($repos[user.to_sym])
+end
+
+When /^I enter "([^\"]*)"$/ do |input|
+ input = gsub_variables(input)
+ type(input)
+end
+
+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
+end
+
+When /^I checkout (.+)$/ do |branch|
+ branch = gsub_variables(branch)
+ in_current_dir do
+ `git checkout #{branch}`
+ end
end
Then /^gitcycle\.yml should be valid$/ do
@@ -92,6 +155,59 @@ def run_gitcycle(cmd, interactive=false)
end
Then /^output includes \"([^\"]*)"$/ do |expected|
- expected.gsub!('ticket.id', @ticket.attributes['id'])
+ expected = gsub_variables(expected)
+ assert_partial_output(expected, all_output)
+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]
+end
+
+Then /^output does not include \"([^\"]*)"$/ do |expected|
+ expected = gsub_variables(expected)
+ assert_no_partial_output(expected, all_output)
+end
+
+Then /^redis entries valid$/ do
+ add = @scenario_title.include?('custom branch name') ? "-rename" : ""
+ branch = $redis.hget(
+ [
+ "users",
+ config['user'],
+ "repos",
+ "#{config['owner']}:#{config['repo']}",
+ "branches"
+ ].join('/'),
+ $ticket.attributes['id'] + add
+ )
+ branch = Yajl::Parser.parse(branch)
+ should = {
+ 'lighthouse_url' => $ticket.url,
+ 'body' => "<div><p>test</p></div>\n\n#{$ticket.url}",
+ 'name' => $ticket.attributes['id'] + add,
+ 'id' => $ticket.attributes['id'] + add,
+ 'title' => $ticket.title,
+ 'repo' => "#{config['owner']}:#{config['repo']}",
+ 'user' => config['user'],
+ 'source' => 'master'
+ }
+ if @scenario_title == 'Discuss commits w/ no parameters and something committed'
+ should['issue_url'] = $url
+ end
+ branch.should == should
+end
+
+Then /^current branch is \"([^\"]*)"$/ do |branch|
+ branches(:current => true).should == gsub_variables(branch)
+end
+
+Then /^git log should contain the last commit$/ do
+ log($commit_msg).should == true
+end
+
+Then /^URL is a valid issue$/ do
+ $url.should =~ /https:\/\/github.com\/.+\/issues\/\d+/
end
View
@@ -22,7 +22,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "aruba"
s.add_development_dependency "cucumber"
s.add_development_dependency "lighthouse"
+ s.add_development_dependency "redis"
s.add_development_dependency "rspec"
+ s.add_development_dependency "yajl-ruby"
s.add_dependency "launchy", "= 2.0.5"
s.add_dependency "yajl-ruby", "= 1.1.0"
Oops, something went wrong.

0 comments on commit aca2a9b

Please sign in to comment.