Skip to content

Commit

Permalink
DRY up githook tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mroth committed Mar 5, 2015
1 parent 738872a commit 0a4037b
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 72 deletions.
73 changes: 20 additions & 53 deletions features/lolcommits.feature
Expand Up @@ -21,75 +21,42 @@ Feature: Basic UI functionality
Then the output should not match /\-a\, \-\-animate\=SECONDS/

Scenario: Enable in a naked git repo
Given a git repo named "loltest" with no "post-commit" hook
When I cd to "loltest"
And I successfully run `lolcommits --enable`
Given I am in a git repo
When I successfully run `lolcommits --enable`
Then the output should contain "installed lolcommit hook to:"
And the output should contain:
"""
(to remove later, you can use: lolcommits --disable)
"""
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain:
"""
lolcommits --capture
"""
And the lolcommits post-commit hook should be properly installed
And the exit status should be 0

Scenario: Enable in a git repo that already has a post-commit hook
Given a git repo named "loltest" with a "post-commit" hook
And the "loltest" repo "post-commit" hook has content "#!/bin/sh\n\n/my/own/script"
When I cd to "loltest"
And I successfully run `lolcommits --enable`
Given I am in a git repo
And a post-commit hook with "#!/bin/sh\n\n/my/own/script"
When I successfully run `lolcommits --enable`
Then the output should contain "installed lolcommit hook to:"
And the output should contain:
"""
(to remove later, you can use: lolcommits --disable)
"""
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain "#!/bin/sh"
And the file ".git/hooks/post-commit" should contain "/my/own/script"
And the file ".git/hooks/post-commit" should contain "lolcommits --capture"
And the lolcommits post-commit hook should be properly installed
And the post-commit hook should contain "#!/bin/sh"
And the post-commit hook should contain "/my/own/script"
And the exit status should be 0

Scenario: Enable in a git repo that has post-commit hook with a bad shebang
Given a git repo named "loltest" with a "post-commit" hook
And the "loltest" repo "post-commit" hook has content "#!/bin/ruby"
When I cd to "loltest"
Given I am in a git repo
And a post-commit hook with "#!/bin/ruby"
And I run `lolcommits --enable`
Then the output should contain "doesn't start with a good shebang"
And the file ".git/hooks/post-commit" should not contain:
"""
lolcommits --capture
"""
Then the output should contain "doesn't start with a good shebang"
And the post-commit hook should not contain "lolcommits --capture"
And the exit status should be 1

Scenario: Enable in a git repo passing capture arguments
Given a git repo named "loltest" with no "post-commit" hook
When I cd to "loltest"
And I successfully run `lolcommits --enable -w 5 --fork`
Then the output should contain "installed lolcommit hook to:"
And the output should contain:
"""
(to remove later, you can use: lolcommits --disable)
"""
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should contain:
"""
lolcommits --capture -w 5 --fork
"""
And the exit status should be 0
Given I am in a git repo
When I successfully run `lolcommits --enable -w 5 --fork`
Then the post-commit hook should contain "lolcommits --capture -w 5 --fork"
And the exit status should be 0

Scenario: Disable in a enabled git repo
Given I am in a git repo named "lolenabled" with lolcommits enabled
Given I am in a git repo with lolcommits enabled
When I successfully run `lolcommits --disable`
Then the output should contain "uninstalled"
And a file named ".git/hooks/post-commit" should exist
And the file ".git/hooks/post-commit" should not contain:
"""
lolcommits --capture
"""
And the exit status should be 0
And a file named ".git/hooks/post-commit" should exist
And the exit status should be 0

Scenario: Trying to enable while not in a git repo fails
Given I am in a directory named "svnrulez"
Expand Down
52 changes: 33 additions & 19 deletions features/step_definitions/lolcommits_steps.rb
Expand Up @@ -2,6 +2,10 @@
require 'fileutils'
require 'aruba/api'

def postcommit_hook
".git/hooks/post-commit"
end

Given(/^I am in a directory named "(.*?)"$/) do |dir_name|
steps %Q{
Given a directory named "#{dir_name}"
Expand All @@ -15,40 +19,50 @@
}
end

Given(/^the git repo named "(.*?)" has no "(.*?)" hook$/) do |repo, hook_name|
hook_file = File.join current_dir, repo, '.git', 'hooks', hook_name
FileUtils.delete(hook_file) if File.exists? hook_file
Given(/^I am in a git repo named "(.*?)"$/) do |repo|
steps %Q{
Given a git repo named "#{repo}"
And I cd to "#{repo}"
}
end

Given(/^the git repo named "(.*?)" has a "(.*?)" hook$/) do |repo, hook_name|
hook_file = File.join current_dir, repo, '.git', 'hooks', hook_name
FileUtils.touch(hook_file) if not File.exists? hook_file
Given(/^I am in a git repo$/) do
steps %Q{
Given I am in a git repo named "standard"
}
end

Given(/^the "(.*?)" repo "(.*?)" hook has content "(.*?)"$/) do |repo, hook_name, hook_content|
step %{the git repo named "#{repo}" has a "#{hook_name}" hook}
hook_file = File.join current_dir, repo, '.git', 'hooks', hook_name
File.open(hook_file, 'w') { |f| f.write(hook_content) }
Given(/^I am in a git repo named "(.*?)" with lolcommits enabled$/) do |repo|
steps %Q{
Given I am in a git repo named "#{repo}"
And I successfully run `lolcommits --enable`
}
end

Given(/^a git repo named "(.*?)" with (a|no) "(.*?)" hook$/) do |repo, yesno_modifier, hook_name|
Given(/^I am in a git repo with lolcommits enabled$/) do
steps %Q{
Given a git repo named "#{repo}"
And the git repo named "#{repo}" has #{yesno_modifier} "#{hook_name}" hook
Given I am in a git repo named "standard" with lolcommits enabled
}
end

Given(/^I am in a git repo named "(.*?)"$/) do |repo|
Given(/^a post\-commit hook with "(.*?)"$/) do |file_content|
steps %Q{
Given a git repo named "#{repo}"
And I cd to "#{repo}"
Given a file named "#{postcommit_hook}" with:
"""
#{file_content}
"""
}
end

Given(/^I am in a git repo named "(.*?)" with lolcommits enabled$/) do |repo|
Then(/^the lolcommits post\-commit hook should be properly installed$/) do
steps %Q{
Given I am in a git repo named "#{repo}"
And I successfully run `lolcommits --enable`
Then the post-commit hook should contain "lolcommits --capture"
}
end

Then(/^the post\-commit hook (should|should not) contain "(.*?)"$/) do |should, content|
steps %Q{
Then the file "#{postcommit_hook}" #{should} contain "#{content}"
}
end

Expand Down

0 comments on commit 0a4037b

Please sign in to comment.