1

I've just started working with rspec, and I use expect instead of should convention.

How can I transform this test example from CanCan from should to expect?:

require "cancan/matchers"
# ...
describe "User" do
  describe "abilities" do
    subject { ability }
    let(:ability){ Ability.new(user) }
    let(:user){ nil }

    context "when is an account manager" do
      let(:user){ Factory(:accounts_manager) }

      it{ should be_able_to(:manage, Account.new) }
    end
  end
end
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Marcin Doliwa
  • 3,639
  • 3
  • 37
  • 62

1 Answers1

2

You actually don't have to replace this instance of should, per Using implicit `subject` with `expect` in RSpec-2.11, but if you want to, you'd have to give up the one-liner approach and use:

it "should be able to manage a new account" do
  expect(ability).to be_able_to(:manage, Account.new)
end

in place of the current it clause. As an aside, there looks to be some extraneous code in this test.

Community
  • 1
  • 1
Peter Alfvin
  • 28,599
  • 8
  • 68
  • 106