我现在正在学习 rspec,并想通过“设计”来测试我的能力课程,该代码如下:
class Ability
include CanCan::Ability
def initialize(user)
@user = user || User.new
我当前的 rspec 如下所示:
require 'spec_helper.rb'
describe Ability do
let(:user) { User.new }
let(:ability) { Ability.new(user) }
it 'should be an instance of Abiliy' do
# expect(@user).to be_an_instance_of User # also works
ability.should be_an_instance_of Ability
# passes test
end
it "should include CanCan::Ability" do
expect(:ability).to include(CanCan::Ability)
# NoMethodError: undefined method `include?'
end
it 'should initialize with a User' do
pending
end
it 'should have @user instance variable' do
ability.user.should == User
# NoMethodError: undefined method `user'
end
有人可以提供一个例子。我做了一个研究,但没有成功......