From 23d7f6f017f6b46e59c9e0b287db37bec8aea2fa Mon Sep 17 00:00:00 2001 From: Siarhei Kavaliou Date: Mon, 9 Mar 2015 13:24:35 +0000 Subject: [PATCH 1/3] Fixed #997 (RSpec is deprecated) --- lib/cancan/matchers.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/cancan/matchers.rb b/lib/cancan/matchers.rb index 4a4fb947..59509ff4 100644 --- a/lib/cancan/matchers.rb +++ b/lib/cancan/matchers.rb @@ -1,14 +1,24 @@ -rspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # for RSpec 1 compatability -Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args| +rspec_module = Kernel.const_get(defined?(RSpec::Core) ? 'RSpec' : 'Spec') # for RSpec 1 compatability +rspec_module::Matchers.define :be_able_to do |*args| match do |ability| ability.can?(*args) end - failure_message_for_should do |ability| - "expected to be able to #{args.map(&:inspect).join(" ")}" - end + if rspec_module::Version && rspec_module::Version::STRING =~ /^3\./ + failure_message do |ability| + "expected to be able to #{args.map(&:inspect).join(" ")}" + end + + failure_message_when_negated do |ability| + "expected not to be able to #{args.map(&:inspect).join(" ")}" + end + else + failure_message_for_should do |ability| + "expected to be able to #{args.map(&:inspect).join(" ")}" + end - failure_message_for_should_not do |ability| - "expected not to be able to #{args.map(&:inspect).join(" ")}" + failure_message_for_should_not do |ability| + "expected not to be able to #{args.map(&:inspect).join(" ")}" + end end end From 8a8c3e7fce80689540637b2a972795804391cb63 Mon Sep 17 00:00:00 2001 From: Siarhei Kavaliou Date: Mon, 9 Mar 2015 13:34:06 +0000 Subject: [PATCH 2/3] Code cleanup (DRY) --- .rvmrc | 2 +- lib/cancan/matchers.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.rvmrc b/.rvmrc index 4032eb67..a2a997f4 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1 +1 @@ -rvm use 1.8.7@cancan --create +rvm use 1.9.3-p551@cancan --create diff --git a/lib/cancan/matchers.rb b/lib/cancan/matchers.rb index 59509ff4..8a229ee7 100644 --- a/lib/cancan/matchers.rb +++ b/lib/cancan/matchers.rb @@ -1,10 +1,10 @@ -rspec_module = Kernel.const_get(defined?(RSpec::Core) ? 'RSpec' : 'Spec') # for RSpec 1 compatability -rspec_module::Matchers.define :be_able_to do |*args| +rspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # for RSpec 1 compatability +Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args| match do |ability| ability.can?(*args) end - if rspec_module::Version && rspec_module::Version::STRING =~ /^3\./ + if respond_to?(:failure_message) && respond_to?(:failure_message_when_negated) failure_message do |ability| "expected to be able to #{args.map(&:inspect).join(" ")}" end From 967ba702e2071b9134cc02a8c074b0caba1b3113 Mon Sep 17 00:00:00 2001 From: Siarhei Kavaliou Date: Mon, 9 Mar 2015 14:22:22 +0000 Subject: [PATCH 3/3] Reverted back .rvmrc --- .rvmrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rvmrc b/.rvmrc index a2a997f4..4032eb67 100644 --- a/.rvmrc +++ b/.rvmrc @@ -1 +1 @@ -rvm use 1.9.3-p551@cancan --create +rvm use 1.8.7@cancan --create