Skip to content

Commit

Permalink
Passing features using gitnesse-example-sinatra as guinea pig
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Stewart committed Dec 17, 2012
1 parent 1120cb6 commit edb037a
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 25 deletions.
1 change: 0 additions & 1 deletion .gitignore
Expand Up @@ -15,4 +15,3 @@ spec/reports
test/tmp test/tmp
test/version_tmp test/version_tmp
tmp tmp
/config/gitnesse.rb
5 changes: 0 additions & 5 deletions config/gitnesse.rb.example

This file was deleted.

48 changes: 32 additions & 16 deletions features/step_definitions/gitnesse_steps.rb
@@ -1,31 +1,47 @@
Given /^there is a git wiki with cucumber features defined$/ do Given /^there is a git wiki with cucumber features defined$/ do
pending # express the regexp above with the code you wish you had @features_dir = File.join(Dir.home, ".gitnesse_features")
end end


Given /^there is a code repo without any cucumber features defined$/ do Given /^there is a git wiki without any cucumber features defined$/ do
pending # express the regexp above with the code you wish you had @features_dir = File.join(Dir.home, ".gitnesse_features_no_features")
end

When /^developer pulls feature stories from the wiki$/ do
pending # express the regexp above with the code you wish you had
end end


Then /^the feature stories within the code should match the wiki$/ do Given /^there is a code repo with cucumber features defined$/ do
pending # express the regexp above with the code you wish you had @repo_dir = File.join(Dir.home, ".gitnesse_repo")
end end


Given /^there is a git wiki without any cucumber features defined$/ do Given /^there is a code repo without any cucumber features defined$/ do
pending # express the regexp above with the code you wish you had @repo_dir = File.join(Dir.home, ".gitnesse_repo_no_features")
end end


Given /^there is a code repo with cucumber features defined$/ do When /^developer pulls feature stories from the wiki$/ do
pending # express the regexp above with the code you wish you had Dir.chdir(@repo_dir) do
`bundle exec rake gitnesse:pull &> /dev/null`
assert_equal $?, 0
end
end end


When /^developer pushes feature stories to the wiki$/ do When /^developer pushes feature stories to the wiki$/ do
pending # express the regexp above with the code you wish you had Dir.chdir(@repo_dir) do
`bundle exec rake gitnesse:push &> /dev/null`
assert_equal $?, 0
end
end end


Then /^the the feature stories within the code should match the wiki$/ do Then /^the feature stories within the code should match the wiki$/ do
pending # express the regexp above with the code you wish you had assert_dir = File.join(Dir.home, ".gitnesse_features_for_assert")

Dir.mkdir(assert_dir)
Dir.chdir(assert_dir) do
system("git clone #{@features_dir} . &> /dev/null")
end

repo_features = Dir.glob("#{@repo_dir}/features/*.feature").map { |file| File.basename(file, ".feature") }
wiki_files = Dir.glob("#{assert_dir}/*.md").map { |file| File.basename(file, ".md") }

repo_features.each do |feature|
assert(wiki_files.include?(feature) || wiki_files.include?("#{feature}.feature"))
end

FileUtils.rm_rf(assert_dir)
end end
73 changes: 73 additions & 0 deletions features/support/env.rb
@@ -0,0 +1,73 @@
require 'test/unit/assertions'
World(Test::Unit::Assertions)

puts " Setting up Gitnesse for testing..."

@features_dir = File.join(Dir.home, ".gitnesse_features")
@features_dir_no_features = File.join(Dir.home, ".gitnesse_features_no_features")
@repo_dir = File.join(Dir.home, ".gitnesse_repo")
@repo_dir_no_features = File.join(Dir.home, ".gitnesse_repo_no_features")

Dir.mkdir @features_dir
Dir.mkdir @repo_dir
Dir.mkdir @features_dir_no_features
Dir.mkdir @repo_dir_no_features

Dir.chdir(@features_dir) do
system('git clone --bare https://github.com/hybridgroup/gitnesse-demo.wiki.git . &> /dev/null')
if $? == 0
puts " Cloned demo features to #{@features_dir}."
else
abort " Failed to clone demo features to #{@features_dir}."
end
end

Dir.chdir(@features_dir_no_features) do
system('git init --bare &> /dev/null')
if $? == 0
puts " Created demo wiki without features in #{@features_dir_no_features}."
else
abort " Failed to create demo wiki without features in #{@features_dir_no_features}."
end
end

Dir.chdir(@repo_dir) do
system('git clone https://github.com/hybridgroup/gitnesse-example-sinatra.git . &> /dev/null')
if $? == 0
puts " Cloned demo repo to #{@repo_dir}."
else
abort " Failed to clone demo repo to #{@repo_dir}."
end

system('bundle install --path vendor/bundle &> /dev/null')
if $? == 0
puts " Installed gems for demo wiki."
else
abort " Failed to install gems for demo wiki."
end
end

config_file = File.join(@repo_dir, "gitnesse.rb")

config = File.read(config_file)
config.gsub!(/config\.repository_url.*$/, "config.repository_url = '#{@features_dir}'")
File.open(config_file, 'w') { |file| file.puts config }

puts " Updated demo repo configuration to use demo features."

Dir.chdir(@repo_dir_no_features) do
FileUtils.cp_r("#{@repo_dir}/.", @repo_dir_no_features)
Dir.glob("#{@repo_dir_no_features}/**/*.feature") do |file|
File.unlink(file)
end
puts " Created demo repo without features."
end

puts " Finished setting up Gitnesse for testing. Running features.", ""

at_exit do
FileUtils.rm_rf(@features_dir)
FileUtils.rm_rf(@repo_dir)
FileUtils.rm_rf(@features_dir_no_features)
FileUtils.rm_rf(@repo_dir_no_features)
end
6 changes: 3 additions & 3 deletions features/sync_wiki_features_to_code.feature
Expand Up @@ -14,12 +14,12 @@ Feature:


Scenario: Features already exist in code but not in wiki Scenario: Features already exist in code but not in wiki
When developer pushes feature stories to the wiki When developer pushes feature stories to the wiki
Then the the feature stories within the code should match the wiki Then the feature stories within the code should match the wiki


Scenario: Features pushes features from code to existing wiki Scenario: Features pushes features from code to existing wiki
When developer pushes feature stories to the wiki When developer pushes feature stories to the wiki
Then the the feature stories within the code should match the wiki Then the feature stories within the code should match the wiki


Scenario: Features pulls features from wiki to existing code Scenario: Features pulls features from wiki to existing code
When developer pulls feature stories from the wiki When developer pulls feature stories from the wiki
Then the the feature stories within the code should match the wiki Then the feature stories within the code should match the wiki

0 comments on commit edb037a

Please sign in to comment.