Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
bde3f25d
Commit
bde3f25d
authored
Sep 08, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specs for diff parser! Yay!
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
c741fcab
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
121 additions
and
1 deletion
+121
-1
lib/gitlab/diff/file.rb
lib/gitlab/diff/file.rb
+1
-1
spec/lib/gitlab/diff/file_spec.rb
spec/lib/gitlab/diff/file_spec.rb
+25
-0
spec/lib/gitlab/diff/parser_spec.rb
spec/lib/gitlab/diff/parser_spec.rb
+95
-0
No files found.
lib/gitlab/diff/file.rb
View file @
bde3f25d
...
...
@@ -21,7 +21,7 @@ module Gitlab
end
def
mode_changed?
diff
.
a_mode
&&
diff
.
b_mode
&&
diff
.
a_mode
!=
diff
.
b_mode
!!
(
diff
.
a_mode
&&
diff
.
b_mode
&&
diff
.
a_mode
!=
diff
.
b_mode
)
end
def
parser
...
...
spec/lib/gitlab/diff/file_spec.rb
0 → 100644
View file @
bde3f25d
require
'spec_helper'
describe
Gitlab
::
Diff
::
File
do
include
RepoHelpers
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit
)
{
project
.
repository
.
commit
(
sample_commit
.
id
)
}
let
(
:diff
)
{
commit
.
diffs
.
first
}
let
(
:diff_file
)
{
Gitlab
::
Diff
::
File
.
new
(
project
,
commit
,
diff
)
}
describe
:diff_lines
do
let
(
:diff_lines
)
{
diff_file
.
diff_lines
}
it
{
diff_lines
.
size
.
should
==
30
}
it
{
diff_lines
.
first
.
should
be_kind_of
(
Gitlab
::
Diff
::
Line
)
}
end
describe
:blob_exists?
do
it
{
diff_file
.
blob_exists?
.
should
be_true
}
end
describe
:mode_changed?
do
it
{
diff_file
.
mode_changed?
.
should
be_false
}
end
end
spec/lib/gitlab/diff/parser_spec.rb
0 → 100644
View file @
bde3f25d
require
'spec_helper'
describe
Gitlab
::
Diff
::
Parser
do
include
RepoHelpers
let
(
:project
)
{
create
(
:project
)
}
let
(
:commit
)
{
project
.
repository
.
commit
(
sample_commit
.
id
)
}
let
(
:diff
)
{
commit
.
diffs
.
first
}
let
(
:parser
)
{
Gitlab
::
Diff
::
Parser
.
new
}
describe
:parse
do
let
(
:diff
)
do
<<
eos
--- a/files/ruby/popen.rb
+++ b/files/ruby/popen.rb
@@ -6,12 +6,18 @@ module Popen
def popen(cmd, path=nil)
unless cmd.is_a?(Array)
- raise "System commands must be given as an array of strings"
+ raise RuntimeError, "System commands must be given as an array of strings"
end
path ||= Dir.pwd
- vars = { "PWD" => path }
- options = { chdir: path }
+
+ vars = {
+ "PWD" => path
+ }
+
+ options = {
+ chdir: path
+ }
unless File.directory?(path)
FileUtils.mkdir_p(path)
@@ -19,6 +25,7 @@ module Popen
@cmd_output = ""
@cmd_status = 0
+
Open3.popen3(vars, *cmd, options) do |stdin, stdout, stderr, wait_thr|
@cmd_output << stdout.read
@cmd_output << stderr.read
eos
end
let
(
:path
)
{
'files/ruby/popen.rb'
}
before
do
@lines
=
parser
.
parse
(
diff
.
lines
,
path
,
path
)
end
it
{
@lines
.
size
.
should
==
30
}
describe
'lines'
do
describe
'first line'
do
let
(
:line
)
{
@lines
.
first
}
it
{
line
.
type
.
should
==
'match'
}
it
{
line
.
old_pos
.
should
==
6
}
it
{
line
.
new_pos
.
should
==
6
}
it
{
line
.
text
.
should
==
'@@ -6,12 +6,18 @@ module Popen'
}
end
describe
'removal line'
do
let
(
:line
)
{
@lines
[
10
]
}
it
{
line
.
type
.
should
==
'old'
}
it
{
line
.
old_pos
.
should
==
14
}
it
{
line
.
new_pos
.
should
==
13
}
it
{
line
.
text
.
should
==
'- options = { chdir: path }'
}
end
describe
'addition line'
do
let
(
:line
)
{
@lines
[
16
]
}
it
{
line
.
type
.
should
==
'new'
}
it
{
line
.
old_pos
.
should
==
15
}
it
{
line
.
new_pos
.
should
==
18
}
it
{
line
.
text
.
should
==
'+ options = {'
}
end
describe
'unchanged line'
do
let
(
:line
)
{
@lines
.
last
}
it
{
line
.
type
.
should
==
nil
}
it
{
line
.
old_pos
.
should
==
24
}
it
{
line
.
new_pos
.
should
==
31
}
it
{
line
.
text
.
should
==
' @cmd_output << stderr.read'
}
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment