Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

*** 3 sandboxes : clean, with staged/unstanged changes

  • Loading branch information...
commit cfb4c017da53d2d09897be604dec87d4a4942b7f 2 parents cc5a016 + 478271a
@alainravet authored
View
2  .gitignore
@@ -2,3 +2,5 @@
results.html
pkg
html
+
+tmp/
View
98 features/sandbox.feature
@@ -0,0 +1,98 @@
+Feature: playing in the sanbox
+ As a developer
+ In order to test `gitloop` thoroughly
+ I want to Install in tmp/sandbox different prepared git repositories
+ that cover all the possible combinations of staged/unstanged
+ files
+
+
+ Background:
+ * I cleared the sandbox directory
+ * a directory named "sandbox" should not exist
+
+
+#############################
+# Test the git status output :
+#############################
+
+ Scenario: checking the clean sandbox
+
+ Given I unzip the clean git repo in the sandbox
+ * I cd to "sandbox"
+ Then the git status is empty
+
+
+ Scenario: checking the sandbox with some unstaged changes
+
+ Given I unzip the git repo with unstaged changes in the sandbox
+ * I cd to "sandbox"
+ Then the git status is:
+ """
+ M f1
+ ?? unstaged-new-file
+ """
+
+ Scenario: checking the sandbox with some staged changes
+
+ Given I unzip the git repo with staged changes in the sandbox
+ * I cd to "sandbox"
+ Then the git status is:
+ """
+ M f1
+ A unstaged-new-file
+ """
+
+
+
+#############################
+# Test the git log graph output :
+#############################
+
+ Scenario Outline: the sandbox is initialized by unzipping a model git repository
+
+ Given I unzip the <repository> in the sandbox
+ * I cd to "sandbox"
+
+ Then the repo is in its original state
+ Then HEAD starts with edadbb7
+ * the current branch is "master"
+ * there are <outcome>
+
+ Examples:
+ | repository | outcome |
+ | clean git repo | no unstaged nor staged changes |
+
+
+
+ Scenario Outline: the sandbox is initialized by unzipping a model git repository
+
+ Given I unzip the <repository> in the sandbox
+ * I cd to "sandbox"
+
+ Then the git log graph is:
+ """
+ * a059392 c6
+ * e917b56 c5
+ * 933c4d1 c4
+ * 4d72f8a c3
+ * 8aab2de c2
+ * 91182df c1
+ """
+ Then the git log graph matches:
+ """
+ * a059392 c6
+ * <a_sha> c5
+ * 933c4d1 c4
+ * <a_sha> c3
+ * 8aab2de c2
+ * <a_sha> c1
+ """
+ Then HEAD starts with a059392
+ * the current branch is "master"
+ * there are <outcome>
+
+ Examples:
+ | repository | outcome |
+ | git repo with unstaged changes | untracked or uncommited changes|
+ | git repo with staged changes | untracked or uncommited changes|
+
View
21 features/step_definitions/git_steps.rb
@@ -0,0 +1,21 @@
+
+# Setup :
+#########
+
+
+
+# Test :
+#########
+
+Then 'the git status is empty' do
+ untracked_or_uncommited_changes.chomp.should be_empty
+end
+
+Then 'the git status is:' do |text|
+ untracked_or_uncommited_changes.chomp.should == text
+end
+
+
+Then 'the current branch is "$branch"' do |branch|
+ the_current_branch.should == "* #{branch}"
+end
View
46 features/step_definitions/gitloop_steps.rb
@@ -1 +1,45 @@
-# Put your step defintions here
+# -----------
+# Setup :
+# -----------
+
+
+
+# -----------
+# Tests :
+# -----------
+
+
+# Usage :
+# Then HEAD starts with a059392
+
+Then 'HEAD starts with $sha_start' do |sha_start|
+ in_current_dir do
+ `git rev-parse HEAD`.should match(/^#{sha_start}/)
+ end
+end
+
+
+# Usage :
+# Then the git log graph is:
+# """
+# * 4d72f8a c3
+# * 8aab2de c2
+# * 91182df c1
+# """
+
+Then 'the git log graph is:' do |expected_output|
+ the_git_log_graph.should == expected_output
+end
+
+
+# Usage :
+# Then the git log graph matches:
+# """
+# * <a_sha> c3
+# * 8aab2de c2
+# * 91182df c1
+# """
+
+Then 'the git log graph matches:' do |raw_expected_output|
+ the_git_log_graph.should match(make_smart_regexp(raw_expected_output))
+end
View
63 features/step_definitions/sandbox_steps.rb
@@ -0,0 +1,63 @@
+
+# Setup :
+#########
+
+Given /^I cleared the sandbox directory$/ do
+ in_current_dir do
+ FileUtils.rm_rf("sandbox")
+ end
+end
+
+SANDBOX_PATH = {
+ :default => FIXTURES_PATH + '/sandbox.zip',
+ :staged => FIXTURES_PATH + '/sandbox-with-staged-changes.zip',
+ :unstaged => FIXTURES_PATH + '/sandbox-with-unstaged-changes.zip'
+}
+
+Given /^the sandbox is setup$/ do
+ step %Q{I cleared the sandbox directory}
+ step %Q{I unzip the clean git repo in the sandbox}
+end
+
+
+Given /^I unzip the (.*) in the sandbox$/ do |repository|
+ path = case repository
+ when 'clean git repo' then SANDBOX_PATH[:default ]
+ when 'git repo with staged changes' then SANDBOX_PATH[:staged ]
+ when 'git repo with unstaged changes' then SANDBOX_PATH[:unstaged]
+ else raise "NOT SUPPORTED repository : #{repository.inspect}"
+ end
+ record_time_taken("unzip") do
+ in_current_dir do `unzip #{path}` end # 0.5 seconds
+ #step %(I successfully run `unzip #{path}`) # 2.3 seconds
+ end
+end
+
+
+# Test :
+#########
+
+Then /^there are (.*)$/ do |outcome|
+ case outcome
+ when 'no unstaged nor staged changes'
+ untracked_or_uncommited_changes.should be_empty
+ when 'untracked or uncommited changes'
+ untracked_or_uncommited_changes.should_not be_empty
+ else
+ raise "BUG : unsupported outcome #{outcome}"
+ end
+end
+
+
+CLEAN_REPO_LOG =<<TEXT.chomp
+* edadbb7 c6
+* da55377 c5 five - fifth commit
+* 6fddd9c c4 not the third commit
+* bab916a c3 the third commit
+* 7355c79 c2 the second commit
+* 91182df c1
+TEXT
+
+Then /^the (?:clean repo|repo) is in its original state$/ do
+ the_git_log_graph.should == CLEAN_REPO_LOG
+end
View
24 features/support/benchmarking.rb
@@ -0,0 +1,24 @@
+$timers={}
+
+
+def record_time_taken(category)
+ category = category.to_sym
+ $timers[category] ||= [0,0]
+ start = Time.now
+ res = yield
+ time, count = $timers[category]
+ $timers[category] = [time + (Time.now - start), count+1]
+ res
+end
+
+at_exit do
+ puts "-"*80
+ keylength = $timers.keys.collect(&:length).max
+ puts "**** total || secs/run || runs"
+ puts "-"*66
+ $timers.keys.each do |key|
+ time, count = $timers[key]
+ #puts "**** %{key} : total = %{time} sec. || %{count} secs/run || %{loop_time} runs" % {:key => key, :time => time, :count => count, :loop_time => (time/count)}
+ puts "**** %#{keylength+1}s : %#7.2f sec. || %7.3f sec. || %3d runs" % [key, time, (time/count), count]
+ end
+end
View
3  features/support/env.rb
@@ -3,6 +3,9 @@
ENV['PATH'] = "#{File.expand_path(File.dirname(__FILE__) + '/../../bin')}#{File::PATH_SEPARATOR}#{ENV['PATH']}"
LIB_DIR = File.join(File.expand_path(File.dirname(__FILE__)),'..','..','lib')
+require LIB_DIR + '/gitloop'
+
+FIXTURES_PATH = File.join(File.expand_path(File.dirname(__FILE__)),'fixtures')
Before do
# Using "announce" causes massive warnings on 1.9.2
View
BIN  features/support/fixtures/sandbox-with-staged-changes.zip
Binary file not shown
View
BIN  features/support/fixtures/sandbox-with-unstaged-changes.zip
Binary file not shown
View
BIN  features/support/fixtures/sandbox.zip
Binary file not shown
View
21 features/support/git.rb
@@ -0,0 +1,21 @@
+def the_current_branch
+ in_current_dir do
+ `git branch | grep "*"`.chomp
+ end
+end
+
+
+GIT_LOG_GRAPH_COMMAND = "git log --oneline --graph"
+
+def the_git_log_graph
+ step %Q{I run `#{GIT_LOG_GRAPH_COMMAND}`} # runs the actual process
+ output_from(GIT_LOG_GRAPH_COMMAND).chomp # only accesses the previous processes outputs
+end
+
+
+def untracked_or_uncommited_changes
+ in_current_dir do
+ `git status -s`
+ end
+end
+
View
23 features/support/regexp.rb
@@ -0,0 +1,23 @@
+
+# turn the feature multiline "enhanced" text into a regexp
+
+def make_smart_regexp(raw_expected_output)
+ Regexp.compile escape_xxl(raw_expected_output),
+ Regexp::MULTILINE
+end
+
+
+# turn the feature multiline "enhanced" text into a valid regexp-ready string.
+# It
+# - escapes the string
+# - translate <a_sha> -> (\S+)
+# - replace \n by \s+ because of a problem with multiline strings in Cucumber
+
+def escape_xxl(raw_text)
+ Regexp.escape(raw_text).tap do |text|
+ text.gsub!('\n', "\\s*") # necessary (? due to Cucumber ??)
+ text.gsub!(/<a_sha>/, '(\S+)')
+ end
+end
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.