Permalink
Browse files

Refactoring into smaller more granular methods

  • Loading branch information...
1 parent 246f99f commit 7f3df5d7b16162326ca04afb5f7f17c4012706c7 @deadprogram deadprogram committed Nov 2, 2012
Showing with 91 additions and 36 deletions.
  1. +1 −1 LICENSE.txt
  2. +9 −0 README.md
  3. +1 −1 bin/gitnesse
  4. +65 −31 lib/gitnesse.rb
  5. +15 −3 lib/gitnesse/tasks.rb
View
@@ -1,4 +1,4 @@
-Copyright (c) 2012 Luis Hurtado
+Copyright (c) 2012 The Hybrid Group, All Rights Reserved
MIT License
View
@@ -34,6 +34,15 @@ Not Rails 3 ? There is available an executable that requires the path to the con
$ CONFIG='./gitnesse_config.rb' gitnesse
+## Usage
+
+For Rails 3 there is a rake task:
+
+## TODO
+
+ - implement git push back to git wiki
+ - rake tasks for push/pull/run
+
## Contributing
1. Fork it
View
@@ -6,4 +6,4 @@ require 'gitnesse'
abort("Please provide a config file: CONFIG='./gitneese.rb' gitnesse") unless ENV['CONFIG']
load(ENV['CONFIG'])
-Gitnesse.perform
+Gitnesse.run
View
@@ -4,7 +4,7 @@
require 'tmpdir'
require 'gitnesse/railtie' if defined?(Rails::Railtie)
-# core module for settings
+# core module
module Gitnesse
# Public: Return String with url of the git wiki repo containing features.
@@ -71,48 +71,46 @@ def self.config
yield self
end
- def perform
- %w(git cucumber).each do |cmd|
- output=`#{cmd} --version 2>&1`; requirement_ok=$?.success?
- abort("#{cmd} command not found or not working.") unless requirement_ok
+ def run
+ if pull
+ puts "Now going to run cucumber..."
+ exec("cucumber #{Gitnesse.target_directory}/*.feature")
end
+ end
+ module_function :run
- abort("Setup git URL for Gitnesse.") if Gitnesse.repository_url.nil?
-
- puts "Loading features into: #{Gitnesse.target_directory}"
+ # pull features from git wiki, and sync up with features dir
+ def pull
+ ensure_git_and_cucumber_available
+ ensure_repository
- load_ok = false
+ puts "Pulling features into: #{Gitnesse.target_directory} from #{Gitnesse.repository_url}..."
Dir.mktmpdir do |tmp_dir|
- # clone repository into tmp dir
- output=`git clone #{Gitnesse.repository_url} #{tmp_dir} 2>&1`; repo_cloned=$?.success?
-
- if repo_cloned
+ if clone_feature_repo
FileUtils.mkdir(Gitnesse.target_directory) unless File.exists?(Gitnesse.target_directory)
+
wiki_pages = wiki = Gollum::Wiki.new(tmp_dir).pages
-
wiki_pages.each do |wiki_page|
- page_features = get_features(wiki_page.raw_data)
-
- page_features.each do |feature_name, feature_content|
- File.open("#{Gitnesse.target_directory}/#{feature_name}.feature","w") {|f| f.write(feature_content) }
- puts "============================== #{feature_name} =============================="
- puts feature_content
- load_ok = true
- end
+ page_features = extract_features(wiki_page.raw_data)
+ write_feature_file(wiki_page.name, page_features) unless page_features.empty?
end
- else
- puts output
end
end
+ puts "DONE."
+ end
+ module_function :pull
- if load_ok
- puts "Now going to run cucumber..."
- exec("cucumber #{Gitnesse.target_directory}/*.feature")
- end
+ # TODO: push features back up to git wiki from features directory
+ def push
+ ensure_git_and_cucumber_available
+ ensure_repository
+
+ puts "Not implemented yet... pull request for push please!"
end
- module_function :perform
+ module_function :push
- def get_features(data)
+ # look thru wiki page for features
+ def extract_features(data)
features = {}
if match_result = data.match(/\u0060{3}(.+)\u0060{3}/m)
@@ -134,5 +132,41 @@ def get_features(data)
features
end
- module_function :get_features
+ module_function :extract_features
+
+ def clone_feature_repo
+ output = `git clone #{Gitnesse.repository_url} #{tmp_dir} 2>&1`
+ unless $?.success?
+ puts output
+ false
+ end
+ end
+ module_function :clone_feature_repo
+
+ def gather_features(page_features)
+ features = ''
+ page_features.each do |feature_name, feature_content|
+ puts "============================== #{feature_name} =============================="
+ puts feature_content
+ features = features + feature_content
+ end
+ end
+
+ def write_feature_file(page_name, page_features)
+ File.open("#{Gitnesse.target_directory}/#{page_name}.feature","w") {|f| f.write(gather_features(page_features)) }
+ end
+ module_function :write_feature_file
+
+ def ensure_git_and_cucumber_available
+ %w(git cucumber).each do |cmd|
+ output = `#{cmd} --version 2>&1`
+ abort("#{cmd} command not found or not working.") unless $?.success?
+ end
+ end
+ module_function :ensure_git_and_cucumber_available
+
+ def ensure_repository
+ abort("You must select a repository_url to run Gitnesse.") if Gitnesse.repository_url.nil?
+ end
+ module_function :ensure_repository
end
View
@@ -1,4 +1,16 @@
-desc "Update features from remote repository and run cucumber."
-task :gitnesse => :environment do
- Gitnesse.perform
+namespace :gitnesse do
+ desc "Pull features from remote repository and run cucumber."
+ task :run => :environment do
+ Gitnesse.run
+ end
+
+ desc "Pull features from remote git wiki repository."
+ task :pull => :environment do
+ Gitnesse.pull
+ end
+
+ desc "Push features to remote git wiki repository."
+ task :push => :environment do
+ Gitnesse.push
+ end
end

0 comments on commit 7f3df5d

Please sign in to comment.