diff options
author | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-10-09 01:36:38 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com> | 2011-10-09 01:36:38 +0400 |
commit | e98c77857f9f765d1854b92c2dc33049504a596d (patch) | |
tree | 52fbfc1cdb55df21843965479c97be0c91121a9a /spec/support/matchers.rb | |
parent | 0f43e98ef8c2da8908b1107f75b67cda2572c2c4 (diff) |
init commitv0.9.4
Diffstat (limited to 'spec/support/matchers.rb')
-rw-r--r-- | spec/support/matchers.rb | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/support/matchers.rb b/spec/support/matchers.rb new file mode 100644 index 00000000000..953b535698d --- /dev/null +++ b/spec/support/matchers.rb @@ -0,0 +1,46 @@ +RSpec::Matchers.define :be_valid_commit do + match do |actual| + actual != nil + actual.id == ValidCommit::ID + actual.message == ValidCommit::MESSAGE + actual.author.name == ValidCommit::AUTHOR_FULL_NAME + end +end + +RSpec::Matchers.define :be_allowed_for do |user| + match do |url| + include UrlAccess + url_allowed?(user, url) + end +end + +RSpec::Matchers.define :be_denied_for do |user| + match do |url| + include UrlAccess + url_denied?(user, url) + end +end + +module UrlAccess + def url_allowed?(user, url) + emulate_user(user) + visit url + result = (current_path == url) + end + + def url_denied?(user, url) + emulate_user(user) + visit url + result = (current_path != url) + end + + def emulate_user(user) + user = case user + when :user then Factory(:user) + when :visitor then nil + when :admin then Factory(:admin) + else user + end + login_with(user) if user + end +end |