diff options
author | Robert Speicher <rspeicher@gmail.com> | 2012-08-23 05:19:40 -0400 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2012-08-25 14:19:15 -0400 |
commit | fba174e9bc4e4ef5c0c4d6a4282f37e5265b87e2 (patch) | |
tree | f53e56b4f694ffefac5d3b744f48deccceb1631e /spec/support | |
parent | 852b9c28dd80af4a49336b0ff921a1a863dbc929 (diff) | |
download | gitlab-ce-fba174e9bc4e4ef5c0c4d6a4282f37e5265b87e2.tar.gz |
Cleanup spec/support folder and spec/spec_helper
Changes:
* Move spec/monkeypatch to spec/support
* Remove unused support/shared_examples
* Move support/api to support/api_helpers to match module name
* Move support/login to support/login_helpers to match module name
* Move API specs to requests/api (convention over configuration)
* Remove unused support/js_patch
* Simplify login_as helper
* Move DatabaseCleaner stuff to its own support file
* Remove unnecessary configuration and requires from spec_helper
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/api.rb | 7 | ||||
-rw-r--r-- | spec/support/api_helpers.rb | 9 | ||||
-rw-r--r-- | spec/support/db_cleaner.rb | 18 | ||||
-rw-r--r-- | spec/support/js_patch.rb | 6 | ||||
-rw-r--r-- | spec/support/login.rb | 30 | ||||
-rw-r--r-- | spec/support/login_helpers.rb | 23 | ||||
-rw-r--r-- | spec/support/monkeypatch.rb | 51 | ||||
-rw-r--r-- | spec/support/shared_examples.rb | 16 |
8 files changed, 101 insertions, 59 deletions
diff --git a/spec/support/api.rb b/spec/support/api.rb deleted file mode 100644 index d363d8b9a57..00000000000 --- a/spec/support/api.rb +++ /dev/null @@ -1,7 +0,0 @@ -def api_prefix - "/api/#{Gitlab::API::VERSION}" -end - -def json_response - JSON.parse(response.body) -end diff --git a/spec/support/api_helpers.rb b/spec/support/api_helpers.rb new file mode 100644 index 00000000000..e35d5735ec3 --- /dev/null +++ b/spec/support/api_helpers.rb @@ -0,0 +1,9 @@ +module ApiHelpers + def api_prefix + "/api/#{Gitlab::API::VERSION}" + end + + def json_response + JSON.parse(response.body) + end +end diff --git a/spec/support/db_cleaner.rb b/spec/support/db_cleaner.rb new file mode 100644 index 00000000000..f1e072aa15f --- /dev/null +++ b/spec/support/db_cleaner.rb @@ -0,0 +1,18 @@ +require 'database_cleaner' + +RSpec.configure do |config| + config.before do + if example.metadata[:js] + DatabaseCleaner.strategy = :truncation + Capybara::Selenium::Driver::DEFAULT_OPTIONS[:resynchronize] = true + else + DatabaseCleaner.strategy = :transaction + end + + DatabaseCleaner.start + end + + config.after do + DatabaseCleaner.clean + end +end diff --git a/spec/support/js_patch.rb b/spec/support/js_patch.rb deleted file mode 100644 index 0d4ab264e85..00000000000 --- a/spec/support/js_patch.rb +++ /dev/null @@ -1,6 +0,0 @@ -module JsPatch - def confirm_js_popup - page.evaluate_script("window.alert = function(msg) { return true; }") - page.evaluate_script("window.confirm = function(msg) { return true; }") - end -end diff --git a/spec/support/login.rb b/spec/support/login.rb deleted file mode 100644 index 78a907bad0b..00000000000 --- a/spec/support/login.rb +++ /dev/null @@ -1,30 +0,0 @@ -module LoginMacros - def login_as role - @user = User.create(email: "user#{User.count}@mail.com", - name: "John Smith", - password: "123456", - password_confirmation: "123456", - skype: 'user_skype') - - if role == :admin - @user.admin = true - @user.save! - end - - visit new_user_session_path - fill_in "user_email", with: @user.email - fill_in "user_password", with: "123456" - click_button "Sign in" - end - - def login_with(user) - visit new_user_session_path - fill_in "user_email", with: user.email - fill_in "user_password", with: "123456" - click_button "Sign in" - end - - def logout - click_link "Logout" rescue nil - end -end diff --git a/spec/support/login_helpers.rb b/spec/support/login_helpers.rb new file mode 100644 index 00000000000..769034e2286 --- /dev/null +++ b/spec/support/login_helpers.rb @@ -0,0 +1,23 @@ +module LoginHelpers + # Internal: Create and log in as a user of the specified role + # + # role - User role (e.g., :admin, :user) + def login_as(role) + @user = Factory(role) + login_with(@user) + end + + # Internal: Login as the specified user + # + # user - User instance to login with + def login_with(user) + visit new_user_session_path + fill_in "user_email", with: user.email + fill_in "user_password", with: "123456" + click_button "Sign in" + end + + def logout + click_link "Logout" rescue nil + end +end diff --git a/spec/support/monkeypatch.rb b/spec/support/monkeypatch.rb new file mode 100644 index 00000000000..855a31f06de --- /dev/null +++ b/spec/support/monkeypatch.rb @@ -0,0 +1,51 @@ +# Stubbing Project <-> git host path +# create project using Factory only +class Project + def update_repository + true + end + + def destroy_repository + true + end + + def path_to_repo + File.join(Rails.root, "tmp", "tests", path) + end + + def satellite + @satellite ||= FakeSatellite.new + end +end + +class Key + def update_repository + true + end + + def repository_delete_key + true + end +end + +class UsersProject + def update_repository + true + end +end + +class FakeSatellite + def exists? + true + end + + def create + true + end +end + +class ProtectedBranch + def update_repository + true + end +end diff --git a/spec/support/shared_examples.rb b/spec/support/shared_examples.rb deleted file mode 100644 index 9fd207d0db2..00000000000 --- a/spec/support/shared_examples.rb +++ /dev/null @@ -1,16 +0,0 @@ -shared_examples_for :project_side_pane do - subject { page } - it { should have_content((@project || project).name) } - it { should have_content("Commits") } - it { should have_content("Files") } -end - -shared_examples_for :tree_view do - subject { page } - - it "should have Tree View of project" do - should have_content("app") - should have_content("History") - should have_content("Gemfile") - end -end |