gitnesse 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gitnesse.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 The Hybrid Group, All Rights Reserved
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,66 @@
1
+ # Gitnesse
2
+
3
+ Gitnesse is a Cucumber-wiki integration tool.
4
+ It enables a project to store cucumber features in a git-based wiki, and then test them against your code.
5
+ Conceptually influenced by Fitnesse http://fitnesse.org/
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'gitnesse'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install gitnesse
20
+
21
+ Create a `gitnesse.rb` file somewhere in your project, and add something like
22
+ the following to it:
23
+
24
+ Gitnesse.config do
25
+ repository_url "git@github.com:hybridgroup/gitnesse-demo.wiki"
26
+ end
27
+
28
+ ## rake tasks
29
+
30
+ $ rake gitnesse:pull
31
+ $ rake gitnesse:push
32
+ $ rake gitnesse:run
33
+ $ rake gitnesse:info
34
+
35
+ ## Usage In Rails 3
36
+
37
+ For Rails 3 the rake tasks should automatically just appear, as long as you have added the gitnesse gem to your Gemfile.
38
+
39
+ There is an example application using Rails 3 located here: [https://github.com/hybridgroup/gitnesse-example-rails](https://github.com/hybridgroup/gitnesse-example-rails)
40
+
41
+ ## Usage In Sinatra
42
+
43
+ To use gitnesse in a Sinatra application, simple add this line of code to your Rakefile:
44
+
45
+ require "gitnesse/tasks"
46
+
47
+ There is an example application using Sinatra located here: [https://github.com/hybridgroup/gitnesse-example-sinatra](https://github.com/hybridgroup/gitnesse-example-sinatra)
48
+
49
+ ## Other Usage
50
+
51
+ Want to use plain old Gitnesse? There is an executable that requires the path to the configuration file:
52
+
53
+ $ GITNESSE_CONFIG='./gitnesse_config.rb' gitnesse
54
+
55
+ ## TODO
56
+
57
+ - test git push back to git wiki
58
+ - pluggable feature runners, so can be used with Spinach, Cucumber-JS, or ?
59
+
60
+ ## Contributing
61
+
62
+ 1. Fork it
63
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
64
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
65
+ 4. Push to the branch (`git push origin my-new-feature`)
66
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+ require 'rake/testtask'
4
+ require_relative 'lib/gitnesse'
5
+ require_relative 'lib/gitnesse/tasks'
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'lib/gitnesse'
9
+ t.test_files = FileList['test/lib/gitnesse/*_test.rb']
10
+ t.verbose = true
11
+ end
12
+ task :default => :test
13
+
data/bin/gitnesse ADDED
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'gitnesse'
5
+
6
+ Gitnesse.load_config
7
+
8
+ if ARGV[0].nil?
9
+ Gitnesse.run
10
+ end
11
+
12
+ def print_help
13
+ puts "Gitnesse commands:"
14
+ puts " run: pull remote features from git-based wiki to local, and run Cucumber"
15
+ puts " push: push local features to git-based wiki"
16
+ puts " pull: pull remote features from git-based wiki to local"
17
+ puts " info: print current Gitnesse configuration"
18
+ end
19
+
20
+ case ARGV[0]
21
+ when "push"
22
+ Gitnesse.push
23
+ when "pull"
24
+ Gitnesse.pull
25
+ when "run"
26
+ Gitnesse.run
27
+ when "info"
28
+ puts Gitnesse.config_to_hash.to_yaml
29
+ when "help"
30
+ print_help
31
+ else
32
+ print_help
33
+ end
data/gitnesse.gemspec ADDED
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gitnesse/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "gitnesse"
8
+ gem.version = Gitnesse::VERSION
9
+ gem.authors = ["www.hybridgroup.com"]
10
+ gem.email = ["info@hybridgroup.com"]
11
+ gem.description = %q{Use github wiki to store feature stories, then execute then using Cucumber}
12
+ gem.summary = %q{Features on git-based Wiki!}
13
+ gem.homepage = "https://github.com/hybridgroup/gitnesse"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
+ gem.require_paths = ["lib"]
18
+ gem.add_dependency("bundler")
19
+ gem.add_dependency("gollum","~> 2.3.12")
20
+ gem.add_development_dependency("minitest-matchers")
21
+ gem.add_development_dependency("mocha")
22
+ gem.add_development_dependency("cucumber")
23
+ gem.add_development_dependency("rake")
24
+ gem.executables = ['gitnesse']
25
+ end
@@ -0,0 +1,12 @@
1
+ require 'gitnesse'
2
+ require 'rails'
3
+
4
+ module Gitnesse
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :gitnesse
7
+
8
+ rake_tasks do
9
+ load File.dirname(__FILE__) + '/tasks.rake'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,28 @@
1
+ namespace :gitnesse do
2
+ task :environment do
3
+ end
4
+
5
+ desc "Pull features from remote repository and run cucumber."
6
+ task :run => :environment do
7
+ Gitnesse.load_config
8
+ Gitnesse.run
9
+ end
10
+
11
+ desc "Pull features from remote git wiki repository."
12
+ task :pull => :environment do
13
+ Gitnesse.load_config
14
+ Gitnesse.pull
15
+ end
16
+
17
+ desc "Push features to remote git wiki repository."
18
+ task :push => :environment do
19
+ Gitnesse.load_config
20
+ Gitnesse.push
21
+ end
22
+
23
+ desc "Dump the current config info to the console."
24
+ task :info => :environment do
25
+ Gitnesse.load_config
26
+ puts Gitnesse.config_to_hash.to_yaml
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ require "rake"
2
+ require "rake/tasklib"
3
+
4
+ module Gitnesse
5
+ class Tasks < ::Rake::TaskLib
6
+ load File.dirname(__FILE__) + '/tasks.rake'
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Gitnesse
2
+ VERSION = "0.1.0"
3
+ end
data/lib/gitnesse.rb ADDED
@@ -0,0 +1,300 @@
1
+ require 'bundler/setup'
2
+ require 'gollum'
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+ require 'gitnesse/railtie' if defined?(Rails)
6
+
7
+ # core module
8
+ module Gitnesse
9
+
10
+ extend self
11
+
12
+ # Public: Set url of the git-based wiki repo containing features.
13
+ #
14
+ # repository_url - A String containing your repo's url.
15
+ #
16
+ # Example:
17
+ #
18
+ # Gitnesse.config do
19
+ # repository_url "git@github.com:luishurtado/gitnesse-wiki.wiki"
20
+ # end
21
+ #
22
+ def self.repository_url(repository_url = false)
23
+ if repository_url == false
24
+ unless defined?(@@repository_url)
25
+ puts "---"
26
+ puts "No repository_url has been defined for Gitnesse."
27
+ puts "Add a gitnesse.rb file to your project and use it to configure Gitnesse."
28
+ puts "For more details, check out gitnesse.com"
29
+ auts "---"
30
+ exit 1
31
+ end
32
+ return @@repository_url
33
+ else
34
+ @@repository_url = repository_url
35
+ end
36
+ end
37
+
38
+ # Public: Set branch of the git-based wiki repo containing features.
39
+ #
40
+ # branch - A String containing which branch of your repo to use.
41
+ #
42
+ # Example:
43
+ #
44
+ # Gitnesse.config do
45
+ # branch "master"
46
+ # end
47
+ #
48
+ def self.branch(branch = false)
49
+ if branch == false
50
+ @@branch ||= "master"
51
+ else
52
+ @@branch = branch
53
+ end
54
+ end
55
+
56
+ # Public: Set local directory used to sync with git-wiki stored feature stories.
57
+ #
58
+ # target_directory - A String containing which directory to use.
59
+ #
60
+ # Example:
61
+ #
62
+ # Gitnesse.config do
63
+ # target_directory "features"
64
+ # end
65
+ #
66
+ def self.target_directory(target_directory = false)
67
+ if target_directory == false
68
+ @@target_directory ||= File.join(Dir.pwd, 'features')
69
+ else
70
+ @@target_directory = target_directory
71
+ end
72
+ end
73
+
74
+ def self.config(&block)
75
+ instance_eval &block
76
+ end
77
+
78
+ # -- all methods after this are module functions --
79
+ module_function
80
+
81
+ def run
82
+ if pull
83
+ puts "Now going to run cucumber..."
84
+ exec("cucumber #{Gitnesse.target_directory}/*.feature")
85
+ end
86
+ end
87
+
88
+ # pull features from git wiki, and sync up with features dir
89
+ def pull
90
+ ensure_git_available
91
+ ensure_cucumber_available
92
+ ensure_repository
93
+
94
+ puts "Pulling features into #{Gitnesse.target_directory} from #{Gitnesse.repository_url}..."
95
+ Dir.mktmpdir do |tmp_dir|
96
+ if clone_feature_repo(tmp_dir)
97
+ FileUtils.mkdir(Gitnesse.target_directory) unless File.exists?(Gitnesse.target_directory)
98
+
99
+ wiki_pages = Gollum::Wiki.new(tmp_dir).pages
100
+ wiki_pages.each do |wiki_page|
101
+ page_features = extract_features(wiki_page.raw_data)
102
+ write_feature_file(wiki_page.name, page_features) unless page_features.empty?
103
+ end
104
+ end
105
+ end
106
+ puts "DONE."
107
+ end
108
+
109
+ # push features back up to git wiki from features directory
110
+ def push
111
+ ensure_git_available
112
+ ensure_cucumber_available
113
+ ensure_repository
114
+ commit_info
115
+
116
+ puts "Pushing features from #{Gitnesse.target_directory} to #{Gitnesse.repository_url}..."
117
+ Dir.mktmpdir do |tmp_dir|
118
+ if clone_feature_repo(tmp_dir)
119
+ load_feature_files_into_wiki(tmp_dir)
120
+
121
+ # push the changes to the remote git
122
+ Dir.chdir(tmp_dir) do
123
+ puts `git push origin master`
124
+ end
125
+ end
126
+ end
127
+ puts "DONE."
128
+ end
129
+
130
+ def load_feature_files_into_wiki(tmp_dir)
131
+ wiki = Gollum::Wiki.new(tmp_dir)
132
+ feature_files = Dir.glob("#{Gitnesse.target_directory}/*.feature")
133
+
134
+ feature_files.each do |feature_file|
135
+ feature_name = File.basename(feature_file, ".feature")
136
+ feature_content = File.read(feature_file)
137
+ wiki_page = wiki.page(feature_name)
138
+
139
+ if wiki_page
140
+ update_wiki_page(wiki, wiki_page, feature_name, feature_content)
141
+ else
142
+ create_wiki_page(wiki, feature_name, feature_content)
143
+ end
144
+ end
145
+ end
146
+
147
+ def create_wiki_page(wiki, page_name, feature_content)
148
+ new_page_content = build_page_content(feature_content)
149
+
150
+ wiki.write_page(page_name, :markdown, new_page_content, commit_info)
151
+ puts "==== Created page: #{page_name} ==="
152
+ end
153
+
154
+ def update_wiki_page(wiki, wiki_page, page_name, feature_content)
155
+ wiki_page_content = wiki_page.raw_data
156
+ new_page_content = build_page_content(feature_content, wiki_page_content)
157
+
158
+ if new_page_content == wiki_page_content
159
+ puts "=== Page #{page_name} didn't change ==="
160
+ else
161
+ wiki.update_page(wiki_page, page_name, :markdown, new_page_content, commit_info)
162
+ puts "==== Updated page: #{page_name} ==="
163
+ end
164
+ end
165
+
166
+ def build_page_content(feature_content, wiki_page_content = nil)
167
+ return "```gherkin\n#{feature_content}\n```" if wiki_page_content.nil? || wiki_page_content.empty?
168
+ features = extract_features(wiki_page_content)
169
+
170
+ # replace the first feature found in the wiki page
171
+ _, old_feature_content = features.shift
172
+ wiki_page_content.sub(old_feature_content, feature_content)
173
+ end
174
+
175
+ # look thru wiki page for features
176
+ def extract_features(data)
177
+ features = {}
178
+
179
+ if match_result = data.match(/\u0060{3}(.+)\u0060{3}/m)
180
+ captures = match_result.captures
181
+
182
+ # create hash with feature name as key and feature text as value
183
+ captures.each do |capture|
184
+ feature_definition_at = capture.index('Feature:')
185
+ feature_text = capture[feature_definition_at,capture.size-1]
186
+ feature_lines = feature_text.split("\n")
187
+ feature_definition = feature_lines.grep(/^Feature:/).first
188
+
189
+ if feature_definition
190
+ feature_name = feature_definition.split(":").last.strip.gsub(" ","-").downcase
191
+ features[feature_name] = feature_text
192
+ end
193
+ end
194
+ end
195
+
196
+ features
197
+ end
198
+
199
+ def clone_feature_repo(dir)
200
+ output = `git clone #{Gitnesse.repository_url} #{dir} 2>&1`
201
+ puts output
202
+ $?.success?
203
+ end
204
+
205
+ def commit_info
206
+ @commit_info ||= begin
207
+ user_name = read_git_config("user.name")
208
+ email = read_git_config("user.email")
209
+ raise "Can't read git's user.name config" if user_name.nil? || user_name.empty?
210
+ raise "Can't read git's user.email config" if email.nil? || email.empty?
211
+
212
+ {:name => user_name, :email => email, :message => "Update features with Gitnesse"}
213
+ end
214
+ end
215
+
216
+ def commit_info=(commit_info)
217
+ @commit_info = commit_info
218
+ end
219
+
220
+ def read_git_config(config_name)
221
+ config_value = ""
222
+ config_value = `git config --get #{config_name}`
223
+ config_value = `git config --get --global #{config_name}` unless $?.success?
224
+ config_value.strip
225
+ end
226
+
227
+ # we are going to support only one feature per page
228
+ def gather_features(page_features)
229
+ return "" if page_features.nil? or page_features.empty?
230
+
231
+ features = ''
232
+ feature_name, feature_content = page_features.shift
233
+ puts "============================== Pulling Feature: #{feature_name} =============================="
234
+ features = features + feature_content
235
+
236
+ page_features.each do |_feature_name, _feature_content|
237
+ puts "============================== WARNING! Discarded Feature: #{_feature_name} =============================="
238
+ puts _feature_content
239
+ end
240
+
241
+ features
242
+ end
243
+
244
+ def write_feature_file(page_name, page_features)
245
+ File.open("#{Gitnesse.target_directory}/#{page_name}.feature","w") {|f| f.write(gather_features(page_features)) }
246
+ end
247
+
248
+ def ensure_git_available
249
+ raise "git not found or not working." unless Kernel.system("git --version")
250
+ end
251
+
252
+ def ensure_cucumber_available
253
+ raise "cucumber not found or not working." unless Kernel.system("cucumber --version")
254
+ end
255
+
256
+ def ensure_repository
257
+ raise "You must select a repository_url to run Gitnesse." if Gitnesse.repository_url.nil?
258
+ end
259
+
260
+ def load_config
261
+ load(ENV['GITNESSE_CONFIG']) and return if ENV['GITNESSE_CONFIG']
262
+
263
+ possible_config_files = Dir.glob(File.join("**", "gitnesse.rb"))
264
+
265
+ files_with_config = possible_config_files.select do |file_name|
266
+ if FileUtils.compare_file(__FILE__, file_name)
267
+ false
268
+ elsif File.fnmatch("vendor/**/*.rb", file_name)
269
+ false
270
+ else
271
+ file_content = File.read(file_name)
272
+ file_content.match("Gitnesse.config")
273
+ end
274
+ end
275
+
276
+ case files_with_config.length
277
+ when 0
278
+ raise "Can't find a gitnesse.rb file with Gitnesse configuration."
279
+ when 1
280
+ load(File.absolute_path(files_with_config.first))
281
+ else
282
+ raise "Several config files found: #{files_with_config.join(", ")}"
283
+ end
284
+ end
285
+
286
+ def config_to_hash
287
+ { "repository_url" => Gitnesse.repository_url,
288
+ "branch" => Gitnesse.branch,
289
+ "target_directory" => Gitnesse.target_directory }
290
+ end
291
+
292
+ def method_missing(sym, *args, &block)
293
+ unless ["to_str", "to_ary"].contains?(sym)
294
+ raise "Invalid variable name for Gitnesse configuration.
295
+ Allowed variables are repository_url, branch, and target_directory."
296
+ else
297
+ super
298
+ end
299
+ end
300
+ end
@@ -0,0 +1,80 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe ".build_page_content" do
5
+ let(:wiki_page_content) do
6
+ <<-EOS
7
+ # Addition is Awesome
8
+
9
+ ```gherkin
10
+ Feature: Addition
11
+ In order to avoid silly mistakes
12
+ I want to be told the sum of two numbers
13
+
14
+ Scenario: Add two single digit numbers
15
+ Given I have entered 7 into the calculator
16
+ And I have entered 5 into the calculator
17
+ When I add
18
+ Then the result should be 12 on the screen
19
+ ```
20
+ EOS
21
+ end
22
+
23
+ let(:new_feature_content) do
24
+ <<-EOS
25
+ Feature: Addition
26
+ In order to avoid silly mistakes
27
+ I want to be told the sum of two numbers
28
+
29
+ Scenario: Add two double digit numbers
30
+ Given I have entered 50 into the calculator
31
+ And I have entered 70 into the calculator
32
+ When I add
33
+ Then the result should be 120 on the screen
34
+ EOS
35
+ end
36
+
37
+ describe "without existing wiki page content" do
38
+ let(:method) { lambda { Gitnesse.build_page_content(new_feature_content) } }
39
+ let(:expected_result) do
40
+ "```gherkin
41
+ Feature: Addition
42
+ In order to avoid silly mistakes
43
+ I want to be told the sum of two numbers
44
+
45
+ Scenario: Add two double digit numbers
46
+ Given I have entered 50 into the calculator
47
+ And I have entered 70 into the calculator
48
+ When I add
49
+ Then the result should be 120 on the screen
50
+
51
+ ```"
52
+ end
53
+
54
+ it { method.call.must_equal expected_result }
55
+ end
56
+
57
+ describe "with existing wiki page content" do
58
+ let(:method) { lambda { Gitnesse.build_page_content(new_feature_content, wiki_page_content) } }
59
+ let(:expected_result) do
60
+ <<-EOS
61
+ # Addition is Awesome
62
+
63
+ ```gherkin
64
+ Feature: Addition
65
+ In order to avoid silly mistakes
66
+ I want to be told the sum of two numbers
67
+
68
+ Scenario: Add two double digit numbers
69
+ Given I have entered 50 into the calculator
70
+ And I have entered 70 into the calculator
71
+ When I add
72
+ Then the result should be 120 on the screen
73
+ ```
74
+ EOS
75
+ end
76
+
77
+ it { method.call.must_equal expected_result }
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,45 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#ensure_repository" do
5
+ let(:method) { lambda { Gitnesse.ensure_repository } }
6
+
7
+ describe "when repository was defined" do
8
+ before { Gitnesse.repository_url("git://github.com/hybridgroup/gitnesse-demo.wiki") }
9
+ it { method.call.must_be_nil }
10
+ end
11
+
12
+ describe "when repository was not defined" do
13
+ before { Gitnesse.repository_url(nil) }
14
+ it { method.must_raise(RuntimeError) }
15
+ end
16
+ end
17
+
18
+ describe "#ensure_git_available" do
19
+ let(:method) { lambda { Gitnesse.ensure_git_available } }
20
+
21
+ describe "when git is not installed" do
22
+ before { Kernel.expects(:system).with("git --version").returns(false) }
23
+ it { method.must_raise(RuntimeError) }
24
+ end
25
+
26
+ describe "when git is installed" do
27
+ before { Kernel.expects(:system).with("git --version").returns(true) }
28
+ it { method.call.must_be_nil }
29
+ end
30
+ end
31
+
32
+ describe "#ensure_cucumber_available" do
33
+ let(:method) { lambda { Gitnesse.ensure_cucumber_available } }
34
+
35
+ describe "when cucumber is not installed" do
36
+ before { Kernel.expects(:system).with("cucumber --version").returns(false) }
37
+ it { method.must_raise(RuntimeError) }
38
+ end
39
+
40
+ describe "when cucumber is installed" do
41
+ before { Kernel.expects(:system).with("cucumber --version").returns(true) }
42
+ it { method.call.must_be_nil }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,28 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#commit_info" do
5
+ let(:method) { lambda { Gitnesse.commit_info } }
6
+
7
+ describe "with a defined git username and email" do
8
+ before do
9
+ Gitnesse.expects(:read_git_config).with("user.name").returns("Bob Smith")
10
+ Gitnesse.expects(:read_git_config).with("user.email").returns("bob@bobsmith.com")
11
+ end
12
+
13
+ it { method.call.must_equal({ :name => "Bob Smith",
14
+ :email => "bob@bobsmith.com",
15
+ :message => "Update features with Gitnesse" }) }
16
+ end
17
+
18
+ describe "without a defined git username and email" do
19
+ before do
20
+ Gitnesse.commit_info = nil
21
+ Gitnesse.expects(:read_git_config).with("user.name").returns('')
22
+ Gitnesse.expects(:read_git_config).with("user.email").returns('')
23
+ end
24
+
25
+ it { method.must_raise RuntimeError }
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe ".config_to_hash" do
5
+ let(:method) { lambda { Gitnesse.config_to_hash } }
6
+ before do
7
+ Gitnesse.config do
8
+ repository_url "git://github.com/hybridgroup/gitnesse-demo.wiki.git"
9
+ branch "wiki"
10
+ target_directory "feature_files"
11
+ end
12
+ end
13
+
14
+ it { method.call.must_be_instance_of Hash }
15
+
16
+ it "contains the configuration data" do
17
+ hash = method.call
18
+
19
+ hash["repository_url"].must_equal "git://github.com/hybridgroup/gitnesse-demo.wiki.git"
20
+ hash["branch"].must_equal "wiki"
21
+ hash["target_directory"].must_equal "feature_files"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,25 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#branch" do
5
+ describe "defaults to 'master'" do
6
+ before { Gitnesse.branch nil }
7
+ it { Gitnesse.branch.must_equal "master" }
8
+ end
9
+
10
+ describe "when changed" do
11
+ before { Gitnesse.branch "wiki" }
12
+ it { Gitnesse.branch.must_equal "wiki" }
13
+ end
14
+
15
+ describe "when changed through #config" do
16
+ before do
17
+ Gitnesse.config do
18
+ branch "wiki"
19
+ end
20
+ end
21
+
22
+ it { Gitnesse.branch.must_equal "wiki" }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,44 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe ".extract_features" do
5
+ let(:data) do
6
+ <<-EOS
7
+ # Addition is Awesome
8
+
9
+ ```gherkin
10
+ Feature: Addition
11
+ In order to avoid silly mistakes
12
+ I want to be told the sum of two numbers
13
+
14
+ Scenario: Add two single digit numbers
15
+ Given I have entered 7 into the calculator
16
+ And I have entered 5 into the calculator
17
+ When I add
18
+ Then the result should be 12 on the screen
19
+ ```
20
+ EOS
21
+ end
22
+
23
+ let(:expected_result) do
24
+ { "addition" => "Feature: Addition
25
+ In order to avoid silly mistakes
26
+ I want to be told the sum of two numbers
27
+
28
+ Scenario: Add two single digit numbers
29
+ Given I have entered 7 into the calculator
30
+ And I have entered 5 into the calculator
31
+ When I add
32
+ Then the result should be 12 on the screen
33
+ "}
34
+ end
35
+
36
+ let(:method) { lambda { Gitnesse.extract_features(data) } }
37
+
38
+ it { method.call.must_be_instance_of Hash }
39
+
40
+ it "extracts feature data" do
41
+ method.call.must_equal expected_result
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe ".gather_features" do
5
+
6
+ describe "when several features" do
7
+ let(:page_features) { {"test-feature" => "feature content", "another-test-feature" => "another feature content"} }
8
+
9
+ it { Gitnesse.gather_features(page_features).must_equal "feature content" }
10
+ end
11
+
12
+ describe "when one single feature" do
13
+ let(:page_features) { {"test-feature" => "feature content"} }
14
+
15
+ it { Gitnesse.gather_features(page_features).must_equal "feature content" }
16
+ end
17
+
18
+ describe "when no features" do
19
+ let(:page_features) { Hash.new }
20
+
21
+ it { Gitnesse.gather_features(page_features).must_equal "" }
22
+ end
23
+
24
+ describe "when nil" do
25
+ let(:page_features) { nil }
26
+
27
+ it { Gitnesse.gather_features(page_features).must_equal "" }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,34 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#load_feature_files_into_wiki" do
5
+ let(:wiki) { mock() }
6
+ let(:wiki_page) { mock() }
7
+ let(:tmpdir) { Dir.mktmpdir }
8
+ let(:feature_file_dir) { Dir.mktmpdir }
9
+
10
+ before do
11
+ # create test feature
12
+ File.open(File.join(feature_file_dir, "test.feature"), "w") do |file|
13
+ feature = <<-EOF
14
+ Feature: Addition
15
+ In order to avoid silly mistakes
16
+ As a math idiot
17
+ I want to be told the sum of two numbers
18
+
19
+ Scenario: Add two numbers
20
+ Given I have entered 50 into the calculator
21
+ And I have entered 70 into the calculator
22
+ When I press add
23
+ Then the result should be 120 on the screen
24
+ EOF
25
+
26
+ file.write(feature)
27
+ end
28
+
29
+ Dir.expects(:glob).with("#{Gitnesse.target_directory}/*.feature").returns(:feature_file_dir)
30
+ wiki.expects(:page).with("testing").returns(wiki_page)
31
+ Gitnesse.expects(:update_wiki_page).with(wiki_page, "testing", "blarg")
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,35 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#read_git_config" do
5
+ let(:method) { lambda { Gitnesse.read_git_config("user.email") } }
6
+
7
+ describe "when a gitconfig value is not set" do
8
+ before do
9
+ $?.stubs(:success?).returns(false)
10
+ Gitnesse.stubs(:`).with("git config --get user.email").returns("")
11
+ Gitnesse.stubs(:`).with("git config --get --global user.email").returns("")
12
+ end
13
+
14
+ it { method.call.must_equal "" }
15
+ end
16
+
17
+ describe "when a gitconfig value is set" do
18
+ before do
19
+ $?.stubs(:success?).returns(true)
20
+ Gitnesse.stubs(:`).with("git config --get user.email").returns("bob@bobsmith.com\n")
21
+ end
22
+
23
+ it { method.call.must_equal "bob@bobsmith.com" }
24
+ end
25
+
26
+ describe "when a gitconfig value is set globally" do
27
+ before do
28
+ Gitnesse.stubs(:`).with("git config --get user.email").returns("")
29
+ Gitnesse.stubs(:`).with("git config --get --global user.email").returns("bob@bobsmith.com\n")
30
+ end
31
+
32
+ it { method.call.must_equal "bob@bobsmith.com" }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,7 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ subject { Gitnesse::VERSION }
5
+
6
+ it { wont_be_nil }
7
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../../test_helper'
2
+
3
+ describe Gitnesse do
4
+ describe "#write_feature_file" do
5
+ let(:method) { lambda { Gitnesse.write_feature_file } }
6
+ let(:file) { StringIO.new }
7
+
8
+ before do
9
+ File.expects(:open).with("#{Gitnesse.target_directory}/test.feature", "w").yields(file)
10
+ Gitnesse.expects(:gather_features).with({ "test-feature" => "feature content" }).returns("feature content")
11
+ end
12
+
13
+ it "writes to the file" do
14
+ Gitnesse.write_feature_file("test", { "test-feature" => "feature content" })
15
+ file.string.must_equal "feature content"
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,26 @@
1
+ require "minitest/matchers"
2
+ require "minitest/autorun"
3
+ require "minitest/pride"
4
+ require "mocha"
5
+ require File.expand_path('../../lib/gitnesse.rb', __FILE__)
6
+
7
+ module FeatureTestMethods
8
+
9
+ # Creates a basic test feature
10
+ #
11
+ # Returns a string
12
+ def create_test_feature
13
+ <<-EOF
14
+ Feature: Addition
15
+ In order to avoid silly mistakes
16
+ As a math idiot
17
+ I want to be told the sum of two numbers
18
+
19
+ Scenario: Add two numbers
20
+ Given I have entered 50 into the calculator
21
+ And I have entered 70 into the calculator
22
+ When I press add
23
+ Then the result should be 120 on the screen
24
+ EOF
25
+ end
26
+ end
@@ -0,0 +1,11 @@
1
+ require "gollum"
2
+
3
+ module WikiTestMethods
4
+
5
+ # Creates a new Gollum wiki for testing
6
+ #
7
+ # Returns a gollum wiki
8
+ def create_wiki(dir = Dir.mktmpdir)
9
+ Gollum::Wiki.new(dir)
10
+ end
11
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitnesse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - www.hybridgroup.com
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: gollum
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 2.3.12
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 2.3.12
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest-matchers
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: cucumber
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ description: Use github wiki to store feature stories, then execute then using Cucumber
111
+ email:
112
+ - info@hybridgroup.com
113
+ executables:
114
+ - gitnesse
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE.txt
121
+ - README.md
122
+ - Rakefile
123
+ - bin/gitnesse
124
+ - gitnesse.gemspec
125
+ - lib/gitnesse.rb
126
+ - lib/gitnesse/railtie.rb
127
+ - lib/gitnesse/tasks.rake
128
+ - lib/gitnesse/tasks.rb
129
+ - lib/gitnesse/version.rb
130
+ - test/lib/gitnesse/build_page_content_test.rb
131
+ - test/lib/gitnesse/check_dependencies_test.rb
132
+ - test/lib/gitnesse/commit_info_test.rb
133
+ - test/lib/gitnesse/config_to_hash_test.rb
134
+ - test/lib/gitnesse/custom_branch_test.rb
135
+ - test/lib/gitnesse/extract_features_test.rb
136
+ - test/lib/gitnesse/gather_features_test.rb
137
+ - test/lib/gitnesse/load_feature_files_into_wiki_test.rb
138
+ - test/lib/gitnesse/read_git_config_test.rb
139
+ - test/lib/gitnesse/version_test.rb
140
+ - test/lib/gitnesse/write_feature_file_test.rb
141
+ - test/test_helper.rb
142
+ - test/wiki_test_helper.rb
143
+ homepage: https://github.com/hybridgroup/gitnesse
144
+ licenses: []
145
+ post_install_message:
146
+ rdoc_options: []
147
+ require_paths:
148
+ - lib
149
+ required_ruby_version: !ruby/object:Gem::Requirement
150
+ none: false
151
+ requirements:
152
+ - - ! '>='
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ segments:
156
+ - 0
157
+ hash: -126475923394680174
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
159
+ none: false
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ segments:
165
+ - 0
166
+ hash: -126475923394680174
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 1.8.24
170
+ signing_key:
171
+ specification_version: 3
172
+ summary: Features on git-based Wiki!
173
+ test_files:
174
+ - test/lib/gitnesse/build_page_content_test.rb
175
+ - test/lib/gitnesse/check_dependencies_test.rb
176
+ - test/lib/gitnesse/commit_info_test.rb
177
+ - test/lib/gitnesse/config_to_hash_test.rb
178
+ - test/lib/gitnesse/custom_branch_test.rb
179
+ - test/lib/gitnesse/extract_features_test.rb
180
+ - test/lib/gitnesse/gather_features_test.rb
181
+ - test/lib/gitnesse/load_feature_files_into_wiki_test.rb
182
+ - test/lib/gitnesse/read_git_config_test.rb
183
+ - test/lib/gitnesse/version_test.rb
184
+ - test/lib/gitnesse/write_feature_file_test.rb
185
+ - test/test_helper.rb
186
+ - test/wiki_test_helper.rb