git_loc_tracker 0.0.2 → 0.0.3

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.
@@ -7,18 +7,10 @@ module GitLocTracker
7
7
 
8
8
  class Statistics
9
9
 
10
- attr_accessor :git_lines, :git_command, :line_parser
10
+ attr_accessor :git_command_options, :git_lines, :git_command, :line_parser
11
11
 
12
12
  def initialize options
13
- @git_command = GitLocTracker::CommandConstructor.new(options).git_command
14
- end
15
-
16
- def git_lines
17
- @git_lines ||= GitLocTracker::CommandExecutor.new(@git_command).git_lines
18
- end
19
-
20
- def line_parser line
21
- GitLocTracker::LineParser.new(line)
13
+ @git_command_options = options
22
14
  end
23
15
 
24
16
  def new_line_count
@@ -47,6 +39,20 @@ module GitLocTracker
47
39
  puts "********************************"
48
40
  end
49
41
 
42
+ private
43
+
44
+ def git_command
45
+ @git_command ||= GitLocTracker::CommandConstructor.new(git_command_options).git_command
46
+ end
47
+
48
+ def git_lines
49
+ @git_lines ||= GitLocTracker::CommandExecutor.new(git_command).git_lines
50
+ end
51
+
52
+ def line_parser line
53
+ GitLocTracker::LineParser.new(line)
54
+ end
55
+
50
56
  end
51
57
 
52
58
  end
@@ -34,7 +34,7 @@ module GitLocTracker
34
34
  end
35
35
 
36
36
  def existing_search_scope
37
- scope_parts = options[:search_scope].split(" ")
37
+ scope_parts = options[:search_scope] ? options[:search_scope].split(" ") : []
38
38
  existing_scope_dirs = scope_parts.select { |dir| File.exist?("#{options[:path]}/#{dir}") }
39
39
  existing_scope_dirs.empty? ? options[:path] : existing_scope_dirs.join(" ")
40
40
  end
@@ -6,14 +6,6 @@ module GitLocTracker
6
6
  @line = line
7
7
  end
8
8
 
9
- def line_size_without_deleted_code
10
- line.strip.gsub(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP, "").size
11
- end
12
-
13
- def line_size_without_new_code
14
- line.strip.gsub(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP, "").size
15
- end
16
-
17
9
  def is_new?
18
10
  line_size_without_new_code == 0
19
11
  end
@@ -25,5 +17,16 @@ module GitLocTracker
25
17
  def is_modified?
26
18
  !is_new? && !is_deleted?
27
19
  end
20
+
21
+ private
22
+
23
+ def line_size_without_deleted_code
24
+ line.strip.gsub(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP, "").size
25
+ end
26
+
27
+ def line_size_without_new_code
28
+ line.strip.gsub(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP, "").size
29
+ end
30
+
28
31
  end
29
32
  end
