簡體   English   中英

Rspec:如何將數組傳遞給先前定義的shared_example?

[英]Rspec: How pass array to shared_example previously defined?

我有這個shared_example代碼:

....

shared_examples_for 'crud_operation redirect to access denied page' do |actions|
    context "as an not authorized user" do
      actions.each do |a|
          specify "User should not be able to access ##a[:action] via #a[:method]" do
            send(a[:method], a[:action], a[:params])
            response.body.should have_content('Acceso denegado')
          end
      end
    end
end

這個規范的代碼:

...

let(:valid_crud_operation) do
  [
      {:method => :get, :action => :index, params: {}},
      {:method => :delete, :action => :destroy, params: {id: user.to_param}},
      {:method => :get, :action => :show, params: {id: user.to_param}},
      {:method => :get, :action => :edit, params: {id: user.to_param}},
      {:method => :get, :action => :new, params: {}},
      {:method => :post, :action => :create, params: valid_attributes},
      {:method => :put, :action => :update, params: {user: user.to_param, id: user.to_param}}
  ]
end

it_behaves_like 'crud_operation redirect to access denied page', valid_crud_operation

但是,當我運行測試結果時說:未定義的局部變量或方法“ valid_crud_operation”

有人知道如何將先前初始化的數組傳遞給shared_example嗎?

要使用共享示例,必須包含它,如文檔所示 您是否將此放在您的規格中?

include_examples 'crud_operation redirect to access denied page'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM