【问题标题】:Rspec : Custom Matchers : want a matcher with behavior just opposite of existing matcherRspec : Custom Matchers : 想要一个行为与现有匹配器相反的匹配器
【发布时间】:2015-09-16 09:43:45
【问题描述】:

我有情况

let(:user) { create(:user, organization: org, role_ids: [Role::ROLE_CSA]) }
subject(:ability) { Ability.new(user) }
describe 'Not Permitted' do

  # I need this
  it { is_expected_not_to (be_able_to(:index, AdminsController)) }

  # Or this
  it { is_expected_to (not_be_able_to(:index, AdminsController)) }
end

但是不幸的是我发现is_expected_not_tonot_be_able_to不可用。

我可以这样做

  it 'should not permit' do
    expect(ability).not_to be_able_to(:index, AdminsController)
  end

但如果可能的话,我想改用short form。有什么办法可以实现我想要的吗?

如果没有,我想创建新的custom matcher,它的行为与CanCanbe_able_tois_expected_to (如果可能)相反。有人可以帮忙吗?

【问题讨论】:

  • 你能在is前面加一个刘海!吗?

标签: ruby-on-rails rspec cancan


【解决方案1】:

来自:https://www.relishapp.com/rspec/rspec-core/docs/subject/one-liner-syntax

你应该可以做到:

it { is_expected.not_to (be_able_to(:index, AdminsController)) }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多