ryanb / cancan

Authorization Gem for Ruby on Rails.
MIT License
6.27k stars 783 forks source link

RSpec `failure_message_for_should_not` is deprecated. #997

Open justuswilhelm opened 10 years ago

justuswilhelm commented 10 years ago

I am getting this deprecation warning when using Rails 4.0.3, Rspec 3.0.0.beta2 and cancan 1.6.10.

`failure_message_for_should_not` is deprecated. Use `failure_message_when_negated`
instead. Called from /home/vagrant/.rvm/gems/ruby-2.1.1/gems/cancan-
1.6.10/lib/cancan/matchers.rb:11:in `block in <top (required)>'.
zamith commented 10 years ago

@justuswilhelm CanCan development has been stopped for a while now, please take a look at #994

xhoy commented 10 years ago

Dear submitter, Since cancan/raynB hasn't been active for more than 6 months and no body else then ryam himself has commit permissions the cancan project is on a stand still. Since cancan has several issues including missing support for rails 4 cancan is moving forward to cancancan. More details on: #994

If your feel that your pull request or bug is still applicable (and hasn't been merged in to cancan) it would be really appreciated if you would resubmit it to cancancan (https://github.com/cancancommunity/cancancan)

We hope to see you on the other side!

dchacke commented 10 years ago

Might be a little late, but for anyone coming from Google: I just ran into the same issue, and installing cancancan didn't solve it for me.

@justuswilhelm If you want to fix this, simply write your own matcher (more info on that here):

RSpec::Matchers.define :be_able_to do |*args|
  match do |ability|
    ability.can?(*args)
  end

  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
end

Note that this uses #failure_message and #failure_message_when_negated instead of the deprecated methods and makes the deprecation warnings disappear.

justuswilhelm commented 10 years ago

Very helpful. Thank you very much!

vdmgolub commented 10 years ago

I can recommend to switch to https://github.com/CanCanCommunity/cancancan which is community maintained CanCan fork. This issue is fixed there: https://github.com/CanCanCommunity/cancancan/issues/38

justin808 commented 10 years ago

I can confirm that cancancan just resolved that issue for me with rspec 3.

serg-kovalev commented 9 years ago

Has anyone interested?