Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix deprecation warnings when using aegis/spec/matchers with Rspec 1.3+

  • Loading branch information...
commit d4b12525a0002288b433744735c21e9245a738f6 1 parent f159efe
@henning-koch henning-koch authored
Showing with 35 additions and 10 deletions.
  1. +2 −2 Gemfile
  2. +33 −8 lib/aegis/spec/matchers.rb
View
4 Gemfile
@@ -2,6 +2,6 @@ source 'http://rubygems.org'
gem 'rails', '=2.3.8'
gem "aegis", :path => '.'
-gem 'rspec', '=1.2.9'
-gem 'rspec-rails', '=1.2.9'
+gem 'rspec', '=1.3.1'
+gem 'rspec-rails', '=1.3.3'
gem 'ruby-debug'
View
41 lib/aegis/spec/matchers.rb
@@ -44,15 +44,40 @@ def check_permissions(*args)
CheckPermissions.new(*args)
end
- def be_allowed_to(*args)
- simple_matcher do |user, matcher|
- action, *action_args = args
- target = action.to_s + (action_args.present? ? " given #{action_args.inspect}" : "")
- matcher.description = "be allowed to " + target
- matcher.failure_message = "expected #{user.inspect} to be allowed to #{target}"
- matcher.negative_failure_message = "expected #{user.inspect} to be denied to #{target}"
- user.send("may_#{action}?", *action_args)
+ class BeAllowedTo
+
+ def initialize(expected_action, *expected_args)
+ @expected_action = expected_action
+ @expected_args = expected_args
+ end
+
+ def matches?(user)
+ @actual_user = user
+ @actual_user.send("may_#{@expected_action}?", *@expected_args)
+ end
+
+ def description
+ "be allowed to #{action_as_prose}"
+ end
+
+ def failure_message
+ "expected #{@actual_user.inspect} to be allowed to #{action_as_prose}"
end
+
+ def negative_failure_message
+ "expected #{@actual_user.inspect} to be denied to #{action_as_prose}"
+ end
+
+ private
+
+ def action_as_prose
+ @expected_action.to_s + (@expected_args.present? ? " given #{@expected_args.inspect}" : "")
+ end
+
+ end
+
+ def be_allowed_to(*args)
+ BeAllowedTo.new(*args)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.