我有这个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?
答案 0 :(得分:0)
要使用共享示例,您必须将其包含在shown in the documentation中。你把它放在你的规格中了吗?
include_examples 'crud_operation redirect to access denied page'