diff options
author | Jan-Willem van der Meer <mail@jewilmeer.nl> | 2014-09-11 11:46:08 +0200 |
---|---|---|
committer | Jan-Willem van der Meer <mail@jewilmeer.nl> | 2014-09-11 11:46:08 +0200 |
commit | bf0de1a500e7a9aecc7c8bbf623ad39b75c6433b (patch) | |
tree | 382df65e2b17c91e03278d58bce8dce0129a6a7b /spec/lib | |
parent | b18d1c2786c2a385d6b797734a1afad7a01ddf35 (diff) | |
parent | 78ec7d9c9d156fe556d165c1c096bf5534d62d25 (diff) | |
download | gitlab-ce-bf0de1a500e7a9aecc7c8bbf623ad39b75c6433b.tar.gz |
Merge remote-tracking branch 'origin/master' into feature-oauth-refactoring
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/git_ref_validator_spec.rb | 20 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/file_spec.rb | 21 | ||||
-rw-r--r-- | spec/lib/gitlab/diff/parser_spec.rb | 93 |
3 files changed, 134 insertions, 0 deletions
diff --git a/spec/lib/git_ref_validator_spec.rb b/spec/lib/git_ref_validator_spec.rb new file mode 100644 index 00000000000..b2469c18395 --- /dev/null +++ b/spec/lib/git_ref_validator_spec.rb @@ -0,0 +1,20 @@ +require 'spec_helper' + +describe Gitlab::GitRefValidator do + it { Gitlab::GitRefValidator.validate('feature/new').should be_true } + it { Gitlab::GitRefValidator.validate('implement_@all').should be_true } + it { Gitlab::GitRefValidator.validate('my_new_feature').should be_true } + it { Gitlab::GitRefValidator.validate('#1').should be_true } + it { Gitlab::GitRefValidator.validate('feature/~new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/^new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/:new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/?new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/*new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/[new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/new/').should be_false } + it { Gitlab::GitRefValidator.validate('feature/new.').should be_false } + it { Gitlab::GitRefValidator.validate('feature\@{').should be_false } + it { Gitlab::GitRefValidator.validate('feature\new').should be_false } + it { Gitlab::GitRefValidator.validate('feature//new').should be_false } + it { Gitlab::GitRefValidator.validate('feature new').should be_false } +end diff --git a/spec/lib/gitlab/diff/file_spec.rb b/spec/lib/gitlab/diff/file_spec.rb new file mode 100644 index 00000000000..cf0b5c282c1 --- /dev/null +++ b/spec/lib/gitlab/diff/file_spec.rb @@ -0,0 +1,21 @@ +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(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 :mode_changed? do + it { diff_file.mode_changed?.should be_false } + end +end diff --git a/spec/lib/gitlab/diff/parser_spec.rb b/spec/lib/gitlab/diff/parser_spec.rb new file mode 100644 index 00000000000..35b78260acd --- /dev/null +++ b/spec/lib/gitlab/diff/parser_spec.rb @@ -0,0 +1,93 @@ +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 + + before do + @lines = parser.parse(diff.lines) + 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 |