Skip to content
代码片段 群组 项目
提交 0c4a70a3 编辑于 作者: Jeroen van Baarsen's avatar Jeroen van Baarsen
浏览文件

Updated rspec to rspec 3.x syntax

上级 de1c450a
No related branches found
No related tags found
无相关合并请求
显示
104 个添加104 个删除
...@@ -4,4 +4,4 @@ begin ...@@ -4,4 +4,4 @@ begin
rescue LoadError rescue LoadError
end end
require 'bundler/setup' require 'bundler/setup'
load Gem.bin_path('rspec', 'rspec') load Gem.bin_path('rspec-core', 'rspec')
...@@ -7,26 +7,26 @@ ...@@ -7,26 +7,26 @@
it 'should redirect if the user is over their password expiry' do it 'should redirect if the user is over their password expiry' do
user.password_expires_at = Time.new(2002) user.password_expires_at = Time.new(2002)
user.ldap_user?.should be_false expect(user.ldap_user?).to be_falsey
controller.stub(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
controller.should_receive(:redirect_to) expect(controller).to receive(:redirect_to)
controller.should_receive(:new_profile_password_path) expect(controller).to receive(:new_profile_password_path)
controller.send(:check_password_expiration) controller.send(:check_password_expiration)
end end
it 'should not redirect if the user is under their password expiry' do it 'should not redirect if the user is under their password expiry' do
user.password_expires_at = Time.now + 20010101 user.password_expires_at = Time.now + 20010101
user.ldap_user?.should be_false expect(user.ldap_user?).to be_falsey
controller.stub(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
controller.should_not_receive(:redirect_to) expect(controller).not_to receive(:redirect_to)
controller.send(:check_password_expiration) controller.send(:check_password_expiration)
end end
it 'should not redirect if the user is over their password expiry but they are an ldap user' do it 'should not redirect if the user is over their password expiry but they are an ldap user' do
user.password_expires_at = Time.new(2002) user.password_expires_at = Time.new(2002)
user.stub(:ldap_user?).and_return(true) allow(user).to receive(:ldap_user?).and_return(true)
controller.stub(:current_user).and_return(user) allow(controller).to receive(:current_user).and_return(user)
controller.should_not_receive(:redirect_to) expect(controller).not_to receive(:redirect_to)
controller.send(:check_password_expiration) controller.send(:check_password_expiration)
end end
end end
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
project.team << [user, :master] project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz']) allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0']) allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0'])
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
end end
...@@ -21,17 +21,17 @@ ...@@ -21,17 +21,17 @@
context "valid branch, valid file" do context "valid branch, valid file" do
let(:id) { 'master/README.md' } let(:id) { 'master/README.md' }
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context "valid branch, invalid file" do context "valid branch, invalid file" do
let(:id) { 'master/invalid-path.rb' } let(:id) { 'master/invalid-path.rb' }
it { should respond_with(:not_found) } it { is_expected.to respond_with(:not_found) }
end end
context "invalid branch, valid file" do context "invalid branch, valid file" do
let(:id) { 'invalid-branch/README.md' } let(:id) { 'invalid-branch/README.md' }
it { should respond_with(:not_found) } it { is_expected.to respond_with(:not_found) }
end end
end end
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
context 'redirect to tree' do context 'redirect to tree' do
let(:id) { 'markdown/doc' } let(:id) { 'markdown/doc' }
it { should redirect_to("/#{project.path_with_namespace}/tree/markdown/doc") } it { is_expected.to redirect_to("/#{project.path_with_namespace}/tree/markdown/doc") }
end end
end end
end end
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
project.team << [user, :master] project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz']) allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0']) allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0'])
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
end end
...@@ -27,25 +27,25 @@ ...@@ -27,25 +27,25 @@
context "valid branch name, valid source" do context "valid branch name, valid source" do
let(:branch) { "merge_branch" } let(:branch) { "merge_branch" }
let(:ref) { "master" } let(:ref) { "master" }
it { should redirect_to("/#{project.path_with_namespace}/tree/merge_branch") } it { is_expected.to redirect_to("/#{project.path_with_namespace}/tree/merge_branch") }
end end
context "invalid branch name, valid ref" do context "invalid branch name, valid ref" do
let(:branch) { "<script>alert('merge');</script>" } let(:branch) { "<script>alert('merge');</script>" }
let(:ref) { "master" } let(:ref) { "master" }
it { should redirect_to("/#{project.path_with_namespace}/tree/alert('merge');") } it { is_expected.to redirect_to("/#{project.path_with_namespace}/tree/alert('merge');") }
end end
context "valid branch name, invalid ref" do context "valid branch name, invalid ref" do
let(:branch) { "merge_branch" } let(:branch) { "merge_branch" }
let(:ref) { "<script>alert('ref');</script>" } let(:ref) { "<script>alert('ref');</script>" }
it { should render_template("new") } it { is_expected.to render_template("new") }
end end
context "invalid branch name, invalid ref" do context "invalid branch name, invalid ref" do
let(:branch) { "<script>alert('merge');</script>" } let(:branch) { "<script>alert('merge');</script>" }
let(:ref) { "<script>alert('ref');</script>" } let(:ref) { "<script>alert('ref');</script>" }
it { should render_template("new") } it { is_expected.to render_template("new") }
end end
end end
end end
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
end end
it "should generate it" do it "should generate it" do
Commit.any_instance.should_receive(:"to_#{format}") expect_any_instance_of(Commit).to receive(:"to_#{format}")
get :show, project_id: project.to_param, id: commit.id, format: format get :show, project_id: project.to_param, id: commit.id, format: format
end end
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
end end
it "should not escape Html" do it "should not escape Html" do
Commit.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ') allow_any_instance_of(Commit).to receive(:"to_#{format}").and_return('HTML entities &<>" ')
get :show, project_id: project.to_param, id: commit.id, format: format get :show, project_id: project.to_param, id: commit.id, format: format
......
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
context "as atom feed" do context "as atom feed" do
it "should render as atom" do it "should render as atom" do
get :show, project_id: project.to_param, id: "master", format: "atom" get :show, project_id: project.to_param, id: "master", format: "atom"
response.should be_success expect(response).to be_success
response.content_type.should == 'application/atom+xml' expect(response.content_type).to eq('application/atom+xml')
end end
end end
end end
......
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
describe "GET callback" do describe "GET callback" do
it "updates access token" do it "updates access token" do
token = "asdasd12345" token = "asdasd12345"
Gitlab::GithubImport::Client.any_instance.stub(:get_token).and_return(token) allow_any_instance_of(Gitlab::GithubImport::Client).to receive(:get_token).and_return(token)
Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "github") Gitlab.config.omniauth.providers << OpenStruct.new(app_id: "asd123", app_secret: "asd123", name: "github")
get :callback get :callback
user.reload.github_access_token.should == token expect(user.reload.github_access_token).to eq(token)
controller.should redirect_to(status_import_github_url) expect(controller).to redirect_to(status_import_github_url)
end end
end end
...@@ -55,7 +55,7 @@ ...@@ -55,7 +55,7 @@
it "takes already existing namespace" do it "takes already existing namespace" do
namespace = create(:namespace, name: "john", owner: user) namespace = create(:namespace, name: "john", owner: user)
Gitlab::GithubImport::ProjectCreator.should_receive(:new).with(@repo, namespace, user). expect(Gitlab::GithubImport::ProjectCreator).to receive(:new).with(@repo, namespace, user).
and_return(double(execute: true)) and_return(double(execute: true))
controller.stub_chain(:client, :repo).and_return(@repo) controller.stub_chain(:client, :repo).and_return(@repo)
......
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
get :callback get :callback
user.reload.gitlab_access_token.should == token expect(user.reload.gitlab_access_token).to eq(token)
controller.should redirect_to(status_import_gitlab_url) expect(controller).to redirect_to(status_import_gitlab_url)
end end
end end
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
it "takes already existing namespace" do it "takes already existing namespace" do
namespace = create(:namespace, name: "john", owner: user) namespace = create(:namespace, name: "john", owner: user)
Gitlab::GitlabImport::ProjectCreator.should_receive(:new).with(@repo, namespace, user). expect(Gitlab::GitlabImport::ProjectCreator).to receive(:new).with(@repo, namespace, user).
and_return(double(execute: true)) and_return(double(execute: true))
controller.stub_chain(:client, :project).and_return(@repo) controller.stub_chain(:client, :project).and_return(@repo)
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
end end
it "should generate it" do it "should generate it" do
MergeRequest.any_instance.should_receive(:"to_#{format}") expect_any_instance_of(MergeRequest).to receive(:"to_#{format}")
get :show, project_id: project.to_param, id: merge_request.iid, format: format get :show, project_id: project.to_param, id: merge_request.iid, format: format
end end
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
end end
it "should not escape Html" do it "should not escape Html" do
MergeRequest.any_instance.stub(:"to_#{format}").and_return('HTML entities &<>" ') allow_any_instance_of(MergeRequest).to receive(:"to_#{format}").and_return('HTML entities &<>" ')
get :show, project_id: project.to_param, id: merge_request.iid, format: format get :show, project_id: project.to_param, id: merge_request.iid, format: format
......
...@@ -45,18 +45,18 @@ ...@@ -45,18 +45,18 @@
describe "POST #toggle_star" do describe "POST #toggle_star" do
it "toggles star if user is signed in" do it "toggles star if user is signed in" do
sign_in(user) sign_in(user)
expect(user.starred?(public_project)).to be_false expect(user.starred?(public_project)).to be_falsey
post :toggle_star, id: public_project.to_param post :toggle_star, id: public_project.to_param
expect(user.starred?(public_project)).to be_true expect(user.starred?(public_project)).to be_truthy
post :toggle_star, id: public_project.to_param post :toggle_star, id: public_project.to_param
expect(user.starred?(public_project)).to be_false expect(user.starred?(public_project)).to be_falsey
end end
it "does nothing if user is not signed in" do it "does nothing if user is not signed in" do
post :toggle_star, id: public_project.to_param post :toggle_star, id: public_project.to_param
expect(user.starred?(public_project)).to be_false expect(user.starred?(public_project)).to be_falsey
post :toggle_star, id: public_project.to_param post :toggle_star, id: public_project.to_param
expect(user.starred?(public_project)).to be_false expect(user.starred?(public_project)).to be_falsey
end end
end end
end end
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
project.team << [user, :master] project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz']) allow(project).to receive(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0']) allow(project).to receive(:tags).and_return(['v1.0.0', 'v2.0.0'])
controller.instance_variable_set(:@project, project) controller.instance_variable_set(:@project, project)
end end
...@@ -22,22 +22,22 @@ ...@@ -22,22 +22,22 @@
context "valid branch, no path" do context "valid branch, no path" do
let(:id) { 'master' } let(:id) { 'master' }
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context "valid branch, valid path" do context "valid branch, valid path" do
let(:id) { 'master/encoding/' } let(:id) { 'master/encoding/' }
it { should respond_with(:success) } it { is_expected.to respond_with(:success) }
end end
context "valid branch, invalid path" do context "valid branch, invalid path" do
let(:id) { 'master/invalid-path/' } let(:id) { 'master/invalid-path/' }
it { should respond_with(:not_found) } it { is_expected.to respond_with(:not_found) }
end end
context "invalid branch, valid path" do context "invalid branch, valid path" do
let(:id) { 'invalid-branch/encoding/' } let(:id) { 'invalid-branch/encoding/' }
it { should respond_with(:not_found) } it { is_expected.to respond_with(:not_found) }
end end
end end
...@@ -50,7 +50,7 @@ ...@@ -50,7 +50,7 @@
context 'redirect to blob' do context 'redirect to blob' do
let(:id) { 'master/README.md' } let(:id) { 'master/README.md' }
it { should redirect_to("/#{project.path_with_namespace}/blob/master/README.md") } it { is_expected.to redirect_to("/#{project.path_with_namespace}/blob/master/README.md") }
end end
end end
end end
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
next if INVALID_FACTORIES.include?(factory_name) next if INVALID_FACTORIES.include?(factory_name)
describe "#{factory_name} factory" do describe "#{factory_name} factory" do
it 'should be valid' do it 'should be valid' do
build(factory_name).should be_valid expect(build(factory_name)).to be_valid
end end
end end
end end
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
within ".sidebar-wrapper" do within ".sidebar-wrapper" do
click_on "Hooks" click_on "Hooks"
end end
current_path.should == admin_hooks_path expect(current_path).to eq(admin_hooks_path)
end end
it "should have hooks list" do it "should have hooks list" do
visit admin_hooks_path visit admin_hooks_path
page.should have_content(@system_hook.url) expect(page).to have_content(@system_hook.url)
end end
end end
...@@ -33,8 +33,8 @@ ...@@ -33,8 +33,8 @@
end end
it "should open new hook popup" do it "should open new hook popup" do
current_path.should == admin_hooks_path expect(current_path).to eq(admin_hooks_path)
page.should have_content(@url) expect(page).to have_content(@url)
end end
end end
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
click_link "Test Hook" click_link "Test Hook"
end end
it { current_path.should == admin_hooks_path } it { expect(current_path).to eq(admin_hooks_path) }
end end
end end
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
end end
it "should be ok" do it "should be ok" do
current_path.should == admin_projects_path expect(current_path).to eq(admin_projects_path)
end end
it "should have projects list" do it "should have projects list" do
page.should have_content(@project.name) expect(page).to have_content(@project.name)
end end
end end
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
end end
it "should have project info" do it "should have project info" do
page.should have_content(@project.path) expect(page).to have_content(@project.path)
page.should have_content(@project.name) expect(page).to have_content(@project.name)
end end
end end
end end
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
end end
it "should be ok" do it "should be ok" do
current_path.should == admin_users_path expect(current_path).to eq(admin_users_path)
end end
it "should have users list" do it "should have users list" do
page.should have_content(@user.email) expect(page).to have_content(@user.email)
page.should have_content(@user.name) expect(page).to have_content(@user.name)
end end
end end
...@@ -33,19 +33,19 @@ ...@@ -33,19 +33,19 @@
it "should apply defaults to user" do it "should apply defaults to user" do
click_button "Create user" click_button "Create user"
user = User.find_by(username: 'bang') user = User.find_by(username: 'bang')
user.projects_limit.should == Gitlab.config.gitlab.default_projects_limit expect(user.projects_limit).to eq(Gitlab.config.gitlab.default_projects_limit)
user.can_create_group.should == Gitlab.config.gitlab.default_can_create_group expect(user.can_create_group).to eq(Gitlab.config.gitlab.default_can_create_group)
end end
it "should create user with valid data" do it "should create user with valid data" do
click_button "Create user" click_button "Create user"
user = User.find_by(username: 'bang') user = User.find_by(username: 'bang')
user.name.should == "Big Bang" expect(user.name).to eq("Big Bang")
user.email.should == "bigbang@mail.com" expect(user.email).to eq("bigbang@mail.com")
end end
it "should call send mail" do it "should call send mail" do
Notify.should_receive(:new_user_email) expect(Notify).to receive(:new_user_email)
click_button "Create user" click_button "Create user"
end end
...@@ -54,9 +54,9 @@ ...@@ -54,9 +54,9 @@
click_button "Create user" click_button "Create user"
user = User.find_by(username: 'bang') user = User.find_by(username: 'bang')
email = ActionMailer::Base.deliveries.last email = ActionMailer::Base.deliveries.last
email.subject.should have_content("Account was created") expect(email.subject).to have_content("Account was created")
email.text_part.body.should have_content(user.email) expect(email.text_part.body).to have_content(user.email)
email.text_part.body.should have_content('password') expect(email.text_part.body).to have_content('password')
end end
end end
...@@ -67,8 +67,8 @@ ...@@ -67,8 +67,8 @@
end end
it "should have user info" do it "should have user info" do
page.should have_content(@user.email) expect(page).to have_content(@user.email)
page.should have_content(@user.name) expect(page).to have_content(@user.name)
end end
end end
...@@ -80,8 +80,8 @@ ...@@ -80,8 +80,8 @@
end end
it "should have user edit page" do it "should have user edit page" do
page.should have_content("Name") expect(page).to have_content("Name")
page.should have_content("Password") expect(page).to have_content("Password")
end end
describe "Update user" do describe "Update user" do
...@@ -93,14 +93,14 @@ ...@@ -93,14 +93,14 @@
end end
it "should show page with new data" do it "should show page with new data" do
page.should have_content("bigbang@mail.com") expect(page).to have_content("bigbang@mail.com")
page.should have_content("Big Bang") expect(page).to have_content("Big Bang")
end end
it "should change user entry" do it "should change user entry" do
@simple_user.reload @simple_user.reload
@simple_user.name.should == "Big Bang" expect(@simple_user.name).to eq("Big Bang")
@simple_user.is_admin?.should be_true expect(@simple_user.is_admin?).to be_truthy
end end
end end
end end
......
...@@ -4,24 +4,24 @@ ...@@ -4,24 +4,24 @@
describe "GET /admin/projects" do describe "GET /admin/projects" do
subject { admin_projects_path } subject { admin_projects_path }
it { should be_allowed_for :admin } it { is_expected.to be_allowed_for :admin }
it { should be_denied_for :user } it { is_expected.to be_denied_for :user }
it { should be_denied_for :visitor } it { is_expected.to be_denied_for :visitor }
end end
describe "GET /admin/users" do describe "GET /admin/users" do
subject { admin_users_path } subject { admin_users_path }
it { should be_allowed_for :admin } it { is_expected.to be_allowed_for :admin }
it { should be_denied_for :user } it { is_expected.to be_denied_for :user }
it { should be_denied_for :visitor } it { is_expected.to be_denied_for :visitor }
end end
describe "GET /admin/hooks" do describe "GET /admin/hooks" do
subject { admin_hooks_path } subject { admin_hooks_path }
it { should be_allowed_for :admin } it { is_expected.to be_allowed_for :admin }
it { should be_denied_for :user } it { is_expected.to be_denied_for :user }
it { should be_denied_for :visitor } it { is_expected.to be_denied_for :visitor }
end end
end end
...@@ -17,12 +17,12 @@ ...@@ -17,12 +17,12 @@
it "should render atom feed via private token" do it "should render atom feed via private token" do
visit issues_dashboard_path(:atom, private_token: user.private_token) visit issues_dashboard_path(:atom, private_token: user.private_token)
response_headers['Content-Type'].should have_content("application/atom+xml") expect(response_headers['Content-Type']).to have_content("application/atom+xml")
body.should have_selector("title", text: "#{user.name} issues") expect(body).to have_selector("title", text: "#{user.name} issues")
body.should have_selector("author email", text: issue1.author_email) expect(body).to have_selector("author email", text: issue1.author_email)
body.should have_selector("entry summary", text: issue1.title) expect(body).to have_selector("entry summary", text: issue1.title)
body.should have_selector("author email", text: issue2.author_email) expect(body).to have_selector("author email", text: issue2.author_email)
body.should have_selector("entry summary", text: issue2.title) expect(body).to have_selector("entry summary", text: issue2.title)
end end
end end
end end
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
context "projects atom feed via private token" do context "projects atom feed via private token" do
it "should render projects atom feed" do it "should render projects atom feed" do
visit dashboard_path(:atom, private_token: user.private_token) visit dashboard_path(:atom, private_token: user.private_token)
body.should have_selector("feed title") expect(body).to have_selector("feed title")
end end
end end
...@@ -24,11 +24,11 @@ ...@@ -24,11 +24,11 @@
end end
it "should have issue opened event" do it "should have issue opened event" do
body.should have_content("#{user.name} opened issue ##{issue.iid}") expect(body).to have_content("#{user.name} opened issue ##{issue.iid}")
end end
it "should have issue comment event" do it "should have issue comment event" do
body.should have_content("#{user.name} commented on issue ##{issue.iid}") expect(body).to have_content("#{user.name} commented on issue ##{issue.iid}")
end end
end end
end end
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
login_with user login_with user
visit project_issues_path(project, :atom) visit project_issues_path(project, :atom)
response_headers['Content-Type'].should have_content("application/atom+xml") expect(response_headers['Content-Type']).to have_content("application/atom+xml")
body.should have_selector("title", text: "#{project.name} issues") expect(body).to have_selector("title", text: "#{project.name} issues")
body.should have_selector("author email", text: issue.author_email) expect(body).to have_selector("author email", text: issue.author_email)
body.should have_selector("entry summary", text: issue.title) expect(body).to have_selector("entry summary", text: issue.title)
end end
end end
...@@ -24,10 +24,10 @@ ...@@ -24,10 +24,10 @@
it "should render atom feed" do it "should render atom feed" do
visit project_issues_path(project, :atom, private_token: user.private_token) visit project_issues_path(project, :atom, private_token: user.private_token)
response_headers['Content-Type'].should have_content("application/atom+xml") expect(response_headers['Content-Type']).to have_content("application/atom+xml")
body.should have_selector("title", text: "#{project.name} issues") expect(body).to have_selector("title", text: "#{project.name} issues")
body.should have_selector("author email", text: issue.author_email) expect(body).to have_selector("author email", text: issue.author_email)
body.should have_selector("entry summary", text: issue.title) expect(body).to have_selector("entry summary", text: issue.title)
end end
end end
end end
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
context "user atom feed via private token" do context "user atom feed via private token" do
it "should render user atom feed" do it "should render user atom feed" do
visit user_path(user, :atom, private_token: user.private_token) visit user_path(user, :atom, private_token: user.private_token)
body.should have_selector("feed title") expect(body).to have_selector("feed title")
end end
end end
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册