rspec-git 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rspec-git.gemspec
4
+ gemspec
5
+
6
+ gem "grit", ">= 2.4.0"
7
+ gem "rspec"
8
+
9
+ group :development do
10
+ gem "shoulda", ">= 0"
11
+ gem "rdoc", "~> 3.12"
12
+ gem "jeweler", "~> 1.8.4"
13
+ end
@@ -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.
@@ -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
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -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)
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'grit'
3
+
4
+ require 'rspec-git/history.rb'
5
+ require 'rspec-git/oneline_formatter.rb'
6
+ require 'rspec-git/rspec_runner.rb'
7
+ require 'rspec-git/commiter.rb'
@@ -0,0 +1,8 @@
1
+ module RspecGit
2
+ class Command
3
+ def self.run(command, args)
4
+ RspecRunner.new.run
5
+ Commiter.new.create
6
+ end
7
+ end
8
+ end
@@ -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
@@ -0,0 +1,5 @@
1
+ module Rspec
2
+ module Git
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -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: []