Skip to content
Snippets Groups Projects
Commit fd6be573 authored by Valery Sizov's avatar Valery Sizov
Browse files

Merge branch 'rs-rspec3' into 'master'

RSpec 3

Updates CI's specs to be a bit more like CE's to make that transition a little easier.

See merge request !246
parents 305d9e20 77053a6c
No related branches found
No related tags found
No related merge requests found
Showing
with 415 additions and 448 deletions
require 'spec_helper'
 
describe UserSessionsHelper do
describe :generate_oauth_hmac do
describe 'generate_oauth_hmac' do
let (:salt) { 'a' }
let (:salt2) { 'b' }
let (:return_to) { 'b' }
 
it 'should return null if return_to is also null' do
generate_oauth_hmac(salt, nil).should be_nil
expect(generate_oauth_hmac(salt, nil)).to be_nil
end
 
it 'should return not null if return_to is also not null' do
generate_oauth_hmac(salt, return_to).should_not be_nil
expect(generate_oauth_hmac(salt, return_to)).not_to be_nil
end
 
it 'should return different hmacs for different salts' do
secret1 = generate_oauth_hmac(salt, return_to)
secret2 = generate_oauth_hmac(salt2, return_to)
secret1.should_not eq(secret2)
expect(secret1).not_to eq(secret2)
end
end
 
describe :generate_oauth_state do
describe 'generate_oauth_state' do
let (:return_to) { 'b' }
 
it 'should return null if return_to is also null' do
generate_oauth_state(nil).should be_nil
expect(generate_oauth_state(nil)).to be_nil
end
 
it 'should return two different states for same return_to' do
state1 = generate_oauth_state(return_to)
state2 = generate_oauth_state(return_to)
state1.should_not eq(state2)
expect(state1).not_to eq(state2)
end
end
 
describe :get_ouath_state_return_to do
describe 'get_ouath_state_return_to' do
let (:return_to) { 'a' }
let (:state) { generate_oauth_state(return_to) }
 
it 'should return return_to' do
get_ouath_state_return_to(state).should eq(return_to)
expect(get_ouath_state_return_to(state)).to eq(return_to)
end
end
 
describe :is_oauth_state_valid? do
describe 'is_oauth_state_valid?' do
let (:return_to) { 'a' }
let (:state) { generate_oauth_state(return_to) }
let (:forged) { "forged#{state}" }
Loading
Loading
@@ -53,17 +53,17 @@ describe UserSessionsHelper do
let (:invalid3) { 'aa:bb:' }
 
it 'should validate oauth state' do
is_oauth_state_valid?(state).should be_true
expect(is_oauth_state_valid?(state)).to be_truthy
end
 
it 'should not validate forged state' do
is_oauth_state_valid?(forged).should be_false
expect(is_oauth_state_valid?(forged)).to be_falsey
end
 
it 'should not validate invalid state' do
is_oauth_state_valid?(invalid).should be_false
is_oauth_state_valid?(invalid2).should be_false
is_oauth_state_valid?(invalid3).should be_false
expect(is_oauth_state_valid?(invalid)).to be_falsey
expect(is_oauth_state_valid?(invalid2)).to be_falsey
expect(is_oauth_state_valid?(invalid3)).to be_falsey
end
end
end
Loading
Loading
@@ -3,131 +3,131 @@ require 'spec_helper'
describe Ansi2html do
 
it "prints non-ansi as-is" do
Ansi2html::convert("Hello").should == 'Hello'
expect(described_class::convert("Hello")).to eq 'Hello'
end
 
it "strips non-color-changing controll sequences" do
Ansi2html::convert("Hello \e[2Kworld").should == 'Hello world'
expect(described_class::convert("Hello \e[2Kworld")).to eq 'Hello world'
end
 
it "prints simply red" do
Ansi2html::convert("\e[31mHello\e[0m").should == '<span class="term-fg-red">Hello</span>'
expect(described_class::convert("\e[31mHello\e[0m")).to eq '<span class="term-fg-red">Hello</span>'
end
 
it "prints simply red without trailing reset" do
Ansi2html::convert("\e[31mHello").should == '<span class="term-fg-red">Hello</span>'
expect(described_class::convert("\e[31mHello")).to eq '<span class="term-fg-red">Hello</span>'
end
 
it "prints simply yellow" do
Ansi2html::convert("\e[33mHello\e[0m").should == '<span class="term-fg-yellow">Hello</span>'
expect(described_class::convert("\e[33mHello\e[0m")).to eq '<span class="term-fg-yellow">Hello</span>'
end
 
it "prints default on blue" do
Ansi2html::convert("\e[39;44mHello").should == '<span class="term-bg-blue">Hello</span>'
expect(described_class::convert("\e[39;44mHello")).to eq '<span class="term-bg-blue">Hello</span>'
end
 
it "prints red on blue" do
Ansi2html::convert("\e[31;44mHello").should == '<span class="term-fg-red term-bg-blue">Hello</span>'
expect(described_class::convert("\e[31;44mHello")).to eq '<span class="term-fg-red term-bg-blue">Hello</span>'
end
 
it "resets colors after red on blue" do
Ansi2html::convert("\e[31;44mHello\e[0m world").should == '<span class="term-fg-red term-bg-blue">Hello</span> world'
expect(described_class::convert("\e[31;44mHello\e[0m world")).to eq '<span class="term-fg-red term-bg-blue">Hello</span> world'
end
 
