From 1fee24a36143e8057d495e8a7e0f2d4b93d83f2a Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Thu, 16 Jul 2015 14:17:43 -0400 Subject: Remove unused `be_valid_commit` matcher --- spec/support/matchers.rb | 9 --------- 1 file changed, 9 deletions(-) (limited to 'spec/support') diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index a2f853e3e70..87a034cca3b 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,12 +1,3 @@ -RSpec::Matchers.define :be_valid_commit do - match do |actual| - actual && - actual.id == ValidCommit::ID && - actual.message == ValidCommit::MESSAGE && - actual.author_name == ValidCommit::AUTHOR_FULL_NAME - end -end - def emulate_user(user) user = case user when :user then create(:user) -- cgit v1.2.1 From a2ecfdc5859c1703dbbad6dde888f7a0eb5817c8 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 21 Jul 2015 22:09:02 -0400 Subject: Move access-related matchers to their own module --- spec/support/matchers.rb | 34 -------------------- spec/support/matchers/access_matchers.rb | 54 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 34 deletions(-) create mode 100644 spec/support/matchers/access_matchers.rb (limited to 'spec/support') diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb index 87a034cca3b..d9b27ab08d8 100644 --- a/spec/support/matchers.rb +++ b/spec/support/matchers.rb @@ -1,37 +1,3 @@ -def emulate_user(user) - user = case user - when :user then create(:user) - when :visitor then nil - when :admin then create(:admin) - else user - end - login_with(user) if user -end - -RSpec::Matchers.define :be_allowed_for do |user| - match do |url| - emulate_user(user) - visit url - status_code != 404 && current_path != new_user_session_path - end -end - -RSpec::Matchers.define :be_denied_for do |user| - match do |url| - emulate_user(user) - visit url - status_code == 404 || current_path == new_user_session_path - end -end - -RSpec::Matchers.define :be_not_found_for do |user| - match do |url| - emulate_user(user) - visit url - status_code == 404 - end -end - RSpec::Matchers.define :include_module do |expected| match do described_class.included_modules.include?(expected) diff --git a/spec/support/matchers/access_matchers.rb b/spec/support/matchers/access_matchers.rb new file mode 100644 index 00000000000..558e8b1612f --- /dev/null +++ b/spec/support/matchers/access_matchers.rb @@ -0,0 +1,54 @@ +# AccessMatchers +# +# The custom matchers contained in this module are used to test a user's access +# to a URL by emulating a specific user or type of user account, visiting the +# URL, and then checking the response status code and resulting path. +module AccessMatchers + extend RSpec::Matchers::DSL + include Warden::Test::Helpers + + def emulate_user(user) + case user + when :user + login_as(create(:user)) + when :visitor + logout + when :admin + login_as(create(:admin)) + when User + login_as(user) + else + raise ArgumentError, "cannot emulate user #{user}" + end + end + + def description_for(user, type) + if user.kind_of?(User) + # User#inspect displays too much information for RSpec's description + # messages + "be #{type} for supplied User" + else + "be #{type} for #{user}" + end + end + + matcher :be_allowed_for do |user| + match do |url| + emulate_user(user) + visit url + status_code != 404 && current_path != new_user_session_path + end + + description { description_for(user, 'allowed') } + end + + matcher :be_denied_for do |user| + match do |url| + emulate_user(user) + visit url + status_code == 404 || current_path == new_user_session_path + end + + description { description_for(user, 'denied') } + end +end -- cgit v1.2.1 From 0d5cf111f3070994c0e80ef764d1bd4b9e4936b1 Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Tue, 21 Jul 2015 22:09:58 -0400 Subject: Move custom matchers to their own files under spec/support/matchers --- spec/support/matchers.rb | 23 ----------------------- spec/support/matchers/include_module.rb | 13 +++++++++++++ spec/support/matchers/is_within.rb | 9 +++++++++ 3 files changed, 22 insertions(+), 23 deletions(-) delete mode 100644 spec/support/matchers.rb create mode 100644 spec/support/matchers/include_module.rb create mode 100644 spec/support/matchers/is_within.rb (limited to 'spec/support') diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb deleted file mode 100644 index d9b27ab08d8..00000000000 --- a/spec/support/matchers.rb +++ /dev/null @@ -1,23 +0,0 @@ -RSpec::Matchers.define :include_module do |expected| - match do - described_class.included_modules.include?(expected) - end - - description do - "includes the #{expected} module" - end - - failure_message do - "expected #{described_class} to include the #{expected} module" - end -end - -# Extend shoulda-matchers -module Shoulda::Matchers::ActiveModel - class ValidateLengthOfMatcher - # Shortcut for is_at_least and is_at_most - def is_within(range) - is_at_least(range.min) && is_at_most(range.max) - end - end -end diff --git a/spec/support/matchers/include_module.rb b/spec/support/matchers/include_module.rb new file mode 100644 index 00000000000..0a78af1e90e --- /dev/null +++ b/spec/support/matchers/include_module.rb @@ -0,0 +1,13 @@ +RSpec::Matchers.define :include_module do |expected| + match do + described_class.included_modules.include?(expected) + end + + description do + "includes the #{expected} module" + end + + failure_message do + "expected #{described_class} to include the #{expected} module" + end +end diff --git a/spec/support/matchers/is_within.rb b/spec/support/matchers/is_within.rb new file mode 100644 index 00000000000..0c35fc7e899 --- /dev/null +++ b/spec/support/matchers/is_within.rb @@ -0,0 +1,9 @@ +# Extend shoulda-matchers +module Shoulda::Matchers::ActiveModel + class ValidateLengthOfMatcher + # Shortcut for is_at_least and is_at_most + def is_within(range) + is_at_least(range.min) && is_at_most(range.max) + end + end +end -- cgit v1.2.1 From 562242cb9dc11f0a5957a58eb9f91a484a909b40 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 26 Jul 2015 02:17:34 -0700 Subject: Fix commit data retrieval when branch name has single quotes Closes #1724 --- spec/support/test_env.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'spec/support') diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb index dcf2a9e2ce5..dab4535e2c7 100644 --- a/spec/support/test_env.rb +++ b/spec/support/test_env.rb @@ -12,7 +12,8 @@ module TestEnv 'fix' => '12d65c8', 'improve/awesome' => '5937ac0', 'markdown' => '0ed8c6c', - 'master' => '5937ac0' + 'master' => '5937ac0', + "'test'" => 'e56497b', } # gitlab-test-fork is a fork of gitlab-fork, but we don't necessarily -- cgit v1.2.1