rspec-git 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +39 -0
- data/Rakefile +1 -0
- data/bin/rspec-git +13 -0
- data/lib/rspec-git.rb +7 -0
- data/lib/rspec-git/command.rb +8 -0
- data/lib/rspec-git/commiter.rb +47 -0
- data/lib/rspec-git/history.rb +32 -0
- data/lib/rspec-git/oneline_formatter.rb +20 -0
- data/lib/rspec-git/rspec_runner.rb +35 -0
- data/lib/rspec-git/version.rb +5 -0
- data/rspec-git.gemspec +19 -0
- metadata +61 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Nucc
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# Rspec::Git
|
2
|
+
|
3
|
+
Creates a git commit after each TDD step. Uses the new specification name to build the commit message. Built to the Ruby based RSpec.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install rspec-git
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
Extend the spec file with the requirement:
|
12
|
+
|
13
|
+
describe "User" do
|
14
|
+
it "should contain name" do
|
15
|
+
User.new.should respond_to(:name)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
After implementing the feature and all of your specs are green, just call the <code>rspec-git</code> command in your project's root directory:
|
20
|
+
|
21
|
+
$ rspec-git
|
22
|
+
|
23
|
+
It added the new changes to stage and created a git commit with the following message:
|
24
|
+
|
25
|
+
Added user should contain name
|
26
|
+
|
27
|
+
If you remove the spec, the generated message will be the following:
|
28
|
+
|
29
|
+
Removed user should contain name
|
30
|
+
|
31
|
+
Let me know if you have any issue!
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
1. Fork it
|
36
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
37
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
38
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
39
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/rspec-git
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
lib = File.expand_path(File.dirname(__FILE__) + '/../lib')
|
4
|
+
$LOAD_PATH.unshift(lib) if File.directory?(lib) && !$LOAD_PATH.include?(lib)
|
5
|
+
|
6
|
+
require 'rspec-git'
|
7
|
+
require 'rspec-git/command'
|
8
|
+
|
9
|
+
args = ARGV.dup
|
10
|
+
ARGV.clear
|
11
|
+
command = args.shift.strip rescue 'help'
|
12
|
+
|
13
|
+
RspecGit::Command.run(command, args)
|
data/lib/rspec-git.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
module RspecGit
|
2
|
+
class Commiter
|
3
|
+
def initialize
|
4
|
+
@repository = Grit::Repo.new(".")
|
5
|
+
self
|
6
|
+
end
|
7
|
+
|
8
|
+
def create
|
9
|
+
add
|
10
|
+
commit
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def message
|
16
|
+
commit_message = ""
|
17
|
+
diff_chunks.each do |chunk|
|
18
|
+
chunk.diff.each_line do |line|
|
19
|
+
if line =~ /^[+]{1}[^+]+/
|
20
|
+
commit_message += line.downcase!.gsub!(/^\+/, "Added ")
|
21
|
+
end
|
22
|
+
if line =~ /^[-]{1}[^-]+/
|
23
|
+
commit_message += line.downcase!.gsub!(/^\-/, "Removed ")
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
if commit_message == ""
|
28
|
+
puts "There is no new specification. Didn't make commit..."
|
29
|
+
else
|
30
|
+
puts commit_message
|
31
|
+
end
|
32
|
+
commit_message
|
33
|
+
end
|
34
|
+
|
35
|
+
def diff_chunks
|
36
|
+
@repository.diff("", "HEAD", History.file_name)
|
37
|
+
end
|
38
|
+
|
39
|
+
def add
|
40
|
+
@repository.add(".")
|
41
|
+
end
|
42
|
+
|
43
|
+
def commit
|
44
|
+
@repository.commit_all(message)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module RspecGit
|
2
|
+
class History
|
3
|
+
|
4
|
+
def self.file_path
|
5
|
+
"#{prefix}#{file_name}"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.file_name
|
9
|
+
".last_tdd_run"
|
10
|
+
end
|
11
|
+
|
12
|
+
def open
|
13
|
+
@target ||= File.open(self.class.file_path, "w")
|
14
|
+
end
|
15
|
+
|
16
|
+
def file
|
17
|
+
@target
|
18
|
+
end
|
19
|
+
|
20
|
+
def close
|
21
|
+
@target.close
|
22
|
+
@target = nil
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.prefix
|
28
|
+
("#{ENV['PWD']}" && "#{ENV['PWD']}/") || ""
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require 'rspec/core/formatters/base_formatter.rb'
|
3
|
+
|
4
|
+
module RspecGit
|
5
|
+
class OnelineFormatter < RSpec::Core::Formatters::BaseFormatter
|
6
|
+
def output
|
7
|
+
examples.each do |example|
|
8
|
+
context = ""
|
9
|
+
tmp_example = example.metadata
|
10
|
+
while tmp_example[:example_group]
|
11
|
+
context = tmp_example[:example_group][:description_args].join(" ") + " " + context
|
12
|
+
tmp_example = tmp_example[:example_group]
|
13
|
+
end
|
14
|
+
|
15
|
+
testcase = example.metadata[:description_args].join(" ")
|
16
|
+
@output.puts context.to_s + testcase.to_s
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module RspecGit
|
2
|
+
class RspecRunner
|
3
|
+
|
4
|
+
def initialize
|
5
|
+
@config = RSpec.configuration
|
6
|
+
@history = History.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def run
|
10
|
+
open_history
|
11
|
+
@config.instance_variable_set(:@reporter, RSpec::Core::Reporter.new(documentation_formatter, custom_formatter))
|
12
|
+
RSpec::Core::Runner.run(['spec'], $stderr, $stdout)
|
13
|
+
close_history
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def open_history
|
19
|
+
@history.open
|
20
|
+
end
|
21
|
+
|
22
|
+
def close_history
|
23
|
+
@history.close
|
24
|
+
end
|
25
|
+
|
26
|
+
def custom_formatter
|
27
|
+
OnelineFormatter.new(@history.file)
|
28
|
+
end
|
29
|
+
|
30
|
+
def documentation_formatter
|
31
|
+
@config.send(:built_in_formatter, :documentation).new(@config.output)
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
data/rspec-git.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rspec-git/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "rspec-git"
|
8
|
+
gem.version = Rspec::Git::VERSION
|
9
|
+
gem.authors = ["Nucc"]
|
10
|
+
gem.email = ["nucler.pl@gmail.com"]
|
11
|
+
gem.description = %q{Creates a commit in git after each TDD step using the new spec case as a commit message.}
|
12
|
+
gem.summary = %q{Creates a git commit after each TDD round.}
|
13
|
+
gem.homepage = "http://github.com/Nucc/rspec-git"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rspec-git
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nucc
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-27 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Creates a commit in git after each TDD step using the new spec case as
|
15
|
+
a commit message.
|
16
|
+
email:
|
17
|
+
- nucler.pl@gmail.com
|
18
|
+
executables:
|
19
|
+
- rspec-git
|
20
|
+
extensions: []
|
21
|
+
extra_rdoc_files: []
|
22
|
+
files:
|
23
|
+
- .gitignore
|
24
|
+
- Gemfile
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/rspec-git
|
29
|
+
- lib/rspec-git.rb
|
30
|
+
- lib/rspec-git/command.rb
|
31
|
+
- lib/rspec-git/commiter.rb
|
32
|
+
- lib/rspec-git/history.rb
|
33
|
+
- lib/rspec-git/oneline_formatter.rb
|
34
|
+
- lib/rspec-git/rspec_runner.rb
|
35
|
+
- lib/rspec-git/version.rb
|
36
|
+
- rspec-git.gemspec
|
37
|
+
homepage: http://github.com/Nucc/rspec-git
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.23
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Creates a git commit after each TDD round.
|
61
|
+
test_files: []
|