it "performs color change from red/blue to yellow/blue" do
Ansi2html::convert("\e[31;44mHello \e[33mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-blue">world</span>'
expect(described_class::convert("\e[31;44mHello \e[33mworld")).to eq '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-blue">world</span>'
end
 
it "performs color change from red/blue to yellow/green" do
Ansi2html::convert("\e[31;44mHello \e[33;42mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-green">world</span>'
expect(described_class::convert("\e[31;44mHello \e[33;42mworld")).to eq '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-fg-yellow term-bg-green">world</span>'
end
 
it "performs color change from red/blue to reset to yellow/green" do
Ansi2html::convert("\e[31;44mHello\e[0m \e[33;42mworld").should == '<span class="term-fg-red term-bg-blue">Hello</span> <span class="term-fg-yellow term-bg-green">world</span>'
expect(described_class::convert("\e[31;44mHello\e[0m \e[33;42mworld")).to eq '<span class="term-fg-red term-bg-blue">Hello</span> <span class="term-fg-yellow term-bg-green">world</span>'
end
 
it "ignores unsupported codes" do
Ansi2html::convert("\e[51mHello\e[0m").should == 'Hello'
expect(described_class::convert("\e[51mHello\e[0m")).to eq 'Hello'
end
 
it "prints light red" do
Ansi2html::convert("\e[91mHello\e[0m").should == '<span class="term-fg-l-red">Hello</span>'
expect(described_class::convert("\e[91mHello\e[0m")).to eq '<span class="term-fg-l-red">Hello</span>'
end
 
it "prints default on light red" do
Ansi2html::convert("\e[101mHello\e[0m").should == '<span class="term-bg-l-red">Hello</span>'
expect(described_class::convert("\e[101mHello\e[0m")).to eq '<span class="term-bg-l-red">Hello</span>'
end
 
it "performs color change from red/blue to default/blue" do
Ansi2html::convert("\e[31;44mHello \e[39mworld").should == '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>'
expect(described_class::convert("\e[31;44mHello \e[39mworld")).to eq '<span class="term-fg-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>'
end
 
it "performs color change from light red/blue to default/blue" do
Ansi2html::convert("\e[91;44mHello \e[39mworld").should == '<span class="term-fg-l-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>'
expect(described_class::convert("\e[91;44mHello \e[39mworld")).to eq '<span class="term-fg-l-red term-bg-blue">Hello </span><span class="term-bg-blue">world</span>'
end
 
it "prints bold text" do
Ansi2html::convert("\e[1mHello").should == '<span class="term-bold">Hello</span>'
expect(described_class::convert("\e[1mHello")).to eq '<span class="term-bold">Hello</span>'
end
 
it "resets bold text" do
Ansi2html::convert("\e[1mHello\e[21m world").should == '<span class="term-bold">Hello</span> world'
Ansi2html::convert("\e[1mHello\e[22m world").should == '<span class="term-bold">Hello</span> world'
expect(described_class::convert("\e[1mHello\e[21m world")).to eq '<span class="term-bold">Hello</span> world'
expect(described_class::convert("\e[1mHello\e[22m world")).to eq '<span class="term-bold">Hello</span> world'
end
 
it "prints italic text" do
Ansi2html::convert("\e[3mHello").should == '<span class="term-italic">Hello</span>'
expect(described_class::convert("\e[3mHello")).to eq '<span class="term-italic">Hello</span>'
end
 
it "resets italic text" do
Ansi2html::convert("\e[3mHello\e[23m world").should == '<span class="term-italic">Hello</span> world'
expect(described_class::convert("\e[3mHello\e[23m world")).to eq '<span class="term-italic">Hello</span> world'
end
 
it "prints underlined text" do
Ansi2html::convert("\e[4mHello").should == '<span class="term-underline">Hello</span>'
expect(described_class::convert("\e[4mHello")).to eq '<span class="term-underline">Hello</span>'
end
 
it "resets underlined text" do
Ansi2html::convert("\e[4mHello\e[24m world").should == '<span class="term-underline">Hello</span> world'
expect(described_class::convert("\e[4mHello\e[24m world")).to eq '<span class="term-underline">Hello</span> world'
end
 
it "prints concealed text" do
Ansi2html::convert("\e[8mHello").should == '<span class="term-conceal">Hello</span>'
expect(described_class::convert("\e[8mHello")).to eq '<span class="term-conceal">Hello</span>'
end
 
it "resets concealed text" do
Ansi2html::convert("\e[8mHello\e[28m world").should == '<span class="term-conceal">Hello</span> world'
expect(described_class::convert("\e[8mHello\e[28m world")).to eq '<span class="term-conceal">Hello</span> world'
end
 
it "prints crossed-out text" do
Ansi2html::convert("\e[9mHello").should == '<span class="term-cross">Hello</span>'
expect(described_class::convert("\e[9mHello")).to eq '<span class="term-cross">Hello</span>'
end
 
it "resets crossed-out text" do
Ansi2html::convert("\e[9mHello\e[29m world").should == '<span class="term-cross">Hello</span> world'
expect(described_class::convert("\e[9mHello\e[29m world")).to eq '<span class="term-cross">Hello</span> world'
end
 
it "can print 256 xterm fg colors" do
Ansi2html::convert("\e[38;5;16mHello").should == '<span class="xterm-fg-16">Hello</span>'
expect(described_class::convert("\e[38;5;16mHello")).to eq '<span class="xterm-fg-16">Hello</span>'
end
 
it "can print 256 xterm fg colors on normal magenta background" do
Ansi2html::convert("\e[38;5;16;45mHello").should == '<span class="xterm-fg-16 term-bg-magenta">Hello</span>'
expect(described_class::convert("\e[38;5;16;45mHello")).to eq '<span class="xterm-fg-16 term-bg-magenta">Hello</span>'
end
 
it "can print 256 xterm bg colors" do
Ansi2html::convert("\e[48;5;240mHello").should == '<span class="xterm-bg-240">Hello</span>'
expect(described_class::convert("\e[48;5;240mHello")).to eq '<span class="xterm-bg-240">Hello</span>'
end
 
it "can print 256 xterm bg colors on normal magenta foreground" do
Ansi2html::convert("\e[48;5;16;35mHello").should == '<span class="term-fg-magenta xterm-bg-16">Hello</span>'
expect(described_class::convert("\e[48;5;16;35mHello")).to eq '<span class="term-fg-magenta xterm-bg-16">Hello</span>'
end
 
it "prints bold colored text vividly" do
Ansi2html::convert("\e[1;31mHello\e[0m").should == '<span class="term-fg-l-red term-bold">Hello</span>'
expect(described_class::convert("\e[1;31mHello\e[0m")).to eq '<span class="term-fg-l-red term-bold">Hello</span>'
end
 
it "prints bold light colored text correctly" do
Ansi2html::convert("\e[1;91mHello\e[0m").should == '<span class="term-fg-l-red term-bold">Hello</span>'
expect(described_class::convert("\e[1;91mHello\e[0m")).to eq '<span class="term-fg-l-red term-bold">Hello</span>'
end
end
require 'spec_helper'
 
describe "Charts" do
context "build_times" do
before do
@project = FactoryGirl.create(:project)
@commit = FactoryGirl.create(:commit, project: @project)
FactoryGirl.create(:build, commit: @commit)
end
describe Charts::BuildTime do
before do
@project = FactoryGirl.create(:project)
@commit = FactoryGirl.create(:commit, project: @project)
FactoryGirl.create(:build, commit: @commit)
end
 
it 'should return build times in minutes' do
chart = Charts::BuildTime.new(@project)
chart.build_times.should == [2]
end
it 'should return build times in minutes' do
chart = described_class.new(@project)
expect(chart.build_times).to eq [2]
end
end
Loading
Loading
@@ -11,10 +11,10 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec"}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
config_processor.builds_for_stage_and_ref(type, "master").first.should == {
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq 1
expect(config_processor.builds_for_stage_and_ref(type, "master").first).to eq({
stage: "test",
except: nil,
name: :rspec,
Loading
Loading
@@ -23,7 +23,7 @@ describe GitlabCiYamlProcessor do
tags: [],
options: {},
allow_failure: false
}
})
end
 
it "does not return builds if only has another branch" do
Loading
Loading
@@ -32,9 +32,9 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec", only: ["deploy"]}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq 0
end
 
it "does not return builds if only has regexp with another branch" do
Loading
Loading
@@ -43,9 +43,9 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec", only: ["/^deploy$/"]}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "master").size.should == 0
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq 0
end
 
it "returns builds if only has specified this branch" do
Loading
Loading
@@ -54,9 +54,9 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec", only: ["master"]}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "master").size.should == 1
expect(config_processor.builds_for_stage_and_ref(type, "master").size).to eq 1
end
 
it "does not build tags" do
Loading
Loading
@@ -65,9 +65,9 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec", except: ["tags"]}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "0-1", true).size.should == 0
expect(config_processor.builds_for_stage_and_ref(type, "0-1", true).size).to eq 0
end
 
it "returns builds if only has a list of branches including specified" do
Loading
Loading
@@ -76,9 +76,9 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec", type: type, only: ["master", "deploy"]}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq 1
end
 
it "returns build only for specified type" do
Loading
Loading
@@ -91,11 +91,11 @@ describe GitlabCiYamlProcessor do
production: {script: "deploy", type: "deploy", only: ["master", "deploy"]},
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref("production", "deploy").size.should == 0
config_processor.builds_for_stage_and_ref(type, "deploy").size.should == 1
config_processor.builds_for_stage_and_ref("deploy", "deploy").size.should == 2
expect(config_processor.builds_for_stage_and_ref("production", "deploy").size).to eq 0
expect(config_processor.builds_for_stage_and_ref(type, "deploy").size).to eq 1
expect(config_processor.builds_for_stage_and_ref("deploy", "deploy").size).to eq 2
end
end
 
Loading
Loading
@@ -108,10 +108,10 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec"}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq 1
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
except: nil,
stage: "test",
name: :rspec,
Loading
Loading
@@ -123,7 +123,7 @@ describe GitlabCiYamlProcessor do
services: ["mysql"]
},
allow_failure: false
}
})
end
 
it "returns image and service when overridden for job" do
Loading
Loading
@@ -134,10 +134,10 @@ describe GitlabCiYamlProcessor do
rspec: {image: "ruby:2.5", services: ["postgresql"], script: "rspec"}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor = described_class.new(config)
 