@@ -1,3 +1,3 @@
1
1
  module GitLocTracker
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitLocTracker::CommandConstructor do
4
+ it "should receive options" do
5
+ options = {option_1: "a", option_2: "b"}
6
+ command_constructor = GitLocTracker::CommandConstructor.new options
7
+ command_constructor.options.should == options
8
+ end
9
+
10
+ it "should construct git command containing --since option" do
11
+ command_constructor = GitLocTracker::CommandConstructor.new({from: "1 day ago"})
12
+ command_constructor.git_command.should include("--since='1 day ago'")
13
+ end
14
+
15
+ it "should construct git command containing --until option" do
16
+ command_constructor = GitLocTracker::CommandConstructor.new({till: "1 day from now"})
17
+ command_constructor.git_command.should include("--until='1 day from now'")
18
+ end
19
+
20
+ it "should construct git command containing --author option" do
21
+ command_constructor = GitLocTracker::CommandConstructor.new({author: "Janis"})
22
+ command_constructor.git_command.should include("--author='Janis'")
23
+ end
24
+
25
+ it "should construct git command containing path" do
26
+ command_constructor = GitLocTracker::CommandConstructor.new({path: "/home/user/app_root"})
27
+ command_constructor.git_command.should include("cd /home/user/app_root")
28
+ end
29
+
30
+ it "should construct git command containing search scope" do
31
+ command_constructor = GitLocTracker::CommandConstructor.new({search_scope: "lib bin"})
32
+ command_constructor.git_command.should include("lib bin")
33
+ end
34
+
35
+ it "should not construct git command containing non-existing search scope directories" do
36
+ command_constructor = GitLocTracker::CommandConstructor.new({search_scope: "non_existing_1 non_existing_1"})
37
+ command_constructor.git_command.should_not include("non_existing")
38
+ end
39
+
40
+ it "should constrict git command containing modified line matching regexp" do
41
+ command_constructor = GitLocTracker::CommandConstructor.new({})
42
+ command_constructor.git_command.should include(GitLocTracker::CommandConstructor::NEW_CODE_REGEXP.source)
43
+ command_constructor.git_command.should include(GitLocTracker::CommandConstructor::DELETED_CODE_REGEXP.source)
44
+ end
45
+
46
+
47
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitLocTracker::CommandExecutor do
4
+ let(:spec_root) { File.expand_path(File.join(File.dirname(__FILE__), '..', '../../')) }
5
+
6
+ it "should initialize object with command attribute" do
7
+ GitLocTracker::CommandExecutor.new("git command").command.should == "git command"
8
+ end
9
+
10
+ it "should execute git command and return line array" do
11
+ executor = GitLocTracker::CommandExecutor.new("cd #{spec_root}/test_repo/ && git st")
12
+ executor.git_lines.should_not be_empty
13
+ end
14
+
15
+ it "should raise GitCommandError if invalid git command is provided" do
16
+ executor = GitLocTracker::CommandExecutor.new("cd #{spec_root}/test_repo/ && git non_existing_command")
17
+ lambda { executor.git_lines }.should raise_error(GitLocTracker::CommandExecutor::GitCommandError)
18
+ end
19
+
20
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitLocTracker::LineParser do
4
+ it "should initialize object with command attribute" do
5
+ GitLocTracker::LineParser.new("line string").line.should == "line string"
6
+ end
7
+
8
+ it "should detect new line" do
9
+ source_line = "{+Some new line+}"
10
+ GitLocTracker::LineParser.new(source_line).is_new?.should be_true
11
+ end
12
+
13
+ it "should detect deleted line" do
14
+ source_line = "[-Some deleted line-]"
15
+ GitLocTracker::LineParser.new(source_line).is_deleted?.should be_true
16
+ end
17
+
18
+ it "should detect modified line" do
19
+ source_line = "[-old deleted part-]{+replaced with new part+}"
20
+ GitLocTracker::LineParser.new(source_line).is_modified?.should be_true
21
+ end
22
+
23
+ it "should detect modified line which also contains unmodified parts" do
24
+ source_line = "Some unmodified part [-old deleted part-]{+replaced with new part+}"
25
+ GitLocTracker::LineParser.new(source_line).is_modified?.should be_true
26
+ end
27
+
28
+ it "should not count modified line as deleted or new line" do
29
+ source_line = "[-old deleted part-]{+replaced with new part+}"
30
+ GitLocTracker::LineParser.new(source_line).is_new?.should be_false
31
+ GitLocTracker::LineParser.new(source_line).is_deleted?.should be_false
32
+ end
33
+
34
+ end
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ #spec/test_repo is a git repo containing file test_file which was initialized and commited 3 times:
4
+ #1) with 10 new lines
5
+ #2) with 5 modified lines
6
+ #3) with 5 deleted lines
7
+
8
+ describe GitLocTracker::Statistics do
9
+
10
+ TOTAL_LINES_AFFECTED_IN_TEST_REPO = 20
11
+ NEW_LINES_IN_TEST_REPO = 10
12
+ MODIFIED_LINES_IN_TEST_REPO = 5
13
+ DELETED_LINES_IN_TEST_REPO = 5
14
+
15
+ let(:default_git_options) do
16
+ {path: "#{File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))}/test_repo/",
17
+ from: "2012-10-31",
18
+ till: "2012-11-01",
19
+ author: "Janis",
20
+ search_scope: "test_file"}
21
+ end
22
+
23
+ it "should receive git options in initializer" do
24
+ options = {option_1: 1, option_2: 2}
25
+ GitLocTracker::Statistics.new(options).git_command_options.should == options
26
+ end
27
+
28
+ it "should return correct git command" do
29
+ git_command = "cd /home/janis/code/git_loc_tracker/spec/test_repo/ && git log -p --word-diff --since='2012-10-31' --until='2012-11-01' --author='Janis' test_file | egrep '\\[\\-.*\\-\\]|\\{\\+.*\\+\\}'"
30
+ GitLocTracker::Statistics.new(default_git_options).send(:git_command).should == git_command
31
+ end
32
+
33
+ it "should return correct amount of changed line count in test_file" do
34
+ GitLocTracker::Statistics.new(default_git_options).send(:git_lines).count == TOTAL_LINES_AFFECTED_IN_TEST_REPO
35
+ end
36
+
37
+ it "should return correct amount of new lines in test_file" do
38
+ GitLocTracker::Statistics.new(default_git_options).new_line_count.should == NEW_LINES_IN_TEST_REPO
39
+ end
40
+
41
+ it "should return correct amount of deleted lines in test_file" do
42
+ GitLocTracker::Statistics.new(default_git_options).deleted_line_count.should == DELETED_LINES_IN_TEST_REPO
43
+ end
44
+
45
+ it "should return correct amount of modified lines in test_file" do
46
+ GitLocTracker::Statistics.new(default_git_options).modified_line_count.should == MODIFIED_LINES_IN_TEST_REPO
47
+ end
48
+
49
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,11 @@
1
- # This file was generated by the `rspec --init` command. Conventionally, all
2
- # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
5
- #
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'git_loc_tracker'
4
+
6
5
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
6
  RSpec.configure do |config|
8
7
  config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  config.filter_run :focus
11
-
12
- # Run specs in random order to surface order dependencies. If you find an
13
- # order dependency and want to debug it, you can fix the order by providing
14
- # the seed, which is printed after each run.
15
- # --seed 1234
16
10
  config.order = 'random'
17
11
  end
@@ -0,0 +1,5 @@
1
+ modified new line 1
2
+ modified new line 2
3
+ modified new line 3
4
+ modified new line 4
5
+ modified new line 5
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_loc_tracker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-11 00:00:00.000000000Z
12
+ date: 2012-11-01 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: systemu
16
- requirement: &73615600 !ruby/object:Gem::Requirement
16
+ requirement: &85093350 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,7 +21,7 @@ dependencies:
21
21
  version: 2.5.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *73615600
24
+ version_requirements: *85093350
25
25
  description: Counts new, deleted and modified lines in git repository with ability
26
26
  to pass various options
27
27
  email:
@@ -40,6 +40,11 @@ files:
40
40
  - MIT-LICENSE
41
41
  - Rakefile
42
42
  - README.md
43
+ - spec/git_loc_tracker/lib/git_loc_tracker/command_executor_spec.rb
44
+ - spec/git_loc_tracker/lib/git_loc_tracker/line_parser_spec.rb
45
+ - spec/git_loc_tracker/lib/git_loc_tracker/command_constructor_spec.rb
46
+ - spec/git_loc_tracker/lib/git_loc_tracker_spec.rb
47
+ - spec/test_repo/test_file
43
48
  - spec/spec_helper.rb
44
49
  homepage: https://github.com/ithouse/git_loc_tracker
45
50
  licenses: []
@@ -67,4 +72,9 @@ specification_version: 3
67
72
  summary: Counts new, deleted and modified lines in git repository with ability to
68
73
  pass various options
69
74
  test_files:
75
+ - spec/git_loc_tracker/lib/git_loc_tracker/command_executor_spec.rb
76
+ - spec/git_loc_tracker/lib/git_loc_tracker/line_parser_spec.rb
77
+ - spec/git_loc_tracker/lib/git_loc_tracker/command_constructor_spec.rb
78
+ - spec/git_loc_tracker/lib/git_loc_tracker_spec.rb
79
+ - spec/test_repo/test_file
70
80
  - spec/spec_helper.rb