config_processor.builds_for_stage_and_ref("test", "master").size.should == 1
config_processor.builds_for_stage_and_ref("test", "master").first.should == {
expect(config_processor.builds_for_stage_and_ref("test", "master").size).to eq 1
expect(config_processor.builds_for_stage_and_ref("test", "master").first).to eq({
except: nil,
stage: "test",
name: :rspec,
Loading
Loading
@@ -149,7 +149,7 @@ describe GitlabCiYamlProcessor do
services: ["postgresql"]
},
allow_failure: false
}
})
end
end
 
Loading
Loading
@@ -165,147 +165,147 @@ describe GitlabCiYamlProcessor do
rspec: {script: "rspec"}
})
 
config_processor = GitlabCiYamlProcessor.new(config)
config_processor.variables.should == variables
config_processor = described_class.new(config)
expect(config_processor.variables).to eq variables
end
end
 
describe "Error handling" do
it "indicates that object is invalid" do
expect{GitlabCiYamlProcessor.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(GitlabCiYamlProcessor::ValidationError)
expect{described_class.new("invalid_yaml\n!ccdvlf%612334@@@@")}.to raise_error(described_class::ValidationError)
end
 
it "returns errors if tags parameter is invalid" do
config = YAML.dump({rspec: {script: "test", tags: "mysql"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: tags parameter should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: tags parameter should be an array of strings")
end
 
it "returns errors if before_script parameter is invalid" do
config = YAML.dump({before_script: "bundle update", rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "before_script should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "before_script should be an array of strings")
end
 
it "returns errors if image parameter is invalid" do
config = YAML.dump({image: ["test"], rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "image should be a string")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "image should be a string")
end
 
it "returns errors if job image parameter is invalid" do
config = YAML.dump({rspec: {script: "test", image: ["test"]}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: image should be a string")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: image should be a string")
end
 
it "returns errors if services parameter is not an array" do
config = YAML.dump({services: "test", rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "services should be an array of strings")
end
 
it "returns errors if services parameter is not an array of strings" do
config = YAML.dump({services: [10, "test"], rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "services should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "services should be an array of strings")
end
 
it "returns errors if job services parameter is not an array" do
config = YAML.dump({rspec: {script: "test", services: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: services should be an array of strings")
end
 
it "returns errors if job services parameter is not an array of strings" do
config = YAML.dump({rspec: {script: "test", services: [10, "test"]}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: services should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: services should be an array of strings")
end
 
it "returns errors if there are unknown parameters" do
config = YAML.dump({extra: "bundle update"})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "Unknown parameter: extra")
end
 
it "returns errors if there are unknown parameters that are hashes, but doesn't have a script" do
config = YAML.dump({extra: {services: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Unknown parameter: extra")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "Unknown parameter: extra")
end
 
it "returns errors if there is no any jobs defined" do
config = YAML.dump({before_script: ["bundle update"]})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "Please define at least one job")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "Please define at least one job")
end
 
it "returns errors if job allow_failure parameter is not an boolean" do
config = YAML.dump({rspec: {script: "test", allow_failure: "string"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: allow_failure parameter should be an boolean")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: allow_failure parameter should be an boolean")
end
 
it "returns errors if job stage is not a string" do
config = YAML.dump({rspec: {script: "test", type: 1, allow_failure: "string"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
 
it "returns errors if job stage is not a pre-defined stage" do
config = YAML.dump({rspec: {script: "test", type: "acceptance", allow_failure: "string"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test, deploy")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: stage parameter should be build, test, deploy")
end
 
it "returns errors if job stage is not a defined stage" do
config = YAML.dump({types: ["build", "test"], rspec: {script: "test", type: "acceptance", allow_failure: "string"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "rspec job: stage parameter should be build, test")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "rspec job: stage parameter should be build, test")
end
 
it "returns errors if stages is not an array" do
config = YAML.dump({types: "test", rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "stages should be an array of strings")
end
 
it "returns errors if stages is not an array of strings" do
config = YAML.dump({types: [true, "test"], rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "stages should be an array of strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "stages should be an array of strings")
end
 
it "returns errors if variables is not a map" do
config = YAML.dump({variables: "test", rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "variables should be a map of key-valued strings")
end
 
it "returns errors if variables is not a map of key-valued strings" do
config = YAML.dump({variables: {test: false}, rspec: {script: "test"}})
expect do
GitlabCiYamlProcessor.new(config)
end.to raise_error(GitlabCiYamlProcessor::ValidationError, "variables should be a map of key-valued strings")
described_class.new(config)
end.to raise_error(described_class::ValidationError, "variables should be a map of key-valued strings")
end
end
end
require 'spec_helper'
 
describe Upgrader do
let(:upgrader) { Upgrader.new }
let(:upgrader) { described_class.new }
let(:current_version) { GitlabCi::VERSION }
 
describe 'current_version_raw' do
it { upgrader.current_version_raw.should == current_version }
it { expect(upgrader.current_version_raw).to eq current_version }
end
 
describe 'latest_version?' do
it 'should be true if newest version' do
upgrader.stub(latest_version_raw: current_version)
upgrader.latest_version?.should be_true
allow(upgrader).to receive_messages(latest_version_raw: current_version)
expect(upgrader.latest_version?).to be_truthy
end
end
 
Loading
Loading
Loading
Loading
@@ -11,26 +11,26 @@ describe Notify do
end
 
describe 'build success' do
subject { Notify.build_success_email(@build.id, 'wow@example.com') }
subject { described_class.build_success_email(@build.id, 'wow@example.com') }
 
it 'has the correct subject' do
should have_subject /Build success for/
is_expected.to have_subject /Build success for/
end
 
it 'contains name of project' do
should have_body_text /build successful/
is_expected.to have_body_text /build successful/
end
end
 
describe 'build fail' do
subject { Notify.build_fail_email(@build.id, 'wow@example.com') }
subject { described_class.build_fail_email(@build.id, 'wow@example.com') }
 
it 'has the correct subject' do
should have_subject /Build failed for/
is_expected.to have_subject /Build failed for/
end
 
it 'contains name of project' do
should have_body_text /build failed/
is_expected.to have_body_text /build failed/
end
end
end
Loading
Loading
@@ -30,26 +30,26 @@ describe Build do
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit }
 
it { should belong_to(:commit) }
it { should validate_presence_of :status }
it { is_expected.to belong_to(:commit) }
it { is_expected.to validate_presence_of :status }
 
it { should respond_to :success? }
it { should respond_to :failed? }
it { should respond_to :running? }
it { should respond_to :pending? }
it { should respond_to :trace_html }
it { is_expected.to respond_to :success? }
it { is_expected.to respond_to :failed? }
it { is_expected.to respond_to :running? }
it { is_expected.to respond_to :pending? }
it { is_expected.to respond_to :trace_html }
 
describe :first_pending do
describe '.first_pending' do
let(:first) { FactoryGirl.create :build, commit: commit, status: 'pending', created_at: Date.yesterday }
let(:second) { FactoryGirl.create :build, commit: commit, status: 'pending' }
before { first; second }
subject { Build.first_pending }
 
it { should be_a(Build) }
it('returns with the first pending build') { should eq(first) }
it { is_expected.to be_a(Build) }
it('returns with the first pending build') { is_expected.to eq(first) }
end
 
describe :create_from do
describe '.create_from' do
before do
build.status = 'success'
build.save
Loading
Loading
@@ -63,20 +63,20 @@ describe Build do
end
end
 
describe :started? do
describe '#started?' do
subject { build.started? }
 
context 'without started_at' do
before { build.started_at = nil }
 
it { should be_false }
it { is_expected.to be_falsey }
end
 
%w(running success failed).each do |status|
context "if build status is #{status}" do
before { build.status = status }
 
it { should be_true }
it { is_expected.to be_truthy }
end
end
 
Loading
Loading
@@ -84,19 +84,19 @@ describe Build do
context "if build status is #{status}" do
before { build.status = status }
 
it { should be_false }
it { is_expected.to be_falsey }
end
end
end
 
describe :active? do
describe '#active?' do
subject { build.active? }
 
%w(pending running).each do |state|
context "if build.status is #{state}" do
before { build.status = state }
 
it { should be_true }
it { is_expected.to be_truthy }
end
end
 
Loading
Loading
@@ -104,19 +104,19 @@ describe Build do
context "if build.status is #{state}" do
before { build.status = state }
 
it { should be_false }
it { is_expected.to be_falsey }
end
end
end
 
describe :complete? do
describe '#complete?' do
subject { build.complete? }
 
%w(success failed canceled).each do |state|
context "if build.status is #{state}" do
before { build.status = state }
 
it { should be_true }
it { is_expected.to be_truthy }
end
end
 
Loading
Loading
@@ -124,12 +124,12 @@ describe Build do
context "if build.status is #{state}" do
before { build.status = state }
 
it { should be_false }
it { is_expected.to be_falsey }
end
end
end
 
describe :ignored? do
describe '#ignored?' do
subject { build.ignored? }
 
context 'if build is not allowed to fail' do
Loading
Loading
@@ -138,13 +138,13 @@ describe Build do
context 'and build.status is success' do
before { build.status = 'success' }
 
it { should be_false }
it { is_expected.to be_falsey }
end
 
context 'and build.status is failed' do
before { build.status = 'failed' }
 
it { should be_false }
it { is_expected.to be_falsey }
end
end
 
Loading
Loading
@@ -154,41 +154,41 @@ describe Build do
context 'and build.status is success' do
before { build.status = 'success' }
 
it { should be_false }
it { is_expected.to be_falsey }
end
 
context 'and build.status is failed' do
before { build.status = 'failed' }
 
it { should be_true }
it { is_expected.to be_truthy }
end
end
end
 
describe :trace do
describe '#trace' do
subject { build.trace_html }
 
it { should be_empty }
it { is_expected.to be_empty }
 
context 'if build.trace contains text' do
let(:text) { 'example output' }
before { build.trace = text }
 
it { should include(text) }
it { should have_at_least(text.length).items }
it { is_expected.to include(text) }
it { expect(subject.length).to be >= text.length }
end
end
 
describe :timeout do
describe '#timeout' do
subject { build.timeout }
 
it { should eq(commit.project.timeout) }
it { is_expected.to eq(commit.project.timeout) }
end
 
describe :duration do
describe '#duration' do
subject { build.duration }
 
it { should eq(120.0) }
it { is_expected.to eq(120.0) }
 
context 'if the building process has not started yet' do
before do
Loading
Loading
@@ -196,7 +196,7 @@ describe Build do
build.finished_at = nil
end
 
it { should be_nil }
it { is_expected.to be_nil }
end
 
context 'if the building process has started' do
Loading
Loading
@@ -205,12 +205,12 @@ describe Build do
build.finished_at = nil
end
 
it { should be_a(Float) }
it { should > 0.0 }
it { is_expected.to be_a(Float) }
it { is_expected.to be > 0.0 }
end
end
 
describe :options do
describe '#options' do
let(:options) {
{
:image => "ruby:2.1",
Loading
Loading
@@ -221,90 +221,90 @@ describe Build do
}
 
subject { build.options }
it { should eq(options) }
it { is_expected.to eq(options) }
end
 
describe :ref do
describe '#ref' do
subject { build.ref }
 
it { should eq(commit.ref) }
it { is_expected.to eq(commit.ref) }
end
 
describe :sha do
describe '#sha' do
subject { build.sha }
 
it { should eq(commit.sha) }
it { is_expected.to eq(commit.sha) }
end
 
describe :short_sha do
describe '#short_sha' do
subject { build.short_sha }
 
it { should eq(commit.short_sha) }
it { is_expected.to eq(commit.short_sha) }
end
 
describe :before_sha do
describe '#before_sha' do
subject { build.before_sha }
 
it { should eq(commit.before_sha) }
it { is_expected.to eq(commit.before_sha) }
end
 
describe :allow_git_fetch do
describe '#allow_git_fetch' do
subject { build.allow_git_fetch }
 
it { should eq(project.allow_git_fetch) }
it { is_expected.to eq(project.allow_git_fetch) }
end
 
describe :project do
describe '#project' do
subject { build.project }
 
it { should eq(commit.project) }
it { is_expected.to eq(commit.project) }
end
 
describe :project_id do
describe '#project_id' do
subject { build.project_id }
 
it { should eq(commit.project_id) }
it { is_expected.to eq(commit.project_id) }
end
 
describe :project_name do
describe '#project_name' do
subject { build.project_name }
 
it { should eq(project.name) }
it { is_expected.to eq(project.name) }
end
 
describe :repo_url do
describe '#repo_url' do
subject { build.repo_url }
 
it { should eq(project.repo_url_with_auth) }
it { is_expected.to eq(project.repo_url_with_auth) }
end
 
describe :extract_coverage do
describe '#extract_coverage' do
context 'valid content & regex' do
subject { build.extract_coverage('Coverage 1033 / 1051 LOC (98.29%) covered', '\(\d+.\d+\%\) covered') }
 
it { should eq(98.29) }
it { is_expected.to eq(98.29) }
end
 
context 'valid content & bad regex' do
subject { build.extract_coverage('Coverage 1033 / 1051 LOC (98.29%) covered', 'very covered') }
 
it { should be_nil }
it { is_expected.to be_nil }
end
 
context 'no coverage content & regex' do
subject { build.extract_coverage('No coverage for today :sad:', '\(\d+.\d+\%\) covered') }
 
it { should be_nil }
it { is_expected.to be_nil }
end
 
context 'multiple results in content & regex' do
subject { build.extract_coverage(' (98.39%) covered. (98.29%) covered', '\(\d+.\d+\%\) covered') }
 
it { should eq(98.29) }
it { is_expected.to eq(98.29) }
end
end
 
describe :variables do
describe '#variables' do
context 'returns variables' do
subject { build.variables }
 
Loading
Loading
@@ -314,7 +314,7 @@ describe Build do
]
}
 
it { should eq(variables) }
it { is_expected.to eq(variables) }
 
context 'and secure variables' do
let(:secure_variables) {
Loading
Loading
@@ -327,7 +327,7 @@ describe Build do
build.project.variables << Variable.new(key: 'SECRET_KEY', value: 'secret_value')
end
 
it { should eq(variables + secure_variables) }
it { is_expected.to eq(variables + secure_variables) }
 
context 'and trigger variables' do
let(:trigger) { FactoryGirl.create :trigger, project: project }
Loading
Loading
@@ -342,7 +342,7 @@ describe Build do
build.trigger_request = trigger_request
end
 
it { should eq(variables + secure_variables + trigger_variables) }
it { is_expected.to eq(variables + secure_variables + trigger_variables) }
end
end
end
Loading
Loading
Loading
Loading
@@ -23,29 +23,29 @@ describe Commit do
let(:commit_with_project) { FactoryGirl.create :commit, project: project }
let(:config_processor) { GitlabCiYamlProcessor.new(gitlab_ci_yaml) }
 
it { should belong_to(:project) }
it { should have_many(:builds) }
it { should validate_presence_of :before_sha }
it { should validate_presence_of :sha }
it { should validate_presence_of :ref }
it { should validate_presence_of :push_data }
it { should respond_to :git_author_name }
it { should respond_to :git_author_email }
it { should respond_to :short_sha }
describe :last_build do
it { is_expected.to belong_to(:project) }
it { is_expected.to have_many(:builds) }
it { is_expected.to validate_presence_of :before_sha }
it { is_expected.to validate_presence_of :sha }
it { is_expected.to validate_presence_of :ref }
it { is_expected.to validate_presence_of :push_data }
it { is_expected.to respond_to :git_author_name }
it { is_expected.to respond_to :git_author_email }
it { is_expected.to respond_to :short_sha }
describe '#last_build' do
subject { commit.last_build }
before do
@first = FactoryGirl.create :build, commit: commit, created_at: Date.yesterday
@second = FactoryGirl.create :build, commit: commit
end
 
it { should be_a(Build) }
it('returns with the most recently created build') { should eq(@second) }
it { is_expected.to be_a(Build) }
it('returns with the most recently created build') { is_expected.to eq(@second) }
end
 
describe :retry do
describe '#retry' do
before do
@first = FactoryGirl.create :build, commit: commit, created_at: Date.yesterday
@second = FactoryGirl.create :build, commit: commit
Loading
Loading
@@ -58,7 +58,7 @@ describe Commit do
end
end
 
describe :project_recipients do
describe '#project_recipients' do
 
context 'always sending notification' do
it 'should return commit_pusher_email as only recipient when no additional recipients are given' do
Loading
Loading
@@ -67,8 +67,8 @@ describe Commit do
email_recipients: ''
commit = FactoryGirl.create :commit, project: project
expected = 'commit_pusher_email'
commit.stub(:push_data) { { user_email: expected } }
commit.project_recipients.should == [expected]
allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq [expected]
end
 
it 'should return commit_pusher_email and additional recipients' do
Loading
Loading
@@ -77,8 +77,8 @@ describe Commit do
email_recipients: 'rec1 rec2'
commit = FactoryGirl.create :commit, project: project
expected = 'commit_pusher_email'
commit.stub(:push_data) { { user_email: expected } }
commit.project_recipients.should == ['rec1', 'rec2', expected]
allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq ['rec1', 'rec2', expected]
end
 
it 'should return recipients' do
Loading
Loading
@@ -86,7 +86,7 @@ describe Commit do
email_add_pusher: false,
email_recipients: 'rec1 rec2'
commit = FactoryGirl.create :commit, project: project
commit.project_recipients.should == ['rec1', 'rec2']
expect(commit.project_recipients).to eq ['rec1', 'rec2']
end
 
it 'should return unique recipients only' do
Loading
Loading
@@ -95,76 +95,76 @@ describe Commit do
email_recipients: 'rec1 rec1 rec2'
commit = FactoryGirl.create :commit, project: project
expected = 'rec2'
commit.stub(:push_data) { { user_email: expected } }
commit.project_recipients.should == ['rec1', 'rec2']
allow(commit).to receive(:push_data) { { user_email: expected } }
expect(commit.project_recipients).to eq ['rec1', 'rec2']
end
end
end
 
describe :valid_commit_sha do
describe '#valid_commit_sha' do
context 'commit.sha can not start with 00000000' do
before do
commit.sha = '0' * 40
commit.valid_commit_sha
end
 
it('commit errors should not be empty') { commit.errors.should_not be_empty }
it('commit errors should not be empty') { expect(commit.errors).not_to be_empty }
end
end
 
describe :compare? do
describe '#compare?' do
subject { commit_with_project.compare? }
 
context 'if commit.before_sha are not nil' do
it { should be_true }
it { is_expected.to be_truthy }
end
end
 
describe :short_sha do
describe '#short_before_sha' do
subject { commit.short_before_sha }
 
it { should have(8).items }
it { commit.before_sha.should start_with(subject) }
it { expect(subject.length).to eq 8 }
it { expect(commit.before_sha).to start_with(subject) }
end
 
describe :short_sha do
describe '#short_sha' do
subject { commit.short_sha }
 
it { should have(8).items }
it { commit.sha.should start_with(subject) }
it { expect(subject.length).to eq 8 }
it { expect(commit.sha).to start_with(subject) }
end
 
describe :create_next_builds do
describe '#create_next_builds' do
before do
commit.stub(:config_processor).and_return(config_processor)
allow(commit).to receive(:config_processor).and_return(config_processor)
end
 
it "creates builds for next type" do
commit.create_builds.should be_true
expect(commit.create_builds).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
expect(commit.builds.size).to eq 2
 
commit.create_next_builds(nil).should be_true
expect(commit.create_next_builds(nil)).to be_truthy
commit.builds.reload
commit.builds.size.should == 4
expect(commit.builds.size).to eq 4
 
commit.create_next_builds(nil).should be_true
expect(commit.create_next_builds(nil)).to be_truthy
commit.builds.reload
commit.builds.size.should == 5
expect(commit.builds.size).to eq 5
 
commit.create_next_builds(nil).should be_false
expect(commit.create_next_builds(nil)).to be_falsey
end
end
 
describe :create_builds do
describe '#create_builds' do
before do
commit.stub(:config_processor).and_return(config_processor)
allow(commit).to receive(:config_processor).and_return(config_processor)
end
 
it 'creates builds' do
commit.create_builds.should be_true
expect(commit.create_builds).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
expect(commit.builds.size).to eq 2
end
 
context 'for build triggers' do
Loading
Loading
@@ -172,29 +172,29 @@ describe Commit do
let(:trigger_request) { FactoryGirl.create :trigger_request, commit: commit, trigger: trigger }
 
it 'creates builds' do
commit.create_builds(trigger_request).should be_true
expect(commit.create_builds(trigger_request)).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
expect(commit.builds.size).to eq 2
end
 
it 'rebuilds commit' do
commit.create_builds.should be_true
expect(commit.create_builds).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
expect(commit.builds.size).to eq 2
 
commit.create_builds(trigger_request).should be_true
expect(commit.create_builds(trigger_request)).to be_truthy
commit.builds.reload
commit.builds.size.should == 4
expect(commit.builds.size).to eq 4
end
 
it 'creates next builds' do
commit.create_builds(trigger_request).should be_true
expect(commit.create_builds(trigger_request)).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
expect(commit.builds.size).to eq 2
 
commit.create_next_builds(trigger_request).should be_true
expect(commit.create_next_builds(trigger_request)).to be_truthy
commit.builds.reload
commit.builds.size.should == 4
expect(commit.builds.size).to eq 4
end
 
context 'for [ci skip]' do
Loading
Loading
@@ -204,11 +204,11 @@ describe Commit do
end
 
it 'rebuilds commit' do
commit.status.should == 'skipped'
commit.create_builds(trigger_request).should be_true
expect(commit.status).to eq 'skipped'
expect(commit.create_builds(trigger_request)).to be_truthy
commit.builds.reload
commit.builds.size.should == 2
commit.status.should == 'pending'
expect(commit.builds.size).to eq 2
expect(commit.status).to eq 'pending'
end
end
end
Loading
Loading
@@ -222,13 +222,13 @@ describe Commit do
build = FactoryGirl.create :build, commit: commit, finished_at: Time.now - 60
build1 = FactoryGirl.create :build, commit: commit, finished_at: Time.now - 120
 
commit.finished_at.to_i.should == build.finished_at.to_i
expect(commit.finished_at.to_i).to eq build.finished_at.to_i
end
 
it "returns nil if there is no finished build" do
build = FactoryGirl.create :not_started_build, commit: commit
 
commit.finished_at.should be_nil
expect(commit.finished_at).to be_nil
end
end
 
Loading
Loading
@@ -239,26 +239,26 @@ describe Commit do
it "calculates average when there are two builds with coverage" do
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
commit.coverage.should == "35.00"
expect(commit.coverage).to eq "35.00"
end
 
it "calculates average when there are two builds with coverage and one with nil" do
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
FactoryGirl.create :build, commit: commit
commit.coverage.should == "35.00"
expect(commit.coverage).to eq "35.00"
end
 
it "calculates average when there are two builds with coverage and one is retried" do
FactoryGirl.create :build, name: "rspec", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 30, commit: commit
FactoryGirl.create :build, name: "rubocop", coverage: 40, commit: commit
commit.coverage.should == "35.00"
expect(commit.coverage).to eq "35.00"
end
 
it "calculates average when there is one build without coverage" do
FactoryGirl.create :build, commit: commit
commit.coverage.should be_nil
expect(commit.coverage).to be_nil
end
end
end
Loading
Loading
@@ -16,7 +16,7 @@ require 'spec_helper'
 
describe MailService do
describe "Associations" do
it { should belong_to :project }
it { is_expected.to belong_to :project }
end
 
describe "Validations" do
Loading
Loading
@@ -28,7 +28,7 @@ describe MailService do
end
 
describe 'Sends email for' do
let(:mail) { MailService.new }
let(:mail) { described_class.new }
 
describe 'failed build' do
let(:project) { FactoryGirl.create(:project, email_add_pusher: true) }
Loading
Loading
@@ -36,9 +36,7 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :failed, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
end
 
it do
Loading
Loading
@@ -47,8 +45,8 @@ describe MailService do
end
 
def should_email(email)
Notify.should_receive(:build_fail_email).with(build.id, email)
Notify.should_not_receive(:build_success_email).with(build.id, email)
expect(Notify).to receive(:build_fail_email).with(build.id, email)
expect(Notify).not_to receive(:build_success_email).with(build.id, email)
end
end
 
Loading
Loading
@@ -58,9 +56,7 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
end
 
it do
Loading
Loading
@@ -69,8 +65,8 @@ describe MailService do
end
 
def should_email(email)
Notify.should_receive(:build_success_email).with(build.id, email)
Notify.should_not_receive(:build_fail_email).with(build.id, email)
expect(Notify).to receive(:build_success_email).with(build.id, email)
expect(Notify).not_to receive(:build_fail_email).with(build.id, email)
end
end
 
Loading
Loading
@@ -85,9 +81,7 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
end
 
it do
Loading
Loading
@@ -97,8 +91,8 @@ describe MailService do
end
 
def should_email(email)
Notify.should_receive(:build_success_email).with(build.id, email)
Notify.should_not_receive(:build_fail_email).with(build.id, email)
expect(Notify).to receive(:build_success_email).with(build.id, email)
expect(Notify).not_to receive(:build_fail_email).with(build.id, email)
end
end
 
Loading
Loading
@@ -113,9 +107,7 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
end
 
it do
Loading
Loading
@@ -125,8 +117,8 @@ describe MailService do
end
 
def should_email(email)
Notify.should_not_receive(:build_success_email).with(build.id, email)
Notify.should_not_receive(:build_fail_email).with(build.id, email)
expect(Notify).not_to receive(:build_success_email).with(build.id, email)
expect(Notify).not_to receive(:build_fail_email).with(build.id, email)
end
end
 
Loading
Loading
@@ -141,14 +133,12 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :success, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
build
end
 
it do
mail.can_test?.should == true
expect(mail.can_test?).to eq true
end
end
 
Loading
Loading
@@ -163,9 +153,7 @@ describe MailService do
let(:build) { FactoryGirl.create(:build, status: :failed, commit: commit) }
 
before do
mail.stub(
project: project
)
allow(mail).to receive_messages(project: project)
end
 
it do
Loading
Loading
@@ -176,8 +164,8 @@ describe MailService do
end
 
def should_email(email)
Notify.should_not_receive(:build_success_email).with(build.id, email)
Notify.should_not_receive(:build_fail_email).with(build.id, email)
expect(Notify).not_to receive(:build_success_email).with(build.id, email)
expect(Notify).not_to receive(:build_fail_email).with(build.id, email)
end
end
end
Loading
Loading
require 'spec_helper'
 
describe Network do
let(:network) { Network.new }
let(:network) { described_class.new }
 
describe :enable_ci do
describe '#enable_ci' do
subject { network.enable_ci '', '', '' }
 
context 'on success' do
before do
response = double
response.stub(:code) { 200 }
network.class.stub(:put) { response }
allow(response).to receive(:code) { 200 }
allow(network.class).to receive(:put) { response }
end
 
it { should be_true }
it { is_expected.to be_truthy }
end
 
context 'on failure' do
before do
response = double
response.stub(:code) { 404 }
network.class.stub(:put) { response }
allow(response).to receive(:code) { 404 }
allow(network.class).to receive(:put) { response }
end
 
it { should be_nil }
it { is_expected.to be_nil }
end
end
 
describe :disable_ci do
describe '#disable_ci' do
let(:response) { double }
subject { network.disable_ci '', '' }
 
context 'on success' do
let(:parsed_response) { 'parsed' }
before do
response.stub(:code) { 200 }
response.stub(:parsed_response) { parsed_response }
network.class.stub(:delete) { response }
allow(response).to receive(:code) { 200 }
allow(response).to receive(:parsed_response) { parsed_response }
allow(network.class).to receive(:delete) { response }
end
 
it { should equal(parsed_response) }
it { is_expected.to equal(parsed_response) }
end
 
context 'on failure' do
before do
response.stub(:code) { 404 }
network.class.stub(:delete) { response }
allow(response).to receive(:code) { 404 }
allow(network.class).to receive(:delete) { response }
end
 
it { should be_nil }
it { is_expected.to be_nil }
end
end
end
require 'spec_helper'
 
describe HipChatMessage do
subject { HipChatMessage.new(build) }
subject { described_class.new(build) }
 
let(:project) { FactoryGirl.create(:project) }
 
Loading
Loading
@@ -18,7 +18,7 @@ describe HipChatMessage do
build.update(status: "success")
expect( subject.status_color ).to eq 'green'
expect( subject.notify? ).to be_false
expect( subject.notify? ).to be_falsey
expect( subject.to_s ).to match(/Build '[^']+' #\d+/)
expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./)
end
Loading
Loading
@@ -29,7 +29,7 @@ describe HipChatMessage do
build.update(status: "failed")
 
expect( subject.status_color ).to eq 'red'
expect( subject.notify? ).to be_true
expect( subject.notify? ).to be_truthy
expect( subject.to_s ).to match(/Build '[^']+' #\d+/)
expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./)
end
Loading
Loading
@@ -50,7 +50,7 @@ describe HipChatMessage do
commit.reload
 
expect( subject.status_color ).to eq 'green'
expect( subject.notify? ).to be_false
expect( subject.notify? ).to be_falsey
expect( subject.to_s ).to match(/Commit #\d+/)
expect( subject.to_s ).to match(/Successful in \d+ second\(s\)\./)
end
Loading
Loading
@@ -65,7 +65,7 @@ describe HipChatMessage do
second_build.update(status: "failed")
expect( subject.status_color ).to eq 'red'
expect( subject.notify? ).to be_true
expect( subject.notify? ).to be_truthy
expect( subject.to_s ).to match(/Commit #\d+/)
expect( subject.to_s ).to match(/Failed in \d+ second\(s\)\./)
end
Loading
Loading
Loading
Loading
@@ -24,22 +24,22 @@ describe HipChatService do
subject.active = true
end
 
it { should validate_presence_of :hipchat_room }
it { should validate_presence_of :hipchat_token }
it { is_expected.to validate_presence_of :hipchat_room }
it { is_expected.to validate_presence_of :hipchat_token }
 
end
end
 
describe "Execute" do
 
let(:service) { HipChatService.new }
let(:service) { described_class.new }
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit, status: 'failed' }
let(:api_url) { 'https://api.hipchat.com/v2/room/123/notification?auth_token=a1b2c3d4e5f6' }
 
before do
service.stub(
allow(service).to receive_messages(
project: project,
project_id: project.id,
notify_only_broken_builds: false,
Loading
Loading
require 'spec_helper'
 
describe SlackMessage do
subject { SlackMessage.new(commit) }
subject { described_class.new(commit) }
 
let(:project) { FactoryGirl.create :project }
 
Loading
Loading
@@ -19,11 +19,11 @@ describe SlackMessage do
it 'returns a message with succeeded build' do
build.update(status: "success")
 
subject.color.should == color
subject.fallback.should include('Build')
subject.fallback.should include("\##{build.id}")
subject.fallback.should include('succeeded')
subject.attachments.first[:fields].should be_empty
expect(subject.color).to eq color
expect(subject.fallback).to include('Build')
expect(subject.fallback).to include("\##{build.id}")
expect(subject.fallback).to include('succeeded')
expect(subject.attachments.first[:fields]).to be_empty
end
end
 
Loading
Loading
@@ -33,11 +33,11 @@ describe SlackMessage do
it 'returns a message with failed build' do
build.update(status: "failed")
 
subject.color.should == color
subject.fallback.should include('Build')
subject.fallback.should include("\##{build.id}")
subject.fallback.should include('failed')
subject.attachments.first[:fields].should be_empty
expect(subject.color).to eq color
expect(subject.fallback).to include('Build')
expect(subject.fallback).to include("\##{build.id}")
expect(subject.fallback).to include('failed')
expect(subject.attachments.first[:fields]).to be_empty
end
end
end
Loading
Loading
@@ -53,11 +53,11 @@ describe SlackMessage do
commit.builds.update_all(status: "success")
commit.reload
 
subject.color.should == color
subject.fallback.should include('Commit')
subject.fallback.should include("\##{commit.id}")
subject.fallback.should include('succeeded')
subject.attachments.first[:fields].should be_empty
expect(subject.color).to eq color
expect(subject.fallback).to include('Commit')
expect(subject.fallback).to include("\##{commit.id}")
expect(subject.fallback).to include('succeeded')
expect(subject.attachments.first[:fields]).to be_empty
end
end
 
Loading
Loading
@@ -71,13 +71,13 @@ describe SlackMessage do
first_build.update(status: "success")
second_build.update(status: "failed")
subject.color.should == color
subject.fallback.should include('Commit')
subject.fallback.should include("\##{commit.id}")
subject.fallback.should include('failed')
subject.attachments.first[:fields].size.should == 1
subject.attachments.first[:fields].first[:title].should == second_build.name
subject.attachments.first[:fields].first[:value].should include("\##{second_build.id}")
expect(subject.color).to eq color
expect(subject.fallback).to include('Commit')
expect(subject.fallback).to include("\##{commit.id}")
expect(subject.fallback).to include('failed')
expect(subject.attachments.first[:fields].size).to eq 1
expect(subject.attachments.first[:fields].first[:title]).to eq second_build.name
expect(subject.attachments.first[:fields].first[:value]).to include("\##{second_build.id}")
end
end
end
Loading
Loading
Loading
Loading
@@ -16,7 +16,7 @@ require 'spec_helper'
 
describe SlackService do
describe "Associations" do
it { should belong_to :project }
it { is_expected.to belong_to :project }
end
 
describe "Validations" do
Loading
Loading
@@ -25,12 +25,12 @@ describe SlackService do
subject.active = true
end
 
it { should validate_presence_of :webhook }
it { is_expected.to validate_presence_of :webhook }
end
end
 
describe "Execute" do
let(:slack) { SlackService.new }
let(:slack) { described_class.new }
let(:project) { FactoryGirl.create :project }
let(:commit) { FactoryGirl.create :commit, project: project }
let(:build) { FactoryGirl.create :build, commit: commit, status: 'failed' }
Loading
Loading
@@ -38,7 +38,7 @@ describe SlackService do
let(:notify_only_broken_builds) { false }
 
before do
slack.stub(
allow(slack).to receive_messages(
project: project,
project_id: project.id,
webhook: webhook_url,
Loading
Loading
@@ -52,7 +52,7 @@ describe SlackService do
slack.execute(build)
SlackNotifierWorker.drain
 
WebMock.should have_requested(:post, webhook_url).once
expect(WebMock).to have_requested(:post, webhook_url).once
end
end
end
Loading
Loading
@@ -30,21 +30,21 @@ require 'spec_helper'
describe Project do
subject { FactoryGirl.build :project }
 
it { should have_many(:commits) }
it { is_expected.to have_many(:commits) }
 
it { should validate_presence_of :name }
it { should validate_presence_of :timeout }
it { should validate_presence_of :default_ref }
it { is_expected.to validate_presence_of :name }
it { is_expected.to validate_presence_of :timeout }
it { is_expected.to validate_presence_of :default_ref }
 
describe 'before_validation' do
it 'should set an random token if none provided' do
project = FactoryGirl.create :project_without_token
project.token.should_not == ""
expect(project.token).not_to eq ""
end
 
it 'should not set an random toke if one provided' do
project = FactoryGirl.create :project
project.token.should == "iPWx6WM4lhHNedGfBpPJNP"
expect(project.token).to eq "iPWx6WM4lhHNedGfBpPJNP"
end
end
 
Loading
Loading
@@ -57,7 +57,7 @@ describe Project do
FactoryGirl.create :commit, committed_at: 1.hour.ago, project: newest_project
FactoryGirl.create :commit, committed_at: 2.hour.ago, project: oldest_project
 
Project.ordered_by_last_commit_date.should == [newest_project, oldest_project, project_without_commits]
expect(described_class.ordered_by_last_commit_date).to eq [newest_project, oldest_project, project_without_commits]
end
end
 
Loading
Loading
@@ -88,116 +88,116 @@ describe Project do
FactoryGirl.create(:build, commit: commit)
end
 
it { project.status.should == 'pending' }
it { project.last_commit.should be_kind_of(Commit) }
it { project.human_status.should == 'pending' }
it { expect(project.status).to eq 'pending' }
it { expect(project.last_commit).to be_kind_of(Commit) }
it { expect(project.human_status).to eq 'pending' }
end
end
 
describe '#email_notification?' do
it do
project = FactoryGirl.create :project, email_add_pusher: true
project.email_notification?.should == true
expect(project.email_notification?).to eq true
end
 
it do
project = FactoryGirl.create :project, email_add_pusher: false, email_recipients: 'test tesft'
project.email_notification?.should == true
expect(project.email_notification?).to eq true
end
 
it do
project = FactoryGirl.create :project, email_add_pusher: false, email_recipients: ''
project.email_notification?.should == false
expect(project.email_notification?).to eq false
end
end
 
describe '#broken_or_success?' do
it {
project = FactoryGirl.create :project, email_add_pusher: true
project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(true)
project.broken_or_success?.should == true
allow(project).to receive(:broken?).and_return(true)
allow(project).to receive(:success?).and_return(true)
expect(project.broken_or_success?).to eq true
}
 
it {
project = FactoryGirl.create :project, email_add_pusher: true
project.stub(:broken?).and_return(true)
project.stub(:success?).and_return(false)
project.broken_or_success?.should == true
allow(project).to receive(:broken?).and_return(true)
allow(project).to receive(:success?).and_return(false)
expect(project.broken_or_success?).to eq true
}
 
it {
project = FactoryGirl.create :project, email_add_pusher: true
project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(true)
project.broken_or_success?.should == true
allow(project).to receive(:broken?).and_return(false)
allow(project).to receive(:success?).and_return(true)
expect(project.broken_or_success?).to eq true
}
 
it {
project = FactoryGirl.create :project, email_add_pusher: true
project.stub(:broken?).and_return(false)
project.stub(:success?).and_return(false)
project.broken_or_success?.should == false
allow(project).to receive(:broken?).and_return(false)
allow(project).to receive(:success?).and_return(false)
expect(project.broken_or_success?).to eq false
}
end
 
describe 'Project.parse' do
describe '.parse' do
let(:project_dump) { YAML.load File.read(Rails.root.join('spec/support/gitlab_stubs/raw_project.yml')) }
let(:parsed_project) { Project.parse(project_dump) }
let(:parsed_project) { described_class.parse(project_dump) }
 
it { parsed_project.should be_valid }
it { parsed_project.should be_kind_of(Project) }
it { parsed_project.name.should eq("GitLab / api.gitlab.org") }
it { parsed_project.gitlab_id.should eq(189) }
it { parsed_project.gitlab_url.should eq("http://demo.gitlab.com/gitlab/api-gitlab-org") }
it { expect(parsed_project).to be_valid }
it { expect(parsed_project).to be_kind_of(described_class) }
it { expect(parsed_project.name).to eq("GitLab / api.gitlab.org") }
it { expect(parsed_project.gitlab_id).to eq(189) }
it { expect(parsed_project.gitlab_url).to eq("http://demo.gitlab.com/gitlab/api-gitlab-org") }
 
it "parses plain hash" do
Project.parse(project_dump).name.should eq("GitLab / api.gitlab.org")
expect(described_class.parse(project_dump).name).to eq("GitLab / api.gitlab.org")
end
end
 
describe :repo_url_with_auth do
describe '#repo_url_with_auth' do
let(:project) { FactoryGirl.create :project }
subject { project.repo_url_with_auth }
 
it { should be_a(String) }
it { should end_with(".git") }
it { should start_with(project.gitlab_url[0..6]) }
it { should include(project.token) }
it { should include('gitlab-ci-token') }
it { should include(project.gitlab_url[7..-1]) }
it { is_expected.to be_a(String) }
it { is_expected.to end_with(".git") }
it { is_expected.to start_with(project.gitlab_url[0..6]) }
it { is_expected.to include(project.token) }
it { is_expected.to include('gitlab-ci-token') }
it { is_expected.to include(project.gitlab_url[7..-1]) }
end
 
describe :search do
describe '.search' do
let!(:project) { FactoryGirl.create(:project, name: "foo") }
 
it { Project.search('fo').should include(project) }
it { Project.search('bar').should be_empty }
it { expect(described_class.search('fo')).to include(project) }
it { expect(described_class.search('bar')).to be_empty }
end
 
describe :any_runners do
describe '#any_runners' do
it "there are no runners available" do
project = FactoryGirl.create(:project)
project.any_runners?.should be_false
expect(project.any_runners?).to be_falsey
end
 
it "there is a specific runner" do
project = FactoryGirl.create(:project)
project.runners << FactoryGirl.create(:specific_runner)
project.any_runners?.should be_true
expect(project.any_runners?).to be_truthy
end
 
it "there is a shared runner" do
project = FactoryGirl.create(:project, shared_runners_enabled: true)
FactoryGirl.create(:shared_runner)
project.any_runners?.should be_true
expect(project.any_runners?).to be_truthy
end
 
it "there is a shared runner, but they are prohibited to use" do
project = FactoryGirl.create(:project)
FactoryGirl.create(:shared_runner)
project.any_runners?.should be_false
expect(project.any_runners?).to be_falsey
end
end
end
# == Schema Information
#
# Table name: runner_projects
#
# id :integer not null, primary key
# runner_id :integer not null
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
#
require 'spec_helper'
describe RunnerProject do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading
Loading
@@ -37,15 +37,15 @@ describe Runner do
end
end
 
describe :assign_to do
describe '#assign_to' do
let!(:project) { FactoryGirl.create :project }
let!(:shared_runner) { FactoryGirl.create(:shared_runner) }
 
before { shared_runner.assign_to(project) }
 
it { shared_runner.should be_specific }
it { shared_runner.projects.should == [project] }
it { shared_runner.only_for?(project).should be_true }
it { expect(shared_runner).to be_specific }
it { expect(shared_runner.projects).to eq [project] }
it { expect(shared_runner.only_for?(project)).to be_truthy }
end
 
describe "belongs_to_one_project?" do
Loading
Loading
@@ -56,7 +56,7 @@ describe Runner do
project.runners << runner
project1.runners << runner
 
runner.belongs_to_one_project?.should be_false
expect(runner.belongs_to_one_project?).to be_falsey
end
 
it "returns true" do
Loading
Loading
@@ -64,7 +64,7 @@ describe Runner do
project = FactoryGirl.create(:project)
project.runners << runner
 
runner.belongs_to_one_project?.should be_true
expect(runner.belongs_to_one_project?).to be_truthy
end
end
end
Loading
Loading
@@ -17,7 +17,7 @@ require 'spec_helper'
describe Service do
 
describe "Associations" do
it { should belong_to :project }
it { is_expected.to belong_to :project }
end
 
describe "Mass assignment" do
Loading
Loading
@@ -25,7 +25,7 @@ describe Service do
 
describe "Test Button" do
before do
@service = Service.new
@service = described_class.new
end
 
describe "Testable" do
Loading
Loading
@@ -34,15 +34,13 @@ describe Service do
let (:build) { FactoryGirl.create :build, commit: commit }
 
before do
@service.stub(
project: project
)
allow(@service).to receive_messages(project: project)
build
@testable = @service.can_test?
end
 
describe :can_test do
it { @testable.should == true }
describe '#can_test' do
it { expect(@testable).to eq true }
end
end
end
Loading
Loading
Loading
Loading
@@ -6,12 +6,12 @@ describe Trigger do
describe 'before_validation' do
it 'should set an random token if none provided' do
trigger = FactoryGirl.create :trigger_without_token, project: project
trigger.token.should_not be_nil
expect(trigger.token).not_to be_nil
end
 
it 'should not set an random token if one provided' do
trigger = FactoryGirl.create :trigger, project: project
trigger.token.should == 'token'
expect(trigger.token).to eq 'token'
end
end
end
Loading
Loading
@@ -4,7 +4,7 @@ describe User do
 
describe "has_developer_access?" do
before do
@user = User.new({})
@user = described_class.new({})
end
 
let(:project_with_owner_access) do
Loading
Loading
@@ -40,39 +40,39 @@ describe User do
end
 
it "returns false for reporter" do
@user.stub(:project_info).and_return(project_with_reporter_access)
allow(@user).to receive(:project_info).and_return(project_with_reporter_access)
 
@user.has_developer_access?(1).should be_false
expect(@user.has_developer_access?(1)).to be_falsey
end
 
it "returns true for owner" do
@user.stub(:project_info).and_return(project_with_owner_access)
allow(@user).to receive(:project_info).and_return(project_with_owner_access)
 
@user.has_developer_access?(1).should be_true
expect(@user.has_developer_access?(1)).to be_truthy
end
end
 
describe "authorized_projects" do
let (:user) { User.new({}) }
let (:user) { described_class.new({}) }
 
before do
FactoryGirl.create :project, gitlab_id: 1
FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
allow_any_instance_of(described_class).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
end
 
it "returns projects" do
User.any_instance.stub(:can_manage_project?).and_return(true)
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(true)
 
user.authorized_projects.count.should == 2
expect(user.authorized_projects.count).to eq 2
end
 
it "empty list if user miss manage permission" do
User.any_instance.stub(:can_manage_project?).and_return(false)
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(false)
 
user.authorized_projects.count.should == 0
expect(user.authorized_projects.count).to eq 0
end
end
 
Loading
Loading
@@ -82,9 +82,9 @@ describe User do
project1 = FactoryGirl.create :project, gitlab_id: 2
gitlab_project = OpenStruct.new({id: 1})
gitlab_project1 = OpenStruct.new({id: 2})
User.any_instance.stub(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
User.any_instance.stub(:can_manage_project?).and_return(true)
user = User.new({})
allow_any_instance_of(described_class).to receive(:gitlab_projects).and_return([gitlab_project, gitlab_project1])
allow_any_instance_of(described_class).to receive(:can_manage_project?).and_return(true)
user = described_class.new({})
 
runner = FactoryGirl.create :specific_runner
runner1 = FactoryGirl.create :specific_runner
Loading
Loading
@@ -93,8 +93,8 @@ describe User do
project.runners << runner
project1.runners << runner1
 
user.authorized_runners.should include(runner, runner1)
user.authorized_runners.should_not include(runner2)
expect(user.authorized_runners).to include(runner, runner1)
expect(user.authorized_runners).not_to include(runner2)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment